Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrVkUtil.h" |
| 9 | |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 10 | #include "vk/GrVkGpu.h" |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 11 | #include "SkSLCompiler.h" |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 12 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 13 | bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) { |
| 14 | VkFormat dontCare; |
| 15 | if (!format) { |
| 16 | format = &dontCare; |
| 17 | } |
| 18 | |
| 19 | switch (config) { |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 20 | case kUnknown_GrPixelConfig: |
| 21 | return false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 22 | case kRGBA_8888_GrPixelConfig: |
| 23 | *format = VK_FORMAT_R8G8B8A8_UNORM; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 24 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 25 | case kBGRA_8888_GrPixelConfig: |
| 26 | *format = VK_FORMAT_B8G8R8A8_UNORM; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 27 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 28 | case kSRGBA_8888_GrPixelConfig: |
| 29 | *format = VK_FORMAT_R8G8B8A8_SRGB; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 30 | return true; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 31 | case kSBGRA_8888_GrPixelConfig: |
| 32 | *format = VK_FORMAT_B8G8R8A8_SRGB; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 33 | return true; |
| 34 | case kRGBA_8888_sint_GrPixelConfig: |
| 35 | *format = VK_FORMAT_R8G8B8A8_SINT; |
| 36 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | case kRGB_565_GrPixelConfig: |
| 38 | *format = VK_FORMAT_R5G6B5_UNORM_PACK16; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 39 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 40 | case kRGBA_4444_GrPixelConfig: |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 41 | // R4G4B4A4 is not required to be supported so we actually |
| 42 | // store the data is if it was B4G4R4A4 and swizzle in shaders |
| 43 | *format = VK_FORMAT_B4G4R4A4_UNORM_PACK16; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 44 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 45 | case kAlpha_8_GrPixelConfig: |
| 46 | *format = VK_FORMAT_R8_UNORM; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 47 | return true; |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 48 | case kGray_8_GrPixelConfig: |
| 49 | *format = VK_FORMAT_R8_UNORM; |
| 50 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 51 | case kRGBA_float_GrPixelConfig: |
| 52 | *format = VK_FORMAT_R32G32B32A32_SFLOAT; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 53 | return true; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 54 | case kRG_float_GrPixelConfig: |
| 55 | *format = VK_FORMAT_R32G32_SFLOAT; |
| 56 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 57 | case kRGBA_half_GrPixelConfig: |
| 58 | *format = VK_FORMAT_R16G16B16A16_SFLOAT; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 59 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 60 | case kAlpha_half_GrPixelConfig: |
| 61 | *format = VK_FORMAT_R16_SFLOAT; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 62 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 63 | } |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 64 | SkFAIL("Unexpected config"); |
| 65 | return false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 68 | GrPixelConfig GrVkFormatToPixelConfig(VkFormat format) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 69 | switch (format) { |
| 70 | case VK_FORMAT_R8G8B8A8_UNORM: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 71 | return kRGBA_8888_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 72 | case VK_FORMAT_B8G8R8A8_UNORM: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 73 | return kBGRA_8888_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 74 | case VK_FORMAT_R8G8B8A8_SRGB: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 75 | return kSRGBA_8888_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 76 | case VK_FORMAT_B8G8R8A8_SRGB: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 77 | return kSBGRA_8888_GrPixelConfig; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 78 | case VK_FORMAT_R8G8B8A8_SINT: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 79 | return kRGBA_8888_sint_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 80 | case VK_FORMAT_R5G6B5_UNORM_PACK16: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 81 | return kRGB_565_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 82 | break; |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 83 | case VK_FORMAT_B4G4R4A4_UNORM_PACK16: |
| 84 | // R4G4B4A4 is not required to be supported so we actually |
| 85 | // store RGBA_4444 data as B4G4R4A4. |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 86 | return kRGBA_4444_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 87 | case VK_FORMAT_R8_UNORM: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 88 | return kAlpha_8_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 89 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 90 | return kRGBA_float_GrPixelConfig; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 91 | case VK_FORMAT_R32G32_SFLOAT: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 92 | return kRG_float_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 93 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 94 | return kRGBA_half_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 95 | case VK_FORMAT_R16_SFLOAT: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 96 | return kAlpha_half_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 97 | default: |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 98 | return kUnknown_GrPixelConfig; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 99 | } |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 100 | } |
| 101 | |
brianosman | f05ab1b | 2016-05-12 11:01:10 -0700 | [diff] [blame] | 102 | bool GrVkFormatIsSRGB(VkFormat format, VkFormat* linearFormat) { |
| 103 | VkFormat linearFmt = format; |
| 104 | switch (format) { |
| 105 | case VK_FORMAT_R8_SRGB: |
| 106 | linearFmt = VK_FORMAT_R8_UNORM; |
| 107 | break; |
| 108 | case VK_FORMAT_R8G8_SRGB: |
| 109 | linearFmt = VK_FORMAT_R8G8_UNORM; |
| 110 | break; |
| 111 | case VK_FORMAT_R8G8B8_SRGB: |
| 112 | linearFmt = VK_FORMAT_R8G8B8_UNORM; |
| 113 | break; |
| 114 | case VK_FORMAT_B8G8R8_SRGB: |
| 115 | linearFmt = VK_FORMAT_B8G8R8_UNORM; |
| 116 | break; |
| 117 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 118 | linearFmt = VK_FORMAT_R8G8B8A8_UNORM; |
| 119 | break; |
| 120 | case VK_FORMAT_B8G8R8A8_SRGB: |
| 121 | linearFmt = VK_FORMAT_B8G8R8A8_UNORM; |
| 122 | break; |
| 123 | case VK_FORMAT_A8B8G8R8_SRGB_PACK32: |
| 124 | linearFmt = VK_FORMAT_A8B8G8R8_UNORM_PACK32; |
| 125 | break; |
| 126 | case VK_FORMAT_BC1_RGB_SRGB_BLOCK: |
| 127 | linearFmt = VK_FORMAT_BC1_RGB_UNORM_BLOCK; |
| 128 | break; |
| 129 | case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: |
| 130 | linearFmt = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; |
| 131 | break; |
| 132 | case VK_FORMAT_BC2_SRGB_BLOCK: |
| 133 | linearFmt = VK_FORMAT_BC2_UNORM_BLOCK; |
| 134 | break; |
| 135 | case VK_FORMAT_BC3_SRGB_BLOCK: |
| 136 | linearFmt = VK_FORMAT_BC3_UNORM_BLOCK; |
| 137 | break; |
| 138 | case VK_FORMAT_BC7_SRGB_BLOCK: |
| 139 | linearFmt = VK_FORMAT_BC7_UNORM_BLOCK; |
| 140 | break; |
| 141 | case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: |
| 142 | linearFmt = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
| 143 | break; |
| 144 | case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: |
| 145 | linearFmt = VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; |
| 146 | break; |
| 147 | case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: |
| 148 | linearFmt = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; |
| 149 | break; |
| 150 | case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: |
| 151 | linearFmt = VK_FORMAT_ASTC_4x4_UNORM_BLOCK; |
| 152 | break; |
| 153 | case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: |
| 154 | linearFmt = VK_FORMAT_ASTC_5x4_UNORM_BLOCK; |
| 155 | break; |
| 156 | case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: |
| 157 | linearFmt = VK_FORMAT_ASTC_5x5_UNORM_BLOCK; |
| 158 | break; |
| 159 | case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: |
| 160 | linearFmt = VK_FORMAT_ASTC_6x5_UNORM_BLOCK; |
| 161 | break; |
| 162 | case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: |
| 163 | linearFmt = VK_FORMAT_ASTC_6x6_UNORM_BLOCK; |
| 164 | break; |
| 165 | case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: |
| 166 | linearFmt = VK_FORMAT_ASTC_8x5_UNORM_BLOCK; |
| 167 | break; |
| 168 | case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: |
| 169 | linearFmt = VK_FORMAT_ASTC_8x6_UNORM_BLOCK; |
| 170 | break; |
| 171 | case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: |
| 172 | linearFmt = VK_FORMAT_ASTC_8x8_UNORM_BLOCK; |
| 173 | break; |
| 174 | case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: |
| 175 | linearFmt = VK_FORMAT_ASTC_10x5_UNORM_BLOCK; |
| 176 | break; |
| 177 | case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: |
| 178 | linearFmt = VK_FORMAT_ASTC_10x6_UNORM_BLOCK; |
| 179 | break; |
| 180 | case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: |
| 181 | linearFmt = VK_FORMAT_ASTC_10x8_UNORM_BLOCK; |
| 182 | break; |
| 183 | case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: |
| 184 | linearFmt = VK_FORMAT_ASTC_10x10_UNORM_BLOCK; |
| 185 | break; |
| 186 | case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: |
| 187 | linearFmt = VK_FORMAT_ASTC_12x10_UNORM_BLOCK; |
| 188 | break; |
| 189 | case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: |
| 190 | linearFmt = VK_FORMAT_ASTC_12x12_UNORM_BLOCK; |
| 191 | break; |
| 192 | default: |
| 193 | break; |
| 194 | } |
| 195 | if (linearFormat) { |
| 196 | *linearFormat = linearFmt; |
| 197 | } |
| 198 | return (linearFmt != format); |
| 199 | } |
| 200 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 201 | bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples) { |
| 202 | switch (samples) { |
| 203 | case 0: // fall through |
| 204 | case 1: |
| 205 | *vkSamples = VK_SAMPLE_COUNT_1_BIT; |
| 206 | return true; |
| 207 | case 2: |
| 208 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 209 | return true; |
| 210 | case 4: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 211 | *vkSamples = VK_SAMPLE_COUNT_4_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 212 | return true; |
| 213 | case 8: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 214 | *vkSamples = VK_SAMPLE_COUNT_8_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 215 | return true; |
| 216 | case 16: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 217 | *vkSamples = VK_SAMPLE_COUNT_16_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 218 | return true; |
| 219 | case 32: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 220 | *vkSamples = VK_SAMPLE_COUNT_32_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 221 | return true; |
| 222 | case 64: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 223 | *vkSamples = VK_SAMPLE_COUNT_64_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 224 | return true; |
| 225 | default: |
| 226 | return false; |
| 227 | } |
| 228 | } |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 229 | |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 230 | SkSL::Program::Kind vk_shader_stage_to_skiasl_kind(VkShaderStageFlagBits stage) { |
| 231 | if (VK_SHADER_STAGE_VERTEX_BIT == stage) { |
| 232 | return SkSL::Program::kVertex_Kind; |
| 233 | } |
Chris Dalton | 33607c6 | 2017-07-07 11:00:48 -0600 | [diff] [blame^] | 234 | if (VK_SHADER_STAGE_GEOMETRY_BIT == stage) { |
| 235 | return SkSL::Program::kGeometry_Kind; |
| 236 | } |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 237 | SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage); |
| 238 | return SkSL::Program::kFragment_Kind; |
| 239 | } |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 240 | |
| 241 | VkShaderStageFlagBits skiasl_kind_to_vk_shader_stage(SkSL::Program::Kind kind) { |
| 242 | if (SkSL::Program::kVertex_Kind == kind) { |
| 243 | return VK_SHADER_STAGE_VERTEX_BIT; |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 244 | } |
Chris Dalton | 33607c6 | 2017-07-07 11:00:48 -0600 | [diff] [blame^] | 245 | if (SkSL::Program::kGeometry_Kind == kind) { |
| 246 | return VK_SHADER_STAGE_GEOMETRY_BIT; |
| 247 | } |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 248 | SkASSERT(SkSL::Program::kFragment_Kind == kind); |
| 249 | return VK_SHADER_STAGE_FRAGMENT_BIT; |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 250 | } |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 251 | |
| 252 | bool GrCompileVkShaderModule(const GrVkGpu* gpu, |
| 253 | const char* shaderString, |
| 254 | VkShaderStageFlagBits stage, |
| 255 | VkShaderModule* shaderModule, |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 256 | VkPipelineShaderStageCreateInfo* stageInfo, |
| 257 | const SkSL::Program::Settings& settings, |
| 258 | SkSL::Program::Inputs* outInputs) { |
| 259 | std::unique_ptr<SkSL::Program> program = gpu->shaderCompiler()->convertProgram( |
| 260 | vk_shader_stage_to_skiasl_kind(stage), |
| 261 | SkString(shaderString), |
| 262 | settings); |
| 263 | if (!program) { |
| 264 | SkDebugf("SkSL error:\n%s\n", gpu->shaderCompiler()->errorText().c_str()); |
| 265 | SkASSERT(false); |
| 266 | } |
| 267 | *outInputs = program->fInputs; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 268 | SkSL::String code; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 269 | if (!gpu->shaderCompiler()->toSPIRV(*program, &code)) { |
| 270 | SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str()); |
| 271 | return false; |
| 272 | } |
| 273 | |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 274 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 275 | memset(&moduleCreateInfo, 0, sizeof(VkShaderModuleCreateInfo)); |
| 276 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 277 | moduleCreateInfo.pNext = nullptr; |
| 278 | moduleCreateInfo.flags = 0; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 279 | moduleCreateInfo.codeSize = code.size(); |
| 280 | moduleCreateInfo.pCode = (const uint32_t*)code.c_str(); |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 281 | |
| 282 | VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateShaderModule(gpu->device(), |
| 283 | &moduleCreateInfo, |
| 284 | nullptr, |
| 285 | shaderModule)); |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 286 | if (err) { |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | memset(stageInfo, 0, sizeof(VkPipelineShaderStageCreateInfo)); |
| 291 | stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 292 | stageInfo->pNext = nullptr; |
| 293 | stageInfo->flags = 0; |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 294 | stageInfo->stage = skiasl_kind_to_vk_shader_stage(program->fKind); |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 295 | stageInfo->module = *shaderModule; |
| 296 | stageInfo->pName = "main"; |
| 297 | stageInfo->pSpecializationInfo = nullptr; |
| 298 | |
| 299 | return true; |
| 300 | } |