Skip to content

Introduce a new Texture type with DX,VK,MTL implementations.#1020

Open
EmilioLaiso wants to merge 19 commits intollvm:mainfrom
Traverse-Research:render-backend-api-texture
Open

Introduce a new Texture type with DX,VK,MTL implementations.#1020
EmilioLaiso wants to merge 19 commits intollvm:mainfrom
Traverse-Research:render-backend-api-texture

Conversation

@EmilioLaiso
Copy link
Copy Markdown

@EmilioLaiso EmilioLaiso commented Mar 26, 2026

Summary

  • Introduced Texture.h with a shared TextureCreateDesc, TextureFormat enum, TextureUsage flags, ClearValue variant (ClearColor / ClearDepthStencil), and validateTextureCreateDesc returning specific llvm::Error messages
  • Added createTexture to all three backends (DX, Vulkan, Metal) as a virtual method on Device, handling resource creation, optimized clear values, and format/usage validation
  • Unified render target creation via createRenderTargetFromCPUBuffer(Device&, CPUBuffer&) free function — all backends now route through createTexture instead of manually calling API-specific resource creation
  • Unified depth/stencil creation via createDefaultDepthStencilTarget(Device&, Width, Height) free function with D32FloatS8Uint format — added depth testing to DX and Metal backends (previously only Vulkan had it)
  • Readback buffers created through the virtual createBuffer API with MemoryLocation::GpuToCpu; Metal refactored from StorageModeShared texture with getBytes() to StorageModePrivate texture + blit copy to readback buffer (this is to align functionality between backends in preparation of api-agnostic code-flow. Sacrifices had to be made 😛)
  • Views on textures — RTV/DSV descriptor heaps (DX) and VkImageView (VK) are now created at createTexture time for RenderTarget/DepthStencil usage, removing view creation boilerplate from pipeline setup
  • Render target and readback buffer are stored directly as shared_ptr<VulkanTexture> / shared_ptr<VulkanBuffer> on InvocationState
  • Clear values read from texture descriptors in all backends instead of being hardcoded
  • Added toTextureFormat(DataFormat, Channels) as a bridge function while refactoring, with validateTextureDescMatchesCPUBuffer to catch mismatches between the old and new description systems
  • Split Metal storage mode helpers into getMetalTextureStorageMode and getMetalBufferResourceOptions because GpuToCpu maps differently for textures (Managed) vs buffers (Shared)

Future direction

Added for context to better understand some of the changes in this PR.

  • SRV/UAV views on textures — currently not stored on the texture because they would require a descriptor heap allocation scheme
  • Work towards eliminating DataFormat + Channels dual description.
  • Route VK vertex buffer through createBuffer — still uses the old ResourceRef/BufferRef system
  • Abstract readback copy
  • Unify InvocationState across backends

@EmilioLaiso EmilioLaiso force-pushed the render-backend-api-texture branch from ee21f04 to 48dadd6 Compare March 26, 2026 16:13
@EmilioLaiso EmilioLaiso force-pushed the render-backend-api-texture branch 2 times, most recently from 217f6ef to 505d3f0 Compare March 31, 2026 07:37
@EmilioLaiso EmilioLaiso marked this pull request as draft March 31, 2026 08:37
@EmilioLaiso EmilioLaiso marked this pull request as ready for review March 31, 2026 08:44
@EmilioLaiso EmilioLaiso force-pushed the render-backend-api-texture branch from de634bd to 0bf7cfc Compare March 31, 2026 08:53
@EmilioLaiso EmilioLaiso force-pushed the render-backend-api-texture branch from e1c50e9 to eb9f868 Compare April 1, 2026 07:04
const CPUBuffer &B = *P.Bindings.RTargetBufferPtr;
memcpy(B.Data[0].get(), Mapped, B.size());
vkUnmapMemory(Device, ResRef.Host.Memory);
vkUnmapMemory(Device, IS.RTReadback->Memory);
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.

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.

Copy link
Copy Markdown
Contributor

@manon-traverse manon-traverse left a comment

Choose a reason for hiding this comment

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

Just a couple of small comments, but other than that looks good to me

@EmilioLaiso EmilioLaiso force-pushed the render-backend-api-texture branch 3 times, most recently from ec128cd to 4c4f1a6 Compare April 7, 2026 07:17
@EmilioLaiso EmilioLaiso force-pushed the render-backend-api-texture branch from 4c4f1a6 to c0ab760 Compare April 7, 2026 07:56
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.

4 participants