KhronosGroup / KhronosGroup/SPIRV-Cross

Unable to use reflection to retrieve layout(buffer_reference) buffer types without direct usage

Open
#2,118 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
GLSL
Stars
2.5k
Forks
713
Avg merge
2d 18h
Merged PRs (30d)
16

Description

Hello!

I am attempting to use SPIRV-Cross's reflection functionality to extract storage buffers/uniform buffers/push constants/structs/etc used by a shader. I use those struct definitions to generate nice CPU-side interfaces for reading/writing to them (Vulkan and Java is really not a good fit, but it's what I have...). I am going heavy on descriptor indexing and device buffer address usage.

Unfortunately, I am unable to retrieve said struct definitions if a layout(buffer_reference) buffer is only used by casting a uint64_t pointer. Here is a minimal shader with this problem:
```GLSL
#version 460

#extension GL_EXT_buffer_reference2 : require
#extension GL_ARB_gpu_shader_int64 : require

layout(location = 0) in uint64_t pointer;
layout(location = 0) out float x;

layout(buffer_reference, std430) buffer BufferReferenceTest {
float x;
};

void main() {
BufferReferenceTest bufferReference = BufferReferenceTest(pointer);
x = bufferReference.x;
}
```
Surely, the compiler is aware of BufferReferenceTest's existance, since it appears in the SPIR-V disassembly, and can be easily retrieved indirectly if I store a reference to it in for example a uniform buffer. However, I can't find a way to simply get BufferReferenceTest's type when that's not the case. I suppose what I really want to do is not to look at _resources_ directly, but rather go through all user-defined _types_ to find layout(buffer_reference) buffers. Unfortunately, there is no mention of how to do something like that any of the documentation I have been able to find.

Any help with this would be greatly appreciated!

PS: I'm using the C API.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with SPIRV-Cross's C API reflection entry points and inspect how the provided SPIR-V represents BufferReferenceTest when it is reached only through a uint64_t cast. Determine how reflection should expose user-defined layout(buffer_reference) types beyond resources, then verify the type is retrievable through the C API using the shader example.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.