Add reflection support for shader record buffers.

Reflect naming scheme in a context sensitive way that matches the
frontend.

GLSL -> use block name
HLSL (DXC) -> use instance name.
This commit is contained in:
Hans-Kristian Arntzen 2022-10-03 12:20:08 +02:00
Родитель c821207ae2
Коммит f3b1375b13
6 изменённых файлов: 17 добавлений и 2 удалений

Просмотреть файл

@ -332,7 +332,7 @@ if (SPIRV_CROSS_STATIC)
endif()
set(spirv-cross-abi-major 0)
set(spirv-cross-abi-minor 49)
set(spirv-cross-abi-minor 50)
set(spirv-cross-abi-patch 0)
if (SPIRV_CROSS_SHARED)

Просмотреть файл

@ -536,6 +536,7 @@ static void print_resources(const Compiler &compiler, const ShaderResources &res
print_resources(compiler, "push", res.push_constant_buffers);
print_resources(compiler, "counters", res.atomic_counters);
print_resources(compiler, "acceleration structures", res.acceleration_structures);
print_resources(compiler, "record buffers", res.shader_record_buffers);
print_resources(compiler, spv::StorageClassInput, res.builtin_inputs);
print_resources(compiler, spv::StorageClassOutput, res.builtin_outputs);
}

Просмотреть файл

@ -991,6 +991,10 @@ ShaderResources Compiler::get_shader_resources(const unordered_set<VariableID> *
// in the future.
res.push_constant_buffers.push_back({ var.self, var.basetype, type.self, get_name(var.self) });
}
else if (type.storage == StorageClassShaderRecordBufferKHR)
{
res.shader_record_buffers.push_back({ var.self, var.basetype, type.self, get_remapped_declared_block_name(var.self, ssbo_instance_name) });
}
// Images
else if (type.storage == StorageClassUniformConstant && type.basetype == SPIRType::Image &&
type.image.sampled == 2)

Просмотреть файл

@ -99,6 +99,8 @@ struct ShaderResources
// but keep the vector in case this restriction is lifted in the future.
SmallVector<Resource> push_constant_buffers;
SmallVector<Resource> shader_record_buffers;
// For Vulkan GLSL and HLSL source,
// these correspond to separate texture2D and samplers respectively.
SmallVector<Resource> separate_images;

Просмотреть файл

@ -194,6 +194,7 @@ struct spvc_resources_s : ScratchMemoryAllocation
SmallVector<spvc_reflected_resource> sampled_images;
SmallVector<spvc_reflected_resource> atomic_counters;
SmallVector<spvc_reflected_resource> push_constant_buffers;
SmallVector<spvc_reflected_resource> shader_record_buffers;
SmallVector<spvc_reflected_resource> separate_images;
SmallVector<spvc_reflected_resource> separate_samplers;
SmallVector<spvc_reflected_resource> acceleration_structures;
@ -1684,6 +1685,8 @@ bool spvc_resources_s::copy_resources(const ShaderResources &resources)
return false;
if (!copy_resources(push_constant_buffers, resources.push_constant_buffers))
return false;
if (!copy_resources(shader_record_buffers, resources.shader_record_buffers))
return false;
if (!copy_resources(separate_images, resources.separate_images))
return false;
if (!copy_resources(separate_samplers, resources.separate_samplers))
@ -1837,6 +1840,10 @@ spvc_result spvc_resources_get_resource_list_for_type(spvc_resources resources,
list = &resources->acceleration_structures;
break;
case SPVC_RESOURCE_TYPE_SHADER_RECORD_BUFFER:
list = &resources->shader_record_buffers;
break;
default:
break;
}

Просмотреть файл

@ -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 49
#define SPVC_C_API_VERSION_MINOR 50
/* Bumped if internal implementation details change. */
#define SPVC_C_API_VERSION_PATCH 0
@ -225,6 +225,7 @@ typedef enum spvc_resource_type
SPVC_RESOURCE_TYPE_SEPARATE_SAMPLERS = 11,
SPVC_RESOURCE_TYPE_ACCELERATION_STRUCTURE = 12,
SPVC_RESOURCE_TYPE_RAY_QUERY = 13,
SPVC_RESOURCE_TYPE_SHADER_RECORD_BUFFER = 14,
SPVC_RESOURCE_TYPE_INT_MAX = 0x7fffffff
} spvc_resource_type;