Skip to content

Commit 61b7687

Browse files
alsepkowCopilot
andcommitted
[NFC] Express GPU texture formats via CPUBuffer GpuFormat field
Replace the special-cased DataFormat::Depth32 enum value with a general CPUBuffer::GpuFormat field that names a GPU Format directly (e.g. D32Float), instead of inferring it from DataFormat + Channels via toFormat(). This removes the need to extend DataFormat for every special texture format and lets depth-format textures be expressed as a regular float buffer plus an explicit GpuFormat. The Vulkan backend now selects the image/view format and depth/color aspect from GpuFormat; the DX and Check paths drop the now-unused Depth32 cases. Existing GatherCmp/SampleCmp depth tests are migrated from "Format: Depth32" to "Format: Float32" + "GpuFormat: D32Float". No functional change intended. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1f92982 commit 61b7687

9 files changed

Lines changed: 42 additions & 48 deletions

File tree

include/API/FormatConversion.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ inline llvm::Expected<Format> toFormat(DataFormat Format, int Channels) {
8080
return Format::RGBA32Float;
8181
}
8282
break;
83-
case DataFormat::Depth32:
84-
// D32FloatS8Uint is not expressible as DataFormat + Channels because the
85-
// stencil component is uint8, not a second Depth32 channel. Once the
86-
// pipeline uses Format directly, this limitation goes away.
87-
if (Channels == 1)
88-
return Format::D32Float;
89-
break;
9083
case DataFormat::UInt64:
9184
// Only 1 and 2 channels of 64-bit integers are supported.
9285
switch (Channels) {

include/Support/Pipeline.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ enum class DataFormat {
107107
Float16,
108108
Float32,
109109
Float64,
110-
Depth32,
111110
Bool,
112111
};
113112

@@ -198,7 +197,6 @@ static inline uint32_t getFormatSize(DataFormat Format) {
198197
case DataFormat::UInt32:
199198
case DataFormat::Int32:
200199
case DataFormat::Float32:
201-
case DataFormat::Depth32:
202200
case DataFormat::Bool:
203201
return 4;
204202
case DataFormat::Hex64:
@@ -216,6 +214,11 @@ struct CPUBuffer {
216214
int Channels;
217215
int Stride;
218216
uint32_t ArraySize;
217+
// When set, names the GPU texture format directly (e.g. D32Float) instead of
218+
// inferring it from DataFormat + Channels via toFormat(). This lets depth
219+
// buffers and other special formats be expressed without extending
220+
// DataFormat.
221+
std::optional<offloadtest::Format> GpuFormat;
219222
// Data can contain one block of data for a singular resource
220223
// or multiple blocks for a resource array.
221224
llvm::SmallVector<std::unique_ptr<char[]>> Data;
@@ -931,7 +934,6 @@ template <> struct ScalarEnumerationTraits<offloadtest::DataFormat> {
931934
ENUM_CASE(Float16);
932935
ENUM_CASE(Float32);
933936
ENUM_CASE(Float64);
934-
ENUM_CASE(Depth32);
935937
ENUM_CASE(Bool);
936938
#undef ENUM_CASE
937939
}

lib/API/VK/Device.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ static VkFormat getVKFormat(DataFormat Format, int Channels) {
6060
VKFormats(UINT, 64) break;
6161
case DataFormat::Float64:
6262
VKFormats(SFLOAT, 64) break;
63-
case DataFormat::Depth32:
64-
if (Channels != 1)
65-
llvm_unreachable("Depth32 format only supports a single channel.");
66-
return VK_FORMAT_D32_SFLOAT;
6763
default:
6864
llvm_unreachable("Unsupported Resource format specified");
6965
}
@@ -3395,13 +3391,15 @@ class VulkanDevice : public offloadtest::Device {
33953391
llvm::Expected<ResourceRef> createImage(Resource &R, BufferRef &Host,
33963392
int UsageOverride = 0) {
33973393
const offloadtest::CPUBuffer &B = *R.BufferPtr;
3398-
if (B.Format == DataFormat::Depth32 && R.isReadWrite())
3394+
const bool IsDepth = B.GpuFormat.has_value() && isDepthFormat(*B.GpuFormat);
3395+
if (IsDepth && R.isReadWrite())
33993396
return llvm::createStringError(std::errc::invalid_argument,
34003397
"Image memory allocation failed.");
34013398
VkImageCreateInfo ImageCreateInfo = {};
34023399
ImageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
34033400
ImageCreateInfo.imageType = getVKImageType(R.Kind);
3404-
ImageCreateInfo.format = getVKFormat(B.Format, B.Channels);
3401+
ImageCreateInfo.format = B.GpuFormat ? getVulkanFormat(*B.GpuFormat)
3402+
: getVKFormat(B.Format, B.Channels);
34053403
ImageCreateInfo.mipLevels = B.OutputProps.MipLevels;
34063404
ImageCreateInfo.arrayLayers = 1;
34073405
ImageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
@@ -3823,12 +3821,14 @@ class VulkanDevice : public offloadtest::Device {
38233821
ViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
38243822
ViewCreateInfo.viewType = getImageViewType(R.Kind);
38253823
ViewCreateInfo.format =
3826-
getVKFormat(R.BufferPtr->Format, R.BufferPtr->Channels);
3824+
R.BufferPtr->GpuFormat
3825+
? getVulkanFormat(*R.BufferPtr->GpuFormat)
3826+
: getVKFormat(R.BufferPtr->Format, R.BufferPtr->Channels);
38273827
ViewCreateInfo.components = {
38283828
VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G,
38293829
VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A};
38303830
ViewCreateInfo.subresourceRange.aspectMask =
3831-
R.BufferPtr->Format == DataFormat::Depth32
3831+
(R.BufferPtr->GpuFormat && isDepthFormat(*R.BufferPtr->GpuFormat))
38323832
? VK_IMAGE_ASPECT_DEPTH_BIT
38333833
: VK_IMAGE_ASPECT_COLOR_BIT;
38343834
ViewCreateInfo.subresourceRange.baseMipLevel = 0;
@@ -4086,13 +4086,14 @@ class VulkanDevice : public offloadtest::Device {
40864086
return;
40874087
if (R.isImage()) {
40884088
const offloadtest::CPUBuffer &B = *R.BufferPtr;
4089+
const bool IsDepth =
4090+
B.GpuFormat.has_value() && isDepthFormat(*B.GpuFormat);
40894091
llvm::SmallVector<VkBufferImageCopy> Regions;
40904092
uint64_t CurrentOffset = 0;
40914093
for (int I = 0; I < B.OutputProps.MipLevels; ++I) {
40924094
VkBufferImageCopy Region = {};
4093-
Region.imageSubresource.aspectMask = B.Format == DataFormat::Depth32
4094-
? VK_IMAGE_ASPECT_DEPTH_BIT
4095-
: VK_IMAGE_ASPECT_COLOR_BIT;
4095+
Region.imageSubresource.aspectMask =
4096+
IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
40964097
Region.imageSubresource.mipLevel = I;
40974098
Region.imageSubresource.baseArrayLayer = 0;
40984099
Region.imageSubresource.layerCount = 1;
@@ -4110,9 +4111,8 @@ class VulkanDevice : public offloadtest::Device {
41104111
}
41114112

41124113
VkImageSubresourceRange SubRange = {};
4113-
SubRange.aspectMask = B.Format == DataFormat::Depth32
4114-
? VK_IMAGE_ASPECT_DEPTH_BIT
4115-
: VK_IMAGE_ASPECT_COLOR_BIT;
4114+
SubRange.aspectMask =
4115+
IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
41164116
SubRange.baseMipLevel = 0;
41174117
SubRange.levelCount = B.OutputProps.MipLevels;
41184118
SubRange.layerCount = 1;
@@ -4232,10 +4232,11 @@ class VulkanDevice : public offloadtest::Device {
42324232
return;
42334233
if (R.isImage()) {
42344234
const offloadtest::CPUBuffer &B = *R.BufferPtr;
4235+
const bool IsDepth =
4236+
B.GpuFormat.has_value() && isDepthFormat(*B.GpuFormat);
42354237
VkImageSubresourceRange SubRange = {};
4236-
SubRange.aspectMask = B.Format == DataFormat::Depth32
4237-
? VK_IMAGE_ASPECT_DEPTH_BIT
4238-
: VK_IMAGE_ASPECT_COLOR_BIT;
4238+
SubRange.aspectMask =
4239+
IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
42394240
SubRange.baseMipLevel = 0;
42404241
SubRange.levelCount = B.OutputProps.MipLevels;
42414242
SubRange.layerCount = 1;
@@ -4262,9 +4263,8 @@ class VulkanDevice : public offloadtest::Device {
42624263
uint64_t CurrentOffset = 0;
42634264
for (int I = 0; I < B.OutputProps.MipLevels; ++I) {
42644265
VkBufferImageCopy Region = {};
4265-
Region.imageSubresource.aspectMask = B.Format == DataFormat::Depth32
4266-
? VK_IMAGE_ASPECT_DEPTH_BIT
4267-
: VK_IMAGE_ASPECT_COLOR_BIT;
4266+
Region.imageSubresource.aspectMask =
4267+
IsDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
42684268
Region.imageSubresource.mipLevel = I;
42694269
Region.imageSubresource.baseArrayLayer = 0;
42704270
Region.imageSubresource.layerCount = 1;

lib/Support/Check.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ testBufferFloat(std::function<bool(const T &, const T &)> ComparisonFn,
228228
case offloadtest::DataFormat::Float64:
229229
return testAllArray<double>(ComparisonFn, B1, B2);
230230
case offloadtest::DataFormat::Float32:
231-
case offloadtest::DataFormat::Depth32:
232231
return testAllArray<float>(ComparisonFn, B1, B2);
233232
case offloadtest::DataFormat::Float16: {
234233
return testAllArray<uint16_t>(ComparisonFn, B1, B2);
@@ -250,8 +249,7 @@ static bool testBufferFloatEpsilon(offloadtest::CPUBuffer *B1,
250249
};
251250
return testBufferFloat<double>(Fn, B1, B2);
252251
}
253-
case offloadtest::DataFormat::Float32:
254-
case offloadtest::DataFormat::Depth32: {
252+
case offloadtest::DataFormat::Float32: {
255253
auto Fn = [Epsilon, DM](const float &FS, const float &FR) {
256254
return compareFloatEpsilon(FS, FR, (float)Epsilon, DM);
257255
};
@@ -280,8 +278,7 @@ static bool testBufferFloatULP(offloadtest::CPUBuffer *B1,
280278
};
281279
return testBufferFloat<double>(Fn, B1, B2);
282280
}
283-
case offloadtest::DataFormat::Float32:
284-
case offloadtest::DataFormat::Depth32: {
281+
case offloadtest::DataFormat::Float32: {
285282
auto Fn = [ULPT, DM](const float &FS, const float &FR) {
286283
return compareFloatULP(FS, FR, ULPT, DM);
287284
};
@@ -379,7 +376,6 @@ static const std::string getBufferStr(offloadtest::CPUBuffer *B) {
379376
case DF::Float16:
380377
return formatBuffer<llvm::yaml::Hex16>(B); // assuming no native float16
381378
case DF::Float32:
382-
case DF::Depth32:
383379
return formatBuffer<float>(B);
384380
case DF::Float64:
385381
return formatBuffer<double>(B);

lib/Support/Pipeline.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ void MappingTraits<offloadtest::CPUBuffer>::mapping(IO &I,
363363
I.mapRequired("Name", B.Name);
364364
I.mapRequired("Format", B.Format);
365365
I.mapOptional("Channels", B.Channels, 1);
366+
I.mapOptional("GpuFormat", B.GpuFormat);
366367
I.mapOptional("Stride", B.Stride, 0);
367368
I.mapOptional("ArraySize", B.ArraySize, 1);
368369
setCounters(I, B);
@@ -407,9 +408,6 @@ void MappingTraits<offloadtest::CPUBuffer>::mapping(IO &I,
407408
case DF::Float32:
408409
setData<float>(I, B);
409410
break;
410-
case DF::Depth32:
411-
setData<float>(I, B);
412-
break;
413411
case DF::Float64:
414412
setData<double>(I, B);
415413
break;
@@ -528,8 +526,6 @@ void MappingTraits<offloadtest::PushConstantValue>::mapping(
528526
return setData<llvm::yaml::Hex16>(I, B); // assuming no native float16
529527
case DF::Float32:
530528
return setData<float>(I, B);
531-
case DF::Depth32:
532-
return setData<float>(I, B);
533529
case DF::Float64:
534530
return setData<double>(I, B);
535531
case DF::Bool:

test/Feature/Textures/Texture2D.GatherCmp.test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ Shaders:
6868

6969
Buffers:
7070
- Name: Tex
71-
Format: Depth32
71+
Format: Float32
72+
GpuFormat: D32Float
7273
Channels: 1
7374
OutputProps: { Width: 2, Height: 2, Depth: 1 }
7475
Data: [ 0.2, # (0,0) R=0.2

test/Feature/Textures/Texture2D.SampleCmp.test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ Shaders:
107107

108108
Buffers:
109109
- Name: Tex
110-
Format: Depth32
110+
Format: Float32
111+
GpuFormat: D32Float
111112
Channels: 1
112113
OutputProps: { Width: 2, Height: 2, Depth: 1 }
113114
Data: [ 0.2, # (0,0) -> 0.2

test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.GatherCmp.test.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Shaders:
4949

5050
Buffers:
5151
- Name: SampledTexLess
52-
Format: Depth32
52+
Format: Float32
53+
GpuFormat: D32Float
5354
Channels: 1
5455
OutputProps: { Width: 2, Height: 2, Depth: 1 }
5556
Data: [ 0.2, # (0,0) R=0.2
@@ -58,7 +59,8 @@ Buffers:
5859
0.8 ] # (1,1) R=0.8
5960

6061
- Name: SampledTexGreater
61-
Format: Depth32
62+
Format: Float32
63+
GpuFormat: D32Float
6264
Channels: 1
6365
OutputProps: { Width: 2, Height: 2, Depth: 1 }
6466
Data: [ 0.2,
@@ -67,7 +69,8 @@ Buffers:
6769
0.8 ]
6870

6971
- Name: SampledTexRepeat
70-
Format: Depth32
72+
Format: Float32
73+
GpuFormat: D32Float
7174
Channels: 1
7275
OutputProps: { Width: 2, Height: 2, Depth: 1 }
7376
Data: [ 0.2,

test/Feature/Vk.SampledTextures/Vk.SampledTexture2D/Vk.SampledTexture2D.SampleCmp.test.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ Shaders:
8888

8989
Buffers:
9090
- Name: SampledTexLess
91-
Format: Depth32
91+
Format: Float32
92+
GpuFormat: D32Float
9293
Channels: 1
9394
OutputProps: { Width: 2, Height: 2, Depth: 1 }
9495
Data: [ 0.2, # (0,0) -> 0.2
@@ -97,7 +98,8 @@ Buffers:
9798
0.8 ] # (1,1) -> 0.8
9899

99100
- Name: SampledTexGreater
100-
Format: Depth32
101+
Format: Float32
102+
GpuFormat: D32Float
101103
Channels: 1
102104
OutputProps: { Width: 2, Height: 2, Depth: 1 }
103105
Data: [ 0.2,

0 commit comments

Comments
 (0)