diff --git a/include/API/FormatConversion.h b/include/API/FormatConversion.h index 096d6aaf4..763a88705 100644 --- a/include/API/FormatConversion.h +++ b/include/API/FormatConversion.h @@ -80,13 +80,6 @@ inline llvm::Expected toFormat(DataFormat Format, int Channels) { return Format::RGBA32Float; } break; - case DataFormat::Depth32: - // D32FloatS8Uint is not expressible as DataFormat + Channels because the - // stencil component is uint8, not a second Depth32 channel. Once the - // pipeline uses Format directly, this limitation goes away. - if (Channels == 1) - return Format::D32Float; - break; case DataFormat::UInt64: // Only 1 and 2 channels of 64-bit integers are supported. switch (Channels) { diff --git a/include/Support/Pipeline.h b/include/Support/Pipeline.h index 81ceeb985..09bba09e4 100644 --- a/include/Support/Pipeline.h +++ b/include/Support/Pipeline.h @@ -107,7 +107,6 @@ enum class DataFormat { Float16, Float32, Float64, - Depth32, Bool, }; @@ -198,7 +197,6 @@ static inline uint32_t getFormatSize(DataFormat Format) { case DataFormat::UInt32: case DataFormat::Int32: case DataFormat::Float32: - case DataFormat::Depth32: case DataFormat::Bool: return 4; case DataFormat::Hex64: @@ -216,6 +214,11 @@ struct CPUBuffer { int Channels; int Stride; uint32_t ArraySize; + // When set, names the GPU texture format directly (e.g. D32Float) instead of + // inferring it from DataFormat + Channels via toFormat(). This lets depth + // buffers and other special formats be expressed without extending + // DataFormat. + std::optional GPUFormat; // Data can contain one block of data for a singular resource // or multiple blocks for a resource array. llvm::SmallVector> Data; @@ -931,7 +934,6 @@ template <> struct ScalarEnumerationTraits { ENUM_CASE(Float16); ENUM_CASE(Float32); ENUM_CASE(Float64); - ENUM_CASE(Depth32); ENUM_CASE(Bool); #undef ENUM_CASE } diff --git a/lib/API/DX/Device.cpp b/lib/API/DX/Device.cpp index 76d05f39e..2a33f8d2b 100644 --- a/lib/API/DX/Device.cpp +++ b/lib/API/DX/Device.cpp @@ -2559,7 +2559,10 @@ class DXDevice : public offloadtest::Device { "Multiple mip levels are not yet " "supported for DirectX textures."); - auto FormatOrErr = toFormat(R.BufferPtr->Format, R.BufferPtr->Channels); + auto FormatOrErr = + R.BufferPtr->GPUFormat + ? llvm::Expected(*R.BufferPtr->GPUFormat) + : toFormat(R.BufferPtr->Format, R.BufferPtr->Channels); if (!FormatOrErr) return FormatOrErr.takeError(); diff --git a/lib/API/VK/Device.cpp b/lib/API/VK/Device.cpp index f12ccb9f7..fccbdf194 100644 --- a/lib/API/VK/Device.cpp +++ b/lib/API/VK/Device.cpp @@ -60,10 +60,6 @@ static VkFormat getVKFormat(DataFormat Format, int Channels) { VKFormats(UINT, 64) break; case DataFormat::Float64: VKFormats(SFLOAT, 64) break; - case DataFormat::Depth32: - if (Channels != 1) - llvm_unreachable("Depth32 format only supports a single channel."); - return VK_FORMAT_D32_SFLOAT; default: llvm_unreachable("Unsupported Resource format specified"); } @@ -3395,13 +3391,15 @@ class VulkanDevice : public offloadtest::Device { llvm::Expected createImage(Resource &R, BufferRef &Host, int UsageOverride = 0) { const offloadtest::CPUBuffer &B = *R.BufferPtr; - if (B.Format == DataFormat::Depth32 && R.isReadWrite()) + const bool IsDepth = B.GPUFormat && isDepthFormat(*B.GPUFormat); + if (IsDepth && R.isReadWrite()) return llvm::createStringError(std::errc::invalid_argument, "Image memory allocation failed."); VkImageCreateInfo ImageCreateInfo = {}; ImageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; ImageCreateInfo.imageType = getVKImageType(R.Kind); - ImageCreateInfo.format = getVKFormat(B.Format, B.Channels); + ImageCreateInfo.format = B.GPUFormat ? getVulkanFormat(*B.GPUFormat) + : getVKFormat(B.Format, B.Channels); ImageCreateInfo.mipLevels = B.OutputProps.MipLevels; ImageCreateInfo.arrayLayers = 1; ImageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT; @@ -3823,12 +3821,14 @@ class VulkanDevice : public offloadtest::Device { ViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; ViewCreateInfo.viewType = getImageViewType(R.Kind); ViewCreateInfo.format = - getVKFormat(R.BufferPtr->Format, R.BufferPtr->Channels); + R.BufferPtr->GPUFormat + ? getVulkanFormat(*R.BufferPtr->GPUFormat) + : getVKFormat(R.BufferPtr->Format, R.BufferPtr->Channels); ViewCreateInfo.components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A}; ViewCreateInfo.subresourceRange.aspectMask = - R.BufferPtr->Format == DataFormat::Depth32 + (R.BufferPtr->GPUFormat && isDepthFormat(*R.BufferPtr->GPUFormat)) ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; ViewCreateInfo.subresourceRange.baseMipLevel = 0; @@ -4086,13 +4086,13 @@ class VulkanDevice : public offloadtest::Device { return; if (R.isImage()) { const offloadtest::CPUBuffer &B = *R.BufferPtr; + const bool IsDepth = B.GPUFormat && isDepthFormat(*B.GPUFormat); llvm::SmallVector Regions; uint64_t CurrentOffset = 0; for (int I = 0; I < B.OutputProps.MipLevels; ++I) { VkBufferImageCopy Region = {}; - Region.imageSubresource.aspectMask = B.Format == DataFormat::Depth32 - ? VK_IMAGE_ASPECT_DEPTH_BIT - : VK_IMAGE_ASPECT_COLOR_BIT; + Region.imageSubresource.aspectMask = + IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; Region.imageSubresource.mipLevel = I; Region.imageSubresource.baseArrayLayer = 0; Region.imageSubresource.layerCount = 1; @@ -4110,9 +4110,8 @@ class VulkanDevice : public offloadtest::Device { } VkImageSubresourceRange SubRange = {}; - SubRange.aspectMask = B.Format == DataFormat::Depth32 - ? VK_IMAGE_ASPECT_DEPTH_BIT - : VK_IMAGE_ASPECT_COLOR_BIT; + SubRange.aspectMask = + IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; SubRange.baseMipLevel = 0; SubRange.levelCount = B.OutputProps.MipLevels; SubRange.layerCount = 1; @@ -4232,10 +4231,10 @@ class VulkanDevice : public offloadtest::Device { return; if (R.isImage()) { const offloadtest::CPUBuffer &B = *R.BufferPtr; + const bool IsDepth = B.GPUFormat && isDepthFormat(*B.GPUFormat); VkImageSubresourceRange SubRange = {}; - SubRange.aspectMask = B.Format == DataFormat::Depth32 - ? VK_IMAGE_ASPECT_DEPTH_BIT - : VK_IMAGE_ASPECT_COLOR_BIT; + SubRange.aspectMask = + IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; SubRange.baseMipLevel = 0; SubRange.levelCount = B.OutputProps.MipLevels; SubRange.layerCount = 1; @@ -4262,9 +4261,8 @@ class VulkanDevice : public offloadtest::Device { uint64_t CurrentOffset = 0; for (int I = 0; I < B.OutputProps.MipLevels; ++I) { VkBufferImageCopy Region = {}; - Region.imageSubresource.aspectMask = B.Format == DataFormat::Depth32 - ? VK_IMAGE_ASPECT_DEPTH_BIT - : VK_IMAGE_ASPECT_COLOR_BIT; + Region.imageSubresource.aspectMask = + IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; Region.imageSubresource.mipLevel = I; Region.imageSubresource.baseArrayLayer = 0; Region.imageSubresource.layerCount = 1; diff --git a/lib/Support/Check.cpp b/lib/Support/Check.cpp index f9b94a783..e25dad60a 100644 --- a/lib/Support/Check.cpp +++ b/lib/Support/Check.cpp @@ -228,7 +228,6 @@ testBufferFloat(std::function ComparisonFn, case offloadtest::DataFormat::Float64: return testAllArray(ComparisonFn, B1, B2); case offloadtest::DataFormat::Float32: - case offloadtest::DataFormat::Depth32: return testAllArray(ComparisonFn, B1, B2); case offloadtest::DataFormat::Float16: { return testAllArray(ComparisonFn, B1, B2); @@ -250,8 +249,7 @@ static bool testBufferFloatEpsilon(offloadtest::CPUBuffer *B1, }; return testBufferFloat(Fn, B1, B2); } - case offloadtest::DataFormat::Float32: - case offloadtest::DataFormat::Depth32: { + case offloadtest::DataFormat::Float32: { auto Fn = [Epsilon, DM](const float &FS, const float &FR) { return compareFloatEpsilon(FS, FR, (float)Epsilon, DM); }; @@ -280,8 +278,7 @@ static bool testBufferFloatULP(offloadtest::CPUBuffer *B1, }; return testBufferFloat(Fn, B1, B2); } - case offloadtest::DataFormat::Float32: - case offloadtest::DataFormat::Depth32: { + case offloadtest::DataFormat::Float32: { auto Fn = [ULPT, DM](const float &FS, const float &FR) { return compareFloatULP(FS, FR, ULPT, DM); }; @@ -379,7 +376,6 @@ static const std::string getBufferStr(offloadtest::CPUBuffer *B) { case DF::Float16: return formatBuffer(B); // assuming no native float16 case DF::Float32: - case DF::Depth32: return formatBuffer(B); case DF::Float64: return formatBuffer(B); diff --git a/lib/Support/Pipeline.cpp b/lib/Support/Pipeline.cpp index 1d0c566b6..c93a0ba03 100644 --- a/lib/Support/Pipeline.cpp +++ b/lib/Support/Pipeline.cpp @@ -363,6 +363,7 @@ void MappingTraits::mapping(IO &I, I.mapRequired("Name", B.Name); I.mapRequired("Format", B.Format); I.mapOptional("Channels", B.Channels, 1); + I.mapOptional("GPUFormat", B.GPUFormat); I.mapOptional("Stride", B.Stride, 0); I.mapOptional("ArraySize", B.ArraySize, 1); setCounters(I, B); @@ -407,9 +408,6 @@ void MappingTraits::mapping(IO &I, case DF::Float32: setData(I, B); break; - case DF::Depth32: - setData(I, B); - break; case DF::Float64: setData(I, B); break; @@ -528,8 +526,6 @@ void MappingTraits::mapping( return setData(I, B); // assuming no native float16 case DF::Float32: return setData(I, B); - case DF::Depth32: - return setData(I, B); case DF::Float64: return setData(I, B); case DF::Bool: diff --git a/test/Feature/Textures/Texture2D.GatherCmp.test.yaml b/test/Feature/Textures/Texture2D.GatherCmp.test.yaml index 9a950a6c8..980c1dbe6 100644 --- a/test/Feature/Textures/Texture2D.GatherCmp.test.yaml +++ b/test/Feature/Textures/Texture2D.GatherCmp.test.yaml @@ -68,7 +68,8 @@ Shaders: Buffers: - Name: Tex - Format: Depth32 + Format: Float32 + GPUFormat: D32Float Channels: 1 OutputProps: { Width: 2, Height: 2, Depth: 1 } Data: [ 0.2, # (0,0) R=0.2 diff --git a/test/Feature/Textures/Texture2D.SampleCmp.test.yaml b/test/Feature/Textures/Texture2D.SampleCmp.test.yaml index 52a06c512..dae6d1278 100644 --- a/test/Feature/Textures/Texture2D.SampleCmp.test.yaml +++ b/test/Feature/Textures/Texture2D.SampleCmp.test.yaml @@ -107,7 +107,8 @@ Shaders: Buffers: - Name: Tex - Format: Depth32 + Format: Float32 + GPUFormat: D32Float Channels: 1 OutputProps: { Width: 2, Height: 2, Depth: 1 } Data: [ 0.2, # (0,0) -> 0.2 diff --git a/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.GatherCmp.test.yaml b/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.GatherCmp.test.yaml index b37435331..f44589dcd 100644 --- a/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.GatherCmp.test.yaml +++ b/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.GatherCmp.test.yaml @@ -49,7 +49,8 @@ Shaders: Buffers: - Name: SampledTexLess - Format: Depth32 + Format: Float32 + GPUFormat: D32Float Channels: 1 OutputProps: { Width: 2, Height: 2, Depth: 1 } Data: [ 0.2, # (0,0) R=0.2 @@ -58,7 +59,8 @@ Buffers: 0.8 ] # (1,1) R=0.8 - Name: SampledTexGreater - Format: Depth32 + Format: Float32 + GPUFormat: D32Float Channels: 1 OutputProps: { Width: 2, Height: 2, Depth: 1 } Data: [ 0.2, @@ -67,7 +69,8 @@ Buffers: 0.8 ] - Name: SampledTexRepeat - Format: Depth32 + Format: Float32 + GPUFormat: D32Float Channels: 1 OutputProps: { Width: 2, Height: 2, Depth: 1 } Data: [ 0.2, diff --git a/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.SampleCmp.test.yaml b/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.SampleCmp.test.yaml index 7d9a605bc..03d834df6 100644 --- a/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.SampleCmp.test.yaml +++ b/test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.SampleCmp.test.yaml @@ -88,7 +88,8 @@ Shaders: Buffers: - Name: SampledTexLess - Format: Depth32 + Format: Float32 + GPUFormat: D32Float Channels: 1 OutputProps: { Width: 2, Height: 2, Depth: 1 } Data: [ 0.2, # (0,0) -> 0.2 @@ -97,7 +98,8 @@ Buffers: 0.8 ] # (1,1) -> 0.8 - Name: SampledTexGreater - Format: Depth32 + Format: Float32 + GPUFormat: D32Float Channels: 1 OutputProps: { Width: 2, Height: 2, Depth: 1 } Data: [ 0.2,