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

Fix generated hlsl for writes to scalar/vector storage buffer #1903

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/back/hlsl/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ impl<W: fmt::Write> super::Writer<'_, W> {
chain: &[SubAccess],
func_ctx: &FunctionCtx,
) -> BackendResult {
if chain.is_empty() {
write!(self.out, "0")?;
}
for (i, access) in chain.iter().enumerate() {
if i != 0 {
write!(self.out, "+")?;
Expand Down
2 changes: 2 additions & 0 deletions tests/in/access.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
resources: {
(group: 0, binding: 0): (buffer: Some(0), mutable: false),
(group: 0, binding: 1): (buffer: Some(1), mutable: false),
(group: 0, binding: 2): (buffer: Some(2), mutable: false),
},
sizes_buffer: Some(24),
),
fs: (
resources: {
(group: 0, binding: 0): (buffer: Some(0), mutable: true),
(group: 0, binding: 2): (buffer: Some(2), mutable: true),
},
sizes_buffer: Some(24),
),
Expand Down
5 changes: 5 additions & 0 deletions tests/in/access.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct Baz {
@group(0) @binding(1)
var<uniform> baz: Baz;

@group(0) @binding(2)
var<storage,read_write> qux: vec2<i32>;

fn test_matrix_within_struct_accesses() {
var idx = 9;

Expand Down Expand Up @@ -73,6 +76,7 @@ fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4<f32> {
let index = 3u;
let b = bar._matrix[index].x;
let a = bar.data[arrayLength(&bar.data) - 2u].value;
let c = qux;

// test pointer types
let data_pointer: ptr<storage, i32, read_write> = &bar.data[0].value;
Expand All @@ -95,6 +99,7 @@ fn foo_frag() -> @location(0) vec4<f32> {
bar._matrix = mat4x3<f32>(vec3<f32>(0.0), vec3<f32>(1.0), vec3<f32>(2.0), vec3<f32>(3.0));
bar.arr = array<vec2<u32>, 2>(vec2<u32>(0u), vec2<u32>(1u));
bar.data[1].value = 1;
qux = vec2<i32>();

return vec4<f32>(0.0);
}
Expand Down
36 changes: 18 additions & 18 deletions tests/out/glsl/access.atomics.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ layout(std430) buffer Bar_block_0Compute {


float read_from_private(inout float foo_1) {
float _e3 = foo_1;
return _e3;
float _e4 = foo_1;
return _e4;
}

float test_arr_as_arg(float a[5][10]) {
Expand All @@ -32,22 +32,22 @@ float test_arr_as_arg(float a[5][10]) {
void main() {
int tmp = 0;
int value = _group_0_binding_0_cs.atom;
int _e7 = atomicAdd(_group_0_binding_0_cs.atom, 5);
tmp = _e7;
int _e10 = atomicAdd(_group_0_binding_0_cs.atom, -5);
tmp = _e10;
int _e13 = atomicAnd(_group_0_binding_0_cs.atom, 5);
tmp = _e13;
int _e16 = atomicOr(_group_0_binding_0_cs.atom, 5);
tmp = _e16;
int _e19 = atomicXor(_group_0_binding_0_cs.atom, 5);
tmp = _e19;
int _e22 = atomicMin(_group_0_binding_0_cs.atom, 5);
tmp = _e22;
int _e25 = atomicMax(_group_0_binding_0_cs.atom, 5);
tmp = _e25;
int _e28 = atomicExchange(_group_0_binding_0_cs.atom, 5);
tmp = _e28;
int _e8 = atomicAdd(_group_0_binding_0_cs.atom, 5);
tmp = _e8;
int _e11 = atomicAdd(_group_0_binding_0_cs.atom, -5);
tmp = _e11;
int _e14 = atomicAnd(_group_0_binding_0_cs.atom, 5);
tmp = _e14;
int _e17 = atomicOr(_group_0_binding_0_cs.atom, 5);
tmp = _e17;
int _e20 = atomicXor(_group_0_binding_0_cs.atom, 5);
tmp = _e20;
int _e23 = atomicMin(_group_0_binding_0_cs.atom, 5);
tmp = _e23;
int _e26 = atomicMax(_group_0_binding_0_cs.atom, 5);
tmp = _e26;
int _e29 = atomicExchange(_group_0_binding_0_cs.atom, 5);
tmp = _e29;
_group_0_binding_0_cs.atom = value;
return;
}
Expand Down
7 changes: 5 additions & 2 deletions tests/out/glsl/access.foo_frag.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ layout(std430) buffer Bar_block_0Fragment {
AlignedWrapper data[];
} _group_0_binding_0_fs;

layout(std430) buffer type_9_block_1Fragment { ivec2 _group_0_binding_2_fs; };

layout(location = 0) out vec4 _fs2p_location0;

float read_from_private(inout float foo_1) {
float _e3 = foo_1;
return _e3;
float _e4 = foo_1;
return _e4;
}

float test_arr_as_arg(float a[5][10]) {
Expand All @@ -33,6 +35,7 @@ void main() {
_group_0_binding_0_fs._matrix = mat4x3(vec3(0.0), vec3(1.0), vec3(2.0), vec3(3.0));
_group_0_binding_0_fs.arr = uvec2[2](uvec2(0u), uvec2(1u));
_group_0_binding_0_fs.data[1].value = 1;
_group_0_binding_2_fs = ivec2(0, 0);
_fs2p_location0 = vec4(0.0);
return;
}
Expand Down
55 changes: 29 additions & 26 deletions tests/out/glsl/access.foo_vert.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,47 @@ layout(std430) buffer Bar_block_0Vertex {

uniform Baz_block_1Vertex { Baz _group_0_binding_1_vs; };

layout(std430) buffer type_9_block_2Vertex { ivec2 _group_0_binding_2_vs; };


void test_matrix_within_struct_accesses() {
int idx = 9;
Baz t = Baz(mat3x2(0.0));
int _e4 = idx;
idx = (_e4 - 1);
int _e5 = idx;
idx = (_e5 - 1);
mat3x2 unnamed = _group_0_binding_1_vs.m;
vec2 unnamed_1 = _group_0_binding_1_vs.m[0];
int _e14 = idx;
vec2 unnamed_2 = _group_0_binding_1_vs.m[_e14];
int _e15 = idx;
vec2 unnamed_2 = _group_0_binding_1_vs.m[_e15];
float unnamed_3 = _group_0_binding_1_vs.m[0][1];
int _e26 = idx;
float unnamed_4 = _group_0_binding_1_vs.m[0][_e26];
int _e30 = idx;
float unnamed_5 = _group_0_binding_1_vs.m[_e30][1];
int _e36 = idx;
int _e38 = idx;
float unnamed_6 = _group_0_binding_1_vs.m[_e36][_e38];
int _e27 = idx;
float unnamed_4 = _group_0_binding_1_vs.m[0][_e27];
int _e31 = idx;
float unnamed_5 = _group_0_binding_1_vs.m[_e31][1];
int _e37 = idx;
int _e39 = idx;
float unnamed_6 = _group_0_binding_1_vs.m[_e37][_e39];
t = Baz(mat3x2(vec2(1.0), vec2(2.0), vec2(3.0)));
int _e50 = idx;
idx = (_e50 + 1);
int _e51 = idx;
idx = (_e51 + 1);
t.m = mat3x2(vec2(6.0), vec2(5.0), vec2(4.0));
t.m[0] = vec2(9.0);
int _e67 = idx;
t.m[_e67] = vec2(90.0);
int _e68 = idx;
t.m[_e68] = vec2(90.0);
t.m[0][1] = 10.0;
int _e80 = idx;
t.m[0][_e80] = 20.0;
int _e84 = idx;
t.m[_e84][1] = 30.0;
int _e90 = idx;
int _e92 = idx;
t.m[_e90][_e92] = 40.0;
int _e81 = idx;
t.m[0][_e81] = 20.0;
int _e85 = idx;
t.m[_e85][1] = 30.0;
int _e91 = idx;
int _e93 = idx;
t.m[_e91][_e93] = 40.0;
return;
}

float read_from_private(inout float foo_1) {
float _e3 = foo_1;
return _e3;
float _e4 = foo_1;
return _e4;
}

float test_arr_as_arg(float a[5][10]) {
Expand All @@ -75,11 +77,12 @@ void main() {
uvec2 arr[2] = _group_0_binding_0_vs.arr;
float b = _group_0_binding_0_vs._matrix[3][0];
int a_1 = _group_0_binding_0_vs.data[(uint(_group_0_binding_0_vs.data.length()) - 2u)].value;
float _e28 = read_from_private(foo);
ivec2 c_1 = _group_0_binding_2_vs;
float _e30 = read_from_private(foo);
c = int[5](a_1, int(b), 3, 4, 5);
c[(vi + 1u)] = 42;
int value = c[vi];
float _e42 = test_arr_as_arg(float[5][10](float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
float _e44 = test_arr_as_arg(float[5][10](float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
gl_Position = vec4((_matrix * vec4(ivec4(value))), 2.0);
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
Expand Down
87 changes: 45 additions & 42 deletions tests/out/hlsl/access.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ float Constructarray5_array10_float__(float arg0[10], float arg1[10], float arg2

RWByteAddressBuffer bar : register(u0);
cbuffer baz : register(b1) { Baz baz; }
RWByteAddressBuffer qux : register(u2);

float3x2 GetMatmOnBaz(Baz obj) {
return float3x2(obj.m_0, obj.m_1, obj.m_2);
Expand Down Expand Up @@ -60,42 +61,42 @@ void test_matrix_within_struct_accesses()
int idx = 9;
Baz t = (Baz)0;

int _expr4 = idx;
idx = (_expr4 - 1);
int _expr5 = idx;
idx = (_expr5 - 1);
float3x2 unnamed = GetMatmOnBaz(baz);
float2 unnamed_1 = GetMatmOnBaz(baz)[0];
int _expr14 = idx;
float2 unnamed_2 = GetMatmOnBaz(baz)[_expr14];
int _expr15 = idx;
float2 unnamed_2 = GetMatmOnBaz(baz)[_expr15];
float unnamed_3 = GetMatmOnBaz(baz)[0][1];
int _expr26 = idx;
float unnamed_4 = GetMatmOnBaz(baz)[0][_expr26];
int _expr30 = idx;
float unnamed_5 = GetMatmOnBaz(baz)[_expr30][1];
int _expr36 = idx;
int _expr38 = idx;
float unnamed_6 = GetMatmOnBaz(baz)[_expr36][_expr38];
int _expr27 = idx;
float unnamed_4 = GetMatmOnBaz(baz)[0][_expr27];
int _expr31 = idx;
float unnamed_5 = GetMatmOnBaz(baz)[_expr31][1];
int _expr37 = idx;
int _expr39 = idx;
float unnamed_6 = GetMatmOnBaz(baz)[_expr37][_expr39];
t = ConstructBaz(float3x2((1.0).xx, (2.0).xx, (3.0).xx));
int _expr50 = idx;
idx = (_expr50 + 1);
int _expr51 = idx;
idx = (_expr51 + 1);
SetMatmOnBaz(t, float3x2((6.0).xx, (5.0).xx, (4.0).xx));
t.m_0 = (9.0).xx;
int _expr67 = idx;
SetMatVecmOnBaz(t, (90.0).xx, _expr67);
int _expr68 = idx;
SetMatVecmOnBaz(t, (90.0).xx, _expr68);
t.m_0[1] = 10.0;
int _expr80 = idx;
t.m_0[_expr80] = 20.0;
int _expr84 = idx;
SetMatScalarmOnBaz(t, 30.0, _expr84, 1);
int _expr90 = idx;
int _expr92 = idx;
SetMatScalarmOnBaz(t, 40.0, _expr90, _expr92);
int _expr81 = idx;
t.m_0[_expr81] = 20.0;
int _expr85 = idx;
SetMatScalarmOnBaz(t, 30.0, _expr85, 1);
int _expr91 = idx;
int _expr93 = idx;
SetMatScalarmOnBaz(t, 40.0, _expr91, _expr93);
return;
}

float read_from_private(inout float foo_1)
{
float _expr3 = foo_1;
return _expr3;
float _expr4 = foo_1;
return _expr4;
}

float test_arr_as_arg(float a[5][10])
Expand Down Expand Up @@ -127,14 +128,15 @@ float4 foo_vert(uint vi : SV_VertexID) : SV_Position
uint2 arr[2] = {asuint(bar.Load2(104+0)), asuint(bar.Load2(104+8))};
float b = asfloat(bar.Load(0+48+0));
int a_1 = asint(bar.Load(0+(((NagaBufferLengthRW(bar) - 120) / 8) - 2u)*8+120));
const float _e28 = read_from_private(foo);
int2 c_1 = asint(qux.Load2(0));
const float _e30 = read_from_private(foo);
{
int _result[5]=Constructarray5_int_(a_1, int(b), 3, 4, 5);
for(int _i=0; _i<5; ++_i) c[_i] = _result[_i];
}
c[(vi + 1u)] = 42;
int value = c[vi];
const float _e42 = test_arr_as_arg(Constructarray5_array10_float__(Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
const float _e44 = test_arr_as_arg(Constructarray5_array10_float__(Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Constructarray10_float_(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
return float4(mul(float4((value).xxxx), _matrix), 2.0);
}

Expand All @@ -159,6 +161,7 @@ float4 foo_frag() : SV_Target0
bar.Store2(104+8, asuint(_value2[1]));
}
bar.Store(0+8+120, asuint(1));
qux.Store2(0, asuint(int2(0, 0)));
return (0.0).xxxx;
}

Expand All @@ -168,22 +171,22 @@ void atomics()
int tmp = (int)0;

int value_1 = asint(bar.Load(96));
int _e7; bar.InterlockedAdd(96, 5, _e7);
tmp = _e7;
int _e10; bar.InterlockedAdd(96, -5, _e10);
tmp = _e10;
int _e13; bar.InterlockedAnd(96, 5, _e13);
tmp = _e13;
int _e16; bar.InterlockedOr(96, 5, _e16);
tmp = _e16;
int _e19; bar.InterlockedXor(96, 5, _e19);
tmp = _e19;
int _e22; bar.InterlockedMin(96, 5, _e22);
tmp = _e22;
int _e25; bar.InterlockedMax(96, 5, _e25);
tmp = _e25;
int _e28; bar.InterlockedExchange(96, 5, _e28);
tmp = _e28;
int _e8; bar.InterlockedAdd(96, 5, _e8);
tmp = _e8;
int _e11; bar.InterlockedAdd(96, -5, _e11);
tmp = _e11;
int _e14; bar.InterlockedAnd(96, 5, _e14);
tmp = _e14;
int _e17; bar.InterlockedOr(96, 5, _e17);
tmp = _e17;
int _e20; bar.InterlockedXor(96, 5, _e20);
tmp = _e20;
int _e23; bar.InterlockedMin(96, 5, _e23);
tmp = _e23;
int _e26; bar.InterlockedMax(96, 5, _e26);
tmp = _e26;
int _e29; bar.InterlockedExchange(96, 5, _e29);
tmp = _e29;
bar.Store(96, asuint(value_1));
return;
}
Loading