GithubHelp home page GithubHelp logo

Comments (8)

cdwfs avatar cdwfs commented on July 17, 2024

This seems like a compiler issue; if I build your test shader with dxc, spirv-reflect finds both descriptor bindings as expected. With glslc or glslangValidator it behaves as you describe.

from spirv-reflect.

johnkslang avatar johnkslang commented on July 17, 2024

That really just means the trigger being looked for is different. We need a tighter clue about what is actually wrong. The SPIR-V looks correct, and works on drivers. Maybe we should discuss here, until we know?

What trigger is being looked for?

The glslang SPIR-V looks quite similar for the two buffers:

$Global:

                         Decorate 13($Global) Block
13($Global):             TypeStruct 7(fvec4)
         14:             TypePointer Uniform 13($Global)
         15:     14(ptr) Variable Uniform

u_test1:

                         Decorate 21 Block
         21:             TypeStruct 7(fvec4)
         22:             TypePointer Uniform 21(struct)
         23:     22(ptr) Variable Uniform

from spirv-reflect.

cdwfs avatar cdwfs commented on July 17, 2024

Random note: neither fxc nor dxc will compile the original shader unless the cbuffer in b0 is given a name:
cbuffer MyConstants : register(b0)
glslc and glslangValidator accept it as written.

from spirv-reflect.

cdwfs avatar cdwfs commented on July 17, 2024

So @johnkslang, I took the following shader code:

uniform float4 u_test0;

cbuffer MyConstants : register(b0)
{
    float4 u_test1;
    float4 u_test2;
};

void main(out float4 fragColor : SV_TARGET0)
{
    fragColor = u_test0 * u_test1 * u_test2;
}

[EDIT: I just noticed I added a second float to the named cbuffer compared to the original shader; that was for an unrelated test that I forgot to revert, but it should be harmless for the purposes of this issue.]

I compiled it with both compilers:

> glslc -fshader-stage=frag -fentry-point=main -o global_cbuffer_glslc.spv global_cbuffer.hlsl
> dxc -spirv -T ps_6_0 -E main -Fo global_cbuffer_dxc.spv global_cbuffer.hlsl

The disassembled SPIR-V for both cases is attached.

I am a total white-belt when it comes to reading SPIR-V, but I know that SPIRV-Reflect uses Binding decorations to identify descriptor bindings. I see two Binding decorators in the dxc output, and only one in the glslang output. So, that explains the mismatch; the question (which I am not remotely qualified to answer) is which side should be fixed?

global_cbuffer_dxc.spv.txt
global_cbuffer_glslang.spv.txt

from spirv-reflect.

johnkslang avatar johnkslang commented on July 17, 2024

How did dxc know where to bind? That seems a convention, and there are also ways to ask glslang to bind as well. For example, using --amb.

Is there an agreed on convention about how to bind $Global? Is that convention from MS or Google?

from spirv-reflect.

chaoticbob avatar chaoticbob commented on July 17, 2024

IIRC, $Globals and $Params, using FXC, are assigned a register using what appears to be the next available register in #b with space0.

DXC/SPIR-V follows this same convention but assigns a binding in set 0, I believe. There is an attribute directive that permits you to force a binding number for $Globals. I can't recall what it is off the top of my head. @antiagainst will know.

from spirv-reflect.

antiagainst avatar antiagainst commented on July 17, 2024

+1 to what @chaoticbob said. We are following fxc behavior to use the next available binding in set 0 for the $Globals cbuffer. There is no way to manually pick the binding number for it right now. An attribute like vk::globals_binding was considered but haven't gotten implemented yet. One reason is not seeing real requests from developers; another reason is not sure about where to attach that attribute to. (Attaching to the entry point seems reasonable, but then we lose the ability to share the info among multiple entry points in the same file unless we attach all of them.)

from spirv-reflect.

chaoticbob avatar chaoticbob commented on July 17, 2024

Closing this since it's a compiler behavior and not that of SPIRV-Reflect.

from spirv-reflect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.