From 283389b2e26bca0fca5dc1075b206539f8f32aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 6 Jun 2019 22:04:16 -0700 Subject: [PATCH] Updated spirv-cross. --- 3rdparty/spirv-cross/CMakeLists.txt | 29 +- 3rdparty/spirv-cross/cmake/gitversion.in.h | 6 + 3rdparty/spirv-cross/main.cpp | 24 ++ .../asm/frag/line-directive.line.asm.frag | 88 +++++ .../comp/global-parameter-name-alias.asm.comp | 2 +- .../asm/frag/line-directive.line.asm.frag | 84 +++++ .../asm/vert/fake-builtin-input.asm.vert | 22 ++ .../access-private-workgroup-in-function.comp | 2 +- .../opt/shaders-msl/comp/array-length.comp | 29 ++ .../array-length.msl2.argument.discrete.comp | 54 +++ .../opt/shaders-msl/comp/builtins.comp | 2 +- .../shaders-msl/comp/complex-type-alias.comp | 56 +++ .../comp/composite-array-initialization.comp | 14 +- .../comp/force-recompile-hooks.swizzle.comp | 2 +- ...wizzle.msl2.argument.discrete.swizzle.frag | 4 +- ...array-of-texture-swizzle.msl2.swizzle.frag | 2 +- .../opt/shaders-msl/frag/packing-test-3.frag | 2 +- .../asm/frag/line-directive.line.asm.frag | 73 ++++ ...-loop-dominated-variable-preservation.frag | 11 + ...out-ubo-std430.vk.nocompat.invalid.frag.vk | 24 ++ .../rgen/execute_callable.nocompat.vk.rgen.vk | 15 + .../shader_record_buffer.nocompat.vk.rgen.vk | 16 + .../asm/frag/line-directive.line.asm.frag | 86 +++++ .../asm/comp/variable-pointers.asm.comp | 2 +- .../asm/frag/texture-access.swizzle.asm.frag | 20 +- .../frag/texture-access-int.swizzle.frag | 12 +- .../frag/texture-access-leaf.swizzle.frag | 22 +- .../frag/texture-access-uint.swizzle.frag | 12 +- .../frag/texture-access.swizzle.frag | 20 +- .../vert/functions_nested.vert | 2 +- .../texture-access-function.swizzle.vk.frag | 22 +- .../extract-packed-from-composite.asm.frag | 8 +- .../asm/frag/line-directive.line.asm.frag | 84 +++++ ...act-transposed-matrix-from-struct.asm.vert | 4 +- .../asm/vert/fake-builtin-input.asm.vert | 22 ++ .../shaders-msl/comp/array-length.comp | 36 ++ .../array-length.msl2.argument.discrete.comp | 65 ++++ .../shaders-msl/comp/complex-type-alias.comp | 68 ++++ .../comp/composite-array-initialization.comp | 26 +- .../comp/force-recompile-hooks.swizzle.comp | 2 +- .../shaders-msl/comp/packing-test-1.comp | 8 +- .../storage-buffer-std140-vector-array.comp | 20 +- .../shaders-msl/comp/struct-nested.comp | 14 +- .../shaders-msl/comp/type-alias.comp | 28 +- ...wizzle.msl2.argument.discrete.swizzle.frag | 10 +- ...array-of-texture-swizzle.msl2.swizzle.frag | 6 +- .../shaders-msl/frag/packing-test-3.frag | 8 +- .../shaders-msl/vert/copy.flatten.vert | 2 +- .../asm/frag/line-directive.line.asm.frag | 71 ++++ .../asm/geom/unroll-glposition-load.asm.geom | 2 +- .../shaders/flatten/copy.flatten.vert | 2 +- ...-loop-dominated-variable-preservation.frag | 30 ++ ...out-ubo-std430.vk.nocompat.invalid.frag.vk | 24 ++ .../rgen/execute_callable.nocompat.vk.rgen.vk | 17 + .../shader_record_buffer.nocompat.vk.rgen.vk | 17 + .../asm/frag/line-directive.line.asm.frag | 221 +++++++++++ .../asm/frag/line-directive.line.asm.frag | 221 +++++++++++ .../asm/vert/fake-builtin-input.asm.vert | 55 +++ .../shaders-msl/comp/array-length.comp | 22 ++ .../array-length.msl2.argument.discrete.comp | 38 ++ .../shaders-msl/comp/complex-type-alias.comp | 41 ++ .../asm/frag/line-directive.line.asm.frag | 221 +++++++++++ ...-loop-dominated-variable-preservation.frag | 24 ++ ...layout-ubo-std430.vk.nocompat.invalid.frag | 23 ++ .../rgen/execute_callable.nocompat.vk.rgen | 16 + .../shader_record_buffer.nocompat.vk.rgen | 16 + 3rdparty/spirv-cross/spirv_cfg.cpp | 53 ++- 3rdparty/spirv-cross/spirv_cfg.hpp | 2 + 3rdparty/spirv-cross/spirv_common.hpp | 25 ++ 3rdparty/spirv-cross/spirv_cpp.cpp | 2 + 3rdparty/spirv-cross/spirv_cross.cpp | 193 +++++++--- 3rdparty/spirv-cross/spirv_cross.hpp | 7 +- 3rdparty/spirv-cross/spirv_cross_c.cpp | 38 ++ 3rdparty/spirv-cross/spirv_cross_c.h | 11 +- .../spirv-cross/spirv_cross_parsed_ir.cpp | 1 + 3rdparty/spirv-cross/spirv_glsl.cpp | 226 ++++++++--- 3rdparty/spirv-cross/spirv_glsl.hpp | 11 +- 3rdparty/spirv-cross/spirv_hlsl.cpp | 2 + 3rdparty/spirv-cross/spirv_msl.cpp | 351 ++++++++++++++---- 3rdparty/spirv-cross/spirv_msl.hpp | 19 + 3rdparty/spirv-cross/spirv_parser.cpp | 31 +- 3rdparty/spirv-cross/spirv_reflect.cpp | 2 + 3rdparty/spirv-cross/test_shaders.py | 10 +- 3rdparty/spirv-cross/tests-other/c_api_test.c | 8 + 84 files changed, 2873 insertions(+), 350 deletions(-) create mode 100644 3rdparty/spirv-cross/cmake/gitversion.in.h create mode 100644 3rdparty/spirv-cross/reference/opt/shaders-hlsl/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/reference/opt/shaders-msl/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/reference/opt/shaders-msl/asm/vert/fake-builtin-input.asm.vert create mode 100644 3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.comp create mode 100644 3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.msl2.argument.discrete.comp create mode 100644 3rdparty/spirv-cross/reference/opt/shaders-msl/comp/complex-type-alias.comp create mode 100644 3rdparty/spirv-cross/reference/opt/shaders/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/reference/opt/shaders/frag/inside-loop-dominated-variable-preservation.frag create mode 100644 3rdparty/spirv-cross/reference/opt/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk create mode 100644 3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk create mode 100644 3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk create mode 100644 3rdparty/spirv-cross/reference/shaders-hlsl/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/reference/shaders-msl/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/reference/shaders-msl/asm/vert/fake-builtin-input.asm.vert create mode 100644 3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.comp create mode 100644 3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.msl2.argument.discrete.comp create mode 100644 3rdparty/spirv-cross/reference/shaders-msl/comp/complex-type-alias.comp create mode 100644 3rdparty/spirv-cross/reference/shaders/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/reference/shaders/frag/inside-loop-dominated-variable-preservation.frag create mode 100644 3rdparty/spirv-cross/reference/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk create mode 100644 3rdparty/spirv-cross/reference/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk create mode 100644 3rdparty/spirv-cross/reference/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk create mode 100644 3rdparty/spirv-cross/shaders-hlsl/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/shaders-msl/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/shaders-msl/asm/vert/fake-builtin-input.asm.vert create mode 100644 3rdparty/spirv-cross/shaders-msl/comp/array-length.comp create mode 100644 3rdparty/spirv-cross/shaders-msl/comp/array-length.msl2.argument.discrete.comp create mode 100644 3rdparty/spirv-cross/shaders-msl/comp/complex-type-alias.comp create mode 100644 3rdparty/spirv-cross/shaders/asm/frag/line-directive.line.asm.frag create mode 100644 3rdparty/spirv-cross/shaders/frag/inside-loop-dominated-variable-preservation.frag create mode 100644 3rdparty/spirv-cross/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag create mode 100644 3rdparty/spirv-cross/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen create mode 100644 3rdparty/spirv-cross/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen diff --git a/3rdparty/spirv-cross/CMakeLists.txt b/3rdparty/spirv-cross/CMakeLists.txt index 8bca53d3f..adc0b14b7 100644 --- a/3rdparty/spirv-cross/CMakeLists.txt +++ b/3rdparty/spirv-cross/CMakeLists.txt @@ -49,6 +49,25 @@ set(spirv-compiler-options "") set(spirv-compiler-defines "") set(spirv-cross-link-flags "") +message(STATUS "Finding Git version for SPIRV-Cross.") +set(spirv-cross-build-version "unknown") +find_package(Git) +if (GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE spirv-cross-build-version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "Git hash: ${spirv-cross-build-version}") +else() + message(STATUS "Git not found, using unknown build version.") +endif() + +string(TIMESTAMP spirv-cross-timestamp) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.in.h ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h @ONLY) + if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) endif() @@ -237,6 +256,8 @@ if (SPIRV_CROSS_STATIC) if (SPIRV_CROSS_ENABLE_C_API) spirv_cross_add_library(spirv-cross-c spirv_cross_c STATIC ${spirv-cross-c-sources}) + target_include_directories(spirv-cross-c PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_definitions(spirv-cross-c PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION) if (SPIRV_CROSS_ENABLE_GLSL) target_link_libraries(spirv-cross-c PRIVATE spirv-cross-glsl) @@ -266,7 +287,7 @@ if (SPIRV_CROSS_STATIC) endif() set(spirv-cross-abi-major 0) -set(spirv-cross-abi-minor 9) +set(spirv-cross-abi-minor 12) set(spirv-cross-abi-patch 0) if (SPIRV_CROSS_SHARED) @@ -282,6 +303,9 @@ if (SPIRV_CROSS_SHARED) ${spirv-cross-core-sources} ${spirv-cross-c-sources}) + target_include_directories(spirv-cross-c-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_definitions(spirv-cross-c-shared PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION) + if (SPIRV_CROSS_ENABLE_GLSL) target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-glsl-sources}) target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_GLSL=1) @@ -368,7 +392,8 @@ if (SPIRV_CROSS_CLI) endif() add_executable(spirv-cross main.cpp) target_compile_options(spirv-cross PRIVATE ${spirv-compiler-options}) - target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines}) + target_include_directories(spirv-cross PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines} HAVE_SPIRV_CROSS_GIT_VERSION) set_target_properties(spirv-cross PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") install(TARGETS spirv-cross RUNTIME DESTINATION bin) target_link_libraries(spirv-cross PRIVATE diff --git a/3rdparty/spirv-cross/cmake/gitversion.in.h b/3rdparty/spirv-cross/cmake/gitversion.in.h new file mode 100644 index 000000000..7135e283b --- /dev/null +++ b/3rdparty/spirv-cross/cmake/gitversion.in.h @@ -0,0 +1,6 @@ +#ifndef SPIRV_CROSS_GIT_VERSION_H_ +#define SPIRV_CROSS_GIT_VERSION_H_ + +#define SPIRV_CROSS_GIT_REVISION "Git commit: @spirv-cross-build-version@ Timestamp: @spirv-cross-timestamp@" + +#endif diff --git a/3rdparty/spirv-cross/main.cpp b/3rdparty/spirv-cross/main.cpp index cd57f176a..5931aef3f 100644 --- a/3rdparty/spirv-cross/main.cpp +++ b/3rdparty/spirv-cross/main.cpp @@ -31,6 +31,10 @@ #include #include +#ifdef HAVE_SPIRV_CROSS_GIT_VERSION +#include "gitversion.h" +#endif + #ifdef _MSC_VER #pragma warning(disable : 4996) #endif @@ -512,6 +516,7 @@ struct CLIArguments bool msl_texture_buffer_native = false; bool glsl_emit_push_constant_as_ubo = false; bool glsl_emit_ubo_as_plain_uniforms = false; + bool emit_line_directives = false; SmallVector msl_discrete_descriptor_sets; SmallVector pls_in; SmallVector pls_out; @@ -545,8 +550,19 @@ struct CLIArguments bool combined_samplers_inherit_bindings = false; }; +static void print_version() +{ +#ifdef HAVE_SPIRV_CROSS_GIT_VERSION + fprintf(stderr, "%s\n", SPIRV_CROSS_GIT_REVISION); +#else + fprintf(stderr, "Git revision unknown. Build with CMake to create timestamp and revision info.\n"); +#endif +} + static void print_help() { + print_version(); + fprintf(stderr, "Usage: spirv-cross\n" "\t[--output ]\n" "\t[SPIR-V file]\n" @@ -555,6 +571,7 @@ static void print_help() "\t[--version ]\n" "\t[--dump-resources]\n" "\t[--help]\n" + "\t[--revision]\n" "\t[--force-temporary]\n" "\t[--vulkan-semantics]\n" "\t[--flatten-ubo]\n" @@ -596,6 +613,7 @@ static void print_help() "\t[--rename-entry-point ]\n" "\t[--combined-samplers-inherit-bindings]\n" "\t[--no-support-nonzero-baseinstance]\n" + "\t[--emit-line-directives]\n" "\n"); } @@ -857,6 +875,7 @@ static string compile_iteration(const CLIArguments &args, std::vector opts.vertex.support_nonzero_base_instance = args.support_nonzero_baseinstance; opts.emit_push_constant_as_uniform_buffer = args.glsl_emit_push_constant_as_ubo; opts.emit_uniform_buffer_as_plain_uniforms = args.glsl_emit_ubo_as_plain_uniforms; + opts.emit_line_directives = args.emit_line_directives; compiler->set_common_options(opts); // Set HLSL specific options. @@ -1004,6 +1023,10 @@ static int main_inner(int argc, char *argv[]) print_help(); parser.end(); }); + cbs.add("--revision", [](CLIParser &parser) { + print_version(); + parser.end(); + }); cbs.add("--output", [&args](CLIParser &parser) { args.output = parser.next_string(); }); cbs.add("--es", [&args](CLIParser &) { args.es = true; @@ -1113,6 +1136,7 @@ static int main_inner(int argc, char *argv[]) [&args](CLIParser &) { args.combined_samplers_inherit_bindings = true; }); cbs.add("--no-support-nonzero-baseinstance", [&](CLIParser &) { args.support_nonzero_baseinstance = false; }); + cbs.add("--emit-line-directives", [&args](CLIParser &) { args.emit_line_directives = true; }); cbs.default_handler = [&args](const char *value) { args.input = value; }; cbs.error_handler = [] { print_help(); }; diff --git a/3rdparty/spirv-cross/reference/opt/shaders-hlsl/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/reference/opt/shaders-hlsl/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..b596a8446 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders-hlsl/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,88 @@ +static float FragColor; +static float vColor; + +struct SPIRV_Cross_Input +{ + float vColor : TEXCOORD0; +}; + +struct SPIRV_Cross_Output +{ + float FragColor : SV_Target0; +}; + +#line 8 "test.frag" +void frag_main() +{ + float _80; +#line 8 "test.frag" + FragColor = 1.0f; +#line 9 "test.frag" + FragColor = 2.0f; +#line 10 "test.frag" + _80 = vColor; + if (_80 < 0.0f) + { +#line 12 "test.frag" + FragColor = 3.0f; + } + else + { +#line 16 "test.frag" + FragColor = 4.0f; + } + for (int _126 = 0; float(_126) < (40.0f + _80); ) + { +#line 21 "test.frag" + FragColor += 0.20000000298023223876953125f; +#line 22 "test.frag" + FragColor += 0.300000011920928955078125f; + _126 += (int(_80) + 5); + continue; + } + switch (int(_80)) + { + case 0: + { +#line 28 "test.frag" + FragColor += 0.20000000298023223876953125f; +#line 29 "test.frag" + break; + } + case 1: + { +#line 32 "test.frag" + FragColor += 0.4000000059604644775390625f; +#line 33 "test.frag" + break; + } + default: + { +#line 36 "test.frag" + FragColor += 0.800000011920928955078125f; +#line 37 "test.frag" + break; + } + } + for (;;) + { + FragColor += (10.0f + _80); +#line 43 "test.frag" + if (FragColor < 100.0f) + { + } + else + { + break; + } + } +} + +SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) +{ + vColor = stage_input.vColor; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.FragColor = FragColor; + return stage_output; +} diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/comp/global-parameter-name-alias.asm.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/comp/global-parameter-name-alias.asm.comp index b0ff373ac..59fc03a75 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/comp/global-parameter-name-alias.asm.comp +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/comp/global-parameter-name-alias.asm.comp @@ -3,7 +3,7 @@ using namespace metal; -kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) +kernel void main0() { } diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..30018aad4 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,84 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float FragColor [[color(0)]]; +}; + +struct main0_in +{ + float vColor [[user(locn0)]]; +}; + +#line 8 "test.frag" +fragment main0_out main0(main0_in in [[stage_in]]) +{ + main0_out out = {}; + float _80; +#line 8 "test.frag" + out.FragColor = 1.0; +#line 9 "test.frag" + out.FragColor = 2.0; +#line 10 "test.frag" + _80 = in.vColor; + if (_80 < 0.0) + { +#line 12 "test.frag" + out.FragColor = 3.0; + } + else + { +#line 16 "test.frag" + out.FragColor = 4.0; + } + for (int _126 = 0; float(_126) < (40.0 + _80); ) + { +#line 21 "test.frag" + out.FragColor += 0.20000000298023223876953125; +#line 22 "test.frag" + out.FragColor += 0.300000011920928955078125; + _126 += (int(_80) + 5); + continue; + } + switch (int(_80)) + { + case 0: + { +#line 28 "test.frag" + out.FragColor += 0.20000000298023223876953125; +#line 29 "test.frag" + break; + } + case 1: + { +#line 32 "test.frag" + out.FragColor += 0.4000000059604644775390625; +#line 33 "test.frag" + break; + } + default: + { +#line 36 "test.frag" + out.FragColor += 0.800000011920928955078125; +#line 37 "test.frag" + break; + } + } + for (;;) + { + out.FragColor += (10.0 + _80); +#line 43 "test.frag" + if (out.FragColor < 100.0) + { + } + else + { + break; + } + } + return out; +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/vert/fake-builtin-input.asm.vert b/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/vert/fake-builtin-input.asm.vert new file mode 100644 index 000000000..f9fcbc85c --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/asm/vert/fake-builtin-input.asm.vert @@ -0,0 +1,22 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 in_var_POSITION [[attribute(0)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]]) +{ + main0_out out = {}; + out.gl_Position = float4(in.in_var_POSITION, 0.0, 1.0); + return out; +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/access-private-workgroup-in-function.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/access-private-workgroup-in-function.comp index a4ba60c3b..59fc03a75 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/access-private-workgroup-in-function.comp +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/access-private-workgroup-in-function.comp @@ -3,7 +3,7 @@ using namespace metal; -kernel void main0(uint gl_LocalInvocationIndex [[thread_index_in_threadgroup]]) +kernel void main0() { } diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.comp new file mode 100644 index 000000000..5e65e71d7 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.comp @@ -0,0 +1,29 @@ +#include +#include + +using namespace metal; + +struct SSBO +{ + uint size; + float4 v[1]; +}; + +struct SSBO1 +{ + float bz[1]; +}; + +kernel void main0(constant uint* spvBufferSizeConstants [[buffer(25)]], device SSBO& _14 [[buffer(1)]], device SSBO1* ssbos_0 [[buffer(2)]], device SSBO1* ssbos_1 [[buffer(3)]]) +{ + device SSBO1* ssbos[] = + { + ssbos_0, + ssbos_1, + }; + + constant uint& _14BufferSize = spvBufferSizeConstants[1]; + constant uint* ssbosBufferSize = &spvBufferSizeConstants[2]; + _14.size = uint(int((_14BufferSize - 16) / 16) + int((ssbosBufferSize[1] - 0) / 4)); +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.msl2.argument.discrete.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.msl2.argument.discrete.comp new file mode 100644 index 000000000..5cec77c66 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/array-length.msl2.argument.discrete.comp @@ -0,0 +1,54 @@ +#include +#include + +using namespace metal; + +struct SSBO +{ + uint size; + float4 v[1]; +}; + +struct SSBO1 +{ + float bz[1]; +}; + +struct SSBO2 +{ + uint size2; + float4 w[1]; +}; + +struct SSBO3 +{ + float bz[1]; +}; + +struct spvDescriptorSetBuffer0 +{ + constant uint* spvBufferSizeConstants [[id(0)]]; + device SSBO* m_16 [[id(1)]]; +}; + +struct spvDescriptorSetBuffer1 +{ + constant uint* spvBufferSizeConstants [[id(1)]]; + device SSBO1* ssbos [[id(2)]][2]; +}; + +kernel void main0(constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], constant spvDescriptorSetBuffer1& spvDescriptorSet1 [[buffer(1)]], constant uint* spvBufferSizeConstants [[buffer(25)]], device SSBO3* ssbos2_0 [[buffer(2)]], device SSBO3* ssbos2_1 [[buffer(3)]], device SSBO2& _38 [[buffer(5)]]) +{ + device SSBO3* ssbos2[] = + { + ssbos2_0, + ssbos2_1, + }; + + constant uint& spvDescriptorSet0_m_16BufferSize = spvDescriptorSet0.spvBufferSizeConstants[1]; + constant uint* spvDescriptorSet1_ssbosBufferSize = &spvDescriptorSet1.spvBufferSizeConstants[2]; + constant uint& _38BufferSize = spvBufferSizeConstants[5]; + constant uint* ssbos2BufferSize = &spvBufferSizeConstants[2]; + (*spvDescriptorSet0.m_16).size = ((uint(int((spvDescriptorSet0_m_16BufferSize - 16) / 16)) + uint(int((spvDescriptorSet1_ssbosBufferSize[1] - 0) / 4))) + uint(int((_38BufferSize - 16) / 16))) + uint(int((ssbos2BufferSize[0] - 0) / 4)); +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/builtins.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/builtins.comp index cbb76c9cd..7576715df 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/builtins.comp +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/builtins.comp @@ -5,7 +5,7 @@ using namespace metal; constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(8u, 4u, 2u); -kernel void main0(uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]], uint gl_LocalInvocationIndex [[thread_index_in_threadgroup]], uint3 gl_NumWorkGroups [[threadgroups_per_grid]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]]) +kernel void main0() { } diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/complex-type-alias.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/complex-type-alias.comp new file mode 100644 index 000000000..43e129758 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/complex-type-alias.comp @@ -0,0 +1,56 @@ +#include +#include + +using namespace metal; + +struct Foo0 +{ + float a; +}; + +struct Foo1 +{ + Foo0 a; +}; + +struct Foo2 +{ + Foo1 a; + float weight; +}; + +struct Foo0_1 +{ + float a; +}; + +struct Foo1_1 +{ + Foo0_1 a; +}; + +struct Foo2_1 +{ + Foo1_1 a; + float weight; +}; + +struct SSBO +{ + Foo2_1 outputs[1]; +}; + +constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(8u, 8u, 1u); + +kernel void main0(device SSBO& _53 [[buffer(0)]], uint gl_LocalInvocationIndex [[thread_index_in_threadgroup]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]]) +{ + threadgroup Foo2 coeffs[64]; + coeffs[gl_LocalInvocationIndex] = Foo2{ Foo1{ Foo0{ 0.0 } }, 0.0 }; + threadgroup_barrier(mem_flags::mem_threadgroup); + if (gl_LocalInvocationIndex == 0u) + { + _53.outputs[gl_WorkGroupID.x].a.a.a = coeffs[0].a.a.a; + _53.outputs[gl_WorkGroupID.x].weight = coeffs[0].weight; + } +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/composite-array-initialization.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/composite-array-initialization.comp index 55f796676..8dec8bddb 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/composite-array-initialization.comp +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/composite-array-initialization.comp @@ -11,23 +11,23 @@ struct Data float b; }; +constant float X_tmp [[function_constant(0)]]; +constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0; + struct Data_1 { float a; float b; }; -constant float X_tmp [[function_constant(0)]]; -constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0; - struct SSBO { - Data outdata[1]; + Data_1 outdata[1]; }; constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(2u, 1u, 1u); -constant Data_1 _25[2] = { Data_1{ 1.0, 2.0 }, Data_1{ 3.0, 4.0 } }; +constant Data _25[2] = { Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } }; // Implementation of an array copy function to cover GLSL's ability to copy an array via assignment. template @@ -44,8 +44,8 @@ void spvArrayCopyFromConstant1(thread T (&dst)[N], constant T (&src)[N]) kernel void main0(device SSBO& _53 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) { - Data_1 _31[2] = { Data_1{ X, 2.0 }, Data_1{ 3.0, 5.0 } }; - Data_1 data2[2]; + Data _31[2] = { Data{ X, 2.0 }, Data{ 3.0, 5.0 } }; + Data data2[2]; spvArrayCopyFromStack1(data2, _31); _53.outdata[gl_WorkGroupID.x].a = _25[gl_LocalInvocationID.x].a + data2[gl_LocalInvocationID.x].a; _53.outdata[gl_WorkGroupID.x].b = _25[gl_LocalInvocationID.x].b + data2[gl_LocalInvocationID.x].b; diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/force-recompile-hooks.swizzle.comp b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/force-recompile-hooks.swizzle.comp index 2d9d423e3..7cb8913da 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/force-recompile-hooks.swizzle.comp +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/comp/force-recompile-hooks.swizzle.comp @@ -127,7 +127,7 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p kernel void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture2d foo [[texture(0)]], texture2d bar [[texture(1)]], sampler fooSmplr [[sampler(0)]]) { - constant uint32_t& fooSwzl = spvSwizzleConstants[0]; + constant uint& fooSwzl = spvSwizzleConstants[0]; bar.write(spvTextureSwizzle(foo.sample(fooSmplr, float2(1.0), level(0.0)), fooSwzl), uint2(int2(0))); } diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag b/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag index b8e8f9d80..67a5c2c82 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag @@ -145,8 +145,8 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], constant uint* spvSwizzleConstants [[buffer(30)]], texture2d uSampler1 [[texture(0)]], sampler uSampler1Smplr [[sampler(0)]]) { main0_out out = {}; - constant uint32_t* spvDescriptorSet0_uSampler0Swzl = &spvDescriptorSet0.spvSwizzleConstants[1]; - constant uint32_t& uSampler1Swzl = spvSwizzleConstants[0]; + constant uint* spvDescriptorSet0_uSampler0Swzl = &spvDescriptorSet0.spvSwizzleConstants[1]; + constant uint& uSampler1Swzl = spvSwizzleConstants[0]; out.FragColor = spvTextureSwizzle(spvDescriptorSet0.uSampler0[2].sample(spvDescriptorSet0.uSampler0Smplr[2], in.vUV), spvDescriptorSet0_uSampler0Swzl[2]); out.FragColor += spvTextureSwizzle(uSampler1.sample(uSampler1Smplr, in.vUV), uSampler1Swzl); out.FragColor += spvTextureSwizzle(spvDescriptorSet0.uSampler0[1].sample(spvDescriptorSet0.uSampler0Smplr[1], in.vUV), spvDescriptorSet0_uSampler0Swzl[1]); diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag b/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag index 8e97cab98..337abb99d 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag @@ -138,7 +138,7 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p fragment main0_out main0(main0_in in [[stage_in]], constant uint* spvSwizzleConstants [[buffer(30)]], array, 4> uSampler [[texture(0)]], array uSamplerSmplr [[sampler(0)]]) { main0_out out = {}; - constant uint32_t* uSamplerSwzl = &spvSwizzleConstants[0]; + constant uint* uSamplerSwzl = &spvSwizzleConstants[0]; out.FragColor = spvTextureSwizzle(uSampler[2].sample(uSamplerSmplr[2], in.vUV), uSamplerSwzl[2]); out.FragColor += spvTextureSwizzle(uSampler[1].sample(uSamplerSmplr[1], in.vUV), uSamplerSwzl[1]); return out; diff --git a/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/packing-test-3.frag b/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/packing-test-3.frag index 436829e85..8cc5f5c75 100644 --- a/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/packing-test-3.frag +++ b/3rdparty/spirv-cross/reference/opt/shaders-msl/frag/packing-test-3.frag @@ -19,7 +19,7 @@ struct main0_out float4 _entryPointOutput [[color(0)]]; }; -fragment main0_out main0(constant CB0& _26 [[buffer(0)]], float4 gl_FragCoord [[position]]) +fragment main0_out main0(constant CB0& _26 [[buffer(0)]]) { main0_out out = {}; out._entryPointOutput = float4(_26.CB0[1].position[0], _26.CB0[1].position[1], _26.CB0[1].position[2], _26.CB0[1].radius); diff --git a/3rdparty/spirv-cross/reference/opt/shaders/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/reference/opt/shaders/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..30be934fc --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,73 @@ +#version 450 +#extension GL_GOOGLE_cpp_style_line_directive : require + +layout(location = 0) out float FragColor; +layout(location = 0) in float vColor; + +#line 8 "test.frag" +void main() +{ + float _80; +#line 8 "test.frag" + FragColor = 1.0; +#line 9 "test.frag" + FragColor = 2.0; +#line 10 "test.frag" + _80 = vColor; + if (_80 < 0.0) + { +#line 12 "test.frag" + FragColor = 3.0; + } + else + { +#line 16 "test.frag" + FragColor = 4.0; + } + for (int _126 = 0; float(_126) < (40.0 + _80); ) + { +#line 21 "test.frag" + FragColor += 0.20000000298023223876953125; +#line 22 "test.frag" + FragColor += 0.300000011920928955078125; + _126 += (int(_80) + 5); + continue; + } + switch (int(_80)) + { + case 0: + { +#line 28 "test.frag" + FragColor += 0.20000000298023223876953125; +#line 29 "test.frag" + break; + } + case 1: + { +#line 32 "test.frag" + FragColor += 0.4000000059604644775390625; +#line 33 "test.frag" + break; + } + default: + { +#line 36 "test.frag" + FragColor += 0.800000011920928955078125; +#line 37 "test.frag" + break; + } + } + for (;;) + { + FragColor += (10.0 + _80); +#line 43 "test.frag" + if (FragColor < 100.0) + { + } + else + { + break; + } + } +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders/frag/inside-loop-dominated-variable-preservation.frag b/3rdparty/spirv-cross/reference/opt/shaders/frag/inside-loop-dominated-variable-preservation.frag new file mode 100644 index 000000000..7724b1462 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders/frag/inside-loop-dominated-variable-preservation.frag @@ -0,0 +1,11 @@ +#version 310 es +precision mediump float; +precision highp int; + +layout(location = 0) out vec4 FragColor; + +void main() +{ + FragColor = vec4(1.0); +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk b/3rdparty/spirv-cross/reference/opt/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk new file mode 100644 index 000000000..434cb3d3d --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk @@ -0,0 +1,24 @@ +#version 450 +#extension GL_EXT_scalar_block_layout : require + +layout(set = 0, binding = 0, std430) uniform UBO +{ + float a[1024]; + vec3 b[2]; +} _17; + +layout(set = 0, binding = 1, std430) uniform UBOEnhancedLayout +{ + layout(offset = 0) float c[1024]; + layout(offset = 4096) vec3 d[2]; + layout(offset = 10000) float e; +} _30; + +layout(location = 0) out float FragColor; +layout(location = 0) flat in int vIndex; + +void main() +{ + FragColor = (_17.a[vIndex] + _30.c[vIndex]) + _30.e; +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk b/3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk new file mode 100644 index 000000000..926546c04 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk @@ -0,0 +1,15 @@ +#version 460 +#extension GL_NV_ray_tracing : require + +layout(set = 0, binding = 0) uniform accelerationStructureNV as; +layout(set = 0, binding = 1, rgba32f) uniform writeonly image2D image; +layout(location = 0) rayPayloadNV vec4 payload; +layout(location = 0) callableDataNV float blend; + +void main() +{ + traceNV(as, 1u, 255u, 0u, 0u, 0u, vec3(0.0), 0.0, vec3(0.0, 0.0, -1.0), 100.0, 0); + executeCallableNV(0u, 0); + imageStore(image, ivec2(gl_LaunchIDNV.xy), payload + vec4(blend)); +} + diff --git a/3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk b/3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk new file mode 100644 index 000000000..daa9c3ee6 --- /dev/null +++ b/3rdparty/spirv-cross/reference/opt/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk @@ -0,0 +1,16 @@ +#version 460 +#extension GL_NV_ray_tracing : require + +layout(shaderRecordNV, std430) buffer sbt +{ + vec3 direction; + float tmax; +} _20; + +layout(set = 0, binding = 0) uniform accelerationStructureNV as; + +void main() +{ + traceNV(as, 0u, 255u, 0u, 1u, 0u, vec3(0.0), 0.0, _20.direction, _20.tmax, 0); +} + diff --git a/3rdparty/spirv-cross/reference/shaders-hlsl/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/reference/shaders-hlsl/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..f0d99f7c7 --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders-hlsl/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,86 @@ +static float FragColor; +static float vColor; + +struct SPIRV_Cross_Input +{ + float vColor : TEXCOORD0; +}; + +struct SPIRV_Cross_Output +{ + float FragColor : SV_Target0; +}; + +#line 6 "test.frag" +void func() +{ +#line 8 "test.frag" + FragColor = 1.0f; +#line 9 "test.frag" + FragColor = 2.0f; +#line 10 "test.frag" + if (vColor < 0.0f) + { +#line 12 "test.frag" + FragColor = 3.0f; + } + else + { +#line 16 "test.frag" + FragColor = 4.0f; + } +#line 19 "test.frag" + for (int i = 0; float(i) < (40.0f + vColor); i += (int(vColor) + 5)) + { +#line 21 "test.frag" + FragColor += 0.20000000298023223876953125f; +#line 22 "test.frag" + FragColor += 0.300000011920928955078125f; + } +#line 25 "test.frag" + switch (int(vColor)) + { + case 0: + { +#line 28 "test.frag" + FragColor += 0.20000000298023223876953125f; +#line 29 "test.frag" + break; + } + case 1: + { +#line 32 "test.frag" + FragColor += 0.4000000059604644775390625f; +#line 33 "test.frag" + break; + } + default: + { +#line 36 "test.frag" + FragColor += 0.800000011920928955078125f; +#line 37 "test.frag" + break; + } + } + do + { +#line 42 "test.frag" + FragColor += (10.0f + vColor); + } while (FragColor < 100.0f); +} + +#line 46 "test.frag" +void frag_main() +{ +#line 48 "test.frag" + func(); +} + +SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) +{ + vColor = stage_input.vColor; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.FragColor = FragColor; + return stage_output; +} diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/comp/variable-pointers.asm.comp b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/comp/variable-pointers.asm.comp index d2e564c99..dd69ce5f4 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/comp/variable-pointers.asm.comp +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/comp/variable-pointers.asm.comp @@ -37,7 +37,7 @@ threadgroup int* select_tgsm(constant bar& cb, threadgroup int (&tgsm)[128]) return (cb.d != 0) ? &tgsm[0u] : nullptr; } -kernel void main0(device foo& buf [[buffer(0)]], constant bar& cb [[buffer(3)]], device baz& buf2 [[buffer(4)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) +kernel void main0(device foo& buf [[buffer(0)]], constant bar& cb [[buffer(3)]], device baz& buf2 [[buffer(4)]]) { threadgroup int tgsm[128]; device int* sbuf = select_buffer(buf, buf2, cb); diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/frag/texture-access.swizzle.asm.frag b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/frag/texture-access.swizzle.asm.frag index 68445b792..1652c8c89 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/frag/texture-access.swizzle.asm.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/asm/frag/texture-access.swizzle.asm.frag @@ -133,16 +133,16 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p fragment void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture1d tex1d [[texture(0)]], texture2d tex2d [[texture(1)]], texture3d tex3d [[texture(2)]], texturecube texCube [[texture(3)]], texture2d_array tex2dArray [[texture(4)]], texturecube_array texCubeArray [[texture(5)]], texture2d texBuffer [[texture(6)]], depth2d depth2d [[texture(7)]], depthcube depthCube [[texture(8)]], depth2d_array depth2dArray [[texture(9)]], depthcube_array depthCubeArray [[texture(10)]], sampler tex1dSamp [[sampler(0)]], sampler tex2dSamp [[sampler(1)]], sampler tex3dSamp [[sampler(2)]], sampler texCubeSamp [[sampler(3)]], sampler tex2dArraySamp [[sampler(4)]], sampler texCubeArraySamp [[sampler(5)]], sampler depth2dSamp [[sampler(7)]], sampler depthCubeSamp [[sampler(8)]], sampler depth2dArraySamp [[sampler(9)]], sampler depthCubeArraySamp [[sampler(10)]]) { - constant uint32_t& tex1dSwzl = spvSwizzleConstants[0]; - constant uint32_t& tex2dSwzl = spvSwizzleConstants[1]; - constant uint32_t& tex3dSwzl = spvSwizzleConstants[2]; - constant uint32_t& texCubeSwzl = spvSwizzleConstants[3]; - constant uint32_t& tex2dArraySwzl = spvSwizzleConstants[4]; - constant uint32_t& texCubeArraySwzl = spvSwizzleConstants[5]; - constant uint32_t& depth2dSwzl = spvSwizzleConstants[7]; - constant uint32_t& depthCubeSwzl = spvSwizzleConstants[8]; - constant uint32_t& depth2dArraySwzl = spvSwizzleConstants[9]; - constant uint32_t& depthCubeArraySwzl = spvSwizzleConstants[10]; + constant uint& tex1dSwzl = spvSwizzleConstants[0]; + constant uint& tex2dSwzl = spvSwizzleConstants[1]; + constant uint& tex3dSwzl = spvSwizzleConstants[2]; + constant uint& texCubeSwzl = spvSwizzleConstants[3]; + constant uint& tex2dArraySwzl = spvSwizzleConstants[4]; + constant uint& texCubeArraySwzl = spvSwizzleConstants[5]; + constant uint& depth2dSwzl = spvSwizzleConstants[7]; + constant uint& depthCubeSwzl = spvSwizzleConstants[8]; + constant uint& depth2dArraySwzl = spvSwizzleConstants[9]; + constant uint& depthCubeArraySwzl = spvSwizzleConstants[10]; float4 c = spvTextureSwizzle(tex1d.sample(tex1dSamp, 0.0), tex1dSwzl); c = spvTextureSwizzle(tex2d.sample(tex2dSamp, float2(0.0)), tex2dSwzl); c = spvTextureSwizzle(tex3d.sample(tex3dSamp, float3(0.0)), tex3dSwzl); diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-int.swizzle.frag b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-int.swizzle.frag index 3f854e701..4cb0fdd59 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-int.swizzle.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-int.swizzle.frag @@ -133,12 +133,12 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p fragment void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture1d tex1d [[texture(0)]], texture2d tex2d [[texture(1)]], texture3d tex3d [[texture(2)]], texturecube texCube [[texture(3)]], texture2d_array tex2dArray [[texture(4)]], texturecube_array texCubeArray [[texture(5)]], texture2d texBuffer [[texture(6)]], sampler tex1dSmplr [[sampler(0)]], sampler tex2dSmplr [[sampler(1)]], sampler tex3dSmplr [[sampler(2)]], sampler texCubeSmplr [[sampler(3)]], sampler tex2dArraySmplr [[sampler(4)]], sampler texCubeArraySmplr [[sampler(5)]]) { - constant uint32_t& tex1dSwzl = spvSwizzleConstants[0]; - constant uint32_t& tex2dSwzl = spvSwizzleConstants[1]; - constant uint32_t& tex3dSwzl = spvSwizzleConstants[2]; - constant uint32_t& texCubeSwzl = spvSwizzleConstants[3]; - constant uint32_t& tex2dArraySwzl = spvSwizzleConstants[4]; - constant uint32_t& texCubeArraySwzl = spvSwizzleConstants[5]; + constant uint& tex1dSwzl = spvSwizzleConstants[0]; + constant uint& tex2dSwzl = spvSwizzleConstants[1]; + constant uint& tex3dSwzl = spvSwizzleConstants[2]; + constant uint& texCubeSwzl = spvSwizzleConstants[3]; + constant uint& tex2dArraySwzl = spvSwizzleConstants[4]; + constant uint& texCubeArraySwzl = spvSwizzleConstants[5]; float4 c = float4(spvTextureSwizzle(tex1d.sample(tex1dSmplr, 0.0), tex1dSwzl)); c = float4(spvTextureSwizzle(tex2d.sample(tex2dSmplr, float2(0.0)), tex2dSwzl)); c = float4(spvTextureSwizzle(tex3d.sample(tex3dSmplr, float3(0.0)), tex3dSwzl)); diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-leaf.swizzle.frag b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-leaf.swizzle.frag index 01a5ae64d..2b11faa02 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-leaf.swizzle.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-leaf.swizzle.frag @@ -131,7 +131,7 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p return t.gather_compare(s, spvForward(params)...); } -float4 doSwizzle(thread texture1d tex1d, thread const sampler tex1dSmplr, constant uint32_t& tex1dSwzl, thread texture2d tex2d, thread const sampler tex2dSmplr, constant uint32_t& tex2dSwzl, thread texture3d tex3d, thread const sampler tex3dSmplr, constant uint32_t& tex3dSwzl, thread texturecube texCube, thread const sampler texCubeSmplr, constant uint32_t& texCubeSwzl, thread texture2d_array tex2dArray, thread const sampler tex2dArraySmplr, constant uint32_t& tex2dArraySwzl, thread texturecube_array texCubeArray, thread const sampler texCubeArraySmplr, constant uint32_t& texCubeArraySwzl, thread depth2d depth2d, thread const sampler depth2dSmplr, constant uint32_t& depth2dSwzl, thread depthcube depthCube, thread const sampler depthCubeSmplr, constant uint32_t& depthCubeSwzl, thread depth2d_array depth2dArray, thread const sampler depth2dArraySmplr, constant uint32_t& depth2dArraySwzl, thread depthcube_array depthCubeArray, thread const sampler depthCubeArraySmplr, constant uint32_t& depthCubeArraySwzl, thread texture2d texBuffer) +float4 doSwizzle(thread texture1d tex1d, thread const sampler tex1dSmplr, constant uint& tex1dSwzl, thread texture2d tex2d, thread const sampler tex2dSmplr, constant uint& tex2dSwzl, thread texture3d tex3d, thread const sampler tex3dSmplr, constant uint& tex3dSwzl, thread texturecube texCube, thread const sampler texCubeSmplr, constant uint& texCubeSwzl, thread texture2d_array tex2dArray, thread const sampler tex2dArraySmplr, constant uint& tex2dArraySwzl, thread texturecube_array texCubeArray, thread const sampler texCubeArraySmplr, constant uint& texCubeArraySwzl, thread depth2d depth2d, thread const sampler depth2dSmplr, constant uint& depth2dSwzl, thread depthcube depthCube, thread const sampler depthCubeSmplr, constant uint& depthCubeSwzl, thread depth2d_array depth2dArray, thread const sampler depth2dArraySmplr, constant uint& depth2dArraySwzl, thread depthcube_array depthCubeArray, thread const sampler depthCubeArraySmplr, constant uint& depthCubeArraySwzl, thread texture2d texBuffer) { float4 c = spvTextureSwizzle(tex1d.sample(tex1dSmplr, 0.0), tex1dSwzl); c = spvTextureSwizzle(tex2d.sample(tex2dSmplr, float2(0.0)), tex2dSwzl); @@ -180,16 +180,16 @@ float4 doSwizzle(thread texture1d tex1d, thread const sampler tex1dSmplr, fragment void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture1d tex1d [[texture(0)]], texture2d tex2d [[texture(1)]], texture3d tex3d [[texture(2)]], texturecube texCube [[texture(3)]], texture2d_array tex2dArray [[texture(4)]], texturecube_array texCubeArray [[texture(5)]], texture2d texBuffer [[texture(6)]], depth2d depth2d [[texture(7)]], depthcube depthCube [[texture(8)]], depth2d_array depth2dArray [[texture(9)]], depthcube_array depthCubeArray [[texture(10)]], sampler tex1dSmplr [[sampler(0)]], sampler tex2dSmplr [[sampler(1)]], sampler tex3dSmplr [[sampler(2)]], sampler texCubeSmplr [[sampler(3)]], sampler tex2dArraySmplr [[sampler(4)]], sampler texCubeArraySmplr [[sampler(5)]], sampler depth2dSmplr [[sampler(7)]], sampler depthCubeSmplr [[sampler(8)]], sampler depth2dArraySmplr [[sampler(9)]], sampler depthCubeArraySmplr [[sampler(10)]]) { - constant uint32_t& tex1dSwzl = spvSwizzleConstants[0]; - constant uint32_t& tex2dSwzl = spvSwizzleConstants[1]; - constant uint32_t& tex3dSwzl = spvSwizzleConstants[2]; - constant uint32_t& texCubeSwzl = spvSwizzleConstants[3]; - constant uint32_t& tex2dArraySwzl = spvSwizzleConstants[4]; - constant uint32_t& texCubeArraySwzl = spvSwizzleConstants[5]; - constant uint32_t& depth2dSwzl = spvSwizzleConstants[7]; - constant uint32_t& depthCubeSwzl = spvSwizzleConstants[8]; - constant uint32_t& depth2dArraySwzl = spvSwizzleConstants[9]; - constant uint32_t& depthCubeArraySwzl = spvSwizzleConstants[10]; + constant uint& tex1dSwzl = spvSwizzleConstants[0]; + constant uint& tex2dSwzl = spvSwizzleConstants[1]; + constant uint& tex3dSwzl = spvSwizzleConstants[2]; + constant uint& texCubeSwzl = spvSwizzleConstants[3]; + constant uint& tex2dArraySwzl = spvSwizzleConstants[4]; + constant uint& texCubeArraySwzl = spvSwizzleConstants[5]; + constant uint& depth2dSwzl = spvSwizzleConstants[7]; + constant uint& depthCubeSwzl = spvSwizzleConstants[8]; + constant uint& depth2dArraySwzl = spvSwizzleConstants[9]; + constant uint& depthCubeArraySwzl = spvSwizzleConstants[10]; float4 c = doSwizzle(tex1d, tex1dSmplr, tex1dSwzl, tex2d, tex2dSmplr, tex2dSwzl, tex3d, tex3dSmplr, tex3dSwzl, texCube, texCubeSmplr, texCubeSwzl, tex2dArray, tex2dArraySmplr, tex2dArraySwzl, texCubeArray, texCubeArraySmplr, texCubeArraySwzl, depth2d, depth2dSmplr, depth2dSwzl, depthCube, depthCubeSmplr, depthCubeSwzl, depth2dArray, depth2dArraySmplr, depth2dArraySwzl, depthCubeArray, depthCubeArraySmplr, depthCubeArraySwzl, texBuffer); } diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-uint.swizzle.frag b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-uint.swizzle.frag index 5a3013ba8..86b712536 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-uint.swizzle.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access-uint.swizzle.frag @@ -133,12 +133,12 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p fragment void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture1d tex1d [[texture(0)]], texture2d tex2d [[texture(1)]], texture3d tex3d [[texture(2)]], texturecube texCube [[texture(3)]], texture2d_array tex2dArray [[texture(4)]], texturecube_array texCubeArray [[texture(5)]], texture2d texBuffer [[texture(6)]], sampler tex1dSmplr [[sampler(0)]], sampler tex2dSmplr [[sampler(1)]], sampler tex3dSmplr [[sampler(2)]], sampler texCubeSmplr [[sampler(3)]], sampler tex2dArraySmplr [[sampler(4)]], sampler texCubeArraySmplr [[sampler(5)]]) { - constant uint32_t& tex1dSwzl = spvSwizzleConstants[0]; - constant uint32_t& tex2dSwzl = spvSwizzleConstants[1]; - constant uint32_t& tex3dSwzl = spvSwizzleConstants[2]; - constant uint32_t& texCubeSwzl = spvSwizzleConstants[3]; - constant uint32_t& tex2dArraySwzl = spvSwizzleConstants[4]; - constant uint32_t& texCubeArraySwzl = spvSwizzleConstants[5]; + constant uint& tex1dSwzl = spvSwizzleConstants[0]; + constant uint& tex2dSwzl = spvSwizzleConstants[1]; + constant uint& tex3dSwzl = spvSwizzleConstants[2]; + constant uint& texCubeSwzl = spvSwizzleConstants[3]; + constant uint& tex2dArraySwzl = spvSwizzleConstants[4]; + constant uint& texCubeArraySwzl = spvSwizzleConstants[5]; float4 c = float4(spvTextureSwizzle(tex1d.sample(tex1dSmplr, 0.0), tex1dSwzl)); c = float4(spvTextureSwizzle(tex2d.sample(tex2dSmplr, float2(0.0)), tex2dSwzl)); c = float4(spvTextureSwizzle(tex3d.sample(tex3dSmplr, float3(0.0)), tex3dSwzl)); diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access.swizzle.frag b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access.swizzle.frag index befee5bcc..a819e2d5e 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access.swizzle.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/frag/texture-access.swizzle.frag @@ -133,16 +133,16 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p fragment void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture1d tex1d [[texture(0)]], texture2d tex2d [[texture(1)]], texture3d tex3d [[texture(2)]], texturecube texCube [[texture(3)]], texture2d_array tex2dArray [[texture(4)]], texturecube_array texCubeArray [[texture(5)]], texture2d texBuffer [[texture(6)]], depth2d depth2d [[texture(7)]], depthcube depthCube [[texture(8)]], depth2d_array depth2dArray [[texture(9)]], depthcube_array depthCubeArray [[texture(10)]], sampler tex1dSmplr [[sampler(0)]], sampler tex2dSmplr [[sampler(1)]], sampler tex3dSmplr [[sampler(2)]], sampler texCubeSmplr [[sampler(3)]], sampler tex2dArraySmplr [[sampler(4)]], sampler texCubeArraySmplr [[sampler(5)]], sampler depth2dSmplr [[sampler(7)]], sampler depthCubeSmplr [[sampler(8)]], sampler depth2dArraySmplr [[sampler(9)]], sampler depthCubeArraySmplr [[sampler(10)]]) { - constant uint32_t& tex1dSwzl = spvSwizzleConstants[0]; - constant uint32_t& tex2dSwzl = spvSwizzleConstants[1]; - constant uint32_t& tex3dSwzl = spvSwizzleConstants[2]; - constant uint32_t& texCubeSwzl = spvSwizzleConstants[3]; - constant uint32_t& tex2dArraySwzl = spvSwizzleConstants[4]; - constant uint32_t& texCubeArraySwzl = spvSwizzleConstants[5]; - constant uint32_t& depth2dSwzl = spvSwizzleConstants[7]; - constant uint32_t& depthCubeSwzl = spvSwizzleConstants[8]; - constant uint32_t& depth2dArraySwzl = spvSwizzleConstants[9]; - constant uint32_t& depthCubeArraySwzl = spvSwizzleConstants[10]; + constant uint& tex1dSwzl = spvSwizzleConstants[0]; + constant uint& tex2dSwzl = spvSwizzleConstants[1]; + constant uint& tex3dSwzl = spvSwizzleConstants[2]; + constant uint& texCubeSwzl = spvSwizzleConstants[3]; + constant uint& tex2dArraySwzl = spvSwizzleConstants[4]; + constant uint& texCubeArraySwzl = spvSwizzleConstants[5]; + constant uint& depth2dSwzl = spvSwizzleConstants[7]; + constant uint& depthCubeSwzl = spvSwizzleConstants[8]; + constant uint& depth2dArraySwzl = spvSwizzleConstants[9]; + constant uint& depthCubeArraySwzl = spvSwizzleConstants[10]; float4 c = spvTextureSwizzle(tex1d.sample(tex1dSmplr, 0.0), tex1dSwzl); c = spvTextureSwizzle(tex2d.sample(tex2dSmplr, float2(0.0)), tex2dSwzl); c = spvTextureSwizzle(tex3d.sample(tex3dSmplr, float3(0.0)), tex3dSwzl); diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vert/functions_nested.vert b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vert/functions_nested.vert index 037ead392..521109573 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vert/functions_nested.vert +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vert/functions_nested.vert @@ -69,13 +69,13 @@ float4 fetch_attr(thread const attr_desc& desc, thread const int& vertex_id, thr float4 result = float4(0.0, 0.0, 0.0, 1.0); bool reverse_order = false; int first_byte = (vertex_id * desc.stride) + desc.starting_offset; + uint4 tmp; for (int n = 0; n < 4; n++) { if (n == desc.attribute_size) { break; } - uint4 tmp; switch (desc.type) { case 0: diff --git a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vulkan/frag/texture-access-function.swizzle.vk.frag b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vulkan/frag/texture-access-function.swizzle.vk.frag index aa3aae238..af920dbfe 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vulkan/frag/texture-access-function.swizzle.vk.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl-no-opt/vulkan/frag/texture-access-function.swizzle.vk.frag @@ -136,7 +136,7 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p return t.gather_compare(s, spvForward(params)...); } -float4 do_samples(thread const texture1d t1, thread const sampler t1Smplr, constant uint32_t& t1Swzl, thread const texture2d t2, constant uint32_t& t2Swzl, thread const texture3d t3, thread const sampler t3Smplr, constant uint32_t& t3Swzl, thread const texturecube tc, constant uint32_t& tcSwzl, thread const texture2d_array t2a, thread const sampler t2aSmplr, constant uint32_t& t2aSwzl, thread const texturecube_array tca, thread const sampler tcaSmplr, constant uint32_t& tcaSwzl, thread const texture2d tb, thread const depth2d d2, thread const sampler d2Smplr, constant uint32_t& d2Swzl, thread const depthcube dc, thread const sampler dcSmplr, constant uint32_t& dcSwzl, thread const depth2d_array d2a, constant uint32_t& d2aSwzl, thread const depthcube_array dca, thread const sampler dcaSmplr, constant uint32_t& dcaSwzl, thread sampler defaultSampler, thread sampler shadowSampler) +float4 do_samples(thread const texture1d t1, thread const sampler t1Smplr, constant uint& t1Swzl, thread const texture2d t2, constant uint& t2Swzl, thread const texture3d t3, thread const sampler t3Smplr, constant uint& t3Swzl, thread const texturecube tc, constant uint& tcSwzl, thread const texture2d_array t2a, thread const sampler t2aSmplr, constant uint& t2aSwzl, thread const texturecube_array tca, thread const sampler tcaSmplr, constant uint& tcaSwzl, thread const texture2d tb, thread const depth2d d2, thread const sampler d2Smplr, constant uint& d2Swzl, thread const depthcube dc, thread const sampler dcSmplr, constant uint& dcSwzl, thread const depth2d_array d2a, constant uint& d2aSwzl, thread const depthcube_array dca, thread const sampler dcaSmplr, constant uint& dcaSwzl, thread sampler defaultSampler, thread sampler shadowSampler) { float4 c = spvTextureSwizzle(t1.sample(t1Smplr, 0.0), t1Swzl); c = spvTextureSwizzle(t2.sample(defaultSampler, float2(0.0)), t2Swzl); @@ -186,16 +186,16 @@ float4 do_samples(thread const texture1d t1, thread const sampler t1Smplr fragment main0_out main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture1d tex1d [[texture(0)]], texture2d tex2d [[texture(1)]], texture3d tex3d [[texture(2)]], texturecube texCube [[texture(3)]], texture2d_array tex2dArray [[texture(4)]], texturecube_array texCubeArray [[texture(5)]], texture2d texBuffer [[texture(6)]], depth2d depth2d [[texture(7)]], depthcube depthCube [[texture(8)]], depth2d_array depth2dArray [[texture(9)]], depthcube_array depthCubeArray [[texture(10)]], sampler tex1dSmplr [[sampler(0)]], sampler tex3dSmplr [[sampler(2)]], sampler tex2dArraySmplr [[sampler(4)]], sampler texCubeArraySmplr [[sampler(5)]], sampler depth2dSmplr [[sampler(7)]], sampler depthCubeSmplr [[sampler(8)]], sampler depthCubeArraySmplr [[sampler(10)]], sampler defaultSampler [[sampler(11)]], sampler shadowSampler [[sampler(12)]]) { main0_out out = {}; - constant uint32_t& tex1dSwzl = spvSwizzleConstants[0]; - constant uint32_t& tex2dSwzl = spvSwizzleConstants[1]; - constant uint32_t& tex3dSwzl = spvSwizzleConstants[2]; - constant uint32_t& texCubeSwzl = spvSwizzleConstants[3]; - constant uint32_t& tex2dArraySwzl = spvSwizzleConstants[4]; - constant uint32_t& texCubeArraySwzl = spvSwizzleConstants[5]; - constant uint32_t& depth2dSwzl = spvSwizzleConstants[7]; - constant uint32_t& depthCubeSwzl = spvSwizzleConstants[8]; - constant uint32_t& depth2dArraySwzl = spvSwizzleConstants[9]; - constant uint32_t& depthCubeArraySwzl = spvSwizzleConstants[10]; + constant uint& tex1dSwzl = spvSwizzleConstants[0]; + constant uint& tex2dSwzl = spvSwizzleConstants[1]; + constant uint& tex3dSwzl = spvSwizzleConstants[2]; + constant uint& texCubeSwzl = spvSwizzleConstants[3]; + constant uint& tex2dArraySwzl = spvSwizzleConstants[4]; + constant uint& texCubeArraySwzl = spvSwizzleConstants[5]; + constant uint& depth2dSwzl = spvSwizzleConstants[7]; + constant uint& depthCubeSwzl = spvSwizzleConstants[8]; + constant uint& depth2dArraySwzl = spvSwizzleConstants[9]; + constant uint& depthCubeArraySwzl = spvSwizzleConstants[10]; out.fragColor = do_samples(tex1d, tex1dSmplr, tex1dSwzl, tex2d, tex2dSwzl, tex3d, tex3dSmplr, tex3dSwzl, texCube, texCubeSwzl, tex2dArray, tex2dArraySmplr, tex2dArraySwzl, texCubeArray, texCubeArraySmplr, texCubeArraySwzl, texBuffer, depth2d, depth2dSmplr, depth2dSwzl, depthCube, depthCubeSmplr, depthCubeSwzl, depth2dArray, depth2dArraySwzl, depthCubeArray, depthCubeArraySmplr, depthCubeArraySwzl, defaultSampler, shadowSampler); return out; } diff --git a/3rdparty/spirv-cross/reference/shaders-msl/asm/frag/extract-packed-from-composite.asm.frag b/3rdparty/spirv-cross/reference/shaders-msl/asm/frag/extract-packed-from-composite.asm.frag index 957b77f2e..1f92b341a 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/asm/frag/extract-packed-from-composite.asm.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl/asm/frag/extract-packed-from-composite.asm.frag @@ -7,19 +7,19 @@ using namespace metal; struct Foo { - packed_float3 a; + float3 a; float b; }; struct Foo_1 { - float3 a; + packed_float3 a; float b; }; struct buf { - Foo results[16]; + Foo_1 results[16]; float4 bar; }; @@ -31,7 +31,7 @@ struct main0_out float4 _main(thread const float4& pos, constant buf& v_11) { int _46 = int(pos.x) % 16; - Foo_1 foo; + Foo foo; foo.a = float3(v_11.results[_46].a); foo.b = v_11.results[_46].b; return float4(dot(foo.a, v_11.bar.xyz), foo.b, 0.0, 0.0); diff --git a/3rdparty/spirv-cross/reference/shaders-msl/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/reference/shaders-msl/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..e1d2a9d7b --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders-msl/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,84 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float FragColor [[color(0)]]; +}; + +struct main0_in +{ + float vColor [[user(locn0)]]; +}; + +#line 6 "test.frag" +void func(thread float& FragColor, thread float& vColor) +{ +#line 8 "test.frag" + FragColor = 1.0; +#line 9 "test.frag" + FragColor = 2.0; +#line 10 "test.frag" + if (vColor < 0.0) + { +#line 12 "test.frag" + FragColor = 3.0; + } + else + { +#line 16 "test.frag" + FragColor = 4.0; + } +#line 19 "test.frag" + for (int i = 0; float(i) < (40.0 + vColor); i += (int(vColor) + 5)) + { +#line 21 "test.frag" + FragColor += 0.20000000298023223876953125; +#line 22 "test.frag" + FragColor += 0.300000011920928955078125; + } +#line 25 "test.frag" + switch (int(vColor)) + { + case 0: + { +#line 28 "test.frag" + FragColor += 0.20000000298023223876953125; +#line 29 "test.frag" + break; + } + case 1: + { +#line 32 "test.frag" + FragColor += 0.4000000059604644775390625; +#line 33 "test.frag" + break; + } + default: + { +#line 36 "test.frag" + FragColor += 0.800000011920928955078125; +#line 37 "test.frag" + break; + } + } + do + { +#line 42 "test.frag" + FragColor += (10.0 + vColor); + } while (FragColor < 100.0); +} + +#line 46 "test.frag" +fragment main0_out main0(main0_in in [[stage_in]]) +{ + main0_out out = {}; +#line 48 "test.frag" + func(out.FragColor, in.vColor); + return out; +} + diff --git a/3rdparty/spirv-cross/reference/shaders-msl/asm/vert/extract-transposed-matrix-from-struct.asm.vert b/3rdparty/spirv-cross/reference/shaders-msl/asm/vert/extract-transposed-matrix-from-struct.asm.vert index c6a5fec6f..667d363a3 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/asm/vert/extract-transposed-matrix-from-struct.asm.vert +++ b/3rdparty/spirv-cross/reference/shaders-msl/asm/vert/extract-transposed-matrix-from-struct.asm.vert @@ -25,7 +25,7 @@ struct InstanceData_1 struct gInstanceData { - InstanceData _data[1]; + InstanceData_1 _data[1]; }; struct main0_out @@ -41,7 +41,7 @@ struct main0_in V2F _VS(thread const float3& PosL, thread const uint& instanceID, const device gInstanceData& gInstanceData_1) { - InstanceData_1 instData; + InstanceData instData; instData.MATRIX_MVP = transpose(gInstanceData_1._data[instanceID].MATRIX_MVP); instData.Color = gInstanceData_1._data[instanceID].Color; V2F v2f; diff --git a/3rdparty/spirv-cross/reference/shaders-msl/asm/vert/fake-builtin-input.asm.vert b/3rdparty/spirv-cross/reference/shaders-msl/asm/vert/fake-builtin-input.asm.vert new file mode 100644 index 000000000..f9fcbc85c --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders-msl/asm/vert/fake-builtin-input.asm.vert @@ -0,0 +1,22 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 in_var_POSITION [[attribute(0)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]]) +{ + main0_out out = {}; + out.gl_Position = float4(in.in_var_POSITION, 0.0, 1.0); + return out; +} + diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.comp new file mode 100644 index 000000000..6bba2ab4f --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.comp @@ -0,0 +1,36 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct SSBO +{ + uint size; + float4 v[1]; +}; + +struct SSBO1 +{ + float bz[1]; +}; + +uint get_size(device SSBO& v_14, constant uint& v_14BufferSize, device SSBO1* (&ssbos)[2], constant uint* ssbosBufferSize) +{ + return uint(int((v_14BufferSize - 16) / 16) + int((ssbosBufferSize[1] - 0) / 4)); +} + +kernel void main0(constant uint* spvBufferSizeConstants [[buffer(25)]], device SSBO& v_14 [[buffer(1)]], device SSBO1* ssbos_0 [[buffer(2)]], device SSBO1* ssbos_1 [[buffer(3)]]) +{ + device SSBO1* ssbos[] = + { + ssbos_0, + ssbos_1, + }; + + constant uint& v_14BufferSize = spvBufferSizeConstants[1]; + constant uint* ssbosBufferSize = &spvBufferSizeConstants[2]; + v_14.size = get_size(v_14, v_14BufferSize, ssbos, ssbosBufferSize); +} + diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.msl2.argument.discrete.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.msl2.argument.discrete.comp new file mode 100644 index 000000000..89d9809e1 --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/array-length.msl2.argument.discrete.comp @@ -0,0 +1,65 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct SSBO +{ + uint size; + float4 v[1]; +}; + +struct SSBO1 +{ + float bz[1]; +}; + +struct SSBO2 +{ + uint size2; + float4 w[1]; +}; + +struct SSBO3 +{ + float bz[1]; +}; + +struct spvDescriptorSetBuffer0 +{ + constant uint* spvBufferSizeConstants [[id(0)]]; + device SSBO* v_16 [[id(1)]]; +}; + +struct spvDescriptorSetBuffer1 +{ + constant uint* spvBufferSizeConstants [[id(1)]]; + device SSBO1* ssbos [[id(2)]][2]; +}; + +uint get_size(device SSBO& v_16, constant uint& v_16BufferSize, device SSBO1* constant (&ssbos)[2], constant uint* ssbosBufferSize, device SSBO2& v_38, constant uint& v_38BufferSize, device SSBO3* (&ssbos2)[2], constant uint* ssbos2BufferSize) +{ + uint len = uint(int((v_16BufferSize - 16) / 16)); + len += uint(int((ssbosBufferSize[1] - 0) / 4)); + len += uint(int((v_38BufferSize - 16) / 16)); + len += uint(int((ssbos2BufferSize[0] - 0) / 4)); + return len; +} + +kernel void main0(constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], constant spvDescriptorSetBuffer1& spvDescriptorSet1 [[buffer(1)]], constant uint* spvBufferSizeConstants [[buffer(25)]], device SSBO3* ssbos2_0 [[buffer(2)]], device SSBO3* ssbos2_1 [[buffer(3)]], device SSBO2& v_38 [[buffer(5)]]) +{ + device SSBO3* ssbos2[] = + { + ssbos2_0, + ssbos2_1, + }; + + constant uint& spvDescriptorSet0_v_16BufferSize = spvDescriptorSet0.spvBufferSizeConstants[1]; + constant uint* spvDescriptorSet1_ssbosBufferSize = &spvDescriptorSet1.spvBufferSizeConstants[2]; + constant uint& v_38BufferSize = spvBufferSizeConstants[5]; + constant uint* ssbos2BufferSize = &spvBufferSizeConstants[2]; + (*spvDescriptorSet0.v_16).size = get_size((*spvDescriptorSet0.v_16), spvDescriptorSet0_v_16BufferSize, spvDescriptorSet1.ssbos, spvDescriptorSet1_ssbosBufferSize, v_38, v_38BufferSize, ssbos2, ssbos2BufferSize); +} + diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/complex-type-alias.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/complex-type-alias.comp new file mode 100644 index 000000000..9101f89b7 --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/complex-type-alias.comp @@ -0,0 +1,68 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct Foo0 +{ + float a; +}; + +struct Foo1 +{ + Foo0 a; +}; + +struct Foo2 +{ + Foo1 a; + float weight; +}; + +struct Foo0_1 +{ + float a; +}; + +struct Foo1_1 +{ + Foo0_1 a; +}; + +struct Foo2_1 +{ + Foo1_1 a; + float weight; +}; + +struct SSBO +{ + Foo2_1 outputs[1]; +}; + +constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(8u, 8u, 1u); + +void Zero(thread Foo0& v) +{ + v.a = 0.0; +} + +kernel void main0(device SSBO& _53 [[buffer(0)]], uint gl_LocalInvocationIndex [[thread_index_in_threadgroup]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]]) +{ + threadgroup Foo2 coeffs[64]; + Foo2 data; + data.weight = 0.0; + Foo0 param; + Zero(param); + data.a.a = param; + coeffs[gl_LocalInvocationIndex] = data; + threadgroup_barrier(mem_flags::mem_threadgroup); + if (gl_LocalInvocationIndex == 0u) + { + _53.outputs[gl_WorkGroupID.x].a.a.a = coeffs[0].a.a.a; + _53.outputs[gl_WorkGroupID.x].weight = coeffs[0].weight; + } +} + diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/composite-array-initialization.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/composite-array-initialization.comp index 9d35115e8..ac10e7501 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/comp/composite-array-initialization.comp +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/composite-array-initialization.comp @@ -11,23 +11,23 @@ struct Data float b; }; +constant float X_tmp [[function_constant(0)]]; +constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0; + struct Data_1 { float a; float b; }; -constant float X_tmp [[function_constant(0)]]; -constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0; - struct SSBO { - Data outdata[1]; + Data_1 outdata[1]; }; constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(2u, 1u, 1u); -constant Data_1 _25[2] = { Data_1{ 1.0, 2.0 }, Data_1{ 3.0, 4.0 } }; +constant Data _25[2] = { Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } }; // Implementation of an array copy function to cover GLSL's ability to copy an array via assignment. template @@ -42,20 +42,20 @@ void spvArrayCopyFromConstant1(thread T (&dst)[N], constant T (&src)[N]) for (uint i = 0; i < N; dst[i] = src[i], i++); } -Data_1 combine(thread const Data_1& a, thread const Data_1& b) +Data combine(thread const Data& a, thread const Data& b) { - return Data_1{ a.a + b.a, a.b + b.b }; + return Data{ a.a + b.a, a.b + b.b }; } kernel void main0(device SSBO& _53 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) { - Data_1 data[2] = { Data_1{ 1.0, 2.0 }, Data_1{ 3.0, 4.0 } }; - Data_1 _31[2] = { Data_1{ X, 2.0 }, Data_1{ 3.0, 5.0 } }; - Data_1 data2[2]; + Data data[2] = { Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } }; + Data _31[2] = { Data{ X, 2.0 }, Data{ 3.0, 5.0 } }; + Data data2[2]; spvArrayCopyFromStack1(data2, _31); - Data_1 param = data[gl_LocalInvocationID.x]; - Data_1 param_1 = data2[gl_LocalInvocationID.x]; - Data_1 _73 = combine(param, param_1); + Data param = data[gl_LocalInvocationID.x]; + Data param_1 = data2[gl_LocalInvocationID.x]; + Data _73 = combine(param, param_1); _53.outdata[gl_WorkGroupID.x].a = _73.a; _53.outdata[gl_WorkGroupID.x].b = _73.b; } diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/force-recompile-hooks.swizzle.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/force-recompile-hooks.swizzle.comp index b784940e8..f9608de34 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/comp/force-recompile-hooks.swizzle.comp +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/force-recompile-hooks.swizzle.comp @@ -127,7 +127,7 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p kernel void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture2d foo [[texture(0)]], texture2d bar [[texture(1)]], sampler fooSmplr [[sampler(0)]]) { - constant uint32_t& fooSwzl = spvSwizzleConstants[0]; + constant uint& fooSwzl = spvSwizzleConstants[0]; float4 a = spvTextureSwizzle(foo.sample(fooSmplr, float2(1.0), level(0.0)), fooSwzl); bar.write(a, uint2(int2(0))); } diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/packing-test-1.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/packing-test-1.comp index e9b107367..eae01fff4 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/comp/packing-test-1.comp +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/packing-test-1.comp @@ -5,19 +5,19 @@ using namespace metal; struct T1 { - packed_float3 a; + float3 a; float b; }; struct T1_1 { - float3 a; + packed_float3 a; float b; }; struct Buffer0 { - T1 buf0[1]; + T1_1 buf0[1]; }; struct Buffer1 @@ -29,7 +29,7 @@ constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(32u, 1u, 1u); kernel void main0(device Buffer0& _15 [[buffer(1)]], device Buffer1& _34 [[buffer(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) { - T1_1 v; + T1 v; v.a = float3(_15.buf0[0].a); v.b = _15.buf0[0].b; float x = v.b; diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/storage-buffer-std140-vector-array.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/storage-buffer-std140-vector-array.comp index a5a1cf9ec..6988febfa 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/comp/storage-buffer-std140-vector-array.comp +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/storage-buffer-std140-vector-array.comp @@ -4,14 +4,6 @@ using namespace metal; struct Sub -{ - float4 f[2]; - float4 f2[2]; - float3 f3[2]; - float4 f4[2]; -}; - -struct Sub_1 { float f[2]; float2 f2[2]; @@ -19,14 +11,22 @@ struct Sub_1 float4 f4[2]; }; +struct Sub_1 +{ + float4 f[2]; + float4 f2[2]; + float3 f3[2]; + float4 f4[2]; +}; + struct SSBO { - Sub sub[2]; + Sub_1 sub[2]; }; kernel void main0(device SSBO& _27 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) { - Sub_1 foo; + Sub foo; foo.f[0] = _27.sub[gl_WorkGroupID.x].f[0].x; foo.f[1] = _27.sub[gl_WorkGroupID.x].f[1].x; foo.f2[0] = _27.sub[gl_WorkGroupID.x].f2[0].xy; diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/struct-nested.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/struct-nested.comp index c94d9c335..117e492d6 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/comp/struct-nested.comp +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/struct-nested.comp @@ -13,24 +13,24 @@ struct s2 s1 b; }; -struct s2_1 -{ - s1 b; -}; - struct s1_1 { int a; }; +struct s2_1 +{ + s1_1 b; +}; + struct dstbuffer { - s2 test[1]; + s2_1 test[1]; }; kernel void main0(device dstbuffer& _19 [[buffer(1)]]) { - s2_1 testVal; + s2 testVal; testVal.b.a = 0; _19.test[0].b.a = testVal.b.a; } diff --git a/3rdparty/spirv-cross/reference/shaders-msl/comp/type-alias.comp b/3rdparty/spirv-cross/reference/shaders-msl/comp/type-alias.comp index 9052bdd14..25a49f59f 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/comp/type-alias.comp +++ b/3rdparty/spirv-cross/reference/shaders-msl/comp/type-alias.comp @@ -10,14 +10,19 @@ struct S0 float4 a; }; +struct S1 +{ + float4 a; +}; + struct S0_1 { float4 a; }; -struct S1 +struct SSBO0 { - float4 a; + S0_1 s0s[1]; }; struct S1_1 @@ -25,14 +30,9 @@ struct S1_1 float4 a; }; -struct SSBO0 -{ - S0 s0s[1]; -}; - struct SSBO1 { - S1 s1s[1]; + S1_1 s1s[1]; }; struct SSBO2 @@ -40,24 +40,24 @@ struct SSBO2 float4 outputs[1]; }; -float4 overload(thread const S0_1& s0) +float4 overload(thread const S0& s0) { return s0.a; } -float4 overload(thread const S1_1& s1) +float4 overload(thread const S1& s1) { return s1.a; } kernel void main0(device SSBO0& _36 [[buffer(0)]], device SSBO1& _55 [[buffer(1)]], device SSBO2& _66 [[buffer(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) { - S0_1 s0; + S0 s0; s0.a = _36.s0s[gl_GlobalInvocationID.x].a; - S1_1 s1; + S1 s1; s1.a = _55.s1s[gl_GlobalInvocationID.x].a; - S0_1 param = s0; - S1_1 param_1 = s1; + S0 param = s0; + S1 param_1 = s1; _66.outputs[gl_GlobalInvocationID.x] = overload(param) + overload(param_1); } diff --git a/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag b/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag index 5e749b3ab..2b5afe235 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag @@ -142,17 +142,17 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p return t.gather_compare(s, spvForward(params)...); } -float4 sample_in_func_1(thread const array, 4> uSampler0, thread const array uSampler0Smplr, constant uint32_t* uSampler0Swzl, thread float2& vUV) +float4 sample_in_func_1(thread const array, 4> uSampler0, thread const array uSampler0Smplr, constant uint* uSampler0Swzl, thread float2& vUV) { return spvTextureSwizzle(uSampler0[2].sample(uSampler0Smplr[2], vUV), uSampler0Swzl[2]); } -float4 sample_in_func_2(thread float2& vUV, thread texture2d uSampler1, thread const sampler uSampler1Smplr, constant uint32_t& uSampler1Swzl) +float4 sample_in_func_2(thread float2& vUV, thread texture2d uSampler1, thread const sampler uSampler1Smplr, constant uint& uSampler1Swzl) { return spvTextureSwizzle(uSampler1.sample(uSampler1Smplr, vUV), uSampler1Swzl); } -float4 sample_single_in_func(thread const texture2d s, thread const sampler sSmplr, constant uint32_t& sSwzl, thread float2& vUV) +float4 sample_single_in_func(thread const texture2d s, thread const sampler sSmplr, constant uint& sSwzl, thread float2& vUV) { return spvTextureSwizzle(s.sample(sSmplr, vUV), sSwzl); } @@ -160,8 +160,8 @@ float4 sample_single_in_func(thread const texture2d s, thread const sampl fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], constant uint* spvSwizzleConstants [[buffer(30)]], texture2d uSampler1 [[texture(0)]], sampler uSampler1Smplr [[sampler(0)]]) { main0_out out = {}; - constant uint32_t* spvDescriptorSet0_uSampler0Swzl = &spvDescriptorSet0.spvSwizzleConstants[1]; - constant uint32_t& uSampler1Swzl = spvSwizzleConstants[0]; + constant uint* spvDescriptorSet0_uSampler0Swzl = &spvDescriptorSet0.spvSwizzleConstants[1]; + constant uint& uSampler1Swzl = spvSwizzleConstants[0]; out.FragColor = sample_in_func_1(spvDescriptorSet0.uSampler0, spvDescriptorSet0.uSampler0Smplr, spvDescriptorSet0_uSampler0Swzl, in.vUV); out.FragColor += sample_in_func_2(in.vUV, uSampler1, uSampler1Smplr, uSampler1Swzl); out.FragColor += sample_single_in_func(spvDescriptorSet0.uSampler0[1], spvDescriptorSet0.uSampler0Smplr[1], spvDescriptorSet0_uSampler0Swzl[1], in.vUV); diff --git a/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag b/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag index 0e4972c6d..ebaa28a57 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag @@ -135,12 +135,12 @@ inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... p return t.gather_compare(s, spvForward(params)...); } -float4 sample_in_func(thread const array, 4> uSampler, thread const array uSamplerSmplr, constant uint32_t* uSamplerSwzl, thread float2& vUV) +float4 sample_in_func(thread const array, 4> uSampler, thread const array uSamplerSmplr, constant uint* uSamplerSwzl, thread float2& vUV) { return spvTextureSwizzle(uSampler[2].sample(uSamplerSmplr[2], vUV), uSamplerSwzl[2]); } -float4 sample_single_in_func(thread const texture2d s, thread const sampler sSmplr, constant uint32_t& sSwzl, thread float2& vUV) +float4 sample_single_in_func(thread const texture2d s, thread const sampler sSmplr, constant uint& sSwzl, thread float2& vUV) { return spvTextureSwizzle(s.sample(sSmplr, vUV), sSwzl); } @@ -148,7 +148,7 @@ float4 sample_single_in_func(thread const texture2d s, thread const sampl fragment main0_out main0(main0_in in [[stage_in]], constant uint* spvSwizzleConstants [[buffer(30)]], array, 4> uSampler [[texture(0)]], array uSamplerSmplr [[sampler(0)]]) { main0_out out = {}; - constant uint32_t* uSamplerSwzl = &spvSwizzleConstants[0]; + constant uint* uSamplerSwzl = &spvSwizzleConstants[0]; out.FragColor = sample_in_func(uSampler, uSamplerSmplr, uSamplerSwzl, in.vUV); out.FragColor += sample_single_in_func(uSampler[1], uSamplerSmplr[1], uSamplerSwzl[1], in.vUV); return out; diff --git a/3rdparty/spirv-cross/reference/shaders-msl/frag/packing-test-3.frag b/3rdparty/spirv-cross/reference/shaders-msl/frag/packing-test-3.frag index 916ab8757..d8310d6ac 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/frag/packing-test-3.frag +++ b/3rdparty/spirv-cross/reference/shaders-msl/frag/packing-test-3.frag @@ -12,19 +12,19 @@ struct VertexOutput struct TestStruct { - packed_float3 position; + float3 position; float radius; }; struct TestStruct_1 { - float3 position; + packed_float3 position; float radius; }; struct CB0 { - TestStruct CB0[16]; + TestStruct_1 CB0[16]; }; struct main0_out @@ -34,7 +34,7 @@ struct main0_out float4 _main(thread const VertexOutput& IN, constant CB0& v_26) { - TestStruct_1 st; + TestStruct st; st.position = float3(v_26.CB0[1].position); st.radius = v_26.CB0[1].radius; float4 col = float4(st.position, st.radius); diff --git a/3rdparty/spirv-cross/reference/shaders-msl/vert/copy.flatten.vert b/3rdparty/spirv-cross/reference/shaders-msl/vert/copy.flatten.vert index 3230e4fbd..a762f7e79 100644 --- a/3rdparty/spirv-cross/reference/shaders-msl/vert/copy.flatten.vert +++ b/3rdparty/spirv-cross/reference/shaders-msl/vert/copy.flatten.vert @@ -40,9 +40,9 @@ vertex main0_out main0(main0_in in [[stage_in]], constant UBO& _21 [[buffer(0)]] main0_out out = {}; out.gl_Position = _21.uMVP * in.aVertex; out.vColor = float4(0.0); + Light_1 light; for (int i = 0; i < 4; i++) { - Light_1 light; light.Position = float3(_21.lights[i].Position); light.Radius = _21.lights[i].Radius; light.Color = _21.lights[i].Color; diff --git a/3rdparty/spirv-cross/reference/shaders/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/reference/shaders/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..35aa9f8c4 --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,71 @@ +#version 450 +#extension GL_GOOGLE_cpp_style_line_directive : require + +layout(location = 0) out float FragColor; +layout(location = 0) in float vColor; + +#line 6 "test.frag" +void func() +{ +#line 8 "test.frag" + FragColor = 1.0; +#line 9 "test.frag" + FragColor = 2.0; +#line 10 "test.frag" + if (vColor < 0.0) + { +#line 12 "test.frag" + FragColor = 3.0; + } + else + { +#line 16 "test.frag" + FragColor = 4.0; + } +#line 19 "test.frag" + for (int i = 0; float(i) < (40.0 + vColor); i += (int(vColor) + 5)) + { +#line 21 "test.frag" + FragColor += 0.20000000298023223876953125; +#line 22 "test.frag" + FragColor += 0.300000011920928955078125; + } +#line 25 "test.frag" + switch (int(vColor)) + { + case 0: + { +#line 28 "test.frag" + FragColor += 0.20000000298023223876953125; +#line 29 "test.frag" + break; + } + case 1: + { +#line 32 "test.frag" + FragColor += 0.4000000059604644775390625; +#line 33 "test.frag" + break; + } + default: + { +#line 36 "test.frag" + FragColor += 0.800000011920928955078125; +#line 37 "test.frag" + break; + } + } + do + { +#line 42 "test.frag" + FragColor += (10.0 + vColor); + } while (FragColor < 100.0); +} + +#line 46 "test.frag" +void main() +{ +#line 48 "test.frag" + func(); +} + diff --git a/3rdparty/spirv-cross/reference/shaders/asm/geom/unroll-glposition-load.asm.geom b/3rdparty/spirv-cross/reference/shaders/asm/geom/unroll-glposition-load.asm.geom index de437fae6..39bc097d8 100644 --- a/3rdparty/spirv-cross/reference/shaders/asm/geom/unroll-glposition-load.asm.geom +++ b/3rdparty/spirv-cross/reference/shaders/asm/geom/unroll-glposition-load.asm.geom @@ -9,9 +9,9 @@ struct SceneOut void _main(vec4 positions[3], SceneOut OUT) { + SceneOut o; for (int i = 0; i < 3; i++) { - SceneOut o; o.pos = positions[i]; gl_Position = o.pos; EmitVertex(); diff --git a/3rdparty/spirv-cross/reference/shaders/flatten/copy.flatten.vert b/3rdparty/spirv-cross/reference/shaders/flatten/copy.flatten.vert index 0ca7de347..4703d938d 100644 --- a/3rdparty/spirv-cross/reference/shaders/flatten/copy.flatten.vert +++ b/3rdparty/spirv-cross/reference/shaders/flatten/copy.flatten.vert @@ -16,10 +16,10 @@ void main() { gl_Position = mat4(UBO[0], UBO[1], UBO[2], UBO[3]) * aVertex; vColor = vec4(0.0); + Light light; for (int i = 0; i < 4; i++) { Light _52 = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]); - Light light; light.Position = _52.Position; light.Radius = _52.Radius; light.Color = _52.Color; diff --git a/3rdparty/spirv-cross/reference/shaders/frag/inside-loop-dominated-variable-preservation.frag b/3rdparty/spirv-cross/reference/shaders/frag/inside-loop-dominated-variable-preservation.frag new file mode 100644 index 000000000..2947b19fb --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders/frag/inside-loop-dominated-variable-preservation.frag @@ -0,0 +1,30 @@ +#version 310 es +precision mediump float; +precision highp int; + +layout(location = 0) out vec4 FragColor; + +void main() +{ + bool written = false; + float v; + for (mediump int j = 0; j < 10; j++) + { + for (mediump int i = 0; i < 4; i++) + { + float w = 0.0; + if (written) + { + w += v; + } + else + { + v = 20.0; + } + v += float(i); + written = true; + } + } + FragColor = vec4(1.0); +} + diff --git a/3rdparty/spirv-cross/reference/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk b/3rdparty/spirv-cross/reference/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk new file mode 100644 index 000000000..434cb3d3d --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag.vk @@ -0,0 +1,24 @@ +#version 450 +#extension GL_EXT_scalar_block_layout : require + +layout(set = 0, binding = 0, std430) uniform UBO +{ + float a[1024]; + vec3 b[2]; +} _17; + +layout(set = 0, binding = 1, std430) uniform UBOEnhancedLayout +{ + layout(offset = 0) float c[1024]; + layout(offset = 4096) vec3 d[2]; + layout(offset = 10000) float e; +} _30; + +layout(location = 0) out float FragColor; +layout(location = 0) flat in int vIndex; + +void main() +{ + FragColor = (_17.a[vIndex] + _30.c[vIndex]) + _30.e; +} + diff --git a/3rdparty/spirv-cross/reference/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk b/3rdparty/spirv-cross/reference/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk new file mode 100644 index 000000000..d8c579673 --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen.vk @@ -0,0 +1,17 @@ +#version 460 +#extension GL_NV_ray_tracing : require + +layout(set = 0, binding = 0) uniform accelerationStructureNV as; +layout(set = 0, binding = 1, rgba32f) uniform writeonly image2D image; +layout(location = 0) rayPayloadNV vec4 payload; +layout(location = 0) callableDataNV float blend; + +void main() +{ + vec3 origin = vec3(0.0); + vec3 direction = vec3(0.0, 0.0, -1.0); + traceNV(as, 1u, 255u, 0u, 0u, 0u, origin, 0.0, direction, 100.0, 0); + executeCallableNV(0u, 0); + imageStore(image, ivec2(gl_LaunchIDNV.xy), payload + vec4(blend)); +} + diff --git a/3rdparty/spirv-cross/reference/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk b/3rdparty/spirv-cross/reference/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk new file mode 100644 index 000000000..058ccf9a6 --- /dev/null +++ b/3rdparty/spirv-cross/reference/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen.vk @@ -0,0 +1,17 @@ +#version 460 +#extension GL_NV_ray_tracing : require + +layout(shaderRecordNV, std430) buffer sbt +{ + vec3 direction; + float tmax; +} _20; + +layout(set = 0, binding = 0) uniform accelerationStructureNV as; +layout(location = 0) rayPayloadNV float payload; + +void main() +{ + traceNV(as, 0u, 255u, 0u, 1u, 0u, vec3(0.0), 0.0, _20.direction, _20.tmax, 0); +} + diff --git a/3rdparty/spirv-cross/shaders-hlsl/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/shaders-hlsl/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..9e08e9a89 --- /dev/null +++ b/3rdparty/spirv-cross/shaders-hlsl/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,221 @@ +; SPIR-V +; Version: 1.0 +; Generator: Google Shaderc over Glslang; 7 +; Bound: 83 +; Schema: 0 + OpCapability Shader + %2 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint Fragment %main "main" %FragColor %vColor + OpExecutionMode %main OriginUpperLeft + %1 = OpString "test.frag" + OpSource GLSL 450 %1 "// OpModuleProcessed entry-point main +// OpModuleProcessed client vulkan100 +// OpModuleProcessed target-env vulkan1.0 +// OpModuleProcessed entry-point main +#line 1 +#version 450 + +layout(location = 0) in float vColor; +layout(location = 0) out float FragColor; + +void func() +{ + FragColor = 1.0; + FragColor = 2.0; + if (vColor < 0.0) + { + FragColor = 3.0; + } + else + { + FragColor = 4.0; + } + + for (int i = 0; i < 40 + vColor; i += int(vColor) + 5) + { + FragColor += 0.2; + FragColor += 0.3; + } + + switch (int(vColor)) + { + case 0: + FragColor += 0.2; + break; + + case 1: + FragColor += 0.4; + break; + + default: + FragColor += 0.8; + break; + } + + do + { + FragColor += 10.0 + vColor; + } while(FragColor < 100.0); +} + +void main() +{ + func(); +} +" + OpSourceExtension "GL_GOOGLE_cpp_style_line_directive" + OpSourceExtension "GL_GOOGLE_include_directive" + OpName %main "main" + OpName %func_ "func(" + OpName %FragColor "FragColor" + OpName %vColor "vColor" + OpName %i "i" + OpDecorate %FragColor Location 0 + OpDecorate %vColor Location 0 + %void = OpTypeVoid + %4 = OpTypeFunction %void + %float = OpTypeFloat 32 +%_ptr_Output_float = OpTypePointer Output %float + %FragColor = OpVariable %_ptr_Output_float Output + %float_1 = OpConstant %float 1 + %float_2 = OpConstant %float 2 +%_ptr_Input_float = OpTypePointer Input %float + %vColor = OpVariable %_ptr_Input_float Input + %float_0 = OpConstant %float 0 + %bool = OpTypeBool + %float_3 = OpConstant %float 3 + %float_4 = OpConstant %float 4 + %int = OpTypeInt 32 1 + + ; Should be ignored + OpLine %1 5 0 + +%_ptr_Function_int = OpTypePointer Function %int + %int_0 = OpConstant %int 0 + %float_40 = OpConstant %float 40 +%float_0_200000003 = OpConstant %float 0.200000003 +%float_0_300000012 = OpConstant %float 0.300000012 + %int_5 = OpConstant %int 5 + + ; Should be ignored + OpLine %1 5 0 + +%float_0_400000006 = OpConstant %float 0.400000006 +%float_0_800000012 = OpConstant %float 0.800000012 + %float_10 = OpConstant %float 10 + %float_100 = OpConstant %float 100 + %main = OpFunction %void None %4 + OpLine %1 46 0 + %6 = OpLabel + OpLine %1 48 0 + %82 = OpFunctionCall %void %func_ + OpReturn + OpFunctionEnd + + ; Should be ignored + OpLine %1 5 0 + + %func_ = OpFunction %void None %4 + OpLine %1 6 0 + %8 = OpLabel + %i = OpVariable %_ptr_Function_int Function + OpLine %1 8 0 + OpStore %FragColor %float_1 + OpLine %1 9 0 + OpStore %FragColor %float_2 + OpLine %1 10 0 + %16 = OpLoad %float %vColor + %19 = OpFOrdLessThan %bool %16 %float_0 + OpSelectionMerge %21 None + OpBranchConditional %19 %20 %23 + %20 = OpLabel + OpLine %1 12 0 + OpStore %FragColor %float_3 + OpBranch %21 + %23 = OpLabel + OpLine %1 16 0 + OpStore %FragColor %float_4 + OpBranch %21 + %21 = OpLabel + OpLine %1 19 0 + OpStore %i %int_0 + OpBranch %29 + %29 = OpLabel + OpLoopMerge %31 %32 None + OpBranch %33 + %33 = OpLabel + %34 = OpLoad %int %i + %35 = OpConvertSToF %float %34 + %37 = OpLoad %float %vColor + %38 = OpFAdd %float %float_40 %37 + %39 = OpFOrdLessThan %bool %35 %38 + OpBranchConditional %39 %30 %31 + %30 = OpLabel + OpLine %1 21 0 + %41 = OpLoad %float %FragColor + %42 = OpFAdd %float %41 %float_0_200000003 + OpStore %FragColor %42 + OpLine %1 22 0 + %44 = OpLoad %float %FragColor + %45 = OpFAdd %float %44 %float_0_300000012 + OpStore %FragColor %45 + OpBranch %32 + %32 = OpLabel + OpLine %1 19 0 + %46 = OpLoad %float %vColor + %47 = OpConvertFToS %int %46 + %49 = OpIAdd %int %47 %int_5 + %50 = OpLoad %int %i + %51 = OpIAdd %int %50 %49 + OpStore %i %51 + OpBranch %29 + %31 = OpLabel + OpLine %1 25 0 + %52 = OpLoad %float %vColor + %53 = OpConvertFToS %int %52 + OpSelectionMerge %57 None + OpSwitch %53 %56 0 %54 1 %55 + %56 = OpLabel + OpLine %1 36 0 + %66 = OpLoad %float %FragColor + %67 = OpFAdd %float %66 %float_0_800000012 + OpStore %FragColor %67 + OpLine %1 37 0 + OpBranch %57 + %54 = OpLabel + OpLine %1 28 0 + %58 = OpLoad %float %FragColor + %59 = OpFAdd %float %58 %float_0_200000003 + OpStore %FragColor %59 + OpLine %1 29 0 + OpBranch %57 + %55 = OpLabel + OpLine %1 32 0 + %62 = OpLoad %float %FragColor + %63 = OpFAdd %float %62 %float_0_400000006 + OpStore %FragColor %63 + OpLine %1 33 0 + OpBranch %57 + %57 = OpLabel + OpBranch %70 + OpLine %1 43 0 + %70 = OpLabel + OpLoopMerge %72 %73 None + OpBranch %71 + %71 = OpLabel + OpLine %1 42 0 + %75 = OpLoad %float %vColor + %76 = OpFAdd %float %float_10 %75 + %77 = OpLoad %float %FragColor + %78 = OpFAdd %float %77 %76 + OpStore %FragColor %78 + OpBranch %73 + %73 = OpLabel + OpLine %1 43 0 + %79 = OpLoad %float %FragColor + %81 = OpFOrdLessThan %bool %79 %float_100 + OpBranchConditional %81 %70 %72 + %72 = OpLabel + OpReturn + OpFunctionEnd diff --git a/3rdparty/spirv-cross/shaders-msl/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/shaders-msl/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..9e08e9a89 --- /dev/null +++ b/3rdparty/spirv-cross/shaders-msl/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,221 @@ +; SPIR-V +; Version: 1.0 +; Generator: Google Shaderc over Glslang; 7 +; Bound: 83 +; Schema: 0 + OpCapability Shader + %2 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint Fragment %main "main" %FragColor %vColor + OpExecutionMode %main OriginUpperLeft + %1 = OpString "test.frag" + OpSource GLSL 450 %1 "// OpModuleProcessed entry-point main +// OpModuleProcessed client vulkan100 +// OpModuleProcessed target-env vulkan1.0 +// OpModuleProcessed entry-point main +#line 1 +#version 450 + +layout(location = 0) in float vColor; +layout(location = 0) out float FragColor; + +void func() +{ + FragColor = 1.0; + FragColor = 2.0; + if (vColor < 0.0) + { + FragColor = 3.0; + } + else + { + FragColor = 4.0; + } + + for (int i = 0; i < 40 + vColor; i += int(vColor) + 5) + { + FragColor += 0.2; + FragColor += 0.3; + } + + switch (int(vColor)) + { + case 0: + FragColor += 0.2; + break; + + case 1: + FragColor += 0.4; + break; + + default: + FragColor += 0.8; + break; + } + + do + { + FragColor += 10.0 + vColor; + } while(FragColor < 100.0); +} + +void main() +{ + func(); +} +" + OpSourceExtension "GL_GOOGLE_cpp_style_line_directive" + OpSourceExtension "GL_GOOGLE_include_directive" + OpName %main "main" + OpName %func_ "func(" + OpName %FragColor "FragColor" + OpName %vColor "vColor" + OpName %i "i" + OpDecorate %FragColor Location 0 + OpDecorate %vColor Location 0 + %void = OpTypeVoid + %4 = OpTypeFunction %void + %float = OpTypeFloat 32 +%_ptr_Output_float = OpTypePointer Output %float + %FragColor = OpVariable %_ptr_Output_float Output + %float_1 = OpConstant %float 1 + %float_2 = OpConstant %float 2 +%_ptr_Input_float = OpTypePointer Input %float + %vColor = OpVariable %_ptr_Input_float Input + %float_0 = OpConstant %float 0 + %bool = OpTypeBool + %float_3 = OpConstant %float 3 + %float_4 = OpConstant %float 4 + %int = OpTypeInt 32 1 + + ; Should be ignored + OpLine %1 5 0 + +%_ptr_Function_int = OpTypePointer Function %int + %int_0 = OpConstant %int 0 + %float_40 = OpConstant %float 40 +%float_0_200000003 = OpConstant %float 0.200000003 +%float_0_300000012 = OpConstant %float 0.300000012 + %int_5 = OpConstant %int 5 + + ; Should be ignored + OpLine %1 5 0 + +%float_0_400000006 = OpConstant %float 0.400000006 +%float_0_800000012 = OpConstant %float 0.800000012 + %float_10 = OpConstant %float 10 + %float_100 = OpConstant %float 100 + %main = OpFunction %void None %4 + OpLine %1 46 0 + %6 = OpLabel + OpLine %1 48 0 + %82 = OpFunctionCall %void %func_ + OpReturn + OpFunctionEnd + + ; Should be ignored + OpLine %1 5 0 + + %func_ = OpFunction %void None %4 + OpLine %1 6 0 + %8 = OpLabel + %i = OpVariable %_ptr_Function_int Function + OpLine %1 8 0 + OpStore %FragColor %float_1 + OpLine %1 9 0 + OpStore %FragColor %float_2 + OpLine %1 10 0 + %16 = OpLoad %float %vColor + %19 = OpFOrdLessThan %bool %16 %float_0 + OpSelectionMerge %21 None + OpBranchConditional %19 %20 %23 + %20 = OpLabel + OpLine %1 12 0 + OpStore %FragColor %float_3 + OpBranch %21 + %23 = OpLabel + OpLine %1 16 0 + OpStore %FragColor %float_4 + OpBranch %21 + %21 = OpLabel + OpLine %1 19 0 + OpStore %i %int_0 + OpBranch %29 + %29 = OpLabel + OpLoopMerge %31 %32 None + OpBranch %33 + %33 = OpLabel + %34 = OpLoad %int %i + %35 = OpConvertSToF %float %34 + %37 = OpLoad %float %vColor + %38 = OpFAdd %float %float_40 %37 + %39 = OpFOrdLessThan %bool %35 %38 + OpBranchConditional %39 %30 %31 + %30 = OpLabel + OpLine %1 21 0 + %41 = OpLoad %float %FragColor + %42 = OpFAdd %float %41 %float_0_200000003 + OpStore %FragColor %42 + OpLine %1 22 0 + %44 = OpLoad %float %FragColor + %45 = OpFAdd %float %44 %float_0_300000012 + OpStore %FragColor %45 + OpBranch %32 + %32 = OpLabel + OpLine %1 19 0 + %46 = OpLoad %float %vColor + %47 = OpConvertFToS %int %46 + %49 = OpIAdd %int %47 %int_5 + %50 = OpLoad %int %i + %51 = OpIAdd %int %50 %49 + OpStore %i %51 + OpBranch %29 + %31 = OpLabel + OpLine %1 25 0 + %52 = OpLoad %float %vColor + %53 = OpConvertFToS %int %52 + OpSelectionMerge %57 None + OpSwitch %53 %56 0 %54 1 %55 + %56 = OpLabel + OpLine %1 36 0 + %66 = OpLoad %float %FragColor + %67 = OpFAdd %float %66 %float_0_800000012 + OpStore %FragColor %67 + OpLine %1 37 0 + OpBranch %57 + %54 = OpLabel + OpLine %1 28 0 + %58 = OpLoad %float %FragColor + %59 = OpFAdd %float %58 %float_0_200000003 + OpStore %FragColor %59 + OpLine %1 29 0 + OpBranch %57 + %55 = OpLabel + OpLine %1 32 0 + %62 = OpLoad %float %FragColor + %63 = OpFAdd %float %62 %float_0_400000006 + OpStore %FragColor %63 + OpLine %1 33 0 + OpBranch %57 + %57 = OpLabel + OpBranch %70 + OpLine %1 43 0 + %70 = OpLabel + OpLoopMerge %72 %73 None + OpBranch %71 + %71 = OpLabel + OpLine %1 42 0 + %75 = OpLoad %float %vColor + %76 = OpFAdd %float %float_10 %75 + %77 = OpLoad %float %FragColor + %78 = OpFAdd %float %77 %76 + OpStore %FragColor %78 + OpBranch %73 + %73 = OpLabel + OpLine %1 43 0 + %79 = OpLoad %float %FragColor + %81 = OpFOrdLessThan %bool %79 %float_100 + OpBranchConditional %81 %70 %72 + %72 = OpLabel + OpReturn + OpFunctionEnd diff --git a/3rdparty/spirv-cross/shaders-msl/asm/vert/fake-builtin-input.asm.vert b/3rdparty/spirv-cross/shaders-msl/asm/vert/fake-builtin-input.asm.vert new file mode 100644 index 000000000..4de1d1945 --- /dev/null +++ b/3rdparty/spirv-cross/shaders-msl/asm/vert/fake-builtin-input.asm.vert @@ -0,0 +1,55 @@ +; SPIR-V +; Version: 1.3 +; Generator: Google spiregg; 0 +; Bound: 29 +; Schema: 0 + OpCapability Shader + OpCapability Float16 + OpCapability StorageInputOutput16 + OpMemoryModel Logical GLSL450 + OpEntryPoint Vertex %vertexShader "main" %in_var_POSITION %gl_Position %gl_FragCoord %out_var_SV_Target + OpEntryPoint Fragment %fragmentShader "fragmentShader" %in_var_POSITION %gl_Position %gl_FragCoord %out_var_SV_Target + OpExecutionMode %fragmentShader OriginUpperLeft + OpSource HLSL 640 + OpName %in_var_POSITION "in.var.POSITION" + OpName %out_var_SV_Target "out.var.SV_Target" + OpName %vertexShader "vertexShader" + OpName %fragmentShader "fragmentShader" + OpDecorate %gl_Position BuiltIn Position + OpDecorate %gl_FragCoord BuiltIn FragCoord + OpDecorate %in_var_POSITION Location 0 + OpDecorate %out_var_SV_Target Location 0 + %float = OpTypeFloat 32 + %float_0 = OpConstant %float 0 + %float_1 = OpConstant %float 1 + %half = OpTypeFloat 16 +%half_0x1p_0 = OpConstant %half 0x1p+0 +%half_0x0p_0 = OpConstant %half 0x0p+0 + %v4half = OpTypeVector %half 4 + %14 = OpConstantComposite %v4half %half_0x1p_0 %half_0x0p_0 %half_0x1p_0 %half_0x1p_0 + %v2float = OpTypeVector %float 2 +%_ptr_Input_v2float = OpTypePointer Input %v2float + %v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float +%_ptr_Input_v4float = OpTypePointer Input %v4float +%_ptr_Output_v4half = OpTypePointer Output %v4half + %void = OpTypeVoid + %22 = OpTypeFunction %void +%in_var_POSITION = OpVariable %_ptr_Input_v2float Input +%gl_Position = OpVariable %_ptr_Output_v4float Output +%gl_FragCoord = OpVariable %_ptr_Input_v4float Input +%out_var_SV_Target = OpVariable %_ptr_Output_v4half Output +%vertexShader = OpFunction %void None %22 + %23 = OpLabel + %24 = OpLoad %v2float %in_var_POSITION + %25 = OpCompositeExtract %float %24 0 + %26 = OpCompositeExtract %float %24 1 + %27 = OpCompositeConstruct %v4float %25 %26 %float_0 %float_1 + OpStore %gl_Position %27 + OpReturn + OpFunctionEnd +%fragmentShader = OpFunction %void None %22 + %28 = OpLabel + OpStore %out_var_SV_Target %14 + OpReturn + OpFunctionEnd diff --git a/3rdparty/spirv-cross/shaders-msl/comp/array-length.comp b/3rdparty/spirv-cross/shaders-msl/comp/array-length.comp new file mode 100644 index 000000000..6189d3560 --- /dev/null +++ b/3rdparty/spirv-cross/shaders-msl/comp/array-length.comp @@ -0,0 +1,22 @@ +#version 450 +layout(local_size_x = 1) in; +layout(set = 0, binding = 1, std140) buffer SSBO +{ + uint size; + float v[]; +}; + +layout(set = 0, binding = 2, std430) buffer SSBO1 +{ + float bz[]; +} ssbos[2]; + +uint get_size() +{ + return v.length() + ssbos[1].bz.length(); +} + +void main() +{ + size = get_size(); +} diff --git a/3rdparty/spirv-cross/shaders-msl/comp/array-length.msl2.argument.discrete.comp b/3rdparty/spirv-cross/shaders-msl/comp/array-length.msl2.argument.discrete.comp new file mode 100644 index 000000000..61e61916b --- /dev/null +++ b/3rdparty/spirv-cross/shaders-msl/comp/array-length.msl2.argument.discrete.comp @@ -0,0 +1,38 @@ +#version 450 +layout(local_size_x = 1) in; +layout(set = 0, binding = 1, std140) buffer SSBO +{ + uint size; + float v[]; +}; + +layout(set = 1, binding = 2, std430) buffer SSBO1 +{ + float bz[]; +} ssbos[2]; + +layout(set = 2, binding = 5, std140) buffer SSBO2 +{ + uint size2; + float w[]; +}; + +layout(set = 3, binding = 2, std430) buffer SSBO3 +{ + float bz[]; +} ssbos2[2]; + + +uint get_size() +{ + uint len = v.length(); + len += ssbos[1].bz.length(); + len += w.length(); + len += ssbos2[0].bz.length(); + return len; +} + +void main() +{ + size = get_size(); +} diff --git a/3rdparty/spirv-cross/shaders-msl/comp/complex-type-alias.comp b/3rdparty/spirv-cross/shaders-msl/comp/complex-type-alias.comp new file mode 100644 index 000000000..4b9b6eddb --- /dev/null +++ b/3rdparty/spirv-cross/shaders-msl/comp/complex-type-alias.comp @@ -0,0 +1,41 @@ +#version 450 +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +struct Foo0 +{ + float a; +}; + +struct Foo1 +{ + Foo0 a; +}; + +void Zero(out Foo0 v) +{ + v.a = 0.0; +} + +struct Foo2 +{ + Foo1 a; + float weight; +}; + +layout(std430, binding = 0) buffer SSBO +{ + Foo2 outputs[]; +}; + +shared Foo2 coeffs[64]; + +void main() +{ + Foo2 data; + data.weight = 0.0; + Zero(data.a.a); + coeffs[gl_LocalInvocationIndex] = data; + barrier(); + if (gl_LocalInvocationIndex == 0u) + outputs[gl_WorkGroupID.x] = coeffs[0]; +} diff --git a/3rdparty/spirv-cross/shaders/asm/frag/line-directive.line.asm.frag b/3rdparty/spirv-cross/shaders/asm/frag/line-directive.line.asm.frag new file mode 100644 index 000000000..9e08e9a89 --- /dev/null +++ b/3rdparty/spirv-cross/shaders/asm/frag/line-directive.line.asm.frag @@ -0,0 +1,221 @@ +; SPIR-V +; Version: 1.0 +; Generator: Google Shaderc over Glslang; 7 +; Bound: 83 +; Schema: 0 + OpCapability Shader + %2 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint Fragment %main "main" %FragColor %vColor + OpExecutionMode %main OriginUpperLeft + %1 = OpString "test.frag" + OpSource GLSL 450 %1 "// OpModuleProcessed entry-point main +// OpModuleProcessed client vulkan100 +// OpModuleProcessed target-env vulkan1.0 +// OpModuleProcessed entry-point main +#line 1 +#version 450 + +layout(location = 0) in float vColor; +layout(location = 0) out float FragColor; + +void func() +{ + FragColor = 1.0; + FragColor = 2.0; + if (vColor < 0.0) + { + FragColor = 3.0; + } + else + { + FragColor = 4.0; + } + + for (int i = 0; i < 40 + vColor; i += int(vColor) + 5) + { + FragColor += 0.2; + FragColor += 0.3; + } + + switch (int(vColor)) + { + case 0: + FragColor += 0.2; + break; + + case 1: + FragColor += 0.4; + break; + + default: + FragColor += 0.8; + break; + } + + do + { + FragColor += 10.0 + vColor; + } while(FragColor < 100.0); +} + +void main() +{ + func(); +} +" + OpSourceExtension "GL_GOOGLE_cpp_style_line_directive" + OpSourceExtension "GL_GOOGLE_include_directive" + OpName %main "main" + OpName %func_ "func(" + OpName %FragColor "FragColor" + OpName %vColor "vColor" + OpName %i "i" + OpDecorate %FragColor Location 0 + OpDecorate %vColor Location 0 + %void = OpTypeVoid + %4 = OpTypeFunction %void + %float = OpTypeFloat 32 +%_ptr_Output_float = OpTypePointer Output %float + %FragColor = OpVariable %_ptr_Output_float Output + %float_1 = OpConstant %float 1 + %float_2 = OpConstant %float 2 +%_ptr_Input_float = OpTypePointer Input %float + %vColor = OpVariable %_ptr_Input_float Input + %float_0 = OpConstant %float 0 + %bool = OpTypeBool + %float_3 = OpConstant %float 3 + %float_4 = OpConstant %float 4 + %int = OpTypeInt 32 1 + + ; Should be ignored + OpLine %1 5 0 + +%_ptr_Function_int = OpTypePointer Function %int + %int_0 = OpConstant %int 0 + %float_40 = OpConstant %float 40 +%float_0_200000003 = OpConstant %float 0.200000003 +%float_0_300000012 = OpConstant %float 0.300000012 + %int_5 = OpConstant %int 5 + + ; Should be ignored + OpLine %1 5 0 + +%float_0_400000006 = OpConstant %float 0.400000006 +%float_0_800000012 = OpConstant %float 0.800000012 + %float_10 = OpConstant %float 10 + %float_100 = OpConstant %float 100 + %main = OpFunction %void None %4 + OpLine %1 46 0 + %6 = OpLabel + OpLine %1 48 0 + %82 = OpFunctionCall %void %func_ + OpReturn + OpFunctionEnd + + ; Should be ignored + OpLine %1 5 0 + + %func_ = OpFunction %void None %4 + OpLine %1 6 0 + %8 = OpLabel + %i = OpVariable %_ptr_Function_int Function + OpLine %1 8 0 + OpStore %FragColor %float_1 + OpLine %1 9 0 + OpStore %FragColor %float_2 + OpLine %1 10 0 + %16 = OpLoad %float %vColor + %19 = OpFOrdLessThan %bool %16 %float_0 + OpSelectionMerge %21 None + OpBranchConditional %19 %20 %23 + %20 = OpLabel + OpLine %1 12 0 + OpStore %FragColor %float_3 + OpBranch %21 + %23 = OpLabel + OpLine %1 16 0 + OpStore %FragColor %float_4 + OpBranch %21 + %21 = OpLabel + OpLine %1 19 0 + OpStore %i %int_0 + OpBranch %29 + %29 = OpLabel + OpLoopMerge %31 %32 None + OpBranch %33 + %33 = OpLabel + %34 = OpLoad %int %i + %35 = OpConvertSToF %float %34 + %37 = OpLoad %float %vColor + %38 = OpFAdd %float %float_40 %37 + %39 = OpFOrdLessThan %bool %35 %38 + OpBranchConditional %39 %30 %31 + %30 = OpLabel + OpLine %1 21 0 + %41 = OpLoad %float %FragColor + %42 = OpFAdd %float %41 %float_0_200000003 + OpStore %FragColor %42 + OpLine %1 22 0 + %44 = OpLoad %float %FragColor + %45 = OpFAdd %float %44 %float_0_300000012 + OpStore %FragColor %45 + OpBranch %32 + %32 = OpLabel + OpLine %1 19 0 + %46 = OpLoad %float %vColor + %47 = OpConvertFToS %int %46 + %49 = OpIAdd %int %47 %int_5 + %50 = OpLoad %int %i + %51 = OpIAdd %int %50 %49 + OpStore %i %51 + OpBranch %29 + %31 = OpLabel + OpLine %1 25 0 + %52 = OpLoad %float %vColor + %53 = OpConvertFToS %int %52 + OpSelectionMerge %57 None + OpSwitch %53 %56 0 %54 1 %55 + %56 = OpLabel + OpLine %1 36 0 + %66 = OpLoad %float %FragColor + %67 = OpFAdd %float %66 %float_0_800000012 + OpStore %FragColor %67 + OpLine %1 37 0 + OpBranch %57 + %54 = OpLabel + OpLine %1 28 0 + %58 = OpLoad %float %FragColor + %59 = OpFAdd %float %58 %float_0_200000003 + OpStore %FragColor %59 + OpLine %1 29 0 + OpBranch %57 + %55 = OpLabel + OpLine %1 32 0 + %62 = OpLoad %float %FragColor + %63 = OpFAdd %float %62 %float_0_400000006 + OpStore %FragColor %63 + OpLine %1 33 0 + OpBranch %57 + %57 = OpLabel + OpBranch %70 + OpLine %1 43 0 + %70 = OpLabel + OpLoopMerge %72 %73 None + OpBranch %71 + %71 = OpLabel + OpLine %1 42 0 + %75 = OpLoad %float %vColor + %76 = OpFAdd %float %float_10 %75 + %77 = OpLoad %float %FragColor + %78 = OpFAdd %float %77 %76 + OpStore %FragColor %78 + OpBranch %73 + %73 = OpLabel + OpLine %1 43 0 + %79 = OpLoad %float %FragColor + %81 = OpFOrdLessThan %bool %79 %float_100 + OpBranchConditional %81 %70 %72 + %72 = OpLabel + OpReturn + OpFunctionEnd diff --git a/3rdparty/spirv-cross/shaders/frag/inside-loop-dominated-variable-preservation.frag b/3rdparty/spirv-cross/shaders/frag/inside-loop-dominated-variable-preservation.frag new file mode 100644 index 000000000..695bcaea8 --- /dev/null +++ b/3rdparty/spirv-cross/shaders/frag/inside-loop-dominated-variable-preservation.frag @@ -0,0 +1,24 @@ +#version 310 es +precision mediump float; +layout(location = 0) out vec4 FragColor; + +void main() +{ + float v; + bool written = false; + for (int j = 0; j < 10; j++) + { + for (int i = 0; i < 4; i++) + { + float w = 0.0; + if (written) + w += v; + else + v = 20.0; + + v += float(i); + written = true; + } + } + FragColor = vec4(1.0); +} diff --git a/3rdparty/spirv-cross/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag b/3rdparty/spirv-cross/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag new file mode 100644 index 000000000..faa20fa65 --- /dev/null +++ b/3rdparty/spirv-cross/shaders/vulkan/frag/scalar-block-layout-ubo-std430.vk.nocompat.invalid.frag @@ -0,0 +1,23 @@ +#version 450 +#extension GL_EXT_scalar_block_layout : require + +layout(std430, binding = 0) uniform UBO +{ + float a[1024]; + vec3 b[2]; +}; + +layout(std430, binding = 1) uniform UBOEnhancedLayout +{ + float c[1024]; + vec3 d[2]; + layout(offset = 10000) float e; +}; + +layout(location = 0) flat in int vIndex; +layout(location = 0) out float FragColor; + +void main() +{ + FragColor = a[vIndex] + c[vIndex] + e; +} diff --git a/3rdparty/spirv-cross/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen b/3rdparty/spirv-cross/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen new file mode 100644 index 000000000..0cb8e9577 --- /dev/null +++ b/3rdparty/spirv-cross/shaders/vulkan/rgen/execute_callable.nocompat.vk.rgen @@ -0,0 +1,16 @@ +#version 460 +#extension GL_NV_ray_tracing : require + +layout(set = 0, binding = 0) uniform accelerationStructureNV as; +layout(set = 0, binding = 1, rgba32f) uniform writeonly image2D image; +layout(location = 0) rayPayloadNV vec4 payload; +layout(location = 0) callableDataNV float blend; + +void main() +{ + vec3 origin = vec3(0.0); + vec3 direction = vec3(0.0, 0.0, -1.0); + traceNV(as, gl_RayFlagsOpaqueNV, 0xFF, 0u, 0u, 0u, origin, 0.0, direction, 100.0f, 0); + executeCallableNV(0u, 0); + imageStore(image, ivec2(gl_LaunchIDNV.xy), payload + vec4(blend)); +} diff --git a/3rdparty/spirv-cross/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen b/3rdparty/spirv-cross/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen new file mode 100644 index 000000000..9cca9a168 --- /dev/null +++ b/3rdparty/spirv-cross/shaders/vulkan/rgen/shader_record_buffer.nocompat.vk.rgen @@ -0,0 +1,16 @@ +#version 460 +#extension GL_NV_ray_tracing : require + +layout(shaderRecordNV, std430) buffer sbt +{ + vec3 direction; + float tmax; +}; + +layout(set = 0, binding = 0) uniform accelerationStructureNV as; +layout(location = 0) rayPayloadNV float payload; + +void main() +{ + traceNV(as, 0u, 255u, 0u, 1u, 0u, vec3(0.0), 0.0, direction, tmax, 0); +} diff --git a/3rdparty/spirv-cross/spirv_cfg.cpp b/3rdparty/spirv-cross/spirv_cfg.cpp index 2f3cf257a..cc1db1c73 100644 --- a/3rdparty/spirv-cross/spirv_cfg.cpp +++ b/3rdparty/spirv-cross/spirv_cfg.cpp @@ -124,7 +124,8 @@ bool CFG::post_order_visit(uint32_t block_id) // To the CFG, this is linear control flow, but we risk picking the do/while scope as our dominating block. // This makes sure that if we are accessing a variable outside the do/while, we choose the loop header as dominator. if (block.merge == SPIRBlock::MergeLoop) - add_branch(block_id, block.merge_block); + if (post_order_visit(block.merge_block)) + add_branch(block_id, block.merge_block); // Then visit ourselves. Start counting at one, to let 0 be a magic value for testing back vs. crossing edges. visit_order[block_id].get() = ++visit_count; @@ -152,6 +153,56 @@ void CFG::add_branch(uint32_t from, uint32_t to) add_unique(succeeding_edges[from], to); } +uint32_t CFG::find_loop_dominator(uint32_t block_id) const +{ + while (block_id != SPIRBlock::NoDominator) + { + auto itr = preceding_edges.find(block_id); + if (itr == end(preceding_edges)) + return SPIRBlock::NoDominator; + if (itr->second.empty()) + return SPIRBlock::NoDominator; + + uint32_t pred_block_id = SPIRBlock::NoDominator; + bool ignore_loop_header = false; + + // If we are a merge block, go directly to the header block. + // Only consider a loop dominator if we are branching from inside a block to a loop header. + // NOTE: In the CFG we forced an edge from header to merge block always to support variable scopes properly. + for (auto &pred : itr->second) + { + auto &pred_block = compiler.get(pred); + if (pred_block.merge == SPIRBlock::MergeLoop && pred_block.merge_block == block_id) + { + pred_block_id = pred; + ignore_loop_header = true; + break; + } + else if (pred_block.merge == SPIRBlock::MergeSelection && pred_block.next_block == block_id) + { + pred_block_id = pred; + break; + } + } + + // No merge block means we can just pick any edge. Loop headers dominate the inner loop, so any path we + // take will lead there. + if (pred_block_id == SPIRBlock::NoDominator) + pred_block_id = itr->second.front(); + + block_id = pred_block_id; + + if (!ignore_loop_header && block_id) + { + auto &block = compiler.get(block_id); + if (block.merge == SPIRBlock::MergeLoop) + return block_id; + } + } + + return block_id; +} + DominatorBuilder::DominatorBuilder(const CFG &cfg_) : cfg(cfg_) { diff --git a/3rdparty/spirv-cross/spirv_cfg.hpp b/3rdparty/spirv-cross/spirv_cfg.hpp index be10371c9..2262eb79b 100644 --- a/3rdparty/spirv-cross/spirv_cfg.hpp +++ b/3rdparty/spirv-cross/spirv_cfg.hpp @@ -93,6 +93,8 @@ public: walk_from(seen_blocks, b, op); } + uint32_t find_loop_dominator(uint32_t block) const; + private: struct VisitOrder { diff --git a/3rdparty/spirv-cross/spirv_common.hpp b/3rdparty/spirv-cross/spirv_common.hpp index 0cf1f5685..82e305a51 100644 --- a/3rdparty/spirv-cross/spirv_common.hpp +++ b/3rdparty/spirv-cross/spirv_common.hpp @@ -299,6 +299,7 @@ enum Types TypeCombinedImageSampler, TypeAccessChain, TypeUndef, + TypeString, TypeCount }; @@ -318,6 +319,23 @@ struct SPIRUndef : IVariant SPIRV_CROSS_DECLARE_CLONE(SPIRUndef) }; +struct SPIRString : IVariant +{ + enum + { + type = TypeString + }; + + explicit SPIRString(std::string str_) + : str(std::move(str_)) + { + } + + std::string str; + + SPIRV_CROSS_DECLARE_CLONE(SPIRString) +}; + // This type is only used by backends which need to access the combined image and sampler IDs separately after // the OpSampledImage opcode. struct SPIRCombinedImageSampler : IVariant @@ -766,6 +784,13 @@ struct SPIRFunction : IVariant SmallVector blocks; SmallVector combined_parameters; + struct EntryLine + { + uint32_t file_id = 0; + uint32_t line_literal = 0; + }; + EntryLine entry_line; + void add_local_variable(uint32_t id) { local_variables.push_back(id); diff --git a/3rdparty/spirv-cross/spirv_cpp.cpp b/3rdparty/spirv-cross/spirv_cpp.cpp index 90566c1cf..25966b32a 100644 --- a/3rdparty/spirv-cross/spirv_cpp.cpp +++ b/3rdparty/spirv-cross/spirv_cpp.cpp @@ -321,6 +321,8 @@ string CompilerCPP::compile() backend.explicit_struct_type = true; backend.use_initializer_list = true; + fixup_type_alias(); + reorder_type_alias(); build_function_control_flow_graphs_and_analyze(); update_active_builtins(); diff --git a/3rdparty/spirv-cross/spirv_cross.cpp b/3rdparty/spirv-cross/spirv_cross.cpp index 6b66b7460..53f9d2a21 100644 --- a/3rdparty/spirv-cross/spirv_cross.cpp +++ b/3rdparty/spirv-cross/spirv_cross.cpp @@ -708,6 +708,7 @@ bool Compiler::InterfaceVariableAccessHandler::handle(Op opcode, const uint32_t case OpAtomicAnd: case OpAtomicOr: case OpAtomicXor: + case OpArrayLength: // Invalid SPIR-V. if (length < 3) return false; @@ -872,65 +873,6 @@ bool Compiler::type_is_block_like(const SPIRType &type) const return false; } -void Compiler::fixup_type_alias() -{ - // Due to how some backends work, the "master" type of type_alias must be a block-like type if it exists. - // FIXME: Multiple alias types which are both block-like will be awkward, for now, it's best to just drop the type - // alias if the slave type is a block type. - ir.for_each_typed_id([&](uint32_t self, SPIRType &type) { - if (type.type_alias && type_is_block_like(type)) - { - // Become the master. - ir.for_each_typed_id([&](uint32_t other_id, SPIRType &other_type) { - if (other_id == type.self) - return; - - if (other_type.type_alias == type.type_alias) - other_type.type_alias = type.self; - }); - - this->get(type.type_alias).type_alias = self; - type.type_alias = 0; - } - }); - - ir.for_each_typed_id([&](uint32_t, SPIRType &type) { - if (type.type_alias && type_is_block_like(type)) - { - // This is not allowed, drop the type_alias. - type.type_alias = 0; - } - }); - - // Reorder declaration of types so that the master of the type alias is always emitted first. - // We need this in case a type B depends on type A (A must come before in the vector), but A is an alias of a type Abuffer, which - // means declaration of A doesn't happen (yet), and order would be B, ABuffer and not ABuffer, B. Fix this up here. - auto &type_ids = ir.ids_for_type[TypeType]; - for (auto alias_itr = begin(type_ids); alias_itr != end(type_ids); ++alias_itr) - { - auto &type = get(*alias_itr); - if (type.type_alias != 0 && !has_extended_decoration(type.type_alias, SPIRVCrossDecorationPacked)) - { - // We will skip declaring this type, so make sure the type_alias type comes before. - auto master_itr = find(begin(type_ids), end(type_ids), type.type_alias); - assert(master_itr != end(type_ids)); - - if (alias_itr < master_itr) - { - // Must also swap the type order for the constant-type joined array. - auto &joined_types = ir.ids_for_constant_or_type; - auto alt_alias_itr = find(begin(joined_types), end(joined_types), *alias_itr); - auto alt_master_itr = find(begin(joined_types), end(joined_types), *master_itr); - assert(alt_alias_itr != end(joined_types)); - assert(alt_master_itr != end(joined_types)); - - swap(*alias_itr, *master_itr); - swap(*alt_alias_itr, *alt_master_itr); - } - } - } -} - void Compiler::parse_fixup() { // Figure out specialization constants for work group sizes. @@ -964,8 +906,6 @@ void Compiler::parse_fixup() aliased_variables.push_back(var.self); } } - - fixup_type_alias(); } void Compiler::update_name_cache(unordered_set &cache_primary, const unordered_set &cache_secondary, @@ -1669,6 +1609,12 @@ SPIRBlock::ContinueBlockType Compiler::continue_block_type(const SPIRBlock &bloc if (block.merge == SPIRBlock::MergeLoop) return SPIRBlock::WhileLoop; + if (block.loop_dominator == SPIRBlock::NoDominator) + { + // Continue block is never reached from CFG. + return SPIRBlock::ComplexLoop; + } + auto &dominator = get(block.loop_dominator); if (execution_is_noop(block, dominator)) @@ -3096,6 +3042,7 @@ bool Compiler::AnalyzeVariableScopeAccessHandler::handle(spv::Op op, const uint3 } case OpArrayLength: + case OpLine: // Uses literals, but cannot be a phi variable or temporary, so ignore. break; @@ -3334,6 +3281,28 @@ void Compiler::analyze_variable_scope(SPIRFunction &entry, AnalyzeVariableScopeA unordered_map potential_loop_variables; + // Find the loop dominator block for each block. + for (auto &block_id : entry.blocks) + { + auto &block = get(block_id); + + auto itr = ir.continue_block_to_loop_header.find(block_id); + if (itr != end(ir.continue_block_to_loop_header) && itr->second != block_id) + { + // Continue block might be unreachable in the CFG, but we still like to know the loop dominator. + // Edge case is when continue block is also the loop header, don't set the dominator in this case. + block.loop_dominator = itr->second; + } + else + { + uint32_t loop_dominator = cfg.find_loop_dominator(block_id); + if (loop_dominator != block_id) + block.loop_dominator = loop_dominator; + else + block.loop_dominator = SPIRBlock::NoDominator; + } + } + // For each variable which is statically accessed. for (auto &var : handler.accessed_variables_to_block) { @@ -3381,6 +3350,34 @@ void Compiler::analyze_variable_scope(SPIRFunction &entry, AnalyzeVariableScopeA // Add it to a per-block list of variables. uint32_t dominating_block = builder.get_dominator(); + // For variables whose dominating block is inside a loop, there is a risk that these variables + // actually need to be preserved across loop iterations. We can express this by adding + // a "read" access to the loop header. + // In the dominating block, we must see an OpStore or equivalent as the first access of an OpVariable. + // Should that fail, we look for the outermost loop header and tack on an access there. + // Phi nodes cannot have this problem. + if (dominating_block) + { + auto &variable = get(var.first); + if (!variable.phi_variable) + { + auto *block = &get(dominating_block); + bool preserve = may_read_undefined_variable_in_block(*block, var.first); + if (preserve) + { + // Find the outermost loop scope. + while (block->loop_dominator != SPIRBlock::NoDominator) + block = &get(block->loop_dominator); + + if (block->self != dominating_block) + { + builder.add_block(block->self); + dominating_block = builder.get_dominator(); + } + } + } + } + // If all blocks here are dead code, this will be 0, so the variable in question // will be completely eliminated. if (dominating_block) @@ -3572,6 +3569,79 @@ void Compiler::analyze_variable_scope(SPIRFunction &entry, AnalyzeVariableScopeA } } +bool Compiler::may_read_undefined_variable_in_block(const SPIRBlock &block, uint32_t var) +{ + for (auto &op : block.ops) + { + auto *ops = stream(op); + switch (op.op) + { + case OpStore: + case OpCopyMemory: + if (ops[0] == var) + return false; + break; + + case OpAccessChain: + case OpInBoundsAccessChain: + case OpPtrAccessChain: + // Access chains are generally used to partially read and write. It's too hard to analyze + // if all constituents are written fully before continuing, so just assume it's preserved. + // This is the same as the parameter preservation analysis. + if (ops[2] == var) + return true; + break; + + case OpSelect: + // Variable pointers. + // We might read before writing. + if (ops[3] == var || ops[4] == var) + return true; + break; + + case OpPhi: + { + // Variable pointers. + // We might read before writing. + if (op.length < 2) + break; + + uint32_t count = op.length - 2; + for (uint32_t i = 0; i < count; i += 2) + if (ops[i + 2] == var) + return true; + break; + } + + case OpCopyObject: + case OpLoad: + if (ops[2] == var) + return true; + break; + + case OpFunctionCall: + { + if (op.length < 3) + break; + + // May read before writing. + uint32_t count = op.length - 3; + for (uint32_t i = 0; i < count; i++) + if (ops[i + 3] == var) + return true; + break; + } + + default: + break; + } + } + + // Not accessed somehow, at least not in a usual fashion. + // It's likely accessed in a branch, so assume we must preserve. + return true; +} + Bitset Compiler::get_buffer_block_flags(uint32_t id) const { return ir.get_buffer_block_flags(get(id)); @@ -4110,6 +4180,7 @@ bool Compiler::instruction_to_result_type(uint32_t &result_type, uint32_t &resul case OpCommitWritePipe: case OpGroupCommitReadPipe: case OpGroupCommitWritePipe: + case OpLine: return false; default: diff --git a/3rdparty/spirv-cross/spirv_cross.hpp b/3rdparty/spirv-cross/spirv_cross.hpp index 4129e8166..5bb6dcade 100644 --- a/3rdparty/spirv-cross/spirv_cross.hpp +++ b/3rdparty/spirv-cross/spirv_cross.hpp @@ -947,6 +947,7 @@ protected: void analyze_variable_scope(SPIRFunction &function, AnalyzeVariableScopeAccessHandler &handler); void find_function_local_luts(SPIRFunction &function, const AnalyzeVariableScopeAccessHandler &handler, bool single_function); + bool may_read_undefined_variable_in_block(const SPIRBlock &block, uint32_t var); void make_constant_null(uint32_t id, uint32_t type); @@ -972,15 +973,13 @@ protected: void unset_extended_member_decoration(uint32_t type, uint32_t index, ExtendedDecorations decoration); bool type_is_array_of_pointers(const SPIRType &type) const; + bool type_is_block_like(const SPIRType &type) const; + bool type_is_opaque_value(const SPIRType &type) const; private: // Used only to implement the old deprecated get_entry_point() interface. const SPIREntryPoint &get_first_entry_point(const std::string &name) const; SPIREntryPoint &get_first_entry_point(const std::string &name); - - void fixup_type_alias(); - bool type_is_block_like(const SPIRType &type) const; - bool type_is_opaque_value(const SPIRType &type) const; }; } // namespace SPIRV_CROSS_NAMESPACE diff --git a/3rdparty/spirv-cross/spirv_cross_c.cpp b/3rdparty/spirv-cross/spirv_cross_c.cpp index 6811d0274..4e2db1004 100644 --- a/3rdparty/spirv-cross/spirv_cross_c.cpp +++ b/3rdparty/spirv-cross/spirv_cross_c.cpp @@ -33,6 +33,11 @@ #if SPIRV_CROSS_C_API_REFLECT #include "spirv_reflect.hpp" #endif + +#ifdef HAVE_SPIRV_CROSS_GIT_VERSION +#include "gitversion.h" +#endif + #include "spirv_parser.hpp" #include #include @@ -412,6 +417,9 @@ spvc_result spvc_compiler_options_set_uint(spvc_compiler_options options, spvc_c case SPVC_COMPILER_OPTION_FLIP_VERTEX_Y: options->glsl.vertex.flip_vert_y = value != 0; break; + case SPVC_COMPILER_OPTION_EMIT_LINE_DIRECTIVES: + options->glsl.emit_line_directives = value != 0; + break; case SPVC_COMPILER_OPTION_GLSL_SUPPORT_NONZERO_BASE_INSTANCE: options->glsl.vertex.support_nonzero_base_instance = value != 0; @@ -533,6 +541,10 @@ spvc_result spvc_compiler_options_set_uint(spvc_compiler_options options, spvc_c case SPVC_COMPILER_OPTION_MSL_TEXTURE_BUFFER_NATIVE: options->msl.texture_buffer_native = value != 0; break; + + case SPVC_COMPILER_OPTION_MSL_BUFFER_SIZE_BUFFER_INDEX: + options->msl.buffer_size_buffer_index = value; + break; #endif default: @@ -743,6 +755,23 @@ spvc_bool spvc_compiler_msl_needs_swizzle_buffer(spvc_compiler compiler) #endif } +spvc_bool spvc_compiler_msl_needs_buffer_size_buffer(spvc_compiler compiler) +{ +#if SPIRV_CROSS_C_API_MSL + if (compiler->backend != SPVC_BACKEND_MSL) + { + compiler->context->report_error("MSL function used on a non-MSL backend."); + return SPVC_FALSE; + } + + auto &msl = *static_cast(compiler->compiler.get()); + return msl.needs_buffer_size_buffer() ? SPVC_TRUE : SPVC_FALSE; +#else + compiler->context->report_error("MSL function used on a non-MSL backend."); + return SPVC_FALSE; +#endif +} + spvc_bool spvc_compiler_msl_needs_aux_buffer(spvc_compiler compiler) { return spvc_compiler_msl_needs_swizzle_buffer(compiler); @@ -1902,6 +1931,15 @@ void spvc_get_version(unsigned *major, unsigned *minor, unsigned *patch) *patch = SPVC_C_API_VERSION_PATCH; } +const char *spvc_get_commit_revision_and_timestamp(void) +{ +#ifdef HAVE_SPIRV_CROSS_GIT_VERSION + return SPIRV_CROSS_GIT_REVISION; +#else + return ""; +#endif +} + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/3rdparty/spirv-cross/spirv_cross_c.h b/3rdparty/spirv-cross/spirv_cross_c.h index 43eb924fb..60ba0386a 100644 --- a/3rdparty/spirv-cross/spirv_cross_c.h +++ b/3rdparty/spirv-cross/spirv_cross_c.h @@ -33,7 +33,7 @@ extern "C" { /* Bumped if ABI or API breaks backwards compatibility. */ #define SPVC_C_API_VERSION_MAJOR 0 /* Bumped if APIs or enumerations are added in a backwards compatible way. */ -#define SPVC_C_API_VERSION_MINOR 9 +#define SPVC_C_API_VERSION_MINOR 12 /* Bumped if internal implementation details change. */ #define SPVC_C_API_VERSION_PATCH 0 @@ -58,6 +58,9 @@ extern "C" { */ SPVC_PUBLIC_API void spvc_get_version(unsigned *major, unsigned *minor, unsigned *patch); +/* Gets a human readable version string to identify which commit a particular binary was created from. */ +SPVC_PUBLIC_API const char *spvc_get_commit_revision_and_timestamp(void); + /* These types are opaque to the user. */ typedef struct spvc_context_s *spvc_context; typedef struct spvc_parsed_ir_s *spvc_parsed_ir; @@ -299,6 +302,7 @@ SPVC_PUBLIC_API void spvc_msl_resource_binding_init(spvc_msl_resource_binding *b #define SPVC_MSL_PUSH_CONSTANT_DESC_SET (~(0u)) #define SPVC_MSL_PUSH_CONSTANT_BINDING (0) #define SPVC_MSL_SWIZZLE_BUFFER_BINDING (~(1u)) +#define SPVC_MSL_BUFFER_SIZE_BUFFER_BINDING (~(2u)) /* Obsolete. Sticks around for backwards compatibility. */ #define SPVC_MSL_AUX_BUFFER_STRUCT_VERSION 1 @@ -443,6 +447,10 @@ typedef enum spvc_compiler_option SPVC_COMPILER_OPTION_GLSL_EMIT_UNIFORM_BUFFER_AS_PLAIN_UNIFORMS = 35 | SPVC_COMPILER_OPTION_GLSL_BIT, + SPVC_COMPILER_OPTION_MSL_BUFFER_SIZE_BUFFER_INDEX = 36 | SPVC_COMPILER_OPTION_MSL_BIT, + + SPVC_COMPILER_OPTION_EMIT_LINE_DIRECTIVES = 37 | SPVC_COMPILER_OPTION_COMMON_BIT, + SPVC_COMPILER_OPTION_INT_MAX = 0x7fffffff } spvc_compiler_option; @@ -524,6 +532,7 @@ SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_is_rasterization_disabled(spvc_compi /* Obsolete. Renamed to needs_swizzle_buffer. */ SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_aux_buffer(spvc_compiler compiler); SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_swizzle_buffer(spvc_compiler compiler); +SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_buffer_size_buffer(spvc_compiler compiler); SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_output_buffer(spvc_compiler compiler); SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_patch_output_buffer(spvc_compiler compiler); diff --git a/3rdparty/spirv-cross/spirv_cross_parsed_ir.cpp b/3rdparty/spirv-cross/spirv_cross_parsed_ir.cpp index 108000cd1..f0b6f7b1d 100644 --- a/3rdparty/spirv-cross/spirv_cross_parsed_ir.cpp +++ b/3rdparty/spirv-cross/spirv_cross_parsed_ir.cpp @@ -41,6 +41,7 @@ ParsedIR::ParsedIR() pool_group->pools[TypeCombinedImageSampler].reset(new ObjectPool); pool_group->pools[TypeAccessChain].reset(new ObjectPool); pool_group->pools[TypeUndef].reset(new ObjectPool); + pool_group->pools[TypeString].reset(new ObjectPool); } // Should have been default-implemented, but need this on MSVC 2013. diff --git a/3rdparty/spirv-cross/spirv_glsl.cpp b/3rdparty/spirv-cross/spirv_glsl.cpp index 32582fb62..cb7ed0fab 100644 --- a/3rdparty/spirv-cross/spirv_glsl.cpp +++ b/3rdparty/spirv-cross/spirv_glsl.cpp @@ -494,6 +494,8 @@ string CompilerGLSL::compile() backend.supports_extensions = true; // Scan the SPIR-V to find trivial uses of extensions. + fixup_type_alias(); + reorder_type_alias(); build_function_control_flow_graphs_and_analyze(); find_static_extensions(); fixup_image_load_store_access(); @@ -1408,6 +1410,8 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var) if (options.vulkan_semantics && var.storage == StorageClassPushConstant) attr.push_back("push_constant"); + else if (var.storage == StorageClassShaderRecordBufferNV) + attr.push_back("shaderRecordNV"); if (flags.get(DecorationRowMajor)) attr.push_back("row_major"); @@ -1453,14 +1457,14 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var) // Do not emit set = decoration in regular GLSL output, but // we need to preserve it in Vulkan GLSL mode. - if (var.storage != StorageClassPushConstant) + if (var.storage != StorageClassPushConstant && var.storage != StorageClassShaderRecordBufferNV) { if (flags.get(DecorationDescriptorSet) && options.vulkan_semantics) attr.push_back(join("set = ", dec.set)); } bool push_constant_block = options.vulkan_semantics && var.storage == StorageClassPushConstant; - bool ssbo_block = var.storage == StorageClassStorageBuffer || + bool ssbo_block = var.storage == StorageClassStorageBuffer || var.storage == StorageClassShaderRecordBufferNV || (var.storage == StorageClassUniform && typeflags.get(DecorationBufferBlock)); bool emulated_ubo = var.storage == StorageClassPushConstant && options.emit_push_constant_as_uniform_buffer; bool ubo_block = var.storage == StorageClassUniform && typeflags.get(DecorationBlock); @@ -1482,6 +1486,9 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var) if (!can_use_buffer_blocks && var.storage == StorageClassUniform) can_use_binding = false; + if (var.storage == StorageClassShaderRecordBufferNV) + can_use_binding = false; + if (can_use_binding && flags.get(DecorationBinding)) attr.push_back(join("binding = ", dec.binding)); @@ -1517,9 +1524,9 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var) return res; } -string CompilerGLSL::buffer_to_packing_standard(const SPIRType &type, bool check_std430) +string CompilerGLSL::buffer_to_packing_standard(const SPIRType &type, bool support_std430_without_scalar_layout) { - if (check_std430 && buffer_is_packing_standard(type, BufferPackingStd430)) + if (support_std430_without_scalar_layout && buffer_is_packing_standard(type, BufferPackingStd430)) return "std430"; else if (buffer_is_packing_standard(type, BufferPackingStd140)) return "std140"; @@ -1528,7 +1535,8 @@ string CompilerGLSL::buffer_to_packing_standard(const SPIRType &type, bool check require_extension_internal("GL_EXT_scalar_block_layout"); return "scalar"; } - else if (check_std430 && buffer_is_packing_standard(type, BufferPackingStd430EnhancedLayout)) + else if (support_std430_without_scalar_layout && + buffer_is_packing_standard(type, BufferPackingStd430EnhancedLayout)) { if (options.es && !options.vulkan_semantics) SPIRV_CROSS_THROW("Push constant block cannot be expressed as neither std430 nor std140. ES-targets do " @@ -1559,6 +1567,21 @@ string CompilerGLSL::buffer_to_packing_standard(const SPIRType &type, bool check require_extension_internal("GL_EXT_scalar_block_layout"); return "scalar"; } + else if (!support_std430_without_scalar_layout && options.vulkan_semantics && + buffer_is_packing_standard(type, BufferPackingStd430)) + { + // UBOs can support std430 with GL_EXT_scalar_block_layout. + require_extension_internal("GL_EXT_scalar_block_layout"); + return "std430"; + } + else if (!support_std430_without_scalar_layout && options.vulkan_semantics && + buffer_is_packing_standard(type, BufferPackingStd430EnhancedLayout)) + { + // UBOs can support std430 with GL_EXT_scalar_block_layout. + set_extended_decoration(type.self, SPIRVCrossDecorationPacked); + require_extension_internal("GL_EXT_scalar_block_layout"); + return "std430"; + } else { SPIRV_CROSS_THROW("Buffer block cannot be expressed as any of std430, std140, scalar, even with enhanced " @@ -1727,7 +1750,7 @@ void CompilerGLSL::emit_buffer_block_native(const SPIRVariable &var) auto &type = get(var.basetype); Bitset flags = ir.get_buffer_block_flags(var); - bool ssbo = var.storage == StorageClassStorageBuffer || + bool ssbo = var.storage == StorageClassStorageBuffer || var.storage == StorageClassShaderRecordBufferNV || ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock); bool is_restrict = ssbo && flags.get(DecorationRestrict); bool is_writeonly = ssbo && flags.get(DecorationNonReadable); @@ -1844,6 +1867,14 @@ const char *CompilerGLSL::to_storage_qualifiers_glsl(const SPIRVariable &var) { return "hitAttributeNV "; } + else if (var.storage == StorageClassCallableDataNV) + { + return "callableDataNV "; + } + else if (var.storage == StorageClassIncomingCallableDataNV) + { + return "callableDataInNV "; + } return ""; } @@ -2545,7 +2576,8 @@ void CompilerGLSL::emit_resources() ir.for_each_typed_id([&](uint32_t, SPIRVariable &var) { auto &type = this->get(var.basetype); - bool is_block_storage = type.storage == StorageClassStorageBuffer || type.storage == StorageClassUniform; + bool is_block_storage = type.storage == StorageClassStorageBuffer || type.storage == StorageClassUniform || + type.storage == StorageClassShaderRecordBufferNV; bool has_block_flags = ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) || ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock); @@ -2585,8 +2617,9 @@ void CompilerGLSL::emit_resources() if (var.storage != StorageClassFunction && type.pointer && (type.storage == StorageClassUniformConstant || type.storage == StorageClassAtomicCounter || - type.storage == StorageClassRayPayloadNV || type.storage == StorageClassHitAttributeNV || - type.storage == StorageClassIncomingRayPayloadNV) && + type.storage == StorageClassRayPayloadNV || type.storage == StorageClassIncomingRayPayloadNV || + type.storage == StorageClassCallableDataNV || type.storage == StorageClassIncomingCallableDataNV || + type.storage == StorageClassHitAttributeNV) && !is_hidden_variable(var)) { emit_uniform(var); @@ -2762,13 +2795,22 @@ string CompilerGLSL::dereference_expression(const SPIRType &expr_type, const std string CompilerGLSL::address_of_expression(const std::string &expr) { - // If this expression starts with a dereference operator ('*'), then - // just return the part after the operator. - // TODO: Strip parens if unnecessary? - if (expr.front() == '*') + if (expr.size() > 3 && expr[0] == '(' && expr[1] == '*' && expr.back() == ')') + { + // If we have an expression which looks like (*foo), taking the address of it is the same as stripping + // the first two and last characters. We might have to enclose the expression. + // This doesn't work for cases like (*foo + 10), + // but this is an r-value expression which we cannot take the address of anyways. + return enclose_expression(expr.substr(2, expr.size() - 3)); + } + else if (expr.front() == '*') + { + // If this expression starts with a dereference operator ('*'), then + // just return the part after the operator. return expr.substr(1); + } else - return join('&', expr); + return join('&', enclose_expression(expr)); } // Just like to_expression except that we enclose the expression inside parentheses if needed. @@ -9564,6 +9606,12 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) // Undefined value has been declared. break; + case OpLine: + { + emit_line_directive(ops[0], ops[1]); + break; + } + default: statement("// unimplemented op ", instruction.op); break; @@ -10503,6 +10551,8 @@ void CompilerGLSL::emit_function(SPIRFunction &func, const Bitset &return_flags) } } + if (func.entry_line.file_id != 0) + emit_line_directive(func.entry_line.file_id, func.entry_line.line_literal); emit_function_prototype(func, return_flags); begin_scope(); @@ -10523,6 +10573,8 @@ void CompilerGLSL::emit_function(SPIRFunction &func, const Bitset &return_flags) for (auto &v : func.local_variables) { auto &var = get(v); + var.deferred_declaration = false; + if (var.storage == StorageClassWorkgroup) { // Special variable type which cannot have initializer, @@ -10582,10 +10634,16 @@ void CompilerGLSL::emit_function(SPIRFunction &func, const Bitset &return_flags) var.deferred_declaration = false; } + // Enforce declaration order for regression testing purposes. + for (auto &block_id : func.blocks) + { + auto &block = get(block_id); + sort(begin(block.dominated_variables), end(block.dominated_variables)); + } + for (auto &line : current_function->fixup_hooks_in) line(); - entry_block.loop_dominator = SPIRBlock::NoDominator; emit_block_chain(entry_block); end_scope(); @@ -10844,44 +10902,6 @@ void CompilerGLSL::branch(uint32_t from, uint32_t cond, uint32_t true_block, uin } } -void CompilerGLSL::propagate_loop_dominators(const SPIRBlock &block) -{ - // Propagate down the loop dominator block, so that dominated blocks can back trace. - if (block.merge == SPIRBlock::MergeLoop || block.loop_dominator) - { - uint32_t dominator = block.merge == SPIRBlock::MergeLoop ? block.self : block.loop_dominator; - - auto set_dominator = [this](uint32_t self, uint32_t new_dominator) { - auto &dominated_block = this->get(self); - - // If we already have a loop dominator, we're trying to break out to merge targets - // which should not update the loop dominator. - if (!dominated_block.loop_dominator) - dominated_block.loop_dominator = new_dominator; - }; - - // After merging a loop, we inherit the loop dominator always. - if (block.merge_block) - set_dominator(block.merge_block, block.loop_dominator); - - if (block.true_block) - set_dominator(block.true_block, dominator); - if (block.false_block) - set_dominator(block.false_block, dominator); - if (block.next_block) - set_dominator(block.next_block, dominator); - if (block.default_block) - set_dominator(block.default_block, dominator); - - for (auto &c : block.cases) - set_dominator(c.block, dominator); - - // In older glslang output continue_block can be == loop header. - if (block.continue_block && block.continue_block != block.self) - set_dominator(block.continue_block, dominator); - } -} - // FIXME: This currently cannot handle complex continue blocks // as in do-while. // This should be seen as a "trivial" continue block. @@ -10902,7 +10922,6 @@ string CompilerGLSL::emit_continue_block(uint32_t continue_block, bool follow_tr // Stamp out all blocks one after each other. while ((ir.block_meta[block->self] & ParsedIR::BLOCK_META_LOOP_HEADER_BIT) == 0) { - propagate_loop_dominators(*block); // Write out all instructions we have in this block. emit_block_instructions(*block); @@ -11146,7 +11165,6 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method if (current_count == statement_count && condition_is_temporary) { - propagate_loop_dominators(child); uint32_t target_block = child.true_block; switch (continue_type) @@ -11210,8 +11228,6 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method void CompilerGLSL::flush_undeclared_variables(SPIRBlock &block) { - // Enforce declaration order for regression testing purposes. - sort(begin(block.dominated_variables), end(block.dominated_variables)); for (auto &v : block.dominated_variables) flush_variable_declaration(v); } @@ -11240,8 +11256,6 @@ void CompilerGLSL::emit_hoisted_temporaries(SmallVector void CompilerGLSL::emit_block_chain(SPIRBlock &block) { - propagate_loop_dominators(block); - bool select_branch_to_true_block = false; bool select_branch_to_false_block = false; bool skip_direct_branch = false; @@ -11258,6 +11272,15 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block) for (auto var : block.loop_variables) get(var).loop_variable_enable = true; + // Remember deferred declaration state. We will restore it before returning. + SmallVector rearm_dominated_variables(block.dominated_variables.size()); + for (size_t i = 0; i < block.dominated_variables.size(); i++) + { + uint32_t var_id = block.dominated_variables[i]; + auto &var = get(var_id); + rearm_dominated_variables[i] = var.deferred_declaration; + } + // This is the method often used by spirv-opt to implement loops. // The loop header goes straight into the continue block. // However, don't attempt this on ESSL 1.0, because if a loop variable is used in a continue block, @@ -11636,6 +11659,15 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block) // Forget about control dependent expressions now. block.invalidate_expressions.clear(); + + // After we return, we must be out of scope, so if we somehow have to re-emit this function, + // re-declare variables if necessary. + assert(rearm_dominated_variables.size() == block.dominated_variables.size()); + for (size_t i = 0; i < block.dominated_variables.size(); i++) + { + uint32_t var = block.dominated_variables[i]; + get(var).deferred_declaration = rearm_dominated_variables[i]; + } } void CompilerGLSL::begin_scope() @@ -11898,3 +11930,79 @@ void CompilerGLSL::reset_name_caches() block_names.clear(); function_overloads.clear(); } + +void CompilerGLSL::fixup_type_alias() +{ + // Due to how some backends work, the "master" type of type_alias must be a block-like type if it exists. + // FIXME: Multiple alias types which are both block-like will be awkward, for now, it's best to just drop the type + // alias if the slave type is a block type. + ir.for_each_typed_id([&](uint32_t self, SPIRType &type) { + if (type.type_alias && type_is_block_like(type)) + { + // Become the master. + ir.for_each_typed_id([&](uint32_t other_id, SPIRType &other_type) { + if (other_id == type.self) + return; + + if (other_type.type_alias == type.type_alias) + other_type.type_alias = type.self; + }); + + this->get(type.type_alias).type_alias = self; + type.type_alias = 0; + } + }); + + ir.for_each_typed_id([&](uint32_t, SPIRType &type) { + if (type.type_alias && type_is_block_like(type)) + { + // This is not allowed, drop the type_alias. + type.type_alias = 0; + } + }); +} + +void CompilerGLSL::reorder_type_alias() +{ + // Reorder declaration of types so that the master of the type alias is always emitted first. + // We need this in case a type B depends on type A (A must come before in the vector), but A is an alias of a type Abuffer, which + // means declaration of A doesn't happen (yet), and order would be B, ABuffer and not ABuffer, B. Fix this up here. + auto &type_ids = ir.ids_for_type[TypeType]; + for (auto alias_itr = begin(type_ids); alias_itr != end(type_ids); ++alias_itr) + { + auto &type = get(*alias_itr); + if (type.type_alias != 0 && !has_extended_decoration(type.type_alias, SPIRVCrossDecorationPacked)) + { + // We will skip declaring this type, so make sure the type_alias type comes before. + auto master_itr = find(begin(type_ids), end(type_ids), type.type_alias); + assert(master_itr != end(type_ids)); + + if (alias_itr < master_itr) + { + // Must also swap the type order for the constant-type joined array. + auto &joined_types = ir.ids_for_constant_or_type; + auto alt_alias_itr = find(begin(joined_types), end(joined_types), *alias_itr); + auto alt_master_itr = find(begin(joined_types), end(joined_types), *master_itr); + assert(alt_alias_itr != end(joined_types)); + assert(alt_master_itr != end(joined_types)); + + swap(*alias_itr, *master_itr); + swap(*alt_alias_itr, *alt_master_itr); + } + } + } +} + +void CompilerGLSL::emit_line_directive(uint32_t file_id, uint32_t line_literal) +{ + // If we are redirecting statements, ignore the line directive. + // Common case here is continue blocks. + if (redirect_statement) + return; + + if (options.emit_line_directives) + { + require_extension_internal("GL_GOOGLE_cpp_style_line_directive"); + statement_no_indent("#line ", line_literal, " \"", get(file_id).str, "\""); + } +} diff --git a/3rdparty/spirv-cross/spirv_glsl.hpp b/3rdparty/spirv-cross/spirv_glsl.hpp index 184bbbd81..6ca281fd0 100644 --- a/3rdparty/spirv-cross/spirv_glsl.hpp +++ b/3rdparty/spirv-cross/spirv_glsl.hpp @@ -103,6 +103,10 @@ public: // Does not apply to shader storage or push constant blocks. bool emit_uniform_buffer_as_plain_uniforms = false; + // Emit OpLine directives if present in the module. + // May not correspond exactly to original source, but should be a good approximation. + bool emit_line_directives = false; + enum Precision { DontCare, @@ -233,6 +237,7 @@ protected: virtual void emit_spv_amd_gcn_shader_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args, uint32_t count); virtual void emit_header(); + void emit_line_directive(uint32_t file_id, uint32_t line_literal); void build_workgroup_size(SmallVector &arguments, const SpecializationConstant &x, const SpecializationConstant &y, const SpecializationConstant &z); @@ -418,7 +423,6 @@ protected: void emit_specialization_constant_op(const SPIRConstantOp &constant); std::string emit_continue_block(uint32_t continue_block, bool follow_true_block, bool follow_false_block); bool attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method); - void propagate_loop_dominators(const SPIRBlock &block); void branch(uint32_t from, uint32_t to); void branch_to_continue(uint32_t from, uint32_t to); @@ -525,7 +529,7 @@ protected: bool buffer_is_packing_standard(const SPIRType &type, BufferPackingStandard packing, uint32_t start_offset = 0, uint32_t end_offset = ~(0u)); - std::string buffer_to_packing_standard(const SPIRType &type, bool enable_std430); + std::string buffer_to_packing_standard(const SPIRType &type, bool support_std430_without_scalar_layout); uint32_t type_to_packed_base_size(const SPIRType &type, BufferPackingStandard packing); uint32_t type_to_packed_alignment(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing); @@ -661,6 +665,9 @@ protected: char current_locale_radix_character = '.'; + void fixup_type_alias(); + void reorder_type_alias(); + private: void init(); }; diff --git a/3rdparty/spirv-cross/spirv_hlsl.cpp b/3rdparty/spirv-cross/spirv_hlsl.cpp index 46613c50f..d2dcdfb8a 100644 --- a/3rdparty/spirv-cross/spirv_hlsl.cpp +++ b/3rdparty/spirv-cross/spirv_hlsl.cpp @@ -4696,6 +4696,8 @@ string CompilerHLSL::compile() backend.can_return_array = false; backend.nonuniform_qualifier = "NonUniformResourceIndex"; + fixup_type_alias(); + reorder_type_alias(); build_function_control_flow_graphs_and_analyze(); validate_shader_model(); update_active_builtins(); diff --git a/3rdparty/spirv-cross/spirv_msl.cpp b/3rdparty/spirv-cross/spirv_msl.cpp index 1d57cceca..b4c5e0314 100644 --- a/3rdparty/spirv-cross/spirv_msl.cpp +++ b/3rdparty/spirv-cross/spirv_msl.cpp @@ -208,6 +208,7 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInFragCoord); builtin_frag_coord_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInFragCoord, var_id); } if (!has_sample_id && need_sample_pos) @@ -234,6 +235,7 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInSampleId); builtin_sample_id_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInSampleId, var_id); } if (need_vertex_params && (!has_vertex_idx || !has_base_vertex || !has_instance_idx || !has_base_instance)) @@ -263,7 +265,9 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInVertexIndex); builtin_vertex_idx_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInVertexIndex, var_id); } + if (!has_base_vertex) { uint32_t var_id = ir.increase_bound_by(1); @@ -272,7 +276,9 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInBaseVertex); builtin_base_vertex_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInBaseVertex, var_id); } + if (!has_instance_idx) { uint32_t var_id = ir.increase_bound_by(1); @@ -281,7 +287,9 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInInstanceIndex); builtin_instance_idx_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInInstanceIndex, var_id); } + if (!has_base_instance) { uint32_t var_id = ir.increase_bound_by(1); @@ -290,6 +298,7 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInBaseInstance); builtin_base_instance_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInBaseInstance, var_id); } } @@ -320,7 +329,9 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInInvocationId); builtin_invocation_id_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInInvocationId, var_id); } + if (!has_primitive_id) { uint32_t var_id = ir.increase_bound_by(1); @@ -329,6 +340,7 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInPrimitiveId); builtin_primitive_id_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInPrimitiveId, var_id); } } @@ -356,6 +368,7 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInSubgroupLocalInvocationId); builtin_subgroup_invocation_id_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInSubgroupLocalInvocationId, var_id); } if (!has_subgroup_size && need_subgroup_ge_mask) @@ -382,43 +395,82 @@ void CompilerMSL::build_implicit_builtins() set(var_id, type_ptr_id, StorageClassInput); set_decoration(var_id, DecorationBuiltIn, BuiltInSubgroupSize); builtin_subgroup_size_id = var_id; + mark_implicit_builtin(StorageClassInput, BuiltInSubgroupSize, var_id); } } if (needs_swizzle_buffer_def) { - uint32_t offset = ir.increase_bound_by(4); - uint32_t type_id = offset; - uint32_t type_ptr_id = offset + 1; - uint32_t type_ptr_ptr_id = offset + 2; - uint32_t var_id = offset + 3; - - // Create a buffer to hold extra data, including the swizzle constants. - SPIRType uint_type; - uint_type.basetype = SPIRType::UInt; - uint_type.width = 32; - set(type_id, uint_type); - - SPIRType uint_type_pointer = uint_type; - uint_type_pointer.pointer = true; - uint_type_pointer.pointer_depth = 1; - uint_type_pointer.parent_type = type_id; - uint_type_pointer.storage = StorageClassUniform; - set(type_ptr_id, uint_type_pointer); - set_decoration(type_ptr_id, DecorationArrayStride, 4); - - SPIRType uint_type_pointer2 = uint_type_pointer; - uint_type_pointer2.pointer_depth++; - uint_type_pointer2.parent_type = type_ptr_id; - set(type_ptr_ptr_id, uint_type_pointer2); - - set(var_id, type_ptr_ptr_id, StorageClassUniformConstant); + uint32_t var_id = build_constant_uint_array_pointer(); set_name(var_id, "spvSwizzleConstants"); // This should never match anything. - set_decoration(var_id, DecorationDescriptorSet, 0xFFFFFFFE); + set_decoration(var_id, DecorationDescriptorSet, kSwizzleBufferBinding); set_decoration(var_id, DecorationBinding, msl_options.swizzle_buffer_index); swizzle_buffer_id = var_id; } + + if (!buffers_requiring_array_length.empty()) + { + uint32_t var_id = build_constant_uint_array_pointer(); + set_name(var_id, "spvBufferSizeConstants"); + // This should never match anything. + set_decoration(var_id, DecorationDescriptorSet, kBufferSizeBufferBinding); + set_decoration(var_id, DecorationBinding, msl_options.buffer_size_buffer_index); + buffer_size_buffer_id = var_id; + } +} + +void CompilerMSL::mark_implicit_builtin(StorageClass storage, BuiltIn builtin, uint32_t id) +{ + Bitset *active_builtins = nullptr; + switch (storage) + { + case StorageClassInput: + active_builtins = &active_input_builtins; + break; + + case StorageClassOutput: + active_builtins = &active_output_builtins; + break; + + default: + break; + } + + assert(active_builtins != nullptr); + active_builtins->set(builtin); + get_entry_point().interface_variables.push_back(id); +} + +uint32_t CompilerMSL::build_constant_uint_array_pointer() +{ + uint32_t offset = ir.increase_bound_by(4); + uint32_t type_id = offset; + uint32_t type_ptr_id = offset + 1; + uint32_t type_ptr_ptr_id = offset + 2; + uint32_t var_id = offset + 3; + + // Create a buffer to hold extra data, including the swizzle constants. + SPIRType uint_type; + uint_type.basetype = SPIRType::UInt; + uint_type.width = 32; + set(type_id, uint_type); + + SPIRType uint_type_pointer = uint_type; + uint_type_pointer.pointer = true; + uint_type_pointer.pointer_depth = 1; + uint_type_pointer.parent_type = type_id; + uint_type_pointer.storage = StorageClassUniform; + set(type_ptr_id, uint_type_pointer); + set_decoration(type_ptr_id, DecorationArrayStride, 4); + + SPIRType uint_type_pointer2 = uint_type_pointer; + uint_type_pointer2.pointer_depth++; + uint_type_pointer2.parent_type = type_ptr_id; + set(type_ptr_ptr_id, uint_type_pointer2); + + set(var_id, type_ptr_ptr_id, StorageClassUniformConstant); + return var_id; } static string create_sampler_address(const char *prefix, MSLSamplerAddress addr) @@ -650,6 +702,7 @@ string CompilerMSL::compile() capture_output_to_buffer = msl_options.capture_output_to_buffer; is_rasterization_disabled = msl_options.disable_rasterization || capture_output_to_buffer; + fixup_type_alias(); replace_illegal_names(); struct_member_padding.clear(); @@ -666,6 +719,8 @@ string CompilerMSL::compile() set_enabled_interface_variables(get_active_interface_variables()); if (swizzle_buffer_id) active_interface_variables.insert(swizzle_buffer_id); + if (buffer_size_buffer_id) + active_interface_variables.insert(buffer_size_buffer_id); // Create structs to hold input, output and uniform variables. // Do output first to ensure out. is declared at top of entry function. @@ -691,6 +746,7 @@ string CompilerMSL::compile() // Mark any non-stage-in structs to be tightly packed. mark_packable_structs(); + reorder_type_alias(); // Add fixup hooks required by shader inputs and outputs. This needs to happen before // the loop, so the hooks aren't added multiple times. @@ -844,6 +900,7 @@ void CompilerMSL::extract_global_variables_from_function(uint32_t func_id, std:: case OpInBoundsAccessChain: case OpAccessChain: case OpPtrAccessChain: + case OpArrayLength: { uint32_t base_id = ops[2]; if (global_var_ids.find(base_id) != global_var_ids.end()) @@ -1884,21 +1941,38 @@ void CompilerMSL::fix_up_interface_member_indices(StorageClass storage, uint32_t // Returns the ID of the newly added variable, or zero if no variable was added. uint32_t CompilerMSL::add_interface_block(StorageClass storage, bool patch) { - // Accumulate the variables that should appear in the interface struct + // Accumulate the variables that should appear in the interface struct. SmallVector vars; - bool incl_builtins = (storage == StorageClassOutput || is_tessellation_shader()); + bool incl_builtins = storage == StorageClassOutput || is_tessellation_shader(); ir.for_each_typed_id([&](uint32_t var_id, SPIRVariable &var) { + if (var.storage != storage) + return; + auto &type = this->get(var.basetype); - BuiltIn bi_type = BuiltIn(get_decoration(var_id, DecorationBuiltIn)); - if (var.storage == storage && interface_variable_exists_in_entry_point(var.self) && - !is_hidden_variable(var, incl_builtins) && type.pointer && - (has_decoration(var_id, DecorationPatch) || is_patch_block(type)) == patch && - (!is_builtin_variable(var) || bi_type == BuiltInPosition || bi_type == BuiltInPointSize || - bi_type == BuiltInClipDistance || bi_type == BuiltInCullDistance || bi_type == BuiltInLayer || - bi_type == BuiltInViewportIndex || bi_type == BuiltInFragDepth || bi_type == BuiltInSampleMask || - (get_execution_model() == ExecutionModelTessellationEvaluation && - (bi_type == BuiltInTessLevelOuter || bi_type == BuiltInTessLevelInner)))) + + bool is_builtin = is_builtin_variable(var); + auto bi_type = BuiltIn(get_decoration(var_id, DecorationBuiltIn)); + + // These builtins are part of the stage in/out structs. + bool is_interface_block_builtin = + (bi_type == BuiltInPosition || bi_type == BuiltInPointSize || bi_type == BuiltInClipDistance || + bi_type == BuiltInCullDistance || bi_type == BuiltInLayer || bi_type == BuiltInViewportIndex || + bi_type == BuiltInFragDepth || bi_type == BuiltInSampleMask) || + (get_execution_model() == ExecutionModelTessellationEvaluation && + (bi_type == BuiltInTessLevelOuter || bi_type == BuiltInTessLevelInner)); + + bool is_active = interface_variable_exists_in_entry_point(var.self); + if (is_builtin && is_active) + { + // Only emit the builtin if it's active in this entry point. Interface variable list might lie. + is_active = has_active_builtin(bi_type, storage); + } + + bool filter_patch_decoration = (has_decoration(var_id, DecorationPatch) || is_patch_block(type)) == patch; + + if (is_active && !is_hidden_variable(var, incl_builtins) && type.pointer && filter_patch_decoration && + (!is_builtin || is_interface_block_builtin)) { vars.push_back(&var); } @@ -4027,6 +4101,17 @@ void CompilerMSL::emit_instruction(const Instruction &instruction) break; } + case OpArrayLength: + { + auto &type = expression_type(ops[2]); + uint32_t offset = type_struct_member_offset(type, ops[3]); + uint32_t stride = type_struct_member_array_stride(type, ops[3]); + + auto expr = join("(", to_buffer_size_expression(ops[2]), " - ", offset, ") / ", stride); + emit_op(ops[0], ops[1], expr, true); + break; + } + default: CompilerGLSL::emit_instruction(instruction); break; @@ -4558,7 +4643,13 @@ void CompilerMSL::emit_function_prototype(SPIRFunction &func, const Bitset &) if (msl_options.swizzle_texture_samples && has_sampled_images && is_sampled_image_type(arg_type)) { bool arg_is_array = !arg_type.array.empty(); - decl += join(", constant uint32_t", arg_is_array ? "* " : "& ", to_swizzle_expression(arg.id)); + decl += join(", constant uint", arg_is_array ? "* " : "& ", to_swizzle_expression(arg.id)); + } + + if (buffers_requiring_array_length.count(name_id)) + { + bool arg_is_array = !arg_type.array.empty(); + decl += join(", constant uint", arg_is_array ? "* " : "& ", to_buffer_size_expression(name_id)); } if (&arg != &func.arguments.back()) @@ -5038,17 +5129,20 @@ string CompilerMSL::to_func_call_arg(uint32_t id) arg_str += ", " + to_sampler_expression(var_id ? var_id : id); } + uint32_t var_id = 0; + auto *var = maybe_get(id); + if (var) + var_id = var->basevariable; + if (msl_options.swizzle_texture_samples && has_sampled_images && is_sampled_image_type(type)) { // Need to check the base variable in case we need to apply a qualified alias. - uint32_t var_id = 0; - auto *sampler_var = maybe_get(id); - if (sampler_var) - var_id = sampler_var->basevariable; - arg_str += ", " + to_swizzle_expression(var_id ? var_id : id); } + if (buffers_requiring_array_length.count(var_id)) + arg_str += ", " + to_buffer_size_expression(var_id ? var_id : id); + return arg_str; } @@ -5097,6 +5191,32 @@ string CompilerMSL::to_swizzle_expression(uint32_t id) } } +string CompilerMSL::to_buffer_size_expression(uint32_t id) +{ + auto expr = to_expression(id); + auto index = expr.find_first_of('['); + + // This is quite crude, but we need to translate the reference name (*spvDescriptorSetN.name) to + // the pointer expression spvDescriptorSetN.name to make a reasonable expression here. + // This only happens if we have argument buffers and we are using OpArrayLength on a lone SSBO in that set. + if (expr.size() >= 3 && expr[0] == '(' && expr[1] == '*') + expr = address_of_expression(expr); + + // If a buffer is part of an argument buffer translate this to a legal identifier. + for (auto &c : expr) + if (c == '.') + c = '_'; + + if (index == string::npos) + return expr + buffer_size_name_suffix; + else + { + auto buffer_expr = expr.substr(0, index); + auto array_expr = expr.substr(index); + return buffer_expr + buffer_size_name_suffix + array_expr; + } +} + // Checks whether the type is a Block all of whose members have DecorationPatch. bool CompilerMSL::is_patch_block(const SPIRType &type) { @@ -5786,7 +5906,7 @@ void CompilerMSL::entry_point_args_builtin(string &ep_args) { // Builtin variables ir.for_each_typed_id([&](uint32_t var_id, SPIRVariable &var) { - BuiltIn bi_type = ir.meta[var_id].decoration.builtin_type; + auto bi_type = BuiltIn(get_decoration(var_id, DecorationBuiltIn)); // Don't emit SamplePosition as a separate parameter. In the entry // point, we get that by calling get_sample_position() on the sample ID. @@ -5794,6 +5914,13 @@ void CompilerMSL::entry_point_args_builtin(string &ep_args) get_variable_data_type(var).basetype != SPIRType::Struct && get_variable_data_type(var).basetype != SPIRType::ControlPointArray) { + // If the builtin is not part of the active input builtin set, don't emit it. + // Relevant for multiple entry-point modules which might declare unused builtins. + if (!active_input_builtins.get(bi_type) || !interface_variable_exists_in_entry_point(var_id)) + return; + + // These builtins are emitted specially. If we pass this branch, the builtin directly matches + // a MSL builtin. if (bi_type != BuiltInSamplePosition && bi_type != BuiltInHelperInvocation && bi_type != BuiltInPatchVertices && bi_type != BuiltInTessLevelInner && bi_type != BuiltInTessLevelOuter && bi_type != BuiltInPosition && bi_type != BuiltInPointSize && @@ -6047,15 +6174,13 @@ string CompilerMSL::entry_point_args_classic(bool append_comma) void CompilerMSL::fix_up_shader_inputs_outputs() { - // Look for sampled images. Add hooks to set up the swizzle constants. + // Look for sampled images and buffer. Add hooks to set up the swizzle constants or array lengths. ir.for_each_typed_id([&](uint32_t, SPIRVariable &var) { auto &type = get_variable_data_type(var); - uint32_t var_id = var.self; + bool ssbo = has_decoration(type.self, DecorationBufferBlock); - if ((var.storage == StorageClassUniform || var.storage == StorageClassUniformConstant || - var.storage == StorageClassPushConstant || var.storage == StorageClassStorageBuffer) && - !is_hidden_variable(var)) + if (var.storage == StorageClassUniformConstant && !is_hidden_variable(var)) { if (msl_options.swizzle_texture_samples && has_sampled_images && is_sampled_image_type(type)) { @@ -6066,7 +6191,7 @@ void CompilerMSL::fix_up_shader_inputs_outputs() uint32_t desc_set = get_decoration(var_id, DecorationDescriptorSet); if (descriptor_set_is_argument_buffer(desc_set)) { - statement("constant uint32_t", is_array_type ? "* " : "& ", to_swizzle_expression(var_id), + statement("constant uint", is_array_type ? "* " : "& ", to_swizzle_expression(var_id), is_array_type ? " = &" : " = ", to_name(argument_buffer_ids[desc_set]), ".spvSwizzleConstants", "[", convert_to_string(get_metal_resource_index(var, SPIRType::Image)), "];"); @@ -6074,13 +6199,40 @@ void CompilerMSL::fix_up_shader_inputs_outputs() else { // If we have an array of images, we need to be able to index into it, so take a pointer instead. - statement("constant uint32_t", is_array_type ? "* " : "& ", to_swizzle_expression(var_id), + statement("constant uint", is_array_type ? "* " : "& ", to_swizzle_expression(var_id), is_array_type ? " = &" : " = ", to_name(swizzle_buffer_id), "[", convert_to_string(get_metal_resource_index(var, SPIRType::Image)), "];"); } }); } } + else if ((var.storage == StorageClassStorageBuffer || (var.storage == StorageClassUniform && ssbo)) && + !is_hidden_variable(var)) + { + if (buffers_requiring_array_length.count(var.self)) + { + auto &entry_func = this->get(ir.default_entry_point); + entry_func.fixup_hooks_in.push_back([this, &type, &var, var_id]() { + bool is_array_type = !type.array.empty(); + + uint32_t desc_set = get_decoration(var_id, DecorationDescriptorSet); + if (descriptor_set_is_argument_buffer(desc_set)) + { + statement("constant uint", is_array_type ? "* " : "& ", to_buffer_size_expression(var_id), + is_array_type ? " = &" : " = ", to_name(argument_buffer_ids[desc_set]), + ".spvBufferSizeConstants", "[", + convert_to_string(get_metal_resource_index(var, SPIRType::Image)), "];"); + } + else + { + // If we have an array of images, we need to be able to index into it, so take a pointer instead. + statement("constant uint", is_array_type ? "* " : "& ", to_buffer_size_expression(var_id), + is_array_type ? " = &" : " = ", to_name(buffer_size_buffer_id), "[", + convert_to_string(get_metal_resource_index(var, type.basetype)), "];"); + } + }); + } + } }); // Builtin variables @@ -6363,17 +6515,21 @@ string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg) if (msl_options.argument_buffers) { - // An awkward case where we need to emit *more* address space declarations (yay!). - // An example is where we pass down an array of buffer pointers to leaf functions. - // It's a constant array containing pointers to constants. - // The pointer array is always constant however. E.g. - // device SSBO * constant (&array)[N]. - // const device SSBO * constant (&array)[N]. - // constant SSBO * constant (&array)[N]. - // However, this only matters for argument buffers, since for MSL 1.0 style codegen, - // we emit the buffer array on stack instead, and that seems to work just fine apparently. - if (storage == StorageClassUniform || storage == StorageClassStorageBuffer) + uint32_t desc_set = get_decoration(name_id, DecorationDescriptorSet); + if ((storage == StorageClassUniform || storage == StorageClassStorageBuffer) && + descriptor_set_is_argument_buffer(desc_set)) + { + // An awkward case where we need to emit *more* address space declarations (yay!). + // An example is where we pass down an array of buffer pointers to leaf functions. + // It's a constant array containing pointers to constants. + // The pointer array is always constant however. E.g. + // device SSBO * constant (&array)[N]. + // const device SSBO * constant (&array)[N]. + // constant SSBO * constant (&array)[N]. + // However, this only matters for argument buffers, since for MSL 1.0 style codegen, + // we emit the buffer array on stack instead, and that seems to work just fine apparently. decl += " constant"; + } } decl += " (&"; @@ -7847,6 +8003,28 @@ bool CompilerMSL::OpCodePreprocessor::handle(Op opcode, const uint32_t *args, ui needs_subgroup_invocation_id = true; break; + case OpArrayLength: + { + auto *var = compiler.maybe_get_backing_variable(args[2]); + if (var) + compiler.buffers_requiring_array_length.insert(var->self); + break; + } + + case OpInBoundsAccessChain: + case OpAccessChain: + case OpPtrAccessChain: + { + // OpArrayLength might want to know if taking ArrayLength of an array of SSBOs. + uint32_t result_type = args[0]; + uint32_t id = args[1]; + uint32_t ptr = args[2]; + compiler.set(id, "", result_type, true); + compiler.register_read(id, ptr, true); + compiler.ir.ids[id].set_allow_type_rewrite(); + break; + } + default: break; } @@ -8242,6 +8420,8 @@ void CompilerMSL::analyze_argument_buffers() SmallVector resources_in_set[kMaxArgumentBuffers]; bool set_needs_swizzle_buffer[kMaxArgumentBuffers] = {}; + bool set_needs_buffer_sizes[kMaxArgumentBuffers] = {}; + bool needs_buffer_sizes = false; ir.for_each_typed_id([&](uint32_t self, SPIRVariable &var) { if ((var.storage == StorageClassUniform || var.storage == StorageClassUniformConstant || @@ -8290,24 +8470,29 @@ void CompilerMSL::analyze_argument_buffers() // Check if this descriptor set needs a swizzle buffer. if (needs_swizzle_buffer_def && is_sampled_image_type(type)) set_needs_swizzle_buffer[desc_set] = true; + else if (buffers_requiring_array_length.count(var_id) != 0) + { + set_needs_buffer_sizes[desc_set] = true; + needs_buffer_sizes = true; + } } }); - if (needs_swizzle_buffer_def) + if (needs_swizzle_buffer_def || needs_buffer_sizes) { - uint32_t swizzle_buffer_type_id = 0; + uint32_t uint_ptr_type_id = 0; // We might have to add a swizzle buffer resource to the set. for (uint32_t desc_set = 0; desc_set < kMaxArgumentBuffers; desc_set++) { - if (!set_needs_swizzle_buffer[desc_set]) + if (!set_needs_swizzle_buffer[desc_set] && !set_needs_buffer_sizes[desc_set]) continue; - if (swizzle_buffer_type_id == 0) + if (uint_ptr_type_id == 0) { uint32_t offset = ir.increase_bound_by(2); uint32_t type_id = offset; - swizzle_buffer_type_id = offset + 1; + uint_ptr_type_id = offset + 1; // Create a buffer to hold extra data, including the swizzle constants. SPIRType uint_type; @@ -8320,17 +8505,31 @@ void CompilerMSL::analyze_argument_buffers() uint_type_pointer.pointer_depth = 1; uint_type_pointer.parent_type = type_id; uint_type_pointer.storage = StorageClassUniform; - set(swizzle_buffer_type_id, uint_type_pointer); - set_decoration(swizzle_buffer_type_id, DecorationArrayStride, 4); + set(uint_ptr_type_id, uint_type_pointer); + set_decoration(uint_ptr_type_id, DecorationArrayStride, 4); } - uint32_t var_id = ir.increase_bound_by(1); - auto &var = set(var_id, swizzle_buffer_type_id, StorageClassUniformConstant); - set_name(var_id, "spvSwizzleConstants"); - set_decoration(var_id, DecorationDescriptorSet, desc_set); - set_decoration(var_id, DecorationBinding, kSwizzleBufferBinding); - resources_in_set[desc_set].push_back( - { &var, to_name(var_id), SPIRType::UInt, get_metal_resource_index(var, SPIRType::UInt) }); + if (set_needs_swizzle_buffer[desc_set]) + { + uint32_t var_id = ir.increase_bound_by(1); + auto &var = set(var_id, uint_ptr_type_id, StorageClassUniformConstant); + set_name(var_id, "spvSwizzleConstants"); + set_decoration(var_id, DecorationDescriptorSet, desc_set); + set_decoration(var_id, DecorationBinding, kSwizzleBufferBinding); + resources_in_set[desc_set].push_back( + { &var, to_name(var_id), SPIRType::UInt, get_metal_resource_index(var, SPIRType::UInt) }); + } + + if (set_needs_buffer_sizes[desc_set]) + { + uint32_t var_id = ir.increase_bound_by(1); + auto &var = set(var_id, uint_ptr_type_id, StorageClassUniformConstant); + set_name(var_id, "spvBufferSizeConstants"); + set_decoration(var_id, DecorationDescriptorSet, desc_set); + set_decoration(var_id, DecorationBinding, kBufferSizeBufferBinding); + resources_in_set[desc_set].push_back( + { &var, to_name(var_id), SPIRType::UInt, get_metal_resource_index(var, SPIRType::UInt) }); + } } } diff --git a/3rdparty/spirv-cross/spirv_msl.hpp b/3rdparty/spirv-cross/spirv_msl.hpp index 6e7c83c3b..7b2925c00 100644 --- a/3rdparty/spirv-cross/spirv_msl.hpp +++ b/3rdparty/spirv-cross/spirv_msl.hpp @@ -156,6 +156,10 @@ static const uint32_t kPushConstBinding = 0; // element to indicate the buffer binding for swizzle buffers. static const uint32_t kSwizzleBufferBinding = ~(1u); +// Special constant used in a MSLResourceBinding binding +// element to indicate the buffer binding for buffer size buffers to support OpArrayLength. +static const uint32_t kBufferSizeBufferBinding = ~(2u); + static const uint32_t kMaxArgumentBuffers = 8; // Decompiles SPIR-V to Metal Shading Language @@ -179,6 +183,7 @@ public: uint32_t shader_output_buffer_index = 28; uint32_t shader_patch_output_buffer_index = 27; uint32_t shader_tess_factor_buffer_index = 26; + uint32_t buffer_size_buffer_index = 25; uint32_t shader_input_wg_index = 0; bool enable_point_size_builtin = true; bool disable_rasterization = false; @@ -249,6 +254,13 @@ public: return used_swizzle_buffer; } + // Provide feedback to calling API to allow it to pass a buffer + // containing STORAGE_BUFFER buffer sizes to support OpArrayLength. + bool needs_buffer_size_buffer() const + { + return !buffers_requiring_array_length.empty(); + } + // Provide feedback to calling API to allow it to pass an output // buffer if the shader needs it. bool needs_output_buffer() const @@ -446,6 +458,7 @@ protected: std::string ensure_valid_name(std::string name, std::string pfx); std::string to_sampler_expression(uint32_t id); std::string to_swizzle_expression(uint32_t id); + std::string to_buffer_size_expression(uint32_t id); std::string builtin_qualifier(spv::BuiltIn builtin); std::string builtin_type_decl(spv::BuiltIn builtin); std::string built_in_func_arg(spv::BuiltIn builtin, bool prefix_comma); @@ -475,6 +488,7 @@ protected: void emit_barrier(uint32_t id_exe_scope, uint32_t id_mem_scope, uint32_t id_mem_sem); void emit_array_copy(const std::string &lhs, uint32_t rhs_id) override; void build_implicit_builtins(); + uint32_t build_constant_uint_array_pointer(); void emit_entry_point_declarations() override; uint32_t builtin_frag_coord_id = 0; uint32_t builtin_sample_id_id = 0; @@ -487,6 +501,7 @@ protected: uint32_t builtin_subgroup_invocation_id_id = 0; uint32_t builtin_subgroup_size_id = 0; uint32_t swizzle_buffer_id = 0; + uint32_t buffer_size_buffer_id = 0; void bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type) override; void bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type) override; @@ -497,6 +512,8 @@ protected: bool emit_tessellation_access_chain(const uint32_t *ops, uint32_t length); bool is_out_of_bounds_tessellation_level(uint32_t id_lhs); + void mark_implicit_builtin(spv::StorageClass storage, spv::BuiltIn builtin, uint32_t id); + Options msl_options; std::set spv_function_implementations; std::unordered_map vtx_attrs_by_location; @@ -535,6 +552,7 @@ protected: std::string patch_stage_out_var_name = "patchOut"; std::string sampler_name_suffix = "Smplr"; std::string swizzle_name_suffix = "Swzl"; + std::string buffer_size_name_suffix = "BufferSize"; std::string input_wg_var_name = "gl_in"; std::string output_buffer_var_name = "spvOut"; std::string patch_output_buffer_var_name = "spvPatchOut"; @@ -542,6 +560,7 @@ protected: spv::Op previous_instruction_opcode = spv::OpNop; std::unordered_map constexpr_samplers; + std::unordered_set buffers_requiring_array_length; SmallVector buffer_arrays; uint32_t argument_buffer_ids[kMaxArgumentBuffers]; diff --git a/3rdparty/spirv-cross/spirv_parser.cpp b/3rdparty/spirv-cross/spirv_parser.cpp index 1c0a830f2..af0b2b35d 100644 --- a/3rdparty/spirv-cross/spirv_parser.cpp +++ b/3rdparty/spirv-cross/spirv_parser.cpp @@ -162,12 +162,16 @@ void Parser::parse(const Instruction &instruction) case OpSourceContinued: case OpSourceExtension: case OpNop: - case OpLine: case OpNoLine: - case OpString: case OpModuleProcessed: break; + case OpString: + { + set(ops[0], extract_string(ir.spirv, instruction.offset + 1)); + break; + } + case OpMemoryModel: ir.addressing_model = static_cast(ops[0]); ir.memory_model = static_cast(ops[1]); @@ -1030,6 +1034,29 @@ void Parser::parse(const Instruction &instruction) break; } + case OpLine: + { + // OpLine might come at global scope, but we don't care about those since they will not be declared in any + // meaningful correct order. + // Ignore all OpLine directives which live outside a function. + if (current_block) + current_block->ops.push_back(instruction); + + // Line directives may arrive before first OpLabel. + // Treat this as the line of the function declaration, + // so warnings for arguments can propagate properly. + if (current_function) + { + // Store the first one we find and emit it before creating the function prototype. + if (current_function->entry_line.file_id == 0) + { + current_function->entry_line.file_id = ops[0]; + current_function->entry_line.line_literal = ops[1]; + } + } + break; + } + // Actual opcodes. default: { diff --git a/3rdparty/spirv-cross/spirv_reflect.cpp b/3rdparty/spirv-cross/spirv_reflect.cpp index 0b2c58575..b187a7fa6 100644 --- a/3rdparty/spirv-cross/spirv_reflect.cpp +++ b/3rdparty/spirv-cross/spirv_reflect.cpp @@ -256,6 +256,8 @@ string CompilerReflection::compile() json_stream = std::make_shared(); json_stream->set_current_locale_radix_character(current_locale_radix_character); json_stream->begin_json_object(); + fixup_type_alias(); + reorder_type_alias(); emit_entry_points(); emit_types(); emit_resources(); diff --git a/3rdparty/spirv-cross/test_shaders.py b/3rdparty/spirv-cross/test_shaders.py index 5c9e31e66..72b8a6241 100755 --- a/3rdparty/spirv-cross/test_shaders.py +++ b/3rdparty/spirv-cross/test_shaders.py @@ -180,6 +180,8 @@ def cross_compile_msl(shader, spirv, opt, iterations, paths): msl_args.append('2') msl_args.append('--msl-discrete-descriptor-set') msl_args.append('3') + if '.line.' in shader: + msl_args.append('--emit-line-directives') subprocess.check_call(msl_args) @@ -273,7 +275,11 @@ def cross_compile_hlsl(shader, spirv, opt, force_no_external_validation, iterati spirv_cross_path = paths.spirv_cross sm = shader_to_sm(shader) - subprocess.check_call([spirv_cross_path, '--entry', 'main', '--output', hlsl_path, spirv_path, '--hlsl-enable-compat', '--hlsl', '--shader-model', sm, '--iterations', str(iterations)]) + + hlsl_args = [spirv_cross_path, '--entry', 'main', '--output', hlsl_path, spirv_path, '--hlsl-enable-compat', '--hlsl', '--shader-model', sm, '--iterations', str(iterations)] + if '.line.' in shader: + hlsl_args.append('--emit-line-directives') + subprocess.check_call(hlsl_args) if not shader_is_invalid_spirv(hlsl_path): subprocess.check_call([paths.spirv_val, '--target-env', 'vulkan1.1', spirv_path]) @@ -345,6 +351,8 @@ def cross_compile(shader, vulkan, spirv, invalid_spirv, eliminate, is_legacy, fl extra_args += ['--flatten-multidimensional-arrays'] if push_ubo: extra_args += ['--glsl-emit-push-constant-as-ubo'] + if '.line.' in shader: + extra_args += ['--emit-line-directives'] spirv_cross_path = paths.spirv_cross diff --git a/3rdparty/spirv-cross/tests-other/c_api_test.c b/3rdparty/spirv-cross/tests-other/c_api_test.c index db396256d..413e2044a 100644 --- a/3rdparty/spirv-cross/tests-other/c_api_test.c +++ b/3rdparty/spirv-cross/tests-other/c_api_test.c @@ -103,6 +103,8 @@ static void compile(spvc_compiler compiler, const char *tag) int main(int argc, char **argv) { + const char *rev = NULL; + spvc_context context = NULL; spvc_parsed_ir ir = NULL; spvc_compiler compiler_glsl = NULL; @@ -116,6 +118,12 @@ int main(int argc, char **argv) SpvId *buffer = NULL; size_t word_count = 0; + rev = spvc_get_commit_revision_and_timestamp(); + if (!rev || *rev == '\0') + return 1; + + printf("Revision: %s\n", rev); + if (argc != 5) return 1;