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

How do I query vertex attributes that are not used in shader? #2280

Open
Algor1tm opened this issue Feb 19, 2024 · 4 comments
Open

How do I query vertex attributes that are not used in shader? #2280

Algor1tm opened this issue Feb 19, 2024 · 4 comments
Labels
question Further progress depends on answer from issue creator.

Comments

@Algor1tm
Copy link

Why spirv_cross::ShaderResources::stage_inputs does not contain inputs that do not used by shader(vertex stage)? I think it is important information to calculate offsets of each attribute and stride for whole vertex. Is there a way to get this information?

@HansKristian-Work
Copy link
Contributor

It should contain that. Which API did you use?

Compiler::get_shader_resources() should return all variables that are part of the entry point. Remember that unused vertex inputs may be stripped away by your GLSL or HLSL compiler, which makes it impossible for spirv-cross to know about missing inputs.

Do you have an example SPIR-V?

@HansKristian-Work HansKristian-Work added the question Further progress depends on answer from issue creator. label Mar 6, 2024
@Algor1tm
Copy link
Author

Algor1tm commented Mar 6, 2024

I use Vulkan and C++, compile with shaderc with generate debug info. I link Spirv-cross and shaderc libraries from VulkanSDK. Shader example looks like this:

#version 460 core
#pragma stage : vertex  // used by my parser

layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec2 a_TexCoords;
layout(location = 2) in vec3 a_Normal;
layout(location = 3) in vec3 a_Tangent;
layout(location = 4) in vec3 a_Bitangent;

layout(push_constant) uniform u_MaterialData
{
    mat4 u_Transform;
};

void main()
{
    gl_Position = u_Transform * vec4(a_Position, 1.0);
}

ShaderResources::stage_inputs contains only a_Position, but spirv byte code actually contains all inputs.

@HansKristian-Work
Copy link
Contributor

How do you invoke the SPIRV-Cross API? I'm getting the inputs just fine here in both --reflect and --dump-resources. Also, do you have the exact SPIR-V you're using?

./spirv-cross /tmp/test.spv --reflect

    "inputs" : [
        {
            "type" : "vec3",
            "name" : "a_Position",
            "location" : 0
        },
        {
            "type" : "vec2",
            "name" : "a_TexCoords",
            "location" : 1
        },
        {
            "type" : "vec3",
            "name" : "a_Normal",
            "location" : 2
        },
        {
            "type" : "vec3",
            "name" : "a_Tangent",
            "location" : 3
        },
        {
            "type" : "vec3",
            "name" : "a_Bitangent",
            "location" : 4
        }
    ],
./spirv-cross /tmp/test.spv --dump-resources

Entry points:
  main (vertex)

Execution modes:

subpass inputs
=============

=============

inputs
=============

 ID 025 : a_Position (Location : 0)
 ID 037 : a_TexCoords (Location : 1)
 ID 038 : a_Normal (Location : 2)
 ID 039 : a_Tangent (Location : 3)
 ID 040 : a_Bitangent (Location : 4)
=============

outputs
=============

=============

textures
=============

=============

separate images
=============

=============

separate samplers
=============

=============

images
=============

=============

ssbos
=============

=============

ubos
=============

=============

push
=============

 ID 019 : _19
=============

counters
=============

=============

acceleration structures
=============

=============

record buffers
=============

=============

builtin inputs
=============

=============

builtin outputs
=============

Builtin Position (float4) (active: yes).
Builtin PointSize (float) (active: no).
Builtin ClipDistance (float[1]) (active: no).
Builtin CullDistance (float[1]) (active: no).
=============

Active members in buffer: _19
==================

Member #  0 (u_Transform): Offset:    0, Range:   64
==================

Specialization constants
==================

==================

Capabilities
============
Capability: 1
============

Extensions
============
============

#version 460

struct u_MaterialData
{
    mat4 u_Transform;
};

uniform u_MaterialData _19;

layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec2 a_TexCoords;
layout(location = 2) in vec3 a_Normal;
layout(location = 3) in vec3 a_Tangent;
layout(location = 4) in vec3 a_Bitangent;

void main()
{
    gl_Position = _19.u_Transform * vec4(a_Position, 1.0);
}

@Algor1tm
Copy link
Author

Algor1tm commented Mar 8, 2024

My code looks like this:

spirv_cross::Compiler compiler(src);
spirv_cross::ShaderResources resources = compiler.get_shader_resources();
resources.stage_inputs;  // here are the inputs (only a_Position)

Sorry, but I dont understand what the SPIR-V do you want. Like actual byte code I get after compilation? I opened it in text editor, some of the symbols is not ASCII and there also was whole copy of my shader. I am compiling with shaderc library from latest VulkanSDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further progress depends on answer from issue creator.
Projects
None yet
Development

No branches or pull requests

2 participants