gfx-rs/wgpu

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

JasondeWolff opened this issue · 1 comments

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"] }

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.