yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1// Test anyvalue packing of 16bit types. 2 3//TEST_DISABLED(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda -output-using-type 4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -render-feature int16,half 5//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_2 -output-using-type 6//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda -profile sm_6_2 -output-using-type 7 8[anyValueSize(32)] 9interface IInterface 10{ 11 float run(); 12} 13 14struct Val : IInterface 15{ 16 int16_t v0; 17 float f0; 18 uint16_t v1; 19 float16_t v2; 20 half v3; 21 uint16_t v4; 22 float run() 23 { 24 return v0 + f0 + v1 + v2 + v3 + v4; 25 } 26}; 27 28struct UserDefinedPackedType 29{ 30 uint4 values[2]; 31}; 32 33//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=gOutputBuffer 34RWStructuredBuffer<float> gOutputBuffer; 35 36//TEST_INPUT: type_conformance Val:IInterface = 11 37 38[numthreads(1, 1, 1)] 39void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 40{ 41 uint half_4_0 = 0x4400; // 4.0f 42 uint half_5_0 = 0x4500; // 5.0f 43 44 UserDefinedPackedType objStorage; 45 objStorage.values[0] = uint4(1, asuint(2.0), (3U | (half_4_0<<16)), (half_5_0 | (6<<16))); 46 objStorage.values[1] = 0; 47 48 IInterface dynamicObj = createDynamicObject<IInterface, UserDefinedPackedType>(11, objStorage); 49 float result = dynamicObj.run(); 50 gOutputBuffer[0] = result; 51 52 Val v; 53 v.v0 = 1; 54 v.f0 = 2; 55 v.v1 = 3; 56 v.v2 = half(4); 57 v.v3 = half(5); 58 v.v4 = 6; 59 IInterface dynamicObj1 = createDynamicObject<IInterface, Val>(11, v);; 60 gOutputBuffer[1] = dynamicObj1.run(); 61 62 var packed = reinterpret<UserDefinedPackedType, Val>(v); 63 var unpacked = reinterpret<Val, UserDefinedPackedType>(packed); 64 gOutputBuffer[2] = unpacked.run(); 65}