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

Push constant of mat4x4<f32> fails to compile on DX12 #5683

Open
JasondeWolff opened this issue May 9, 2024 · 1 comment
Open

Push constant of mat4x4<f32> fails to compile on DX12 #5683

JasondeWolff opened this issue May 9, 2024 · 1 comment
Labels
api: dx12 Issues with DX12 or DXGI area: correctness We're behaving incorrectly area: naga back-end Outputs of naga shader conversion lang: HLSL D3D Shading Language naga Shader Translator

Comments

@JasondeWolff
Copy link

Description
Using a var<push_constant> of type mat4x4<f32> fails to compile on DX12.

Repro steps
Wgsl Shader:

struct VertexOutput {
    @builtin(position) position: vec4<f32>,
};

@group(0)
@binding(0)
var<uniform> view_proj: mat4x4<f32>;

var<push_constant> model: mat4x4<f32>;

@vertex
fn vs_main(
    @location(0) position: vec4<f32>,
    @location(1) normal: vec4<f32>,
    @location(2) tangent: vec4<f32>,
    @location(3) color: vec4<f32>,
    @location(4) tex_coord: vec4<f32>,
    @location(5) joints: vec4<u32>,
    @location(6) weights: vec4<f32>,
) -> VertexOutput {
    var result: VertexOutput;
    result.position = view_proj * model * vec4<f32>(position.xyz, 1.0);
    return result;
}

@fragment
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
    return vec4<f32>(1.0, 0.0, 1.0, 1.0);
}

Naga Hlsl Output:

struct NagaConstants {
    int first_vertex;
    int first_instance;
    uint other;
};
ConstantBuffer<NagaConstants> _NagaConstants: register(b2, space1);

struct VertexOutput {
    float4 position : SV_Position;
};

cbuffer view_proj : register(b1, space1) { row_major float4x4 view_proj; }
ConstantBuffer<row_major float4x4> model: register(b0);

struct VertexOutput_vs_main {
    float4 position_1 : SV_Position;
};

struct FragmentInput_fs_main {
    float4 position_2 : SV_Position;
};

VertexOutput_vs_main vs_main(float4 position : LOC0, float4 normal : LOC1, float4 tangent : LOC2, float4 color : LOC3, float4 tex_coord : LOC4, uint4 joints : LOC5, float4 weights : LOC6)
{
    VertexOutput result = (VertexOutput)0;

    float4x4 _expr10 = view_proj;
    float4x4 _expr12 = model;
    result.position = mul(float4(position.xyz, 1.0), mul(_expr12, _expr10));
    VertexOutput _expr18 = result;
    const VertexOutput vertexoutput = _expr18;
    const VertexOutput_vs_main vertexoutput_1 = { vertexoutput.position };
    return vertexoutput_1;
}

float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
{
    VertexOutput vertex = { fragmentinput_fs_main.position_2 };
    return float4(1.0, 0.0, 1.0, 1.0);
}

Error:
ERROR [wgpu_core::device::global] Device::create_render_pipeline error: Internal error in ShaderStages(VERTEX) shader: FXC D3DCompile error (0x80004005): C:\Dev\undertone\ut-raster-pass::draw(13,16-24): error X3000: syntax error: unexpected token 'row_major' ?

Expected vs observed behavior
I would expect a mat4 to be fine as a push constant? Compiling the shader with just the mat4x4<f32> in the uniform buffer works fine. The above shader does compile fine on VULKAN but DX12 crashes with the error formatted above.

Platform
Windows 11, NVIDIA RTX 4060 8GB, DX12 backend
wgpu = { version = "0.19.3", default-features = false, features = ["wgsl", "metal", "dx12"] }

@cwfitzgerald
Copy link
Member

This is actually a duplicate, but this issue has more info, so I'll favor this issue.

It is indeed a bug on our end.

@cwfitzgerald cwfitzgerald added area: correctness We're behaving incorrectly api: dx12 Issues with DX12 or DXGI area: naga back-end Outputs of naga shader conversion naga Shader Translator lang: HLSL D3D Shading Language labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dx12 Issues with DX12 or DXGI area: correctness We're behaving incorrectly area: naga back-end Outputs of naga shader conversion lang: HLSL D3D Shading Language naga Shader Translator
Projects
None yet
Development

No branches or pull requests

2 participants