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 8bit types. 2 3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -render-feature int16 5//TEST_DISABLED(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_2 -output-using-type 6 7[anyValueSize(20)] 8interface IInterface 9{ 10 float run(); 11} 12 13struct Val : IInterface 14{ 15 int8_t v0; 16 uint8_t v1; 17 float f0; 18 uint16_t v2; 19 uint8_t v3; 20 uint32_t v4; 21 uint8_t v5; 22 float run() 23 { 24 return v0 + v1 + f0 + v2 + v3 + v4 + v5; 25 } 26}; 27 28struct UserDefinedPackedType 29{ 30 uint values[5]; 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 UserDefinedPackedType objStorage; 42 objStorage.values[0] = 0xA5A50201; 43 objStorage.values[1] = asuint(3.0f); 44 objStorage.values[2] = 4u|(0xA505u<<16u); 45 objStorage.values[3] = 6; 46 objStorage.values[4] = 7; 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.v1 = 2; 55 v.f0 = 3; 56 v.v2 = 4; 57 v.v3 = 5; 58 v.v4 = 6; 59 v.v5 = 7; 60 61 IInterface dynamicObj1 = createDynamicObject<IInterface, Val>(11, v);; 62 gOutputBuffer[1] = dynamicObj1.run(); 63 64 var packed = reinterpret<UserDefinedPackedType, Val>(v); 65 var unpacked = reinterpret<Val, UserDefinedPackedType>(packed); 66 gOutputBuffer[2] = unpacked.run(); 67} 68