-
Notifications
You must be signed in to change notification settings - Fork 35
/
SPDIntegration.glsl
192 lines (178 loc) · 5.69 KB
/
SPDIntegration.glsl
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#version 450
#extension GL_GOOGLE_include_directive : enable
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#extension GL_ARB_compute_shader : enable
#extension GL_ARB_shader_group_vote : enable
// SPDSample
//
// Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
//--------------------------------------------------------------------------------------
// Push Constants
//--------------------------------------------------------------------------------------
layout(push_constant) uniform SpdConstants
{
uint mips;
uint numWorkGroups;
ivec2 workGroupOffset;
} spdConstants;
//--------------------------------------------------------------------------------------
// Texture definitions
//--------------------------------------------------------------------------------------
layout(set=0, binding=0, rgba16f) uniform image2DArray imgDst[13]; // don't access mip [6]
layout(set=0, binding=1, rgba16f) coherent uniform image2DArray imgDst6;
//--------------------------------------------------------------------------------------
// Buffer definitions - global atomic counter
//--------------------------------------------------------------------------------------
layout(std430, binding=2) coherent buffer spdGlobalAtomicBuffer
{
uint counter[6];
} spdGlobalAtomic;
#define A_GPU
#define A_GLSL
#include "ffx_a.h"
shared AU1 spdCounter;
// define fetch and store functions Non-Packed
#ifndef SPD_PACKED_ONLY
shared AF1 spdIntermediateR[16][16];
shared AF1 spdIntermediateG[16][16];
shared AF1 spdIntermediateB[16][16];
shared AF1 spdIntermediateA[16][16];
AF4 SpdLoadSourceImage(ASU2 p, AU1 slice)
{
return imageLoad(imgDst[0], ivec3(p,slice));
}
AF4 SpdLoad(ASU2 p, AU1 slice)
{
return imageLoad(imgDst6,ivec3(p,slice));
}
void SpdStore(ASU2 p, AF4 value, AU1 mip, AU1 slice)
{
if (mip == 5)
{
imageStore(imgDst6, ivec3(p,slice), value);
return;
}
imageStore(imgDst[mip+1], ivec3(p,slice), value);
}
void SpdIncreaseAtomicCounter(AU1 slice)
{
spdCounter = atomicAdd(spdGlobalAtomic.counter[slice], 1);
}
AU1 SpdGetAtomicCounter()
{
return spdCounter;
}
void SpdResetAtomicCounter(AU1 slice)
{
spdGlobalAtomic.counter[slice] = 0;
}
AF4 SpdLoadIntermediate(AU1 x, AU1 y)
{
return AF4(
spdIntermediateR[x][y],
spdIntermediateG[x][y],
spdIntermediateB[x][y],
spdIntermediateA[x][y]);
}
void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value)
{
spdIntermediateR[x][y] = value.x;
spdIntermediateG[x][y] = value.y;
spdIntermediateB[x][y] = value.z;
spdIntermediateA[x][y] = value.w;
}
AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3)
{
return (v0+v1+v2+v3)*0.25;
}
#endif
// define fetch and store functions Packed
#ifdef A_HALF
shared AH2 spdIntermediateRG[16][16];
shared AH2 spdIntermediateBA[16][16];
AH4 SpdLoadSourceImageH(ASU2 p, AU1 slice)
{
return AH4(imageLoad(imgDst[0], ivec3(p,slice)));
}
AH4 SpdLoadH(ASU2 p, AU1 slice)
{
return AH4(imageLoad(imgDst6, ivec3(p,slice)));
}
void SpdStoreH(ASU2 p, AH4 value, AU1 mip, AU1 slice)
{
if (mip == 5)
{
imageStore(imgDst6, ivec3(p,slice), AF4(value));
return;
}
imageStore(imgDst[mip+1], ivec3(p,slice), AF4(value));
}
void SpdIncreaseAtomicCounter(AU1 slice)
{
spdCounter = atomicAdd(spdGlobalAtomic.counter[slice], 1);
}
AU1 SpdGetAtomicCounter()
{
return spdCounter;
}
void SpdResetAtomicCounter(AU1 slice)
{
spdGlobalAtomic.counter[slice] = 0;
}
AH4 SpdLoadIntermediateH(AU1 x, AU1 y)
{
return AH4(
spdIntermediateRG[x][y].x,
spdIntermediateRG[x][y].y,
spdIntermediateBA[x][y].x,
spdIntermediateBA[x][y].y);}
void SpdStoreIntermediateH(AU1 x, AU1 y, AH4 value){
spdIntermediateRG[x][y] = value.xy;
spdIntermediateBA[x][y] = value.zw;
}
AH4 SpdReduce4H(AH4 v0, AH4 v1, AH4 v2, AH4 v3)
{
return (v0+v1+v2+v3)*AH1(0.25f);
}
#endif
#include "ffx_spd.h"
// Main function
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
void main()
{
#ifndef A_HALF
SpdDownsample(
AU2(gl_WorkGroupID.xy),
AU1(gl_LocalInvocationIndex),
AU1(spdConstants.mips),
AU1(spdConstants.numWorkGroups),
AU1(gl_WorkGroupID.z),
AU2(spdConstants.workGroupOffset));
#else
SpdDownsampleH(
AU2(gl_WorkGroupID.xy),
AU1(gl_LocalInvocationIndex),
AU1(spdConstants.mips),
AU1(spdConstants.numWorkGroups),
AU1(gl_WorkGroupID.z),
AU2(spdConstants.workGroupOffset));
#endif
}