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

Order of HLSL Semantics Issues #1945

Closed
cwfitzgerald opened this issue May 27, 2022 · 1 comment
Closed

Order of HLSL Semantics Issues #1945

cwfitzgerald opened this issue May 27, 2022 · 1 comment
Labels
area: back-end Outputs of shader conversion kind: bug Something isn't working lang: HLSL High-Level Shading Language

Comments

@cwfitzgerald
Copy link
Member

Seems like gfx-rs/wgpu#5553 has reared its head again.

Given these wgsl shaders:

vertex: https://github.com/BVE-Reborn/rend3/blob/wgpu-upgrade-0.13/rend3-routine/shaders/wgsl/depth.vert.cpu.wgsl
fragment: https://github.com/BVE-Reborn/rend3/blob/wgpu-upgrade-0.13/rend3-routine/shaders/wgsl/depth-cutout.frag.cpu.wgsl

Generate the following HLSL:

vert.hlsl
    struct NagaConstants {
        int base_vertex;
        int base_instance;
        uint other;
    };
    ConstantBuffer<NagaConstants> _NagaConstants: register(b2);

    struct ObjectOutputData {
        row_major float4x4 model_view;
        row_major float4x4 model_view_proj;
        uint material_idx;
        int _pad3_0;
        int _pad3_1;
        int _pad3_2;
        float3 inv_squared_scale;
        int _end_pad_0;
    };

    struct gl_PerVertex {
        float4 gl_Position : SV_Position;
    };

    struct VertexOutput {
        float4 member : LOC0;
        float4 gl_Position : SV_Position;
        nointerpolation uint member_1_ : LOC3;
        float4 member_2_ : LOC2;
        float2 member_3_ : LOC1;
    };

    gl_PerVertex Constructgl_PerVertex(float4 arg0) {
        gl_PerVertex ret = (gl_PerVertex)0;
        ret.gl_Position = arg0;
        return ret;
    }

    static int gl_InstanceIndex_1_ = (int)0;
    ByteAddressBuffer unnamed : register(t0);
    static float3 i_position_1_ = (float3)0;
    static float4 o_position = (float4)0;
    static gl_PerVertex perVertexStruct = Constructgl_PerVertex(float4(0.0, 0.0, 0.0, 1.0));
    static uint o_material = (uint)0;
    static float4 o_color = (float4)0;
    static float4 i_color_1_ = (float4)0;
    static float2 o_coords0_ = (float2)0;
    static float2 i_coords0_1_ = (float2)0;

    struct VertexOutput_main {
        float4 member : LOC0;
        float2 member_3_ : LOC1;
        float4 member_2_ : LOC2;
        nointerpolation uint member_1_ : LOC3;
        float4 gl_Position : SV_Position;
    };

    void main_1_()
    {
        int _e18_ = gl_InstanceIndex_1_;
        float4x4 _e23_ = float4x4(asfloat(unnamed.Load4(64+uint(_e18_)*160+0+0)), asfloat(unnamed.Load4(64+uint(_e18_)*160+0+16)), asfloat(unnamed.Load4(64+uint(_e18_)*160+0+32)), asfloat(unnamed.Load4(64+uint(_e18_)*160+0+48)));
        uint _e25_ = asuint(unnamed.Load(128+uint(_e18_)*160+0));
        float3 _e26_ = i_position_1_;
        float4 _e31_ = mul(float4(_e26_.x, _e26_.y, _e26_.z, 1.0), _e23_);
        o_position = _e31_;
        perVertexStruct.gl_Position = _e31_;
        o_material = _e25_;
        float4 _e33_ = i_color_1_;
        o_color = _e33_;
        float2 _e34_ = i_coords0_1_;
        o_coords0_ = _e34_;
        return;
    }

    VertexOutput ConstructVertexOutput(float4 arg0, float4 arg1, uint arg2, float4 arg3, float2 arg4) {
        VertexOutput ret = (VertexOutput)0;
        ret.member = arg0;
        ret.gl_Position = arg1;
        ret.member_1_ = arg2;
        ret.member_2_ = arg3;
        ret.member_3_ = arg4;
        return ret;
    }

    VertexOutput_main main(uint gl_InstanceIndex : SV_InstanceID, float3 i_position : LOC0, float4 i_color : LOC5, float2 i_coords0_ : LOC3)
    {
        gl_InstanceIndex_1_ = int((_NagaConstants.base_instance + gl_InstanceIndex));
        i_position_1_ = i_position;
        i_color_1_ = i_color;
        i_coords0_1_ = i_coords0_;
        main_1_();
        float4 _e15_ = o_position;
        float4 _e16_ = perVertexStruct.gl_Position;
        uint _e17_ = o_material;
        float4 _e18_1 = o_color;
        float2 _e19_ = o_coords0_;
        const VertexOutput vertexoutput = ConstructVertexOutput(_e15_, _e16_, _e17_, _e18_1, _e19_);
        const VertexOutput_main vertexoutput_1 = { vertexoutput.member, vertexoutput.member_3_, vertexoutput.member_2_, vertexoutput.member_1_, vertexoutput.gl_Position };
        return vertexoutput_1;
    }
