Skip to content

Commit 6637610

Browse files
Merge pull request #1309 from KhronosGroup/fix-1305
Expose query if a resource was used as a comparison/depth resource
2 parents 14f24d7 + 941ccee commit 6637610

6 files changed

+48
-12
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ if (SPIRV_CROSS_STATIC)
323323
endif()
324324

325325
set(spirv-cross-abi-major 0)
326-
set(spirv-cross-abi-minor 29)
326+
set(spirv-cross-abi-minor 30)
327327
set(spirv-cross-abi-patch 0)
328328

329329
if (SPIRV_CROSS_SHARED)

main.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ static void print_resources(const Compiler &compiler, const char *tag, const Sma
277277
fprintf(stderr, " (Set : %u)", compiler.get_decoration(res.id, DecorationDescriptorSet));
278278
if (mask.get(DecorationBinding))
279279
fprintf(stderr, " (Binding : %u)", compiler.get_decoration(res.id, DecorationBinding));
280+
if (static_cast<const CompilerGLSL &>(compiler).variable_is_depth_or_compare(res.id))
281+
fprintf(stderr, " (comparison)");
280282
if (mask.get(DecorationInputAttachmentIndex))
281283
fprintf(stderr, " (Attachment : %u)", compiler.get_decoration(res.id, DecorationInputAttachmentIndex));
282284
if (mask.get(DecorationNonReadable))
@@ -1056,14 +1058,6 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
10561058
}
10571059
}
10581060

1059-
if (args.dump_resources)
1060-
{
1061-
print_resources(*compiler, res);
1062-
print_push_constant_resources(*compiler, res.push_constant_buffers);
1063-
print_spec_constants(*compiler);
1064-
print_capabilities_and_extensions(*compiler);
1065-
}
1066-
10671061
if (combined_image_samplers)
10681062
{
10691063
compiler->build_combined_image_samplers();
@@ -1095,7 +1089,17 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
10951089
static_cast<CompilerHLSL *>(compiler.get())->add_vertex_attribute_remap(remap);
10961090
}
10971091

1098-
return compiler->compile();
1092+
auto ret = compiler->compile();
1093+
1094+
if (args.dump_resources)
1095+
{
1096+
print_resources(*compiler, res);
1097+
print_push_constant_resources(*compiler, res.push_constant_buffers);
1098+
print_spec_constants(*compiler);
1099+
print_capabilities_and_extensions(*compiler);
1100+
}
1101+
1102+
return ret;
10991103
}
11001104

11011105
static int main_inner(int argc, char *argv[])

spirv_cross_c.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,23 @@ spvc_result spvc_compiler_flatten_buffer_block(spvc_compiler compiler, spvc_vari
711711
#endif
712712
}
713713

714+
spvc_bool spvc_compiler_variable_is_depth_or_compare(spvc_compiler compiler, spvc_variable_id id)
715+
{
716+
#if SPIRV_CROSS_C_API_GLSL
717+
if (compiler->backend == SPVC_BACKEND_NONE)
718+
{
719+
compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection.");
720+
return SPVC_ERROR_INVALID_ARGUMENT;
721+
}
722+
723+
return static_cast<CompilerGLSL *>(compiler->compiler.get())->variable_is_depth_or_compare(id) ? SPVC_TRUE : SPVC_FALSE;
724+
#else
725+
(void)id;
726+
compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection.");
727+
return SPVC_FALSE;
728+
#endif
729+
}
730+
714731
spvc_result spvc_compiler_hlsl_set_root_constants_layout(spvc_compiler compiler,
715732
const spvc_hlsl_root_constants *constant_info,
716733
size_t count)

spirv_cross_c.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333
/* Bumped if ABI or API breaks backwards compatibility. */
3434
#define SPVC_C_API_VERSION_MAJOR 0
3535
/* Bumped if APIs or enumerations are added in a backwards compatible way. */
36-
#define SPVC_C_API_VERSION_MINOR 29
36+
#define SPVC_C_API_VERSION_MINOR 30
3737
/* Bumped if internal implementation details change. */
3838
#define SPVC_C_API_VERSION_PATCH 0
3939

@@ -642,6 +642,8 @@ SPVC_PUBLIC_API spvc_result spvc_compiler_add_header_line(spvc_compiler compiler
642642
SPVC_PUBLIC_API spvc_result spvc_compiler_require_extension(spvc_compiler compiler, const char *ext);
643643
SPVC_PUBLIC_API spvc_result spvc_compiler_flatten_buffer_block(spvc_compiler compiler, spvc_variable_id id);
644644

645+
SPVC_PUBLIC_API spvc_bool spvc_compiler_variable_is_depth_or_compare(spvc_compiler compiler, spvc_variable_id id);
646+
645647
/*
646648
* HLSL specifics.
647649
* Maps to C++ API.

spirv_glsl.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,7 @@ void CompilerGLSL::fixup_image_load_store_access()
25432543

25442544
ir.for_each_typed_id<SPIRVariable>([&](uint32_t var, const SPIRVariable &) {
25452545
auto &vartype = expression_type(var);
2546-
if (vartype.basetype == SPIRType::Image)
2546+
if (vartype.basetype == SPIRType::Image && vartype.image.sampled == 2)
25472547
{
25482548
// Very old glslangValidator and HLSL compilers do not emit required qualifiers here.
25492549
// 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()
1370213702
});
1370313703
}
1370413704
}
13705+
13706+
bool CompilerGLSL::variable_is_depth_or_compare(VariableID id) const
13707+
{
13708+
return image_is_comparison(get<SPIRType>(get<SPIRVariable>(id).basetype), id);
13709+
}

spirv_glsl.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ class CompilerGLSL : public Compiler
228228
// The name of the uniform array will be the same as the interface block name.
229229
void flatten_buffer_block(VariableID id);
230230

231+
// After compilation, query if a variable ID was used as a depth resource.
232+
// This is meaningful for MSL since descriptor types depend on this knowledge.
233+
// Cases which return true:
234+
// - Images which are declared with depth = 1 image type.
235+
// - Samplers which are statically used at least once with Dref opcodes.
236+
// - Images which are statically used at least once with Dref opcodes.
237+
bool variable_is_depth_or_compare(VariableID id) const;
238+
231239
protected:
232240
void reset();
233241
void emit_function(SPIRFunction &func, const Bitset &return_flags);

0 commit comments

Comments
 (0)