diff options
| -rw-r--r-- | source/slang/core.meta.slang | 72 | ||||
| -rw-r--r-- | tests/bugs/vec-init.slang | 33 | ||||
| -rw-r--r-- | tests/bugs/vec-init.slang.expected.txt | 4 |
3 files changed, 60 insertions, 49 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 6b20dbc3b..934d30c18 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -427,60 +427,34 @@ struct ParameterBlock {} //@ hidden: -${{{{ - -static const char* kComponentNames[]{ "x", "y", "z", "w" }; -static const char* kVectorNames[]{ "", "x", "xy", "xyz", "xyzw" }; - // Need to add constructors to the types above -for (int N = 2; N <= 4; ++N) -{ - sb << "__generic<T> __extension vector<T, " << N << ">\n{\n"; - - // initialize from N scalars - sb << "__init("; - for (int ii = 0; ii < N; ++ii) - { - if (ii != 0) sb << ", "; - sb << "T " << kComponentNames[ii]; - } - sb << ");\n"; - - // Initialize from an M-vector and then scalars - for (int M = 2; M < N; ++M) - { - sb << "__init(vector<T," << M << "> " << kVectorNames[M]; - for (int ii = M; ii < N; ++ii) - { - sb << ", T " << kComponentNames[ii]; - } - sb << ");\n"; - } - // Initialize from two vectors, of size M and N-M - for(int M = 2; M <= (N-2); ++M) - { - int K = N - M; - SLANG_ASSERT(K >= 2); +__generic<T> __extension vector<T, 2> +{ + __init(T x, T y); +} +__generic<T> __extension vector<T, 3> +{ + __init(T x, T y, T z); + __init(vector<T,2> xy, T z); + __init(T x, vector<T,2> yz); +} +__generic<T> __extension vector<T, 4> +{ + __init(T x, T y, T z, T w); + __init(vector<T,2> xy, T z, T w); + __init(T x, vector<T,2> yz, T w); + __init(T x, T y, vector<T,2> zw); + __init(vector<T,2> xy, vector<T,2> zw); + __init(vector<T,3> xyz, T w); + __init(T x, vector<T,3> yzw); +} - sb << "__init(vector<T," << M << "> " << kVectorNames[M]; - sb << ", vector<T," << K << "> "; - for (int ii = 0; ii < K; ++ii) - { - // The component names for the second parameter - // must start at `M`, so that we get signatures like: - // - // __init(float2 xy, float2 zw) - // - sb << kComponentNames[M + ii]; - } - sb << ");\n"; - } +${{{{ - sb << "}\n"; -} +static const char* kComponentNames[]{ "x", "y", "z", "w" }; -// The above extension was generic in the *type* of the vector, +// The above extensions are generic in the *type* of the vector, // but explicit in the *size*. We will now declare an extension // for each builtin type that is generic in the size. // diff --git a/tests/bugs/vec-init.slang b/tests/bugs/vec-init.slang new file mode 100644 index 000000000..155073ac2 --- /dev/null +++ b/tests/bugs/vec-init.slang @@ -0,0 +1,33 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(4,1,1)] +void computeMain(uint2 dispatchID : SV_DispatchThreadID) +{ + float a = dispatchID.x * 0.5f; + float b = dispatchID.x + 1.0f; + + float2 c2_0 = float2( a, b); + + float3 c3_0 = float3( a, b, a); + float3 c3_1 = float3( float2(a, b), a); + float3 c3_2 = float3( b, float2(a, b)); + + float4 c4_0 = float4(a, b, a, b); + float4 c4_1 = float4(float2(a, b), a, b); + float4 c4_2 = float4(a, float2(b, a), b); + float4 c4_3 = float4(a, b, float2(a, b)); + float4 c4_4 = float4(float2(a, b), float2(a, b)); + float4 c4_5 = float4(float3(a, b, a), a); + float4 c4_6 = float4(a, float3(a, b, a)); + + float r = c2_0.x + + c3_0.y + c3_1.z + c3_2.x + + c4_0.x + c4_1.x + c4_2.x + c4_3.x + c4_4.x + c4_5.x + c4_6.x; + + outputBuffer[dispatchID.x] = r; +}
\ No newline at end of file diff --git a/tests/bugs/vec-init.slang.expected.txt b/tests/bugs/vec-init.slang.expected.txt new file mode 100644 index 000000000..a8dfa1453 --- /dev/null +++ b/tests/bugs/vec-init.slang.expected.txt @@ -0,0 +1,4 @@ +40000000 +41080000 +41700000 +41AC0000 |
