c: Add C API for builtin stage IO reflection.
This commit is contained in:
Родитель
b4a380a04c
Коммит
406af8ff4d
|
@ -332,7 +332,7 @@ if (SPIRV_CROSS_STATIC)
|
|||
endif()
|
||||
|
||||
set(spirv-cross-abi-major 0)
|
||||
set(spirv-cross-abi-minor 46)
|
||||
set(spirv-cross-abi-minor 47)
|
||||
set(spirv-cross-abi-patch 0)
|
||||
|
||||
if (SPIRV_CROSS_SHARED)
|
||||
|
|
|
@ -70,6 +70,7 @@ struct BuiltInResource
|
|||
|
||||
// This is the actual value type of the builtin.
|
||||
// Typically float4, float, array<float, N> for the gl_PerVertex builtins.
|
||||
// If the builtin is a control point, the control point array type will be stripped away here as appropriate.
|
||||
TypeID value_type_id;
|
||||
|
||||
// This refers to the base resource which contains the builtin.
|
||||
|
|
|
@ -197,8 +197,11 @@ struct spvc_resources_s : ScratchMemoryAllocation
|
|||
SmallVector<spvc_reflected_resource> separate_images;
|
||||
SmallVector<spvc_reflected_resource> separate_samplers;
|
||||
SmallVector<spvc_reflected_resource> acceleration_structures;
|
||||
SmallVector<spvc_reflected_builtin_resource> builtin_inputs;
|
||||
SmallVector<spvc_reflected_builtin_resource> builtin_outputs;
|
||||
|
||||
bool copy_resources(SmallVector<spvc_reflected_resource> &outputs, const SmallVector<Resource> &inputs);
|
||||
bool copy_resources(SmallVector<spvc_reflected_builtin_resource> &outputs, const SmallVector<BuiltInResource> &inputs);
|
||||
bool copy_resources(const ShaderResources &resources);
|
||||
};
|
||||
|
||||
|
@ -1589,6 +1592,30 @@ bool spvc_resources_s::copy_resources(SmallVector<spvc_reflected_resource> &outp
|
|||
return true;
|
||||
}
|
||||
|
||||
bool spvc_resources_s::copy_resources(SmallVector<spvc_reflected_builtin_resource> &outputs,
|
||||
const SmallVector<BuiltInResource> &inputs)
|
||||
{
|
||||
for (auto &i : inputs)
|
||||
{
|
||||
spvc_reflected_builtin_resource br;
|
||||
|
||||
br.value_type_id = i.value_type_id;
|
||||
br.builtin = SpvBuiltIn(i.builtin);
|
||||
|
||||
auto &r = br.resource;
|
||||
r.base_type_id = i.resource.base_type_id;
|
||||
r.type_id = i.resource.type_id;
|
||||
r.id = i.resource.id;
|
||||
r.name = context->allocate_name(i.resource.name);
|
||||
if (!r.name)
|
||||
return false;
|
||||
|
||||
outputs.push_back(br);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool spvc_resources_s::copy_resources(const ShaderResources &resources)
|
||||
{
|
||||
if (!copy_resources(uniform_buffers, resources.uniform_buffers))
|
||||
|
@ -1615,6 +1642,10 @@ bool spvc_resources_s::copy_resources(const ShaderResources &resources)
|
|||
return false;
|
||||
if (!copy_resources(acceleration_structures, resources.acceleration_structures))
|
||||
return false;
|
||||
if (!copy_resources(builtin_inputs, resources.builtin_inputs))
|
||||
return false;
|
||||
if (!copy_resources(builtin_outputs, resources.builtin_outputs))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1773,6 +1804,37 @@ spvc_result spvc_resources_get_resource_list_for_type(spvc_resources resources,
|
|||
return SPVC_SUCCESS;
|
||||
}
|
||||
|
||||
spvc_result spvc_resources_get_builtin_resource_list_for_type(
|
||||
spvc_resources resources, spvc_builtin_resource_type type,
|
||||
const spvc_reflected_builtin_resource **resource_list,
|
||||
size_t *resource_size)
|
||||
{
|
||||
const SmallVector<spvc_reflected_builtin_resource> *list = nullptr;
|
||||
switch (type)
|
||||
{
|
||||
case SPVC_BUILTIN_RESOURCE_TYPE_STAGE_INPUT:
|
||||
list = &resources->builtin_inputs;
|
||||
break;
|
||||
|
||||
case SPVC_BUILTIN_RESOURCE_TYPE_STAGE_OUTPUT:
|
||||
list = &resources->builtin_outputs;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!list)
|
||||
{
|
||||
resources->context->report_error("Invalid argument.");
|
||||
return SPVC_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
*resource_size = list->size();
|
||||
*resource_list = list->data();
|
||||
return SPVC_SUCCESS;
|
||||
}
|
||||
|
||||
void spvc_compiler_set_decoration(spvc_compiler compiler, SpvId id, SpvDecoration decoration, unsigned argument)
|
||||
{
|
||||
compiler->compiler->set_decoration(id, static_cast<spv::Decoration>(decoration), argument);
|
||||
|
|
|
@ -40,7 +40,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 46
|
||||
#define SPVC_C_API_VERSION_MINOR 47
|
||||
/* Bumped if internal implementation details change. */
|
||||
#define SPVC_C_API_VERSION_PATCH 0
|
||||
|
||||
|
@ -99,6 +99,13 @@ typedef struct spvc_reflected_resource
|
|||
const char *name;
|
||||
} spvc_reflected_resource;
|
||||
|
||||
typedef struct spvc_reflected_builtin_resource
|
||||
{
|
||||
SpvBuiltIn builtin;
|
||||
spvc_type_id value_type_id;
|
||||
spvc_reflected_resource resource;
|
||||
} spvc_reflected_builtin_resource;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_entry_point
|
||||
{
|
||||
|
@ -221,6 +228,14 @@ typedef enum spvc_resource_type
|
|||
SPVC_RESOURCE_TYPE_INT_MAX = 0x7fffffff
|
||||
} spvc_resource_type;
|
||||
|
||||
typedef enum spvc_builtin_resource_type
|
||||
{
|
||||
SPVC_BUILTIN_RESOURCE_TYPE_UNKNOWN = 0,
|
||||
SPVC_BUILTIN_RESOURCE_TYPE_STAGE_INPUT = 1,
|
||||
SPVC_BUILTIN_RESOURCE_TYPE_STAGE_OUTPUT = 2,
|
||||
SPVC_BUILTIN_RESOURCE_TYPE_INT_MAX = 0x7fffffff
|
||||
} spvc_builtin_resource_type;
|
||||
|
||||
/* Maps to spirv_cross::SPIRType::BaseType. */
|
||||
typedef enum spvc_basetype
|
||||
{
|
||||
|
@ -809,6 +824,11 @@ SPVC_PUBLIC_API spvc_result spvc_resources_get_resource_list_for_type(spvc_resou
|
|||
const spvc_reflected_resource **resource_list,
|
||||
size_t *resource_size);
|
||||
|
||||
SPVC_PUBLIC_API spvc_result spvc_resources_get_builtin_resource_list_for_type(
|
||||
spvc_resources resources, spvc_builtin_resource_type type,
|
||||
const spvc_reflected_builtin_resource **resource_list,
|
||||
size_t *resource_size);
|
||||
|
||||
/*
|
||||
* Decorations.
|
||||
* Maps to C++ API.
|
||||
|
|
Загрузка…
Ссылка в новой задаче