diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-03-24 10:54:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-24 10:54:58 -0700 |
| commit | 79b81083b75dc0abdbb8184568dbe36d082e04f3 (patch) | |
| tree | 8bbfa00e3fb7e00e34a2b7441b562d337db24ced /tools/gfx-unit-test/gfx-test-texture-util.cpp | |
| parent | b8617af2888db01f80efba9e0a103e6a61989c9c (diff) | |
Separated out new texture-related structures and texture data generation from texture copying tests into a new util file to make them accessible to all gfx unit tests (#2169)
Diffstat (limited to 'tools/gfx-unit-test/gfx-test-texture-util.cpp')
| -rw-r--r-- | tools/gfx-unit-test/gfx-test-texture-util.cpp | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/tools/gfx-unit-test/gfx-test-texture-util.cpp b/tools/gfx-unit-test/gfx-test-texture-util.cpp new file mode 100644 index 000000000..24cd1c4a9 --- /dev/null +++ b/tools/gfx-unit-test/gfx-test-texture-util.cpp @@ -0,0 +1,191 @@ +#include "gfx-test-texture-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 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 = texture->texelSize; + + 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); + } + } + } +} |
