diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cce2df7..51d5e722 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -323,7 +323,7 @@ if (SPIRV_CROSS_STATIC) endif() set(spirv-cross-abi-major 0) -set(spirv-cross-abi-minor 29) +set(spirv-cross-abi-minor 30) set(spirv-cross-abi-patch 0) if (SPIRV_CROSS_SHARED) diff --git a/main.cpp b/main.cpp index 83b041de..51090bd0 100644 --- a/main.cpp +++ b/main.cpp @@ -277,6 +277,8 @@ static void print_resources(const Compiler &compiler, const char *tag, const Sma fprintf(stderr, " (Set : %u)", compiler.get_decoration(res.id, DecorationDescriptorSet)); if (mask.get(DecorationBinding)) fprintf(stderr, " (Binding : %u)", compiler.get_decoration(res.id, DecorationBinding)); + if (static_cast(compiler).variable_is_depth_or_compare(res.id)) + fprintf(stderr, " (comparison)"); if (mask.get(DecorationInputAttachmentIndex)) fprintf(stderr, " (Attachment : %u)", compiler.get_decoration(res.id, DecorationInputAttachmentIndex)); if (mask.get(DecorationNonReadable)) @@ -1056,14 +1058,6 @@ static string compile_iteration(const CLIArguments &args, std::vector } } - if (args.dump_resources) - { - print_resources(*compiler, res); - print_push_constant_resources(*compiler, res.push_constant_buffers); - print_spec_constants(*compiler); - print_capabilities_and_extensions(*compiler); - } - if (combined_image_samplers) { compiler->build_combined_image_samplers(); @@ -1095,7 +1089,17 @@ static string compile_iteration(const CLIArguments &args, std::vector static_cast(compiler.get())->add_vertex_attribute_remap(remap); } - return compiler->compile(); + auto ret = compiler->compile(); + + if (args.dump_resources) + { + print_resources(*compiler, res); + print_push_constant_resources(*compiler, res.push_constant_buffers); + print_spec_constants(*compiler); + print_capabilities_and_extensions(*compiler); + } + + return ret; } static int main_inner(int argc, char *argv[]) diff --git a/spirv_cross_c.cpp b/spirv_cross_c.cpp index 2750afcb..528a51f5 100644 --- a/spirv_cross_c.cpp +++ b/spirv_cross_c.cpp @@ -711,6 +711,23 @@ spvc_result spvc_compiler_flatten_buffer_block(spvc_compiler compiler, spvc_vari #endif } +spvc_bool spvc_compiler_variable_is_depth_or_compare(spvc_compiler compiler, spvc_variable_id id) +{ +#if SPIRV_CROSS_C_API_GLSL + if (compiler->backend == SPVC_BACKEND_NONE) + { + compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection."); + return SPVC_ERROR_INVALID_ARGUMENT; + } + + return static_cast(compiler->compiler.get())->variable_is_depth_or_compare(id) ? SPVC_TRUE : SPVC_FALSE; +#else + (void)id; + compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection."); + return SPVC_FALSE; +#endif +} + spvc_result spvc_compiler_hlsl_set_root_constants_layout(spvc_compiler compiler, const spvc_hlsl_root_constants *constant_info, size_t count) diff --git a/spirv_cross_c.h b/spirv_cross_c.h index 6be2d35c..8c74792f 100644 --- a/spirv_cross_c.h +++ b/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 29 +#define SPVC_C_API_VERSION_MINOR 30 /* Bumped if internal implementation details change. */ #define SPVC_C_API_VERSION_PATCH 0 @@ -642,6 +642,8 @@ SPVC_PUBLIC_API spvc_result spvc_compiler_add_header_line(spvc_compiler compiler SPVC_PUBLIC_API spvc_result spvc_compiler_require_extension(spvc_compiler compiler, const char *ext); SPVC_PUBLIC_API spvc_result spvc_compiler_flatten_buffer_block(spvc_compiler compiler, spvc_variable_id id); +SPVC_PUBLIC_API spvc_bool spvc_compiler_variable_is_depth_or_compare(spvc_compiler compiler, spvc_variable_id id); + /* * HLSL specifics. * Maps to C++ API. diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index d5c42833..166364f1 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -2543,7 +2543,7 @@ void CompilerGLSL::fixup_image_load_store_access() ir.for_each_typed_id([&](uint32_t var, const SPIRVariable &) { auto &vartype = expression_type(var); - if (vartype.basetype == SPIRType::Image) + if (vartype.basetype == SPIRType::Image && vartype.image.sampled == 2) { // Very old glslangValidator and HLSL compilers do not emit required qualifiers here. // Solve this by making the image access as restricted as possible and loosen up if we need to. @@ -13702,3 +13702,8 @@ void CompilerGLSL::emit_inout_fragment_outputs_copy_to_subpass_inputs() }); } } + +bool CompilerGLSL::variable_is_depth_or_compare(VariableID id) const +{ + return image_is_comparison(get(get(id).basetype), id); +} diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index 065bdf04..f66202a0 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -228,6 +228,14 @@ public: // The name of the uniform array will be the same as the interface block name. void flatten_buffer_block(VariableID id); + // After compilation, query if a variable ID was used as a depth resource. + // This is meaningful for MSL since descriptor types depend on this knowledge. + // Cases which return true: + // - Images which are declared with depth = 1 image type. + // - Samplers which are statically used at least once with Dref opcodes. + // - Images which are statically used at least once with Dref opcodes. + bool variable_is_depth_or_compare(VariableID id) const; + protected: void reset(); void emit_function(SPIRFunction &func, const Bitset &return_flags);