forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultisample.hlsl
More file actions
214 lines (187 loc) · 6.21 KB
/
multisample.hlsl
File metadata and controls
214 lines (187 loc) · 6.21 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014 Crytek
*
* 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.
******************************************************************************/
// when serialising out a multisampled texture to disk from the app we're capturing
// (or serialising it back in, for that matter), we copy each sample to a slice in a
// 2DArray texture, and vice-versa. These shaders do that copy as appropriate.
struct wireframeV2F
{
float4 pos : SV_Position;
float3 norm : Normal;
float3 color : COLOR;
float2 tex : TEXCOORD0;
};
cbuffer msarraycopyconsts : register(b0)
{
uint sampleCount;
uint currentStencil;
uint currentSample;
uint currentSlice;
};
Texture2DMSArray<uint4, 2> sourceMS2 : register(t1);
Texture2DMSArray<uint4, 4> sourceMS4 : register(t2);
Texture2DMSArray<uint4, 8> sourceMS8 : register(t3);
Texture2DMSArray<uint4, 16> sourceMS16 : register(t4);
Texture2DMSArray<uint4, 32> sourceMS32 : register(t5);
uint4 RENDERDOC_CopyMSToArray(wireframeV2F IN) : SV_Target0
{
uint3 srcCoord = uint3(IN.pos.x, IN.pos.y, currentSlice);
if(sampleCount == 2)
{
return sourceMS2.Load(srcCoord, currentSample);
}
else if(sampleCount == 4)
{
return sourceMS4.Load(srcCoord, currentSample);
}
else if(sampleCount == 8)
{
return sourceMS8.Load(srcCoord, currentSample);
}
else if(sampleCount == 16)
{
return sourceMS16.Load(srcCoord, currentSample);
}
else if(sampleCount == 32)
{
return sourceMS32.Load(srcCoord, currentSample);
}
return 0;
}
Texture2DMSArray<float4, 2> sourceFloatMS2 : register(t1);
Texture2DMSArray<float4, 4> sourceFloatMS4 : register(t2);
Texture2DMSArray<float4, 8> sourceFloatMS8 : register(t3);
Texture2DMSArray<float4, 16> sourceFloatMS16 : register(t4);
Texture2DMSArray<float4, 32> sourceFloatMS32 : register(t5);
float4 RENDERDOC_FloatCopyMSToArray(wireframeV2F IN) : SV_Target0
{
uint3 srcCoord = uint3(IN.pos.x, IN.pos.y, currentSlice);
if(sampleCount == 2)
{
return sourceFloatMS2.Load(srcCoord, currentSample);
}
else if(sampleCount == 4)
{
return sourceFloatMS4.Load(srcCoord, currentSample);
}
else if(sampleCount == 8)
{
return sourceFloatMS8.Load(srcCoord, currentSample);
}
else if(sampleCount == 16)
{
return sourceFloatMS16.Load(srcCoord, currentSample);
}
else if(sampleCount == 32)
{
return sourceFloatMS32.Load(srcCoord, currentSample);
}
return 0;
}
Texture2DMSArray<float2, 2> sourceDepthMS2 : register(t1);
Texture2DMSArray<float2, 4> sourceDepthMS4 : register(t2);
Texture2DMSArray<float2, 8> sourceDepthMS8 : register(t3);
Texture2DMSArray<float2, 16> sourceDepthMS16 : register(t4);
Texture2DMSArray<float2, 32> sourceDepthMS32 : register(t5);
Texture2DMSArray<uint2, 2> sourceStencilMS2 : register(t11);
Texture2DMSArray<uint2, 4> sourceStencilMS4 : register(t12);
Texture2DMSArray<uint2, 8> sourceStencilMS8 : register(t13);
Texture2DMSArray<uint2, 16> sourceStencilMS16 : register(t14);
Texture2DMSArray<uint2, 32> sourceStencilMS32 : register(t15);
float RENDERDOC_DepthCopyMSToArray(wireframeV2F IN) : SV_Depth
{
uint3 srcCoord = uint3(IN.pos.x, IN.pos.y, currentSlice);
if(currentStencil < 256)
{
if(sampleCount == 2)
{
if(sourceStencilMS2.Load(srcCoord, currentSample).y != currentStencil)
discard;
}
else if(sampleCount == 4)
{
if(sourceStencilMS4.Load(srcCoord, currentSample).y != currentStencil)
discard;
}
else if(sampleCount == 8)
{
if(sourceStencilMS8.Load(srcCoord, currentSample).y != currentStencil)
discard;
}
else if(sampleCount == 16)
{
if(sourceStencilMS16.Load(srcCoord, currentSample).y != currentStencil)
discard;
}
else if(sampleCount == 32)
{
if(sourceStencilMS32.Load(srcCoord, currentSample).y != currentStencil)
discard;
}
}
if(sampleCount == 2)
{
return sourceDepthMS2.Load(srcCoord, currentSample).x;
}
else if(sampleCount == 4)
{
return sourceDepthMS4.Load(srcCoord, currentSample).x;
}
else if(sampleCount == 8)
{
return sourceDepthMS8.Load(srcCoord, currentSample).x;
}
else if(sampleCount == 16)
{
return sourceDepthMS16.Load(srcCoord, currentSample).x;
}
else if(sampleCount == 32)
{
return sourceDepthMS32.Load(srcCoord, currentSample).x;
}
return 0;
}
Texture2DArray<uint4> sourceArray : register(t0);
uint4 RENDERDOC_CopyArrayToMS(wireframeV2F IN, uint curSample : SV_SampleIndex) : SV_Target0
{
uint4 srcCoord = uint4(IN.pos.x, IN.pos.y, currentSlice*sampleCount + curSample, 0);
return sourceArray.Load(srcCoord);
}
Texture2DArray<float4> sourceFloatArray : register(t0);
float4 RENDERDOC_FloatCopyArrayToMS(wireframeV2F IN, uint curSample : SV_SampleIndex) : SV_Target0
{
uint4 srcCoord = uint4(IN.pos.x, IN.pos.y, currentSlice*sampleCount + curSample, 0);
return sourceFloatArray.Load(srcCoord);
}
Texture2DArray<float2> sourceDepthArray : register(t0);
Texture2DArray<uint2> sourceStencilArray : register(t1);
float RENDERDOC_DepthCopyArrayToMS(wireframeV2F IN, uint curSample : SV_SampleIndex) : SV_Depth
{
uint4 srcCoord = uint4(IN.pos.x, IN.pos.y, currentSlice*sampleCount + curSample, 0);
if(currentStencil < 1000)
{
if(sourceStencilArray.Load(srcCoord).y != currentStencil)
discard;
}
return sourceDepthArray.Load(srcCoord).x;
}