Skip to content

[NFC] Express GPU texture formats via CPUBuffer GpuFormat field#1327

Open
alsepkow wants to merge 4 commits into
llvm:mainfrom
alsepkow:alex/nfc-gpuformat
Open

[NFC] Express GPU texture formats via CPUBuffer GpuFormat field#1327
alsepkow wants to merge 4 commits into
llvm:mainfrom
alsepkow:alex/nfc-gpuformat

Conversation

@alsepkow

@alsepkow alsepkow commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Resolves #1326.

Replaces the special-cased DataFormat::Depth32 with an optional CPUBuffer::GpuFormat field that names a GPU Format directly. The Vulkan backend now derives the image/view format and depth/color aspect from GpuFormat; the Check path drops the unused Depth32 cases. Existing GatherCmp/SampleCmp depth tests migrate from Format: Depth32 to Format: Float32 + GpuFormat: D32Float.

See #1326 for full motivation.

@alsepkow alsepkow force-pushed the alex/nfc-gpuformat branch from 61b7687 to fcb8406 Compare June 22, 2026 22:28
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>
@alsepkow alsepkow force-pushed the alex/nfc-gpuformat branch from fcb8406 to 3a7a77a Compare June 22, 2026 22:33
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread include/Support/Pipeline.h Outdated
Comment thread lib/API/VK/Device.cpp Outdated
Format: Depth32
Format: Float32
GpuFormat: D32Float
Channels: 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, if GpuFormat is specified then both Format and Channels are ignored. Is there any easy way to represent that in the struct/yaml so they are not silently ignored. Maybe a std::variant works?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your general intuition for the std::variant makes sense. But GPUFormat only implies that Channels are ignored. Format is still used for how we interpret the CPU bytes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we be able to also use GPUFormat to interpret the human-readable data when reading the YAML?

alsepkow and others added 2 commits June 22, 2026 20:42
Addresses review feedback on PR llvm#1327: use all-caps GPU acronym to match
CPUBuffer naming, across the CPUBuffer field, the YAML key, and tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addresses review feedback on PR llvm#1327: prefer 'B.GPUFormat && isDepthFormat(*B.GPUFormat)'
for consistency with the existing image-view check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
// inferring it from DataFormat + Channels via toFormat(). This lets depth
// buffers and other special formats be expressed without extending
// DataFormat.
std::optional<offloadtest::Format> GPUFormat;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this change. In a future PR we should completely get rid of the old way of doing formats and just use the ones that are actually GPU API compatible.

Format: Depth32
Format: Float32
GpuFormat: D32Float
Channels: 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we be able to also use GPUFormat to interpret the human-readable data when reading the YAML?

@bogner bogner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry that this change as is makes things pretty confusing. There are now two slightly incompatible ways to specify the format, and as far as I can tell nothing stops you from doing both.

I realize it would be a massive change to all of the tests to just switch to GPUFormat entirely, but if this is the direction we're going I think we might be better off just ripping off the bandaid and changing it all.

Comment on lines +71 to +72
Format: Float32
GPUFormat: D32Float

@bogner bogner Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Format: Float32 just entirely ignored here since GPUFormat is specified? This feels a bit confusing.

I guess it isn't ignored but it's how we're interpreting the values in the YAML?

Comment thread lib/API/DX/Device.cpp
Comment on lines -2562 to +2565
auto FormatOrErr = toFormat(R.BufferPtr->Format, R.BufferPtr->Channels);
auto FormatOrErr =
R.BufferPtr->GPUFormat
? llvm::Expected<Format>(*R.BufferPtr->GPUFormat)
: toFormat(R.BufferPtr->Format, R.BufferPtr->Channels);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more sound to update toFormat to take all three of the GPUFormat, Format, and Channels and reconcile them. This way we can at least assert if we've somehow specified both in an incompatible way.

Comment thread lib/API/VK/Device.cpp
Comment on lines +3401 to +3402
ImageCreateInfo.format = B.GPUFormat ? getVulkanFormat(*B.GPUFormat)
: getVKFormat(B.Format, B.Channels);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, if we update getVKFormat to reconcile the specification first then we don't need to have all of these places with their own checks that need to be aware of which way we've specified the format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Express GPU texture formats directly via a CPUBuffer GpuFormat field

4 participants