-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAddTwo.sm
More file actions
57 lines (47 loc) · 1.6 KB
/
Copy pathAddTwo.sm
File metadata and controls
57 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT OR Apache-2.0
# Create a HLSL source called csshader
SOURCE csshader
ByteAddressBuffer inbuf[2] : register(t0); // SRV
RWByteAddressBuffer outbuf : register(u0); // UAV
[numthreads(32, 1, 1)]
void CSMain(uint3 DTid : SV_DispatchThreadID)
{
// Take 2 numbers from first buffer, one from second, and sum them
unsigned int first_idx = DTid.x * 2;
float first = inbuf[0].Load<float>(first_idx * 4) + inbuf[0].Load<float>((first_idx + 1) * 4);
float sum = first + inbuf[1].Load<float>(DTid.x * 4);
outbuf.Store<float>(DTid.x * 4, sum);
}
END
# Compile the source with dxc into a binary called csobj
OBJECT csobj csshader cs_6_4 CSMain
# Allocate buffers in GPU memory for input and output
BUFFER inbuf DATA_TYPE float SIZE 64 SERIES_FROM 0 INC_BY .25
BUFFER inbuf2 DATA_TYPE float SIZE 32 SERIES_FROM 10.0 INC_BY .25
BUFFER outbuf DATA_TYPE float SIZE 32 FILL 0
# The root signature
ROOT default
TABLE UAV REGISTER 0 NUMBER 1 SPACE 0
TABLE SRV REGISTER 0 NUMBER 2 SPACE 0
END
# Create a compute pipeline called cspipe
PIPELINE cspipe COMPUTE
ATTACH csobj
ROOT default
END
# Create views that point to the complete buffers
VIEW inview inbuf AS SRV
VIEW inview2 inbuf2 AS SRV
VIEW outview outbuf AS UAV
# Run the pipeline in a 1x1x1 dispatch
DISPATCH cspipe
BIND 0 TABLE outview
BIND 1 TABLE inview
RUN 1 1 1
# Check that the shaders worked as expected
EXPECT outbuf float OFFSET 0 EQ 10.25 11.5 12.75 14
EXPECT outbuf float OFFSET 64 EQ 30.25 31.5 32.75 34
# Use DUMP to see a buffer's content
#DUMP outbuf float