-
Notifications
You must be signed in to change notification settings - Fork 34
[NFC] Express GPU texture formats via CPUBuffer GpuFormat field #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3a7a77a
82cf91b
49c7a1a
0e383ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<Format>(*R.BufferPtr->GPUFormat) | ||
| : toFormat(R.BufferPtr->Format, R.BufferPtr->Channels); | ||
|
Comment on lines
-2562
to
+2565
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be more sound to update |
||
| if (!FormatOrErr) | ||
| return FormatOrErr.takeError(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<ResourceRef> 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); | ||
|
Comment on lines
+3401
to
+3402
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here, if we update |
||
| 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<VkBufferImageCopy> 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,8 @@ Shaders: | |
|
|
||
| Buffers: | ||
| - Name: Tex | ||
| Format: Depth32 | ||
| Format: Float32 | ||
| GPUFormat: D32Float | ||
|
Comment on lines
+71
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess it isn't ignored but it's how we're interpreting the values in the YAML? |
||
| Channels: 1 | ||
| OutputProps: { Width: 2, Height: 2, Depth: 1 } | ||
| Data: [ 0.2, # (0,0) R=0.2 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,8 @@ Shaders: | |
|
|
||
| Buffers: | ||
| - Name: Tex | ||
| Format: Depth32 | ||
| Format: Float32 | ||
| GPUFormat: D32Float | ||
| Channels: 1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your general intuition for the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| OutputProps: { Width: 2, Height: 2, Depth: 1 } | ||
| Data: [ 0.2, # (0,0) -> 0.2 | ||
|
|
||
There was a problem hiding this comment.
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.