mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-13 23:50:08 +00:00
MSL: Add C API for querying automatic resource bindings.
This commit is contained in:
parent
e2c95bdcbc
commit
3a4a9acac9
@ -287,7 +287,7 @@ if (SPIRV_CROSS_STATIC)
|
||||
endif()
|
||||
|
||||
set(spirv-cross-abi-major 0)
|
||||
set(spirv-cross-abi-minor 13)
|
||||
set(spirv-cross-abi-minor 14)
|
||||
set(spirv-cross-abi-patch 0)
|
||||
|
||||
if (SPIRV_CROSS_SHARED)
|
||||
|
@ -1031,6 +1031,44 @@ spvc_result spvc_compiler_msl_set_fragment_output_components(spvc_compiler compi
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned spvc_compiler_msl_get_automatic_resource_binding(spvc_compiler compiler, spvc_variable_id id)
|
||||
{
|
||||
#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 uint32_t(-1);
|
||||
}
|
||||
|
||||
auto &msl = *static_cast<CompilerMSL *>(compiler->compiler.get());
|
||||
msl.get_automatic_msl_resource_binding(id);
|
||||
return SPVC_SUCCESS;
|
||||
#else
|
||||
(void)id;
|
||||
compiler->context->report_error("MSL function used on a non-MSL backend.");
|
||||
return uint32_t(-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned spvc_compiler_msl_get_automatic_resource_binding_secondary(spvc_compiler compiler, spvc_variable_id id)
|
||||
{
|
||||
#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 uint32_t(-1);
|
||||
}
|
||||
|
||||
auto &msl = *static_cast<CompilerMSL *>(compiler->compiler.get());
|
||||
msl.get_automatic_msl_resource_binding_secondary(id);
|
||||
return SPVC_SUCCESS;
|
||||
#else
|
||||
(void)id;
|
||||
compiler->context->report_error("MSL function used on a non-MSL backend.");
|
||||
return uint32_t(-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
spvc_result spvc_compiler_compile(spvc_compiler compiler, const char **source)
|
||||
{
|
||||
SPVC_BEGIN_SAFE_SCOPE
|
||||
|
@ -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 13
|
||||
#define SPVC_C_API_VERSION_MINOR 14
|
||||
/* Bumped if internal implementation details change. */
|
||||
#define SPVC_C_API_VERSION_PATCH 0
|
||||
|
||||
@ -551,6 +551,9 @@ SPVC_PUBLIC_API spvc_result spvc_compiler_msl_remap_constexpr_sampler(spvc_compi
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_remap_constexpr_sampler_by_binding(spvc_compiler compiler, unsigned desc_set, unsigned binding, const spvc_msl_constexpr_sampler *sampler);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_set_fragment_output_components(spvc_compiler compiler, unsigned location, unsigned components);
|
||||
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_msl_get_automatic_resource_binding(spvc_compiler compiler, spvc_variable_id id);
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_msl_get_automatic_resource_binding_secondary(spvc_compiler compiler, spvc_variable_id id);
|
||||
|
||||
/*
|
||||
* Reflect resources.
|
||||
* Maps almost 1:1 to C++ API.
|
||||
|
@ -79,6 +79,16 @@ bool CompilerMSL::is_msl_resource_binding_used(ExecutionModel model, uint32_t de
|
||||
return itr != end(resource_bindings) && itr->second.second;
|
||||
}
|
||||
|
||||
uint32_t CompilerMSL::get_automatic_msl_resource_binding(uint32_t id) const
|
||||
{
|
||||
return get_extended_decoration(id, SPIRVCrossDecorationResourceIndexPrimary);
|
||||
}
|
||||
|
||||
uint32_t CompilerMSL::get_automatic_msl_resource_binding_secondary(uint32_t id) const
|
||||
{
|
||||
return get_extended_decoration(id, SPIRVCrossDecorationResourceIndexSecondary);
|
||||
}
|
||||
|
||||
void CompilerMSL::set_fragment_output_components(uint32_t location, uint32_t components)
|
||||
{
|
||||
fragment_output_components[location] = components;
|
||||
|
@ -314,6 +314,19 @@ public:
|
||||
// by remap_constexpr_sampler(_by_binding).
|
||||
bool is_msl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding);
|
||||
|
||||
// This must only be called after a successful call to CompilerMSL::compile().
|
||||
// For a variable resource ID obtained through reflection API, report the automatically assigned resource index.
|
||||
// If the descriptor set was part of an argument buffer, report the [[id(N)]],
|
||||
// or [[buffer/texture/sampler]] binding for other resources.
|
||||
// If the resource was a combined image sampler, report the image binding here,
|
||||
// use the _secondary version of this call to query the sampler half of the resource.
|
||||
// If no binding exists, uint32_t(-1) is returned.
|
||||
uint32_t get_automatic_msl_resource_binding(uint32_t id) const;
|
||||
|
||||
// Same as get_automatic_msl_resource_binding, but should only be used for combined image samplers, in which case the
|
||||
// sampler's binding is returned instead. For any other resource type, -1 is returned.
|
||||
uint32_t get_automatic_msl_resource_binding_secondary(uint32_t id) const;
|
||||
|
||||
// Compiles the SPIR-V code into Metal Shading Language.
|
||||
std::string compile() override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user