Skip to content

Commit

Permalink
[glsl][ir] Add vector accessors.
Browse files Browse the repository at this point in the history
This Cl adds `LoadVectorElement`, `StoreVectorElement` and `Swizzle`
support to the GLSL IR backend.

Bug: 42251044
Change-Id: I0aac2b2f30f67621ab9407f50a9306cc950f233e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/204854
Commit-Queue: dan sinclair <[email protected]>
Reviewed-by: James Price <[email protected]>
  • Loading branch information
dj2 authored and Dawn LUCI CQ committed Sep 3, 2024
1 parent 6b1e61b commit 32f3eff
Show file tree
Hide file tree
Showing 243 changed files with 5,350 additions and 2,412 deletions.
452 changes: 372 additions & 80 deletions src/tint/lang/glsl/writer/access_test.cc

Large diffs are not rendered by default.

83 changes: 69 additions & 14 deletions src/tint/lang/glsl/writer/printer/printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "src/tint/lang/core/ir/next_iteration.h"
#include "src/tint/lang/core/ir/return.h"
#include "src/tint/lang/core/ir/store.h"
#include "src/tint/lang/core/ir/store_vector_element.h"
#include "src/tint/lang/core/ir/switch.h"
#include "src/tint/lang/core/ir/swizzle.h"
#include "src/tint/lang/core/ir/terminate_invocation.h"
Expand Down Expand Up @@ -264,20 +265,21 @@ class Printer : public tint::TextGenerator {
// TerminateInvocation must come before Call.
[&](const core::ir::TerminateInvocation*) { EmitDiscard(); }, //

[&](const core::ir::BreakIf* i) { EmitBreakIf(i); }, //
[&](const core::ir::Call* i) { EmitCallStmt(i); }, //
[&](const core::ir::Continue*) { EmitContinue(); }, //
[&](const core::ir::ExitIf*) { /* do nothing handled by transform */ }, //
[&](const core::ir::ExitLoop*) { EmitExitLoop(); }, //
[&](const core::ir::ExitSwitch*) { EmitExitSwitch(); }, //
[&](const core::ir::If* i) { EmitIf(i); }, //
[&](const core::ir::Let* i) { EmitLet(i); }, //
[&](const core::ir::Loop* l) { EmitLoop(l); }, //
[&](const core::ir::Return* r) { EmitReturn(r); }, //
[&](const core::ir::Store* s) { EmitStore(s); }, //
[&](const core::ir::Switch* i) { EmitSwitch(i); }, //
[&](const core::ir::Unreachable*) { EmitUnreachable(); }, //
[&](const core::ir::Var* v) { EmitVar(Line(), v); }, //
[&](const core::ir::BreakIf* i) { EmitBreakIf(i); }, //
[&](const core::ir::Call* i) { EmitCallStmt(i); }, //
[&](const core::ir::Continue*) { EmitContinue(); }, //
[&](const core::ir::ExitIf*) { /* do nothing handled by transform */ }, //
[&](const core::ir::ExitLoop*) { EmitExitLoop(); }, //
[&](const core::ir::ExitSwitch*) { EmitExitSwitch(); }, //
[&](const core::ir::If* i) { EmitIf(i); }, //
[&](const core::ir::Let* i) { EmitLet(i); }, //
[&](const core::ir::Loop* l) { EmitLoop(l); }, //
[&](const core::ir::Return* r) { EmitReturn(r); }, //
[&](const core::ir::Store* s) { EmitStore(s); }, //
[&](const core::ir::StoreVectorElement* s) { EmitStoreVectorElement(s); }, //
[&](const core::ir::Switch* i) { EmitSwitch(i); }, //
[&](const core::ir::Unreachable*) { EmitUnreachable(); }, //
[&](const core::ir::Var* v) { EmitVar(Line(), v); }, //

[&](const core::ir::NextIteration*) { /* do nothing */ }, //
[&](const core::ir::ExitIf*) { /* do nothing handled by transform */ }, //
Expand All @@ -294,6 +296,57 @@ class Printer : public tint::TextGenerator {
}
}

