mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
writer/hlsl: Simplify UBO accesses for static indexing
Use the new semantic constant value information to significantly reduce the complex indexing logic emitted for UBO accesses. This will dramatically reduce the number of `for` loops that are decayed to `while` loops. Change-Id: I1b0adb5edde2b4ed39c6beafc2e28106b86e0edd Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57701 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
33
test/buffer/uniform/dynamic_index/read.wgsl
Normal file
33
test/buffer/uniform/dynamic_index/read.wgsl
Normal file
@@ -0,0 +1,33 @@
|
||||
struct Inner {
|
||||
a : vec3<i32>;
|
||||
b : i32;
|
||||
c : vec3<u32>;
|
||||
d : u32;
|
||||
e : vec3<f32>;
|
||||
f : f32;
|
||||
g : vec2<i32>;
|
||||
h : vec2<i32>;
|
||||
i : mat2x3<f32>;
|
||||
[[align(16)]] j : mat3x2<f32>;
|
||||
[[align(16)]] k : [[stride(16)]] array<vec4<i32>, 4>;
|
||||
};
|
||||
|
||||
[[block]]
|
||||
struct S {
|
||||
arr : array<Inner, 8>;
|
||||
};
|
||||
|
||||
[[binding(0), group(0)]] var<uniform> s : S;
|
||||
|
||||
[[stage(compute), workgroup_size(1)]]
|
||||
fn main([[builtin(local_invocation_index)]] idx : u32) {
|
||||
let a = s.arr[idx].a;
|
||||
let b = s.arr[idx].b;
|
||||
let c = s.arr[idx].c;
|
||||
let d = s.arr[idx].d;
|
||||
let e = s.arr[idx].e;
|
||||
let f = s.arr[idx].f;
|
||||
let g = s.arr[idx].g;
|
||||
let h = s.arr[idx].h;
|
||||
let i = s.arr[idx].i;
|
||||
}
|
||||
38
test/buffer/uniform/dynamic_index/read.wgsl.expected.hlsl
Normal file
38
test/buffer/uniform/dynamic_index/read.wgsl.expected.hlsl
Normal file
@@ -0,0 +1,38 @@
|
||||
float2x3 tint_symbol_9(uint4 buffer[96], uint offset) {
|
||||
const uint scalar_offset = ((offset + 0u)) / 4;
|
||||
const uint scalar_offset_1 = ((offset + 16u)) / 4;
|
||||
return float2x3(asfloat(buffer[scalar_offset / 4].xyz), asfloat(buffer[scalar_offset_1 / 4].xyz));
|
||||
}
|
||||
|
||||
cbuffer cbuffer_s : register(b0, space0) {
|
||||
uint4 s[96];
|
||||
};
|
||||
|
||||
struct tint_symbol_1 {
|
||||
uint idx : SV_GroupIndex;
|
||||
};
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main(tint_symbol_1 tint_symbol) {
|
||||
const uint idx = tint_symbol.idx;
|
||||
const uint scalar_offset_2 = ((192u * idx)) / 4;
|
||||
const int3 a = asint(s[scalar_offset_2 / 4].xyz);
|
||||
const uint scalar_offset_3 = (((192u * idx) + 12u)) / 4;
|
||||
const int b = asint(s[scalar_offset_3 / 4][scalar_offset_3 % 4]);
|
||||
const uint scalar_offset_4 = (((192u * idx) + 16u)) / 4;
|
||||
const uint3 c = s[scalar_offset_4 / 4].xyz;
|
||||
const uint scalar_offset_5 = (((192u * idx) + 28u)) / 4;
|
||||
const uint d = s[scalar_offset_5 / 4][scalar_offset_5 % 4];
|
||||
const uint scalar_offset_6 = (((192u * idx) + 32u)) / 4;
|
||||
const float3 e = asfloat(s[scalar_offset_6 / 4].xyz);
|
||||
const uint scalar_offset_7 = (((192u * idx) + 44u)) / 4;
|
||||
const float f = asfloat(s[scalar_offset_7 / 4][scalar_offset_7 % 4]);
|
||||
const uint scalar_offset_8 = (((192u * idx) + 48u)) / 4;
|
||||
uint4 ubo_load = s[scalar_offset_8 / 4];
|
||||
const int2 g = asint(((scalar_offset_8 & 2) ? ubo_load.zw : ubo_load.xy));
|
||||
const uint scalar_offset_9 = (((192u * idx) + 56u)) / 4;
|
||||
uint4 ubo_load_1 = s[scalar_offset_9 / 4];
|
||||
const int2 h = asint(((scalar_offset_9 & 2) ? ubo_load_1.zw : ubo_load_1.xy));
|
||||
const float2x3 i = tint_symbol_9(s, ((192u * idx) + 64u));
|
||||
return;
|
||||
}
|
||||
40
test/buffer/uniform/dynamic_index/read.wgsl.expected.msl
Normal file
40
test/buffer/uniform/dynamic_index/read.wgsl.expected.msl
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
struct tint_array_wrapper {
|
||||
/* 0x0000 */ int4 arr[4];
|
||||
};
|
||||
struct Inner {
|
||||
/* 0x0000 */ packed_int3 a;
|
||||
/* 0x000c */ int b;
|
||||
/* 0x0010 */ packed_uint3 c;
|
||||
/* 0x001c */ uint d;
|
||||
/* 0x0020 */ packed_float3 e;
|
||||
/* 0x002c */ float f;
|
||||
/* 0x0030 */ packed_int2 g;
|
||||
/* 0x0038 */ packed_int2 h;
|
||||
/* 0x0040 */ float2x3 i;
|
||||
/* 0x0060 */ float3x2 j;
|
||||
/* 0x0078 */ int8_t tint_pad[8];
|
||||
/* 0x0080 */ tint_array_wrapper k;
|
||||
};
|
||||
struct tint_array_wrapper_1 {
|
||||
/* 0x0000 */ Inner arr[8];
|
||||
};
|
||||
struct S {
|
||||
/* 0x0000 */ tint_array_wrapper_1 arr;
|
||||
};
|
||||
|
||||
kernel void tint_symbol(uint idx [[thread_index_in_threadgroup]], constant S& s [[buffer(0)]]) {
|
||||
int3 const a = s.arr.arr[idx].a;
|
||||
int const b = s.arr.arr[idx].b;
|
||||
uint3 const c = s.arr.arr[idx].c;
|
||||
uint const d = s.arr.arr[idx].d;
|
||||
float3 const e = s.arr.arr[idx].e;
|
||||
float const f = s.arr.arr[idx].f;
|
||||
int2 const g = s.arr.arr[idx].g;
|
||||
int2 const h = s.arr.arr[idx].h;
|
||||
float2x3 const i = s.arr.arr[idx].i;
|
||||
return;
|
||||
}
|
||||
|
||||
118
test/buffer/uniform/dynamic_index/read.wgsl.expected.spvasm
Normal file
118
test/buffer/uniform/dynamic_index/read.wgsl.expected.spvasm
Normal file
@@ -0,0 +1,118 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 68
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %main "main" %tint_symbol
|
||||
OpExecutionMode %main LocalSize 1 1 1
|
||||
OpName %S "S"
|
||||
OpMemberName %S 0 "arr"
|
||||
OpName %Inner "Inner"
|
||||
OpMemberName %Inner 0 "a"
|
||||
OpMemberName %Inner 1 "b"
|
||||
OpMemberName %Inner 2 "c"
|
||||
OpMemberName %Inner 3 "d"
|
||||
OpMemberName %Inner 4 "e"
|
||||
OpMemberName %Inner 5 "f"
|
||||
OpMemberName %Inner 6 "g"
|
||||
OpMemberName %Inner 7 "h"
|
||||
OpMemberName %Inner 8 "i"
|
||||
OpMemberName %Inner 9 "j"
|
||||
OpMemberName %Inner 10 "k"
|
||||
OpName %s "s"
|
||||
OpName %tint_symbol "tint_symbol"
|
||||
OpName %main "main"
|
||||
OpDecorate %S Block
|
||||
OpMemberDecorate %S 0 Offset 0
|
||||
OpMemberDecorate %Inner 0 Offset 0
|
||||
OpMemberDecorate %Inner 1 Offset 12
|
||||
OpMemberDecorate %Inner 2 Offset 16
|
||||
OpMemberDecorate %Inner 3 Offset 28
|
||||
OpMemberDecorate %Inner 4 Offset 32
|
||||
OpMemberDecorate %Inner 5 Offset 44
|
||||
OpMemberDecorate %Inner 6 Offset 48
|
||||
OpMemberDecorate %Inner 7 Offset 56
|
||||
OpMemberDecorate %Inner 8 Offset 64
|
||||
OpMemberDecorate %Inner 8 ColMajor
|
||||
OpMemberDecorate %Inner 8 MatrixStride 16
|
||||
OpMemberDecorate %Inner 9 Offset 96
|
||||
OpMemberDecorate %Inner 9 ColMajor
|
||||
OpMemberDecorate %Inner 9 MatrixStride 8
|
||||
OpMemberDecorate %Inner 10 Offset 128
|
||||
OpDecorate %_arr_v4int_uint_4 ArrayStride 16
|
||||
OpDecorate %_arr_Inner_uint_8 ArrayStride 192
|
||||
OpDecorate %s NonWritable
|
||||
OpDecorate %s Binding 0
|
||||
OpDecorate %s DescriptorSet 0
|
||||
OpDecorate %tint_symbol BuiltIn LocalInvocationIndex
|
||||
%int = OpTypeInt 32 1
|
||||
%v3int = OpTypeVector %int 3
|
||||
%uint = OpTypeInt 32 0
|
||||
%v3uint = OpTypeVector %uint 3
|
||||
%float = OpTypeFloat 32
|
||||
%v3float = OpTypeVector %float 3
|
||||
%v2int = OpTypeVector %int 2
|
||||
%mat2v3float = OpTypeMatrix %v3float 2
|
||||
%v2float = OpTypeVector %float 2
|
||||
%mat3v2float = OpTypeMatrix %v2float 3
|
||||
%v4int = OpTypeVector %int 4
|
||||
%uint_4 = OpConstant %uint 4
|
||||
%_arr_v4int_uint_4 = OpTypeArray %v4int %uint_4
|
||||
%Inner = OpTypeStruct %v3int %int %v3uint %uint %v3float %float %v2int %v2int %mat2v3float %mat3v2float %_arr_v4int_uint_4
|
||||
%uint_8 = OpConstant %uint 8
|
||||
%_arr_Inner_uint_8 = OpTypeArray %Inner %uint_8
|
||||
%S = OpTypeStruct %_arr_Inner_uint_8
|
||||
%_ptr_Uniform_S = OpTypePointer Uniform %S
|
||||
%s = OpVariable %_ptr_Uniform_S Uniform
|
||||
%_ptr_Input_uint = OpTypePointer Input %uint
|
||||
%tint_symbol = OpVariable %_ptr_Input_uint Input
|
||||
%void = OpTypeVoid
|
||||
%22 = OpTypeFunction %void
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%_ptr_Uniform_v3int = OpTypePointer Uniform %v3int
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%_ptr_Uniform_int = OpTypePointer Uniform %int
|
||||
%uint_2 = OpConstant %uint 2
|
||||
%_ptr_Uniform_v3uint = OpTypePointer Uniform %v3uint
|
||||
%uint_3 = OpConstant %uint 3
|
||||
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
|
||||
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
|
||||
%uint_5 = OpConstant %uint 5
|
||||
%_ptr_Uniform_float = OpTypePointer Uniform %float
|
||||
%uint_6 = OpConstant %uint 6
|
||||
%_ptr_Uniform_v2int = OpTypePointer Uniform %v2int
|
||||
%uint_7 = OpConstant %uint 7
|
||||
%_ptr_Uniform_mat2v3float = OpTypePointer Uniform %mat2v3float
|
||||
%main = OpFunction %void None %22
|
||||
%25 = OpLabel
|
||||
%27 = OpLoad %uint %tint_symbol
|
||||
%29 = OpAccessChain %_ptr_Uniform_v3int %s %uint_0 %27 %uint_0
|
||||
%30 = OpLoad %v3int %29
|
||||
%31 = OpLoad %uint %tint_symbol
|
||||
%34 = OpAccessChain %_ptr_Uniform_int %s %uint_0 %31 %uint_1
|
||||
%35 = OpLoad %int %34
|
||||
%36 = OpLoad %uint %tint_symbol
|
||||
%39 = OpAccessChain %_ptr_Uniform_v3uint %s %uint_0 %36 %uint_2
|
||||
%40 = OpLoad %v3uint %39
|
||||
%41 = OpLoad %uint %tint_symbol
|
||||
%44 = OpAccessChain %_ptr_Uniform_uint %s %uint_0 %41 %uint_3
|
||||
%45 = OpLoad %uint %44
|
||||
%46 = OpLoad %uint %tint_symbol
|
||||
%48 = OpAccessChain %_ptr_Uniform_v3float %s %uint_0 %46 %uint_4
|
||||
%49 = OpLoad %v3float %48
|
||||
%50 = OpLoad %uint %tint_symbol
|
||||
%53 = OpAccessChain %_ptr_Uniform_float %s %uint_0 %50 %uint_5
|
||||
%54 = OpLoad %float %53
|
||||
%55 = OpLoad %uint %tint_symbol
|
||||
%58 = OpAccessChain %_ptr_Uniform_v2int %s %uint_0 %55 %uint_6
|
||||
%59 = OpLoad %v2int %58
|
||||
%60 = OpLoad %uint %tint_symbol
|
||||
%62 = OpAccessChain %_ptr_Uniform_v2int %s %uint_0 %60 %uint_7
|
||||
%63 = OpLoad %v2int %62
|
||||
%64 = OpLoad %uint %tint_symbol
|
||||
%66 = OpAccessChain %_ptr_Uniform_mat2v3float %s %uint_0 %64 %uint_8
|
||||
%67 = OpLoad %mat2v3float %66
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
35
test/buffer/uniform/dynamic_index/read.wgsl.expected.wgsl
Normal file
35
test/buffer/uniform/dynamic_index/read.wgsl.expected.wgsl
Normal file
@@ -0,0 +1,35 @@
|
||||
struct Inner {
|
||||
a : vec3<i32>;
|
||||
b : i32;
|
||||
c : vec3<u32>;
|
||||
d : u32;
|
||||
e : vec3<f32>;
|
||||
f : f32;
|
||||
g : vec2<i32>;
|
||||
h : vec2<i32>;
|
||||
i : mat2x3<f32>;
|
||||
[[align(16)]]
|
||||
j : mat3x2<f32>;
|
||||
[[align(16)]]
|
||||
k : [[stride(16)]] array<vec4<i32>, 4>;
|
||||
};
|
||||
|
||||
[[block]]
|
||||
struct S {
|
||||
arr : array<Inner, 8>;
|
||||
};
|
||||
|
||||
[[binding(0), group(0)]] var<uniform> s : S;
|
||||
|
||||
[[stage(compute), workgroup_size(1)]]
|
||||
fn main([[builtin(local_invocation_index)]] idx : u32) {
|
||||
let a = s.arr[idx].a;
|
||||
let b = s.arr[idx].b;
|
||||
let c = s.arr[idx].c;
|
||||
let d = s.arr[idx].d;
|
||||
let e = s.arr[idx].e;
|
||||
let f = s.arr[idx].f;
|
||||
let g = s.arr[idx].g;
|
||||
let h = s.arr[idx].h;
|
||||
let i = s.arr[idx].i;
|
||||
}
|
||||
Reference in New Issue
Block a user