yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Anders LeinoMigrate render-test away from deprecated compile request API (#6514)f4d5372d3

master
2.8 KiB119 linesraw
1//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj -output-using-type
2//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj -output-using-type -vk
3//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj -output-using-type -mtl
4
5
6// WebGPU only supports 1 MIP level for 1d textures
7// https://www.w3.org/TR/webgpu/#abstract-opdef-maximum-miplevel-count
8//TEST_INPUT: Texture1D(size=4, content = one, mipMaps=1):name=t1D
9//TEST_INPUT: Texture2D(size=4, content = one):name=t2D
10//TEST_INPUT: Texture3D(size=4, content = one):name=t3D
11//TEST_INPUT: TextureCube(size=4, content = one):name=tCube
12//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name=t2dArray
13//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name=tCubeArray
14//TEST_INPUT: Sampler:name=samplerState
15//TEST_INPUT: ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
16
17Texture1D t1D;
18Texture2D t2D;
19Texture3D t3D;
20TextureCube tCube;
21Texture2DArray t2dArray;
22TextureCubeArray tCubeArray;
23SamplerState samplerState;
24RWStructuredBuffer<float> outputBuffer;
25
26cbuffer Uniforms
27{
28	float4x4 modelViewProjection;
29}
30
31struct AssembledVertex
32{
33	float3	position;
34	float3	color;
35    float2  uv;
36};
37
38struct CoarseVertex
39{
40	float3	color;
41    float2  uv;
42};
43
44struct Fragment
45{
46	float4 color;
47};
48
49
50// Vertex  Shader
51
52struct VertexStageInput
53{
54	AssembledVertex assembledVertex	: A;
55};
56
57struct VertexStageOutput
58{
59	CoarseVertex	coarseVertex	: CoarseVertex;
60	float4			sv_position		: SV_Position;
61};
62
63[shader("vertex")]
64VertexStageOutput vertexMain(VertexStageInput input)
65{
66	VertexStageOutput output;
67
68	float3 position = input.assembledVertex.position;
69	float3 color	= input.assembledVertex.color;
70
71	output.coarseVertex.color = color;
72	output.sv_position = mul(modelViewProjection, float4(position, 1.0));
73    output.coarseVertex.uv = input.assembledVertex.uv;
74	return output;
75}
76
77// Fragment Shader
78
79struct FragmentStageInput
80{
81	CoarseVertex	coarseVertex	: CoarseVertex;
82};
83
84struct FragmentStageOutput
85{
86	Fragment fragment	: SV_Target;
87};
88
89[shader("fragment")]
90FragmentStageOutput fragmentMain(FragmentStageInput input)
91{
92	FragmentStageOutput output;
93
94	float3 color = input.coarseVertex.color;
95    float2 uv = input.coarseVertex.uv;
96	output.fragment.color = float4(color, 1.0);
97
98    float4 val = 0.0;
99    val += t1D.Sample(samplerState, uv.x);
100    val += t2D.Sample(samplerState, uv);
101    val += t3D.Sample (samplerState, float3(uv, 0.5));
102    
103    val += t2dArray.Sample(samplerState, float3(uv, 0.0));
104    
105    val += tCubeArray.Sample(samplerState, float4(uv, 0.5, 0.0));
106    val += tCube.Sample(samplerState, float3(uv, 0.5));
107
108    val += t2D.Load(int3(0));
109    val += t2dArray.Load(int4(0));
110
111    val += t3D[int3(0)];
112
113    outputBuffer[0] = val.x;
114
115    int w, h, l, lods;
116    t2dArray.GetDimensions(0, w, h, l, lods);
117    outputBuffer[1] = w + h + l + lods;
118	return output;
119}