mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 14:01:08 +01:00
Parsing currently fails for shaders that attempt to dynamically index
an abstract-typed array (or vector, etc), like so:
var x = array(1, 2, 3)[i];
This is caused by attempting to concretize the Expression::Access
expression, which the ConstantEvaluator fails to do so due to the
presence of a non-constant expression.
To solve this, this patch concretizes the base type *prior* to
indexing it (for non-constant indices), meaning the constant evaluator
never sees any non-constant expressions. This matches the WGSL
specification:
When an abstract array value e is indexed by an expression that is
not a const-expression, then the array is concretized before the
index is applied.
(Similar applies for both vectors and matrices, too.)
This may be somewhat non-optimal in that if there are multiple
accesses of the same abstract expression, we will produce duplicated
concretized versions of that expression. This seems unlikely to be a
major issue in practice, and we can always improve this if and when we
encounter a real issue caused by it.
159 lines
3.1 KiB
HLSL
159 lines
3.1 KiB
HLSL
static const uint TWO = 2u;
|
|
static const int THREE = int(3);
|
|
static const bool TRUE = true;
|
|
static const bool FALSE = false;
|
|
static const int FOUR = int(4);
|
|
static const int FOUR_ALIAS = int(4);
|
|
static const int TEST_CONSTANT_ADDITION = int(8);
|
|
static const int TEST_CONSTANT_ALIAS_ADDITION = int(8);
|
|
static const float PI = 3.141;
|
|
static const float phi_sun = 6.282;
|
|
static const float4 DIV = float4(0.44444445, 0.0, 0.0, 0.0);
|
|
static const int TEXTURE_KIND_REGULAR = int(0);
|
|
static const int TEXTURE_KIND_WARP = int(1);
|
|
static const int TEXTURE_KIND_SKY = int(2);
|
|
static const float2 add_vec = float2(4.0, 5.0);
|
|
static const bool2 compare_vec = bool2(true, false);
|
|
|
|
void swizzle_of_compose()
|
|
{
|
|
int4 out_ = int4(int(4), int(3), int(2), int(1));
|
|
|
|
return;
|
|
}
|
|
|
|
void index_of_compose()
|
|
{
|
|
int out_1 = int(2);
|
|
|
|
return;
|
|
}
|
|
|
|
void compose_three_deep()
|
|
{
|
|
int out_2 = int(6);
|
|
|
|
return;
|
|
}
|
|
|
|
void non_constant_initializers()
|
|
{
|
|
int w = int(30);
|
|
int x = (int)0;
|
|
int y = (int)0;
|
|
int z = int(70);
|
|
int4 out_3 = (int4)0;
|
|
|
|
int _e2 = w;
|
|
x = _e2;
|
|
int _e4 = x;
|
|
y = _e4;
|
|
int _e8 = w;
|
|
int _e9 = x;
|
|
int _e10 = y;
|
|
int _e11 = z;
|
|
out_3 = int4(_e8, _e9, _e10, _e11);
|
|
return;
|
|
}
|
|
|
|
void splat_of_constant()
|
|
{
|
|
int4 out_4 = int4(int(-4), int(-4), int(-4), int(-4));
|
|
|
|
return;
|
|
}
|
|
|
|
void compose_of_constant()
|
|
{
|
|
int4 out_5 = int4(int(-4), int(-4), int(-4), int(-4));
|
|
|
|
return;
|
|
}
|
|
|
|
void compose_of_splat()
|
|
{
|
|
float4 x_1 = float4(2.0, 1.0, 1.0, 1.0);
|
|
|
|
return;
|
|
}
|
|
|
|
void test_local_const()
|
|
{
|
|
float arr[2] = (float[2])0;
|
|
|
|
return;
|
|
}
|
|
|
|
uint map_texture_kind(int texture_kind)
|
|
{
|
|
switch(texture_kind) {
|
|
case 0: {
|
|
return 10u;
|
|
}
|
|
case 1: {
|
|
return 20u;
|
|
}
|
|
case 2: {
|
|
return 30u;
|
|
}
|
|
default: {
|
|
return 0u;
|
|
}
|
|
}
|
|
}
|
|
|
|
void compose_vector_zero_val_binop()
|
|
{
|
|
int3 a = int3(int(1), int(1), int(1));
|
|
int3 b = int3(int(0), int(1), int(2));
|
|
int3 c = int3(int(1), int(0), int(2));
|
|
|
|
return;
|
|
}
|
|
|
|
void relational()
|
|
{
|
|
bool scalar_any_false = false;
|
|
bool scalar_any_true = true;
|
|
bool scalar_all_false = false;
|
|
bool scalar_all_true = true;
|
|
bool vec_any_false = false;
|
|
bool vec_any_true = true;
|
|
bool vec_all_false = false;
|
|
bool vec_all_true = true;
|
|
|
|
return;
|
|
}
|
|
|
|
typedef int ret_Constructarray9_int_[9];
|
|
ret_Constructarray9_int_ Constructarray9_int_(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8) {
|
|
int ret[9] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
|
|
return ret;
|
|
}
|
|
|
|
void abstract_access(uint i)
|
|
{
|
|
float a_1 = 1.0;
|
|
uint b_1 = 1u;
|
|
int c_1 = (int)0;
|
|
int d = (int)0;
|
|
|
|
c_1 = Constructarray9_int_(int(1), int(2), int(3), int(4), int(5), int(6), int(7), int(8), int(9))[min(uint(i), 8u)];
|
|
d = int4(int(1), int(2), int(3), int(4))[min(uint(i), 3u)];
|
|
return;
|
|
}
|
|
|
|
[numthreads(2, 3, 1)]
|
|
void main()
|
|
{
|
|
swizzle_of_compose();
|
|
index_of_compose();
|
|
compose_three_deep();
|
|
non_constant_initializers();
|
|
splat_of_constant();
|
|
compose_of_constant();
|
|
compose_of_splat();
|
|
test_local_const();
|
|
return;
|
|
}
|