yum-mirror/slang

Making it easier to work with shaders

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

jsmall-nvidiansight Aftermath crash example (#2984)1fe5e83f3

master
1.7 KiB81 linesraw
1// This shader is purposefully designed to be so slow it will cause a GPU timeout/crash.
2
3// Uniform data to be passed from application -> shader.
4cbuffer Uniforms
5{
6    float4x4 modelViewProjection;
7
8    // We want to make things fail so we can get an aftermath capture, 
9    // so lets have a count that makes things really slow.
10    int failCount;
11}
12
13// Per-vertex attributes to be assembled from bound vertex buffers.
14struct AssembledVertex
15{
16    float3	position : POSITION;
17    float3	color    : COLOR;
18};
19
20// Output of the vertex shader, and input to the fragment shader.
21struct CoarseVertex
22{
23    float3 color;
24};
25
26// Output of the fragment shader
27struct Fragment
28{
29    float4 color;
30};
31
32// Vertex  Shader
33
34struct VertexStageOutput
35{
36    CoarseVertex    coarseVertex    : CoarseVertex;
37    float4          sv_position     : SV_Position;
38};
39
40[shader("vertex")]
41VertexStageOutput vertexMain(
42    AssembledVertex assembledVertex)
43{
44    VertexStageOutput output;
45
46    float3 position = assembledVertex.position;
47    float3 color    = assembledVertex.color;
48
49    output.coarseVertex.color = color;
50    output.sv_position = mul(modelViewProjection, float4(position, 1.0));
51
52    return output;
53}
54
55// Fragment Shader
56
57[shader("fragment")]
58float4 fragmentMain(
59    CoarseVertex coarseVertex : CoarseVertex) : SV_Target
60{
61    float3 color = coarseVertex.color;
62
63    float factor = 0.0f;
64
65    // Waste lots of cycles
66    for (int i = 0; i < failCount; ++i)
67    {
68        factor += 1.0e-20 * sin(float(i & 0xffff));
69        factor += 1.0e-21 * cos(float(i & 0xfff) + 1.0);
70        factor += 1.0e-8f * tan(float(i & 0xfffff));
71    }
72
73    factor = abs(factor);
74
75    while (factor < 0.25)
76    {
77        factor += factor;
78    }
79
80    return float4(color, 1.0) * factor;
81}