frag.hlsl
    struct NagaConstants {
        int base_vertex;
        int base_instance;
        uint other;
    };
    ConstantBuffer<NagaConstants> _NagaConstants: register(b2);

    struct DataAbi {
        uint stride;
        uint texture_offset;
        uint cutoff_offset;
        uint uv_transform_offset;
    };

    cbuffer unnamed : register(b1) { DataAbi unnamed; }
    static uint i_material_1_ = (uint)0;
    ByteAddressBuffer unnamed_1_ : register(t1);
    static float2 i_coords0_1_ = (float2)0;
    Texture2D<float4> texture_ : register(t2);
    SamplerState primary_sampler : register(s0);

    struct FragmentInput_main {
        float2 i_coords0_1 : LOC1;
        nointerpolation uint i_material_1 : LOC3;
    };

    void main_1_()
    {
        float2 phi_168_ = (float2)0;

        uint _e26_ = unnamed.stride;
        uint _e27_ = i_material_1_;
        uint _e28_ = (_e26_ * _e27_);
        uint _e30_ = unnamed.cutoff_offset;
        float _e34_ = asfloat(unnamed_1_.Load((_e28_ + _e30_)*4+0));
        uint _e36_ = unnamed.uv_transform_offset;
        if ((_e36_ != 4294967295u)) {
            uint _e38_ = (_e28_ + _e36_);
            float _e41_ = asfloat(unnamed_1_.Load(_e38_*4+0));
            float _e45_ = asfloat(unnamed_1_.Load((_e38_ + 1u)*4+0));
            float _e49_ = asfloat(unnamed_1_.Load((_e38_ + 2u)*4+0));
            float _e53_ = asfloat(unnamed_1_.Load((_e38_ + 4u)*4+0));
            float _e57_ = asfloat(unnamed_1_.Load((_e38_ + 5u)*4+0));
            float _e61_ = asfloat(unnamed_1_.Load((_e38_ + 6u)*4+0));
            float _e65_ = asfloat(unnamed_1_.Load((_e38_ + 8u)*4+0));
            float _e69_ = asfloat(unnamed_1_.Load((_e38_ + 9u)*4+0));
            float _e73_ = asfloat(unnamed_1_.Load((_e38_ + 10u)*4+0));
            float2 _e78_ = i_coords0_1_;
            float3 _e82_ = mul(float3(_e78_.x, _e78_.y, 1.0), float3x3(float3(_e41_, _e45_, _e49_), float3(_e53_, _e57_, _e61_), float3(_e65_, _e69_, _e73_)));
            phi_168_ = float2(_e82_.x, _e82_.y);
        } else {
            float2 _e86_ = i_coords0_1_;
            phi_168_ = _e86_;
        }
        float2 _e88_ = phi_168_;
        float2 _e89_ = ddx(_e88_);
        float2 _e90_ = ddy(_e88_);
        uint _e92_ = unnamed.texture_offset;
        float _e96_ = asfloat(unnamed_1_.Load((_e28_ + _e92_)*4+0));
        if (((uint(_e96_) & 1u) != 0u)) {
            float4 _e100_ = texture_.SampleGrad(primary_sampler, _e88_, _e89_, _e90_);
            if ((_e100_.w <= _e34_)) {
                discard;
            }
        }
        return;
    }

    void main(FragmentInput_main fragmentinput_main)
    {
        uint i_material = fragmentinput_main.i_material_1;
        float2 i_coords0_ = fragmentinput_main.i_coords0_1;
        i_material_1_ = i_material;
        i_coords0_1_ = i_coords0_;
        main_1_();
        return;
    }
@cwfitzgerald cwfitzgerald added kind: bug Something isn't working area: back-end Outputs of shader conversion lang: HLSL High-Level Shading Language labels May 27, 2022
@cwfitzgerald
Copy link
Member Author

I'm not sure if this is worth fixing, as it violates a WebGPU rule about mismatched inputs and outputs. See the mentioned wgpu issue.

@cwfitzgerald cwfitzgerald closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2022
Aaron1011 added a commit to Aaron1011/wgpu that referenced this issue Sep 5, 2023
This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.
Aaron1011 added a commit to Aaron1011/wgpu that referenced this issue Sep 5, 2023
This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.
Aaron1011 added a commit to Aaron1011/wgpu that referenced this issue Sep 20, 2023
This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.
cwfitzgerald pushed a commit to gfx-rs/wgpu that referenced this issue Sep 21, 2023
)

* wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12

This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.

* Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check

* Pick an unused feature id
Aaron1011 added a commit to ruffle-rs/wgpu that referenced this issue Sep 30, 2023
…x-rs#4116)

* wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12

This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.

* Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check

* Pick an unused feature id
torokati44 pushed a commit to torokati44/wgpu that referenced this issue Oct 9, 2023
…x-rs#4116)

* wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12

This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.

* Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check

* Pick an unused feature id
torokati44 pushed a commit to torokati44/wgpu that referenced this issue Oct 9, 2023
…x-rs#4116)

* wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12

This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.

* Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check

* Pick an unused feature id
torokati44 pushed a commit to torokati44/wgpu that referenced this issue Oct 10, 2023
…x-rs#4116)

* wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12

This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.

* Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check

* Pick an unused feature id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end Outputs of shader conversion kind: bug Something isn't working lang: HLSL High-Level Shading Language
Projects
None yet
Development

No branches or pull requests

1 participant