Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output reflection data with resource binding info? #1

Open
tgjones opened this issue Oct 25, 2018 · 5 comments
Open

Output reflection data with resource binding info? #1

tgjones opened this issue Oct 25, 2018 · 5 comments

Comments

@tgjones
Copy link

tgjones commented Oct 25, 2018

Hello again! I'm just having a little look at this library. Does it already generate some sort of resource reflection data? I saw some code for iterating resources but I'm not sure if that was doing something different.

spirv-cross has a nice --reflection flag now. I assume the same thing is available when using the API - would you be interested in having it exposed by this library?

@mellinoe
Copy link
Collaborator

@tgjones Sorry that I didn't respond to this issue. We did chat about this briefly in gitter, and I'm definitely interested in exposing the sort of information that the --reflection flag gives. As I said yesterday, I think it would be very useful to be able to directly get a ResourceLayoutDescription[] with all of the elements properly filled in from a set of shaders. On top of that, it should also be possible to get finer-grained information, like the struct types used, and all of the field offsets, etc.

@aniongithub
Copy link

I came here looking for the same thing too. I'd vote this solution as better than the ShaderGen one anyday because this solves the "glue code" problem elegantly.

@gleblebedev
Copy link
Contributor

After looking into SPIR-V code standard and trying to use the reflection for a project I can contribute to the conversation.

Subset of SPIR-V byte codes useful for reflection is quite small. You can use native code to do that but it won't tell you any more useful information. I would recommend to stick with fully managed code for the parser. Each SPIR-V instruction has size embedded into byte code so it's trivial to skip unknown instructions. I bet that the byte code won't change much here with upcoming Vulkan 1.1.

So from the code you can get Uniforms and Uniform Constants. Textures and Samplers are passed as Uniform Constants and every thing else I've encountered are Uniforms. For our purpose it doesn't matter and both could be treated the same way.

Through OpDecorate command we can learn Set and Binding values for each uniform. This is very useful as we can detect what resources are actually used in what stages of the shader. This becomes critical for Direct3D 11 compatibility as we need to remap the uniforms to registers. As Pipeline includes both Shaders and ResourceLayout we can easily mark sets in the layout using the reflection data. This alone would be a great progress for the library.

Through optinal OpName command we can get name of the uniform (it's not that straight forward for uniform buffer with a structure but it's just one hop away in the type info). As this info isn't available we can use an external resolver to get a name by set, binding and kind. All it need is resource layout information. At the same time it can check that set inf binding are valid indices and ResourceKind match the one provided via reflection.

Overall it doesn't look like a big change to the API but it could be very useful.
@mellinoe would you agree to give it a try?

@mellinoe
Copy link
Collaborator

@gleblebedev I recently added reflection info into the VertexFragmentCompilationResult class. You will now get a VertexElementDescription[] array, and a ResourceLayoutDescription[] array, usable for creating ResourceLayouts and/or Pipelines. On top of that, the next version of Veldrid is going to include the "overrides" described in https://github.com/mellinoe/veldrid/issues/203. There will also be a new ResourceLayoutElementOptions.Unused` flag so that you can specify resource slots that aren't used by a Pipeline, and can be filled with anything without breaking validation.

The implementation of this doesn't used a managed SPIR-V parser, and just piggy-backs onto the resource scanning that the native cross-compiler already has to do. You could write a managed SPIR-V parser and output the same information that Veldrid.SPIRV does, and use it to fill in the "Reflected" data in a PipelineDescription.

@gleblebedev
Copy link
Contributor

It looks like you've already implemented the feature so I have nothing to do :)

smoogipoo pushed a commit to smoogipoo/veldrid-spirv that referenced this issue Aug 22, 2023
Fix libveldrid-spirv.dylib not working on macOS 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants