transform::VarForDynamicIndex: Operate on matrices

Much like arrays, the SPIR-V writer cannot cope with dynamic indexing of matrices.

Fixed: tint:825
Change-Id: Ia111f15e0cf6fbd441861a4b3455a33b82b692ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51781
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-05-20 18:16:07 +00:00
committed by Tint LUCI CQ
parent 6c582778cf
commit 351ac4a009
11 changed files with 186 additions and 52 deletions

View File

@@ -17,9 +17,9 @@
OpName %tint_symbol_5 "tint_symbol_5"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %main "main"
OpName %var_for_array "var_for_array"
OpName %var_for_index "var_for_index"
OpName %output "output"
OpName %var_for_array_1 "var_for_array_1"
OpName %var_for_index_1 "var_for_index_1"
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol BuiltIn VertexIndex
OpDecorate %tint_symbol_1 BuiltIn InstanceIndex
@@ -88,21 +88,21 @@
OpFunctionEnd
%main = OpFunction %void None %22
%24 = OpLabel
%var_for_array = OpVariable %_ptr_Function__arr_v2float_uint_4 Function %40
%var_for_index = OpVariable %_ptr_Function__arr_v2float_uint_4 Function %40
%output = OpVariable %_ptr_Function_Output Function %48
%var_for_array_1 = OpVariable %_ptr_Function__arr_v4float_uint_4 Function %62
%var_for_index_1 = OpVariable %_ptr_Function__arr_v4float_uint_4 Function %62
OpStore %tint_pointsize %float_1
OpStore %var_for_array %37
OpStore %var_for_index %37
%41 = OpLoad %uint %tint_symbol_1
%44 = OpAccessChain %_ptr_Function_float %var_for_array %41 %uint_0
%44 = OpAccessChain %_ptr_Function_float %var_for_index %41 %uint_0
%45 = OpLoad %float %44
%50 = OpAccessChain %_ptr_Function_v4float %output %uint_0
%52 = OpCompositeConstruct %v4float %float_0_5 %float_0_5 %45 %float_1
OpStore %50 %52
OpStore %var_for_array_1 %59
OpStore %var_for_index_1 %59
%64 = OpAccessChain %_ptr_Function_v4float %output %uint_1
%65 = OpLoad %uint %tint_symbol_1
%66 = OpAccessChain %_ptr_Function_v4float %var_for_array_1 %65
%66 = OpAccessChain %_ptr_Function_v4float %var_for_index_1 %65
%67 = OpLoad %v4float %66
OpStore %64 %67
%69 = OpLoad %Output %output

6
test/bug/tint/825.wgsl Normal file
View File

@@ -0,0 +1,6 @@
fn f() {
var i : i32;
var j : i32;
let m : mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
let f : f32 = m[i][j];
}

View File

@@ -0,0 +1,12 @@
void f() {
int i = 0;
int j = 0;
const float2x2 m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f));
const float f = m[i][j];
}
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
void f() {
int i = 0;
int j = 0;
float2x2 const m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f));
float const f = m[i][j];
}

View File

@@ -0,0 +1,48 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 30
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %i "i"
OpName %j "j"
OpName %var_for_index "var_for_index"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%10 = OpConstantNull %int
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%float_1 = OpConstant %float 1
%float_2 = OpConstant %float 2
%17 = OpConstantComposite %v2float %float_1 %float_2
%float_3 = OpConstant %float 3
%float_4 = OpConstant %float 4
%20 = OpConstantComposite %v2float %float_3 %float_4
%21 = OpConstantComposite %mat2v2float %17 %20
%_ptr_Function_mat2v2float = OpTypePointer Function %mat2v2float
%24 = OpConstantNull %mat2v2float
%_ptr_Function_float = OpTypePointer Function %float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%i = OpVariable %_ptr_Function_int Function %10
%j = OpVariable %_ptr_Function_int Function %10
%var_for_index = OpVariable %_ptr_Function_mat2v2float Function %24
OpStore %var_for_index %21
%25 = OpLoad %int %i
%26 = OpLoad %int %j
%28 = OpAccessChain %_ptr_Function_float %var_for_index %25 %26
%29 = OpLoad %float %28
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
fn f() {
var i : i32;
var j : i32;
let m : mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
let f : f32 = m[i][j];
}

View File

@@ -16,7 +16,7 @@
OpName %tint_symbol_3 "tint_symbol_3"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %vtx_main "vtx_main"
OpName %var_for_array "var_for_array"
OpName %var_for_index "var_for_index"
OpName %tint_symbol_6 "tint_symbol_6"
OpName %tint_symbol_4 "tint_symbol_4"
OpName %frag_main "frag_main"
@@ -64,11 +64,11 @@
OpFunctionEnd
%vtx_main = OpFunction %void None %29
%31 = OpLabel
%var_for_array = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %35
%var_for_index = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %35
OpStore %tint_pointsize %float_1
OpStore %var_for_array %pos
OpStore %var_for_index %pos
%37 = OpLoad %int %tint_symbol
%39 = OpAccessChain %_ptr_Function_v2float %var_for_array %37
%39 = OpAccessChain %_ptr_Function_v2float %var_for_index %37
%40 = OpLoad %v2float %39
%41 = OpCompositeExtract %float %40 0
%42 = OpCompositeExtract %float %40 1