[spirv-writer] Don't emit abstract accessor source

When traverseing an accessor expression, stop as soon as we hit a
source object that has a constant value. This prevents us from trying
to emit expressions that have abstract types and no materialization
nodes.

Bug: chromium:1442551
Change-Id: I8296ae58e63624e647052cdf966dbff15630a4d8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132040
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2023-05-09 10:57:21 +00:00 committed by Dawn LUCI CQ
parent f91b77dd6d
commit e162a1adee
8 changed files with 84 additions and 0 deletions

View File

@ -1034,6 +1034,11 @@ uint32_t Builder::GenerateAccessorExpression(const ast::AccessorExpression* expr
} else {
break;
}
// Stop traversing if we've hit a constant source expression.
if (builder_.Sem().GetVal(source)->ConstantValue()) {
break;
}
}
AccessorInfo info;

View File

@ -0,0 +1,5 @@
fn f() {
const v = vec3(1, 2, 3);
let i = 1;
var b = v.rg[i];
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
const int i = 1;
int b = int2(1, 2)[i];
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
const int i = 1;
int b = int2(1, 2)[i];
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
int i = 1;
int b = ivec2(1, 2)[i];
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
int const i = 1;
int b = int2(1, 2)[i];
}

View File

@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 16
; 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 %b "b"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%v2int = OpTypeVector %int 2
%int_2 = OpConstant %int 2
%11 = OpConstantComposite %v2int %int_1 %int_2
%_ptr_Function_int = OpTypePointer Function %int
%15 = OpConstantNull %int
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%b = OpVariable %_ptr_Function_int Function %15
%12 = OpVectorExtractDynamic %int %11 %int_1
OpStore %b %12
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,5 @@
fn f() {
const v = vec3(1, 2, 3);
let i = 1;
var b = v.rg[i];
}