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
|
#include "gfx-test-texture-util.h"
#include "gfx-test-util.h"
#include "tools/unit-test/slang-unit-test.h"
#include <slang-com-ptr.h>
#define GFX_ENABLE_RENDERDOC_INTEGRATION 0
#if GFX_ENABLE_RENDERDOC_INTEGRATION
# include "external/renderdoc_app.h"
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
#endif
using namespace Slang;
using namespace gfx;
namespace gfx_test
{
TextureAspect getTextureAspect(Format format)
{
switch (format)
{
case Format::D16_UNORM:
case Format::D32_FLOAT:
return TextureAspect::Depth;
default:
return TextureAspect::Color;
}
}
uint32_t getTexelSize(Format format)
{
FormatInfo info;
GFX_CHECK_CALL_ABORT(gfxGetFormatInfo(format, &info));
return info.blockSizeInBytes / info.pixelsPerBlock;
}
uint32_t getSubresourceIndex(uint32_t mipLevel, uint32_t mipLevelCount, uint32_t baseArrayLayer)
{
return baseArrayLayer * mipLevelCount + mipLevel;
}
RefPtr<ValidationTextureFormatBase> getValidationTextureFormat(Format format)
{
switch (format)
{
case Format::R32G32B32A32_TYPELESS: return new ValidationTextureFormat<uint32_t>(4);
case Format::R32G32B32_TYPELESS: return new ValidationTextureFormat<uint32_t>(3);
case Format::R32G32_TYPELESS: return new ValidationTextureFormat<uint32_t>(2);
case Format::R32_TYPELESS: return new ValidationTextureFormat<uint32_t>(1);
case Format::R16G16B16A16_TYPELESS: return new ValidationTextureFormat<uint16_t>(4);
case Format::R16G16_TYPELESS: return new ValidationTextureFormat<uint16_t>(2);
case Format::R16_TYPELESS: return new ValidationTextureFormat<uint16_t>(1);
case Format::R8G8B8A8_TYPELESS: return new ValidationTextureFormat<uint8_t>(4);
case Format::R8G8_TYPELESS: return new ValidationTextureFormat<uint8_t>(2);
case Format::R8_TYPELESS: return new ValidationTextureFormat<uint8_t>(1);
case Format::B8G8R8A8_TYPELESS: return new ValidationTextureFormat<uint8_t>(4);
case Format::R32G32B32A32_FLOAT: return new ValidationTextureFormat<float>(4);
case Format::R32G32B32_FLOAT: return new ValidationTextureFormat<float>(3);
case Format::R32G32_FLOAT: return new ValidationTextureFormat<float>(2);
case Format::R32_FLOAT: return new ValidationTextureFormat<float>(1);
case Format::R16G16B16A16_FLOAT: return new ValidationTextureFormat<uint16_t>(4);
case Format::R16G16_FLOAT: return new ValidationTextureFormat<uint16_t>(2);
case Format::R16_FLOAT: return new ValidationTextureFormat<uint16_t>(1);
case Format::R32G32B32A32_UINT: return new ValidationTextureFormat<uint32_t>(4);
case Format::R32G32B32_UINT: return new ValidationTextureFormat<uint32_t>(3);
case Format::R32G32_UINT: return new ValidationTextureFormat<uint32_t>(2);
case Format::R32_UINT: return new ValidationTextureFormat<uint32_t>(1);
case Format::R16G16B16A16_UINT: return new ValidationTextureFormat<uint16_t>(4);
case Format::R16G16_UINT: return new ValidationTextureFormat<uint16_t>(2);
case Format::R16_UINT: return new ValidationTextureFormat<uint16_t>(1);
case Format::R8G8B8A8_UINT: return new ValidationTextureFormat<uint8_t>(4);
case Format::R8G8_UINT: return new ValidationTextureFormat<uint8_t>(2);
case Format::R8_UINT: return new ValidationTextureFormat<uint8_t>(1);
case Format::R32G32B32A32_SINT: return new ValidationTextureFormat<int32_t>(4);
case Format::R32G32B32_SINT: return new ValidationTextureFormat<int32_t>(3);
case Format::R32G32_SINT: return new ValidationTextureFormat<int32_t>(2);
case Format::R32_SINT: return new ValidationTextureFormat<int32_t>(1);
case Format::R16G16B16A16_SINT: return new ValidationTextureFormat<int16_t>(4);
case Format::R16G16_SINT: return new ValidationTextureFormat<int16_t>(2);
case Format::R16_SINT: return new ValidationTextureFormat<int16_t>(1);
case Format::R8G8B8A8_SINT: return new ValidationTextureFormat<int8_t>(4);
case Format::R8G8_SINT: return new ValidationTextureFormat<int8_t>(2);
case Format::R8_SINT: return new ValidationTextureFormat<int8_t>(1);
case Format::R16G16B16A16_UNORM: return new ValidationTextureFormat<uint16_t>(4);
case Format::R16G16_UNORM: return new ValidationTextureFormat<uint16_t>(2);
case Format::R16_UNORM: return new ValidationTextureFormat<uint16_t>(1);
case Format::R8G8B8A8_UNORM: return new ValidationTextureFormat<uint8_t>(4);
case Format::R8G8B8A8_UNORM_SRGB: return new ValidationTextureFormat<uint8_t>(4);
case Format::R8G8_UNORM: return new ValidationTextureFormat<uint8_t>(2);
case Format::R8_UNORM: return new ValidationTextureFormat<uint8_t>(1);
case Format::B8G8R8A8_UNORM: return new ValidationTextureFormat<uint8_t>(4);
case Format::B8G8R8A8_UNORM_SRGB: return new ValidationTextureFormat<uint8_t>(4);
case Format::B8G8R8X8_UNORM: return new ValidationTextureFormat<uint8_t>(3);
case Format::B8G8R8X8_UNORM_SRGB: return new ValidationTextureFormat<uint8_t>(3);
case Format::R16G16B16A16_SNORM: return new ValidationTextureFormat<int16_t>(4);
case Format::R16G16_SNORM: return new ValidationTextureFormat<int16_t>(2);
case Format::R16_SNORM: return new ValidationTextureFormat<int16_t>(1);
case Format::R8G8B8A8_SNORM: return new ValidationTextureFormat<int8_t>(4);
case Format::R8G8_SNORM: return new ValidationTextureFormat<int8_t>(2);
case Format::R8_SNORM: return new ValidationTextureFormat<int8_t>(1);
case Format::D32_FLOAT: return new ValidationTextureFormat<float>(1);
case Format::D16_UNORM: return new ValidationTextureFormat<uint16_t>(1);
case Format::B4G4R4A4_UNORM: return new PackedValidationTextureFormat<uint16_t>(4, 4, 4, 4);
case Format::B5G6R5_UNORM: return new PackedValidationTextureFormat<uint16_t>(5, 6, 5, 0);
case Format::B5G5R5A1_UNORM: return new PackedValidationTextureFormat<uint16_t>(5, 5, 5, 1);
case Format::R9G9B9E5_SHAREDEXP: return new ValidationTextureFormat<uint32_t>(1);
case Format::R10G10B10A2_TYPELESS: return new PackedValidationTextureFormat<uint32_t>(10, 10, 10, 2);
case Format::R10G10B10A2_UNORM: return new PackedValidationTextureFormat<uint32_t>(10, 10, 10, 2);
case Format::R10G10B10A2_UINT: return new PackedValidationTextureFormat<uint32_t>(10, 10, 10, 2);
case Format::R11G11B10_FLOAT: return new PackedValidationTextureFormat<uint32_t>(11, 11, 10, 0);
// TODO: Add testing support for BC formats
// BC1_UNORM,
// BC1_UNORM_SRGB,
// BC2_UNORM,
// BC2_UNORM_SRGB,
// BC3_UNORM,
// BC3_UNORM_SRGB,
// BC4_UNORM,
// BC4_SNORM,
// BC5_UNORM,
// BC5_SNORM,
// BC6H_UF16,
// BC6H_SF16,
// BC7_UNORM,
// BC7_UNORM_SRGB,
default:
return nullptr;
}
}
void generateTextureData(RefPtr<TextureInfo> texture, ValidationTextureFormatBase* validationFormat)
{
auto extents = texture->extents;
auto arrayLayers = texture->arrayLayerCount;
auto mipLevels = texture->mipLevelCount;
auto texelSize = getTexelSize(texture->format);
for (uint32_t layer = 0; layer < arrayLayers; ++layer)
{
for (uint32_t mip = 0; mip < mipLevels; ++mip)
{
RefPtr<ValidationTextureData> subresource = new ValidationTextureData();
auto mipWidth = Math::Max(extents.width >> mip, 1);
auto mipHeight = Math::Max(extents.height >> mip, 1);
auto mipDepth = Math::Max(extents.depth >> mip, 1);
auto mipSize = mipWidth * mipHeight * mipDepth * texelSize;
subresource->textureData = malloc(mipSize);
SLANG_CHECK_ABORT(subresource->textureData);
subresource->extents.width = mipWidth;
subresource->extents.height = mipHeight;
subresource->extents.depth = mipDepth;
subresource->strides.x = texelSize;
subresource->strides.y = mipWidth * texelSize;
subresource->strides.z = mipHeight * subresource->strides.y;
texture->subresourceObjects.add(subresource);
for (int z = 0; z < mipDepth; ++z)
{
for (int y = 0; y < mipHeight; ++y)
{
for (int x = 0; x < mipWidth; ++x)
{
auto texel = subresource->getBlockAt(x, y, z);
validationFormat->initializeTexel(texel, x, y, z, mip, layer);
}
}
}
ITextureResource::SubresourceData subData = {};
subData.data = subresource->textureData;
subData.strideY = subresource->strides.y;
subData.strideZ = subresource->strides.z;
texture->subresourceDatas.add(subData);
}
}
}
}
|