Introduce a new Texture type with DX,VK,MTL implementations.#1020
Introduce a new Texture type with DX,VK,MTL implementations.#1020manon-traverse merged 10 commits intollvm:mainfrom
Texture type with DX,VK,MTL implementations.#1020Conversation
ee21f04 to
48dadd6
Compare
217f6ef to
505d3f0
Compare
de634bd to
0bf7cfc
Compare
e1c50e9 to
eb9f868
Compare
| const CPUBuffer &B = *P.Bindings.RTargetBufferPtr; | ||
| memcpy(B.Data[0].get(), Mapped, B.size()); | ||
| vkUnmapMemory(Device, ResRef.Host.Memory); | ||
| vkUnmapMemory(Device, IS.RTReadback->Memory); |
There was a problem hiding this comment.
NOTE: unmapping is not necessary in Vulkan or DX12. It's fine to leave it as is, but I thought it was good to know it's fine to leave this persistently mapped.
manon-traverse
left a comment
There was a problem hiding this comment.
Just a couple of small comments, but other than that looks good to me
4c4f1a6 to
c0ab760
Compare
8786868 to
cbda773
Compare
cbda773 to
352383a
Compare
lib/API/DX/Device.cpp
Outdated
| // Readback heaps do not support UAV access. | ||
| const D3D12_RESOURCE_FLAGS Flags = | ||
| D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| HeapType == D3D12_HEAP_TYPE_READBACK | ||
| ? D3D12_RESOURCE_FLAG_NONE | ||
| : D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; |
There was a problem hiding this comment.
Fwiw in our codebase we use a custom heap that might not place this restriction on buffers.
| std::shared_ptr<VulkanTexture> RenderTarget; | ||
| std::shared_ptr<VulkanBuffer> RTReadback; | ||
| std::shared_ptr<VulkanTexture> DepthStencil; |
There was a problem hiding this comment.
Note: we should try to store the platform-agnostic pointer here and downcast where needed, as the goal is to use these only in the platform-abstract way.
I am fine with keeping it this way for this PR, but it's something we should do in the future. Perhaps once we have an agnostic way of binding resources?
352383a to
f6ac12e
Compare
MarijnS95
left a comment
There was a problem hiding this comment.
LGTM; I can mostly see where the flow is intended to be going, albeit this still needs quite a significant portion of helpers to keep the current APIs working before they're migrated to the new createTexture() call with (more) general arguments.
Left a few notes where comments could be better, specifically some comments that seem to have appeared on the wrong line (maybe a rebase artifact?) but nothing major.
| //===- FormatConversion.h - Refactoring helpers ---------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Transitional helpers for converting between the legacy DataFormat + Channels | ||
| // description system and the unified Format enum. This file should be deleted | ||
| // once the pipeline is fully migrated to use Format directly. |
There was a problem hiding this comment.
Do we have a tracking issue for this conversion and removal?
|
|
||
| Range.memory = ResRef.Host.Memory; | ||
| vkMapMemory(Device, IS.RTReadback->Memory, 0, VK_WHOLE_SIZE, 0, &Mapped); | ||
| vkInvalidateMappedMemoryRanges(Device, 1, &Range); |
f10c02a to
5527e94
Compare
170b07b to
5527e94
Compare
…oryLocation` and `Format` types. Add `FormatConversion.h` containing bridge functions between old and new API.
…earDepthStencil` types defined in `Texture.h` and `validateTextureCreateDesc` function Add `createTexture` function in device and supporting function `createRenderTargetFromCPUBuffer`
…eanup code to use the new helper functions
…ncil support to both MTL and DX backend to align with behaviour of VK backend
5527e94 to
fd2c6de
Compare
fd2c6de to
824ef1e
Compare
s-perron
left a comment
There was a problem hiding this comment.
I looked at the Vulkan code. Looks good to me. My only real question is the use of std::shared_ptr. If other are okay with it, I won't get in the way.
| // Creates a render target texture using the format and dimensions from a | ||
| // CPUBuffer. Does not upload the buffer's data — only uses its description to | ||
| // configure the texture. | ||
| llvm::Expected<std::shared_ptr<Texture>> |
There was a problem hiding this comment.
Do we want to use std::shared_ptr? I know a lot of projects avoid using it because it is slow.
There was a problem hiding this comment.
I would recommend using the shared_ptr. We want to be able to use reference counting to determine if resources need to be kept alive so that we can free them once they are no longer being used on the GPU timeline.
IMO the overhead of shared_ptr is a bit overblown (an atomic increment on copy). If we ever run into a case where we need thousands of textures that need to be kept alive we can look at alternative solutions for those use cases. However, in my experience, that case is only there for bindless resources where you are going to need an alternative anyway.
There was a problem hiding this comment.
I think we need to revisit this. I'm not sure how you count "thousands of textures", but, as the number of tests increases, we could easily reach that over all of the tests. I'll let others like @bogner and @llvm-beanz give their opinions.
I'll go along with what the community thinks.
There was a problem hiding this comment.
@manon-traverse - can you file an issue to follow up on this please? Ideally, we'd get consensus before the PR is merged, but we as long as we figure it all out it's ok to that post-merge.
| std::shared_ptr<VulkanTexture> RenderTarget; | ||
| std::shared_ptr<VulkanBuffer> RTReadback; | ||
| std::shared_ptr<VulkanTexture> DepthStencil; |
There was a problem hiding this comment.
I'm use to the Google style guide. We generally do not allow std::shared_ptr unless there is a very good reason for it.
I've only looked at the code quickly. However, would it be possible to make the std::unqiue_ptr to say that they are owned by the InvocationState?
I'll don't have strong opinions for this project, but we should make a conscience decision.
|
This PR fails some CI tests, but only after changing the name of a getter (unrelated to any errors). It fails on Mac because that machine is out of storage. Intel-clang failure is one that also happens on main, I am going to assume this is because of a change in the llvm-project repo. Because these reasons have nothing to do with the PR and enough reviewing and applying feedback has happened I am gonig to merge this PR so we can move forward. If any more issues arise, we can address those in follow-up PRs. |
Summary
Texture.hwith a sharedTextureCreateDesc,TextureFormatenum,TextureUsageflags,ClearValuevariant (ClearColor/ClearDepthStencil), andvalidateTextureCreateDescreturning specificllvm::ErrormessagescreateTextureto all three backends (DX, Vulkan, Metal) as a virtual method onDevice, handling resource creation, optimized clear values, and format/usage validationcreateRenderTargetFromCPUBuffer(Device&, CPUBuffer&)free function — all backends now route throughcreateTextureinstead of manually calling API-specific resource creationcreateDefaultDepthStencilTarget(Device&, Width, Height)free function withD32FloatS8Uintformat — added depth testing to DX and Metal backends (previously only Vulkan had it)createBufferAPI withMemoryLocation::GpuToCpu; Metal refactored fromStorageModeSharedtexture withgetBytes()toStorageModePrivatetexture + blit copy to readback buffer (this is to align functionality between backends in preparation of api-agnostic code-flow. Sacrifices had to be made 😛)VkImageView(VK) are now created atcreateTexturetime forRenderTarget/DepthStencilusage, removing view creation boilerplate from pipeline setupshared_ptr<VulkanTexture>/shared_ptr<VulkanBuffer>onInvocationStatetoTextureFormat(DataFormat, Channels)as a bridge function while refactoring, withvalidateTextureDescMatchesCPUBufferto catch mismatches between the old and new description systemsgetMetalTextureStorageModeandgetMetalBufferResourceOptionsbecauseGpuToCpumaps differently for textures (Managed) vs buffers (Shared)Future direction
Added for context to better understand some of the changes in this PR.
DataFormat + Channelsdual description.createBuffer— still uses the oldResourceRef/BufferRefsystemInvocationStateacross backends