void EmitStoreVectorElement(const core::ir::StoreVectorElement* l) {
auto out = Line();

EmitValue(out, l->To());
out << "[";
EmitValue(out, l->Index());
out << "] = ";
EmitValue(out, l->Value());
out << ";";
}

void IdxToComponent(StringStream& out, uint32_t idx) {
switch (idx) {
case 0:
out << "x";
break;
case 1:
out << "y";
break;
case 2:
out << "z";
break;
case 3:
out << "w";
break;
default:
TINT_UNREACHABLE();
}
}

void EmitLoadVectorElement(StringStream& out, const core::ir::LoadVectorElement* l) {
EmitValue(out, l->From());

if (auto* cnst = l->Index()->As<core::ir::Constant>()) {
out << ".";
IdxToComponent(out, cnst->Value()->ValueAs<uint32_t>());
} else {
out << "[";
EmitValue(out, l->Index());
out << "]";
}
}

void EmitSwizzle(StringStream& out, const core::ir::Swizzle* swizzle) {
EmitValue(out, swizzle->Object());
out << ".";
for (const auto i : swizzle->Indices()) {
IdxToComponent(out, i);
}
}

void EmitDiscard() { Line() << "discard;"; }

void EmitContinue() {
Expand Down Expand Up @@ -753,7 +806,9 @@ class Printer : public tint::TextGenerator {
[&](const core::ir::CoreUnary* u) { EmitUnary(out, u); },
[&](const core::ir::Let* l) { out << NameOf(l->Result(0)); },
[&](const core::ir::Load* l) { EmitLoad(out, l); },
[&](const core::ir::LoadVectorElement* l) { EmitLoadVectorElement(out, l); },
[&](const core::ir::Store* s) { EmitStore(s); },
[&](const core::ir::Swizzle* s) { EmitSwizzle(out, s); }, //
[&](const core::ir::UserCall* c) { EmitUserCall(out, c); },
[&](const core::ir::Var* var) { out << NameOf(var->Result(0)); },

Expand Down
19 changes: 9 additions & 10 deletions test/tint/access/var/matrix.spvasm.expected.ir.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
SKIP: FAILED
#version 310 es

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:482 internal compiler error: Switch() matched no cases. Type: tint::core::ir::LoadVectorElement
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
void main_1() {
mat3 m = mat3(vec3(0.0f), vec3(0.0f), vec3(0.0f));
float x_16 = m[1].y;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
main_1();
}
21 changes: 11 additions & 10 deletions test/tint/access/var/vector.spvasm.expected.ir.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
SKIP: FAILED
#version 310 es

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:482 internal compiler error: Switch() matched no cases. Type: tint::core::ir::LoadVectorElement
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
void main_1() {
vec3 v = vec3(0.0f);
float x_14 = v.y;
vec2 x_17 = v.xz;
vec3 x_19 = v.xzy;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
main_1();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
SKIP: FAILED
#version 310 es

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:482 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Access
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform mat2 u[4];
float s;
float a(mat2 a_1[4]) {
return a_1[0][0][0u];
}
float b(mat2 m) {
return m[0][0u];
}
float c(vec2 v) {
return v[0u];
}
float d(float f) {
return f;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
float v_1 = a(u);
float v_2 = (v_1 + b(u[1]));
float v_3 = (v_2 + c(u[1][0].yx));
s = (v_3 + d(u[1][0].yx[0u]));
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
SKIP: FAILED
#version 310 es

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:252 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Store
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform mat2 u[4];
float s;
mat2 p[4] = mat2[4](mat2(vec2(0.0f), vec2(0.0f)), mat2(vec2(0.0f), vec2(0.0f)), mat2(vec2(0.0f), vec2(0.0f)), mat2(vec2(0.0f), vec2(0.0f)));
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
p = u;
p[1] = u[2];
p[1][0] = u[0][1].yx;
p[1][0][0u] = u[0][1].x;
s = p[1][0].x;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SKIP: FAILED
#version 310 es

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:252 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Store
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform mat2 u[4];
mat2 s[4];
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
s = u;
s[1] = u[2];
s[1][0] = u[0][1].yx;
s[1][0][0u] = u[0][1].x;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
SKIP: FAILED
#version 310 es
#extension GL_AMD_gpu_shader_half_float: require

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:482 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Access
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform f16mat2x3 u[4];
float16_t s;
float16_t a(f16mat2x3 a_1[4]) {
return a_1[0][0][0u];
}
float16_t b(f16mat2x3 m) {
return m[0][0u];
}
float16_t c(f16vec3 v) {
return v[0u];
}
float16_t d(float16_t f) {
return f;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
float16_t v_1 = a(u);
float16_t v_2 = (v_1 + b(u[1]));
float16_t v_3 = (v_2 + c(u[1][0].zxy));
s = (v_3 + d(u[1][0].zxy[0u]));
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
SKIP: FAILED
#version 310 es
#extension GL_AMD_gpu_shader_half_float: require

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:252 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Store
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform f16mat2x3 u[4];
float16_t s;
f16mat2x3 p[4] = f16mat2x3[4](f16mat2x3(f16vec3(0.0hf), f16vec3(0.0hf)), f16mat2x3(f16vec3(0.0hf), f16vec3(0.0hf)), f16mat2x3(f16vec3(0.0hf), f16vec3(0.0hf)), f16mat2x3(f16vec3(0.0hf), f16vec3(0.0hf)));
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
p = u;
p[1] = u[2];
p[1][0] = u[0][1].zxy;
p[1][0][0u] = u[0][1].x;
s = p[1][0].x;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
SKIP: FAILED
#version 310 es
#extension GL_AMD_gpu_shader_half_float: require

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:482 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Load
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform f16mat2x3 u[4];
f16mat2x3 s[4];
void tint_store_and_preserve_padding_1(inout f16mat2x3 target, f16mat2x3 value_param) {
target[0u] = value_param[0u];
target[1u] = value_param[1u];
}
void tint_store_and_preserve_padding(inout f16mat2x3 target[4], f16mat2x3 value_param[4]) {
{
uint v = 0u;
v = 0u;
while(true) {
uint v_1 = v;
if ((v_1 >= 4u)) {
break;
}
tint_store_and_preserve_padding_1(target[v_1], value_param[v_1]);
{
v = (v_1 + 1u);
}
continue;
}
}
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
tint_store_and_preserve_padding(s, u);
tint_store_and_preserve_padding_1(s[1], u[2]);
s[1][0] = u[0][1].zxy;
s[1][0][0u] = u[0][1].x;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
SKIP: FAILED
#version 310 es

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:482 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Access
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform mat2x3 u[4];
float s;
float a(mat2x3 a_1[4]) {
return a_1[0][0][0u];
}
float b(mat2x3 m) {
return m[0][0u];
}
float c(vec3 v) {
return v[0u];
}
float d(float f) {
return f;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
float v_1 = a(u);
float v_2 = (v_1 + b(u[1]));
float v_3 = (v_2 + c(u[1][0].zxy));
s = (v_3 + d(u[1][0].zxy[0u]));
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
SKIP: FAILED
#version 310 es

<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:252 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Store
********************************************************************
* The tint shader compiler has encountered an unexpected error. *
* *
* Please help us fix this issue by submitting a bug report at *
* crbug.com/tint with the source program that triggered the bug. *
********************************************************************

tint executable returned error: signal: illegal instruction
uniform mat2x3 u[4];
float s;
mat2x3 p[4] = mat2x3[4](mat2x3(vec3(0.0f), vec3(0.0f)), mat2x3(vec3(0.0f), vec3(0.0f)), mat2x3(vec3(0.0f), vec3(0.0f)), mat2x3(vec3(0.0f), vec3(0.0f)));
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
p = u;
p[1] = u[2];
p[1][0] = u[0][1].zxy;
p[1][0][0u] = u[0][1].x;
s = p[1][0].x;
}
Loading

0 comments on commit 32f3eff

Please sign in to comment.