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" |
| 11 | #if USE_SKSL |
| 12 | #include "SkSLCompiler.h" |
| 13 | #endif |
| 14 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 15 | bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) { |
| 16 | VkFormat dontCare; |
| 17 | if (!format) { |
| 18 | format = &dontCare; |
| 19 | } |
| 20 | |
| 21 | switch (config) { |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 22 | case kUnknown_GrPixelConfig: |
| 23 | return false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 24 | case kRGBA_8888_GrPixelConfig: |
| 25 | *format = VK_FORMAT_R8G8B8A8_UNORM; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 26 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 27 | case kBGRA_8888_GrPixelConfig: |
| 28 | *format = VK_FORMAT_B8G8R8A8_UNORM; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 29 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 30 | case kSRGBA_8888_GrPixelConfig: |
| 31 | *format = VK_FORMAT_R8G8B8A8_SRGB; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 32 | return true; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 33 | case kSBGRA_8888_GrPixelConfig: |
| 34 | *format = VK_FORMAT_B8G8R8A8_SRGB; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 35 | return true; |
| 36 | case kRGBA_8888_sint_GrPixelConfig: |
| 37 | *format = VK_FORMAT_R8G8B8A8_SINT; |
| 38 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 39 | case kRGB_565_GrPixelConfig: |
| 40 | *format = VK_FORMAT_R5G6B5_UNORM_PACK16; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 41 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 42 | case kRGBA_4444_GrPixelConfig: |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 43 | // R4G4B4A4 is not required to be supported so we actually |
| 44 | // store the data is if it was B4G4R4A4 and swizzle in shaders |
| 45 | *format = VK_FORMAT_B4G4R4A4_UNORM_PACK16; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 46 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 47 | case kIndex_8_GrPixelConfig: |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 48 | // No current vulkan support for this config |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 49 | return false; |
| 50 | case kAlpha_8_GrPixelConfig: |
| 51 | *format = VK_FORMAT_R8_UNORM; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 52 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 53 | case kETC1_GrPixelConfig: |
| 54 | // converting to ETC2 which is a superset of ETC1 |
| 55 | *format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 56 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 57 | case kLATC_GrPixelConfig: |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 58 | // No current vulkan support for this config |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 59 | return false; |
| 60 | case kR11_EAC_GrPixelConfig: |
| 61 | *format = VK_FORMAT_EAC_R11_UNORM_BLOCK; |
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 | case kASTC_12x12_GrPixelConfig: |
| 64 | *format = VK_FORMAT_ASTC_12x12_UNORM_BLOCK; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 65 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 66 | case kRGBA_float_GrPixelConfig: |
| 67 | *format = VK_FORMAT_R32G32B32A32_SFLOAT; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 68 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 69 | case kRGBA_half_GrPixelConfig: |
| 70 | *format = VK_FORMAT_R16G16B16A16_SFLOAT; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 71 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 72 | case kAlpha_half_GrPixelConfig: |
| 73 | *format = VK_FORMAT_R16_SFLOAT; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 74 | return true; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 75 | } |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 76 | SkFAIL("Unexpected config"); |
| 77 | return false; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 78 | } |
| 79 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 80 | bool GrVkFormatToPixelConfig(VkFormat format, GrPixelConfig* config) { |
| 81 | GrPixelConfig dontCare; |
| 82 | if (!config) { |
| 83 | config = &dontCare; |
| 84 | } |
| 85 | |
| 86 | switch (format) { |
| 87 | case VK_FORMAT_R8G8B8A8_UNORM: |
| 88 | *config = kRGBA_8888_GrPixelConfig; |
| 89 | break; |
| 90 | case VK_FORMAT_B8G8R8A8_UNORM: |
| 91 | *config = kBGRA_8888_GrPixelConfig; |
| 92 | break; |
| 93 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 94 | *config = kSRGBA_8888_GrPixelConfig; |
| 95 | break; |
| 96 | case VK_FORMAT_B8G8R8A8_SRGB: |
| 97 | *config = kSBGRA_8888_GrPixelConfig; |
| 98 | break; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 99 | case VK_FORMAT_R8G8B8A8_SINT: |
| 100 | *config = kRGBA_8888_sint_GrPixelConfig; |
| 101 | break; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 102 | case VK_FORMAT_R5G6B5_UNORM_PACK16: |
| 103 | *config = kRGB_565_GrPixelConfig; |
| 104 | break; |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 105 | case VK_FORMAT_B4G4R4A4_UNORM_PACK16: |
| 106 | // R4G4B4A4 is not required to be supported so we actually |
| 107 | // store RGBA_4444 data as B4G4R4A4. |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 108 | *config = kRGBA_4444_GrPixelConfig; |
| 109 | break; |
| 110 | case VK_FORMAT_R8_UNORM: |
| 111 | *config = kAlpha_8_GrPixelConfig; |
| 112 | break; |
| 113 | case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: |
| 114 | *config = kETC1_GrPixelConfig; |
| 115 | break; |
| 116 | case VK_FORMAT_EAC_R11_UNORM_BLOCK: |
| 117 | *config = kR11_EAC_GrPixelConfig; |
| 118 | break; |
| 119 | case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: |
| 120 | *config = kASTC_12x12_GrPixelConfig; |
| 121 | break; |
| 122 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 123 | *config = kRGBA_float_GrPixelConfig; |
| 124 | break; |
| 125 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 126 | *config = kRGBA_half_GrPixelConfig; |
| 127 | break; |
| 128 | case VK_FORMAT_R16_SFLOAT: |
| 129 | *config = kAlpha_half_GrPixelConfig; |
| 130 | break; |
| 131 | default: |
| 132 | return false; |
| 133 | } |
| 134 | return true; |
| 135 | } |
| 136 | |
brianosman | f05ab1b | 2016-05-12 11:01:10 -0700 | [diff] [blame] | 137 | bool GrVkFormatIsSRGB(VkFormat format, VkFormat* linearFormat) { |
| 138 | VkFormat linearFmt = format; |
| 139 | switch (format) { |
| 140 | case VK_FORMAT_R8_SRGB: |
| 141 | linearFmt = VK_FORMAT_R8_UNORM; |
| 142 | break; |
| 143 | case VK_FORMAT_R8G8_SRGB: |
| 144 | linearFmt = VK_FORMAT_R8G8_UNORM; |
| 145 | break; |
| 146 | case VK_FORMAT_R8G8B8_SRGB: |
| 147 | linearFmt = VK_FORMAT_R8G8B8_UNORM; |
| 148 | break; |
| 149 | case VK_FORMAT_B8G8R8_SRGB: |
| 150 | linearFmt = VK_FORMAT_B8G8R8_UNORM; |
| 151 | break; |
| 152 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 153 | linearFmt = VK_FORMAT_R8G8B8A8_UNORM; |
| 154 | break; |
| 155 | case VK_FORMAT_B8G8R8A8_SRGB: |
| 156 | linearFmt = VK_FORMAT_B8G8R8A8_UNORM; |
| 157 | break; |
| 158 | case VK_FORMAT_A8B8G8R8_SRGB_PACK32: |
| 159 | linearFmt = VK_FORMAT_A8B8G8R8_UNORM_PACK32; |
| 160 | break; |
| 161 | case VK_FORMAT_BC1_RGB_SRGB_BLOCK: |
| 162 | linearFmt = VK_FORMAT_BC1_RGB_UNORM_BLOCK; |
| 163 | break; |
| 164 | case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: |
| 165 | linearFmt = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; |
| 166 | break; |
| 167 | case VK_FORMAT_BC2_SRGB_BLOCK: |
| 168 | linearFmt = VK_FORMAT_BC2_UNORM_BLOCK; |
| 169 | break; |
| 170 | case VK_FORMAT_BC3_SRGB_BLOCK: |
| 171 | linearFmt = VK_FORMAT_BC3_UNORM_BLOCK; |
| 172 | break; |
| 173 | case VK_FORMAT_BC7_SRGB_BLOCK: |
| 174 | linearFmt = VK_FORMAT_BC7_UNORM_BLOCK; |
| 175 | break; |
| 176 | case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: |
| 177 | linearFmt = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; |
| 178 | break; |
| 179 | case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: |
| 180 | linearFmt = VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; |
| 181 | break; |
| 182 | case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: |
| 183 | linearFmt = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; |
| 184 | break; |
| 185 | case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: |
| 186 | linearFmt = VK_FORMAT_ASTC_4x4_UNORM_BLOCK; |
| 187 | break; |
| 188 | case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: |
| 189 | linearFmt = VK_FORMAT_ASTC_5x4_UNORM_BLOCK; |
| 190 | break; |
| 191 | case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: |
| 192 | linearFmt = VK_FORMAT_ASTC_5x5_UNORM_BLOCK; |
| 193 | break; |
| 194 | case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: |
| 195 | linearFmt = VK_FORMAT_ASTC_6x5_UNORM_BLOCK; |
| 196 | break; |
| 197 | case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: |
| 198 | linearFmt = VK_FORMAT_ASTC_6x6_UNORM_BLOCK; |
| 199 | break; |
| 200 | case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: |
| 201 | linearFmt = VK_FORMAT_ASTC_8x5_UNORM_BLOCK; |
| 202 | break; |
| 203 | case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: |
| 204 | linearFmt = VK_FORMAT_ASTC_8x6_UNORM_BLOCK; |
| 205 | break; |
| 206 | case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: |
| 207 | linearFmt = VK_FORMAT_ASTC_8x8_UNORM_BLOCK; |
| 208 | break; |
| 209 | case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: |
| 210 | linearFmt = VK_FORMAT_ASTC_10x5_UNORM_BLOCK; |
| 211 | break; |
| 212 | case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: |
| 213 | linearFmt = VK_FORMAT_ASTC_10x6_UNORM_BLOCK; |
| 214 | break; |
| 215 | case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: |
| 216 | linearFmt = VK_FORMAT_ASTC_10x8_UNORM_BLOCK; |
| 217 | break; |
| 218 | case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: |
| 219 | linearFmt = VK_FORMAT_ASTC_10x10_UNORM_BLOCK; |
| 220 | break; |
| 221 | case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: |
| 222 | linearFmt = VK_FORMAT_ASTC_12x10_UNORM_BLOCK; |
| 223 | break; |
| 224 | case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: |
| 225 | linearFmt = VK_FORMAT_ASTC_12x12_UNORM_BLOCK; |
| 226 | break; |
| 227 | default: |
| 228 | break; |
| 229 | } |
| 230 | if (linearFormat) { |
| 231 | *linearFormat = linearFmt; |
| 232 | } |
| 233 | return (linearFmt != format); |
| 234 | } |
| 235 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 236 | bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples) { |
| 237 | switch (samples) { |
| 238 | case 0: // fall through |
| 239 | case 1: |
| 240 | *vkSamples = VK_SAMPLE_COUNT_1_BIT; |
| 241 | return true; |
| 242 | case 2: |
| 243 | *vkSamples = VK_SAMPLE_COUNT_2_BIT; |
| 244 | return true; |
| 245 | case 4: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 246 | *vkSamples = VK_SAMPLE_COUNT_4_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 247 | return true; |
| 248 | case 8: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 249 | *vkSamples = VK_SAMPLE_COUNT_8_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 250 | return true; |
| 251 | case 16: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 252 | *vkSamples = VK_SAMPLE_COUNT_16_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 253 | return true; |
| 254 | case 32: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 255 | *vkSamples = VK_SAMPLE_COUNT_32_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 256 | return true; |
| 257 | case 64: |
egdaniel | bf63e61 | 2016-08-17 06:26:16 -0700 | [diff] [blame] | 258 | *vkSamples = VK_SAMPLE_COUNT_64_BIT; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 259 | return true; |
| 260 | default: |
| 261 | return false; |
| 262 | } |
| 263 | } |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 264 | |
| 265 | #if USE_SKSL |
| 266 | SkSL::Program::Kind vk_shader_stage_to_skiasl_kind(VkShaderStageFlagBits stage) { |
| 267 | if (VK_SHADER_STAGE_VERTEX_BIT == stage) { |
| 268 | return SkSL::Program::kVertex_Kind; |
| 269 | } |
| 270 | SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage); |
| 271 | return SkSL::Program::kFragment_Kind; |
| 272 | } |
| 273 | #else |
| 274 | shaderc_shader_kind vk_shader_stage_to_shaderc_kind(VkShaderStageFlagBits stage) { |
| 275 | if (VK_SHADER_STAGE_VERTEX_BIT == stage) { |
| 276 | return shaderc_glsl_vertex_shader; |
| 277 | } |
| 278 | SkASSERT(VK_SHADER_STAGE_FRAGMENT_BIT == stage); |
| 279 | return shaderc_glsl_fragment_shader; |
| 280 | } |
| 281 | #endif |
| 282 | |
| 283 | bool GrCompileVkShaderModule(const GrVkGpu* gpu, |
| 284 | const char* shaderString, |
| 285 | VkShaderStageFlagBits stage, |
| 286 | VkShaderModule* shaderModule, |
| 287 | VkPipelineShaderStageCreateInfo* stageInfo) { |
| 288 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 289 | memset(&moduleCreateInfo, 0, sizeof(VkShaderModuleCreateInfo)); |
| 290 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 291 | moduleCreateInfo.pNext = nullptr; |
| 292 | moduleCreateInfo.flags = 0; |
| 293 | |
| 294 | #if USE_SKSL |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 295 | std::string code; |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 296 | #else |
| 297 | shaderc_compilation_result_t result = nullptr; |
| 298 | #endif |
| 299 | |
| 300 | if (gpu->vkCaps().canUseGLSLForShaderModule()) { |
| 301 | moduleCreateInfo.codeSize = strlen(shaderString); |
| 302 | moduleCreateInfo.pCode = (const uint32_t*)shaderString; |
| 303 | } else { |
| 304 | |
| 305 | #if USE_SKSL |
| 306 | bool result = gpu->shaderCompiler()->toSPIRV(vk_shader_stage_to_skiasl_kind(stage), |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 307 | std::string(shaderString), |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 308 | &code); |
| 309 | if (!result) { |
| 310 | SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str()); |
| 311 | return false; |
| 312 | } |
| 313 | moduleCreateInfo.codeSize = code.size(); |
| 314 | moduleCreateInfo.pCode = (const uint32_t*)code.c_str(); |
| 315 | #else |
| 316 | shaderc_compiler_t compiler = gpu->shadercCompiler(); |
| 317 | |
| 318 | shaderc_compile_options_t options = shaderc_compile_options_initialize(); |
| 319 | |
| 320 | shaderc_shader_kind shadercStage = vk_shader_stage_to_shaderc_kind(stage); |
| 321 | result = shaderc_compile_into_spv(compiler, |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 322 | shaderString, |
egdaniel | 88987d8 | 2016-09-19 10:17:34 -0700 | [diff] [blame] | 323 | strlen(shaderString), |
| 324 | shadercStage, |
| 325 | "shader", |
| 326 | "main", |
| 327 | options); |
| 328 | shaderc_compile_options_release(options); |
| 329 | #ifdef SK_DEBUG |
| 330 | if (shaderc_result_get_num_errors(result)) { |
| 331 | SkDebugf("%s\n", shaderString); |
| 332 | SkDebugf("%s\n", shaderc_result_get_error_message(result)); |
| 333 | return false; |
| 334 | } |
| 335 | #endif // SK_DEBUG |
| 336 | |
| 337 | moduleCreateInfo.codeSize = shaderc_result_get_length(result); |
| 338 | moduleCreateInfo.pCode = (const uint32_t*)shaderc_result_get_bytes(result); |
| 339 | #endif // USE_SKSL |
| 340 | } |
| 341 | |
| 342 | VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateShaderModule(gpu->device(), |
| 343 | &moduleCreateInfo, |
| 344 | nullptr, |
| 345 | shaderModule)); |
| 346 | |
| 347 | if (!gpu->vkCaps().canUseGLSLForShaderModule()) { |
| 348 | #if !USE_SKSL |
| 349 | shaderc_result_release(result); |
| 350 | #endif |
| 351 | } |
| 352 | if (err) { |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | memset(stageInfo, 0, sizeof(VkPipelineShaderStageCreateInfo)); |
| 357 | stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 358 | stageInfo->pNext = nullptr; |
| 359 | stageInfo->flags = 0; |
| 360 | stageInfo->stage = stage; |
| 361 | stageInfo->module = *shaderModule; |
| 362 | stageInfo->pName = "main"; |
| 363 | stageInfo->pSpecializationInfo = nullptr; |
| 364 | |
| 365 | return true; |
| 366 | } |