diff --git a/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json index dbed7480..76ddd812 100644 --- a/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json index 1426f18e..3d7e0e5b 100644 --- a/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json index c28ea107..0e58d68d 100644 --- a/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json index 99848e75..1cfec5c6 100644 --- a/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json index dbed7480..76ddd812 100644 --- a/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json index 1426f18e..3d7e0e5b 100644 --- a/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json index c28ea107..0e58d68d 100644 --- a/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json index 99848e75..1cfec5c6 100644 --- a/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/comp/struct-layout.comp.json b/reference/shaders-reflection/comp/struct-layout.comp.json index 2ef84cc5..ef147ee0 100644 --- a/reference/shaders-reflection/comp/struct-layout.comp.json +++ b/reference/shaders-reflection/comp/struct-layout.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/comp/struct-packing.comp.json b/reference/shaders-reflection/comp/struct-packing.comp.json index 9509f3f4..c586ff73 100644 --- a/reference/shaders-reflection/comp/struct-packing.comp.json +++ b/reference/shaders-reflection/comp/struct-packing.comp.json @@ -7,6 +7,11 @@ 1, 1, 1 + ], + "workgroup_size_is_spec_constant_id" : [ + false, + false, + false ] } ], diff --git a/reference/shaders-reflection/comp/workgroup-size-spec-constant.comp.json b/reference/shaders-reflection/comp/workgroup-size-spec-constant.comp.json new file mode 100644 index 00000000..fb63729a --- /dev/null +++ b/reference/shaders-reflection/comp/workgroup-size-spec-constant.comp.json @@ -0,0 +1,56 @@ +{ + "entryPoints" : [ + { + "name" : "main", + "mode" : "comp", + "workgroup_size" : [ + 10, + 40, + 60 + ], + "workgroup_size_is_spec_constant_id" : [ + true, + true, + true + ] + } + ], + "types" : { + "_8" : { + "name" : "SSBO", + "members" : [ + { + "name" : "v", + "type" : "vec4", + "offset" : 0 + } + ] + } + }, + "ssbos" : [ + { + "type" : "_8", + "name" : "SSBO", + "block_size" : 16, + "set" : 0, + "binding" : 0 + } + ], + "specialization_constants" : [ + { + "id" : 10, + "type" : "uint", + "default_value" : 1 + }, + { + "id" : 40, + "type" : "uint", + "default_value" : 1 + }, + { + "id" : 60, + "type" : "uint", + "default_value" : 1 + } + ] +} \ No newline at end of file diff --git a/shaders-reflection/comp/workgroup-size-spec-constant.comp b/shaders-reflection/comp/workgroup-size-spec-constant.comp new file mode 100644 index 00000000..376a3516 --- /dev/null +++ b/shaders-reflection/comp/workgroup-size-spec-constant.comp @@ -0,0 +1,13 @@ +#version 450 + +layout(local_size_x_id = 10, local_size_y_id = 40, local_size_z_id = 60) in; + +layout(std430, set = 0, binding = 0) buffer SSBO +{ + vec4 v; +}; + +void main() +{ + v = vec4(10.0); +} diff --git a/spirv_reflect.cpp b/spirv_reflect.cpp index 08446f39..4fe377ad 100644 --- a/spirv_reflect.cpp +++ b/spirv_reflect.cpp @@ -61,6 +61,7 @@ public: void end_json_array(); void emit_json_array_value(const std::string &value); void emit_json_array_value(uint32_t value); + void emit_json_array_value(bool value); std::string str() const { @@ -158,6 +159,16 @@ void Stream::emit_json_array_value(uint32_t value) stack.top().second = true; } +void Stream::emit_json_array_value(bool value) +{ + if (stack.empty() || stack.top().first != Type::Array) + SPIRV_CROSS_THROW("Invalid JSON state"); + if (stack.top().second) + statement_inner(",\n"); + statement_no_return(value ? "true" : "false"); + stack.top().second = true; +} + void Stream::begin_json_object() { if (!stack.empty() && stack.top().second) @@ -424,13 +435,23 @@ void CompilerReflection::emit_entry_points() json_stream->begin_json_object(); json_stream->emit_json_key_value("name", e.name); json_stream->emit_json_key_value("mode", execution_model_to_str(e.execution_model)); - if(e.execution_model == ExecutionModelGLCompute) + if (e.execution_model == ExecutionModelGLCompute) { const auto &spv_entry = get_entry_point(e.name, e.execution_model); + + SpecializationConstant spec_x, spec_y, spec_z; + get_work_group_size_specialization_constants(spec_x, spec_y, spec_z); + json_stream->emit_json_key_array("workgroup_size"); - json_stream->emit_json_array_value(spv_entry.workgroup_size.x); - json_stream->emit_json_array_value(spv_entry.workgroup_size.y); - json_stream->emit_json_array_value(spv_entry.workgroup_size.z); + json_stream->emit_json_array_value(spec_x.id != ID(0) ? spec_x.constant_id : spv_entry.workgroup_size.x); + json_stream->emit_json_array_value(spec_y.id != ID(0) ? spec_y.constant_id : spv_entry.workgroup_size.y); + json_stream->emit_json_array_value(spec_z.id != ID(0) ? spec_z.constant_id : spv_entry.workgroup_size.z); + json_stream->end_json_array(); + + json_stream->emit_json_key_array("workgroup_size_is_spec_constant_id"); + json_stream->emit_json_array_value(spec_x.id != ID(0)); + json_stream->emit_json_array_value(spec_y.id != ID(0)); + json_stream->emit_json_array_value(spec_z.id != ID(0)); json_stream->end_json_array(); } json_stream->end_json_object();