diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-04-19 14:08:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-19 14:08:30 +0300 |
commit | d7cae5e7cd326ca0ebfb2a7ac4e634a63ecfe19f (patch) | |
tree | 2e5ba5c9a913e445dcbabd6d66360e2187e85bc1 | |
parent | 0500f9ed5d0cac444fdb7e0b972092d11009b69c (diff) | |
parent | d2a4f9842b46212104a92ccc9a003ccf4a22d04e (diff) |
Merge pull request #1917 from KhronosGroup/fix-1906
GLSL: Support GL_EXT_debug_printf.
-rw-r--r-- | reference/shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert.vk | 10 | ||||
-rw-r--r-- | shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert | 29 | ||||
-rw-r--r-- | spirv_common.hpp | 3 | ||||
-rw-r--r-- | spirv_glsl.cpp | 31 | ||||
-rw-r--r-- | spirv_parser.cpp | 2 |
5 files changed, 68 insertions, 7 deletions
diff --git a/reference/shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert.vk b/reference/shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert.vk new file mode 100644 index 00000000..b90912d1 --- /dev/null +++ b/reference/shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert.vk @@ -0,0 +1,10 @@ +#version 450 +#extension GL_EXT_debug_printf : require + +void main() +{ + debugPrintfEXT("Foo %f %f", 1.0, 2.0); + vec4 _17 = vec4(0.0, 0.0, 0.0, 1.0); + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); +} + diff --git a/shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert b/shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert new file mode 100644 index 00000000..38c3de90 --- /dev/null +++ b/shaders-no-opt/asm/vert/debug-printf.asm.vk.nocompat.vert @@ -0,0 +1,29 @@ + OpCapability Shader + OpExtension "SPV_KHR_non_semantic_info" + %1 = OpExtInstImport "NonSemantic.DebugPrintf" + OpMemoryModel Logical GLSL450 + OpEntryPoint Vertex %vert "main" %gl_Position + %4 = OpString "Foo %f %f" + OpSource HLSL 600 + OpName %vert "vert" + OpDecorate %gl_Position BuiltIn Position + %float = OpTypeFloat 32 + %float_1 = OpConstant %float 1 + %float_2 = OpConstant %float 2 + %float_0 = OpConstant %float 0 + %v4float = OpTypeVector %float 4 + %9 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_1 +%_ptr_Output_v4float = OpTypePointer Output %v4float + %void = OpTypeVoid + %12 = OpTypeFunction %void + %13 = OpTypeFunction %v4float +%gl_Position = OpVariable %_ptr_Output_v4float Output +%_ptr_Function_v4float = OpTypePointer Function %v4float + %vert = OpFunction %void None %12 + %15 = OpLabel + %16 = OpVariable %_ptr_Function_v4float Function + %17 = OpExtInst %void %1 1 %4 %float_1 %float_2 + OpStore %16 %9 + OpStore %gl_Position %9 + OpReturn + OpFunctionEnd diff --git a/spirv_common.hpp b/spirv_common.hpp index 4aaa7148..0623f4d5 100644 --- a/spirv_common.hpp +++ b/spirv_common.hpp @@ -638,7 +638,8 @@ struct SPIRExtension : IVariant SPV_AMD_shader_ballot, SPV_AMD_shader_explicit_vertex_parameter, SPV_AMD_shader_trinary_minmax, - SPV_AMD_gcn_shader + SPV_AMD_gcn_shader, + NonSemanticDebugPrintf }; explicit SPIRExtension(Extension ext_) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 4051dd65..1cb1bc49 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -12410,31 +12410,50 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) case OpExtInst: { uint32_t extension_set = ops[2]; + auto ext = get<SPIRExtension>(extension_set).ext; - if (get<SPIRExtension>(extension_set).ext == SPIRExtension::GLSL) + if (ext == SPIRExtension::GLSL) { emit_glsl_op(ops[0], ops[1], ops[3], &ops[4], length - 4); } - else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_shader_ballot) + else if (ext == SPIRExtension::SPV_AMD_shader_ballot) { emit_spv_amd_shader_ballot_op(ops[0], ops[1], ops[3], &ops[4], length - 4); } - else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_shader_explicit_vertex_parameter) + else if (ext == SPIRExtension::SPV_AMD_shader_explicit_vertex_parameter) { emit_spv_amd_shader_explicit_vertex_parameter_op(ops[0], ops[1], ops[3], &ops[4], length - 4); } - else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_shader_trinary_minmax) + else if (ext == SPIRExtension::SPV_AMD_shader_trinary_minmax) { emit_spv_amd_shader_trinary_minmax_op(ops[0], ops[1], ops[3], &ops[4], length - 4); } - else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_gcn_shader) + else if (ext == SPIRExtension::SPV_AMD_gcn_shader) { emit_spv_amd_gcn_shader_op(ops[0], ops[1], ops[3], &ops[4], length - 4); } - else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_debug_info) + else if (ext == SPIRExtension::SPV_debug_info) { break; // Ignore SPIR-V debug information extended instructions. } + else if (ext == SPIRExtension::NonSemanticDebugPrintf) + { + // Operation 1 is printf. + if (ops[3] == 1) + { + if (!options.vulkan_semantics) + SPIRV_CROSS_THROW("Debug printf is only supported in Vulkan GLSL.\n"); + require_extension_internal("GL_EXT_debug_printf"); + auto &format_string = get<SPIRString>(ops[4]).str; + string expr = join("debugPrintfEXT(\"", format_string, "\""); + for (uint32_t i = 5; i < length; i++) + { + expr += ", "; + expr += to_expression(ops[i]); + } + statement(expr, ");"); + } + } else { statement("// unimplemented ext op ", instruction.op); diff --git a/spirv_parser.cpp b/spirv_parser.cpp index 1296f841..262aa70f 100644 --- a/spirv_parser.cpp +++ b/spirv_parser.cpp @@ -279,6 +279,8 @@ void Parser::parse(const Instruction &instruction) set<SPIRExtension>(id, SPIRExtension::SPV_AMD_shader_trinary_minmax); else if (ext == "SPV_AMD_gcn_shader") set<SPIRExtension>(id, SPIRExtension::SPV_AMD_gcn_shader); + else if (ext == "NonSemantic.DebugPrintf") + set<SPIRExtension>(id, SPIRExtension::NonSemanticDebugPrintf); else set<SPIRExtension>(id, SPIRExtension::Unsupported); |