Skip to content

Commit

Permalink
Merge pull request #1309 from KhronosGroup/fix-1305
Browse files Browse the repository at this point in the history
Expose query if a resource was used as a comparison/depth resource
  • Loading branch information
HansKristian-Work committed Apr 3, 2020
2 parents 14f24d7 + 941ccee commit 6637610
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 13 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const CompilerGLSL &>(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))
Expand Down Expand Up @@ -1056,14 +1058,6 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
}
}

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();
Expand Down Expand Up @@ -1095,7 +1089,17 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
static_cast<CompilerHLSL *>(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[])
Expand Down
17 changes: 17 additions & 0 deletions spirv_cross_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompilerGLSL *>(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)
Expand Down
4 changes: 3 additions & 1 deletion spirv_cross_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion spirv_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ void CompilerGLSL::fixup_image_load_store_access()

ir.for_each_typed_id<SPIRVariable>([&](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.
Expand Down Expand Up @@ -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<SPIRType>(get<SPIRVariable>(id).basetype), id);
}
8 changes: 8 additions & 0 deletions spirv_glsl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ class CompilerGLSL : public Compiler
// 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);
Expand Down

0 comments on commit 6637610

Please sign in to comment.