The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/d3d: fix swapchain with UNORDERED_ACCESS and COLOR usage

And fill in the rest of usage bits.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2281>

authored by

Christoph Haag and committed by
Marge Bot
c5c14f04 90b36b16

+41 -9
+41 -9
src/xrt/auxiliary/d3d/d3d_d3d12_bits.h
··· 58 58 { 59 59 D3D12_RESOURCE_STATES state = D3D12_RESOURCE_STATES(0); 60 60 61 - if ((xsub & XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS) != 0) { 62 - state |= D3D12_RESOURCE_STATE_UNORDERED_ACCESS; 63 - } 64 - if ((xsub & XRT_SWAPCHAIN_USAGE_COLOR) != 0) { 61 + bool use_color = (xsub & XRT_SWAPCHAIN_USAGE_COLOR) != 0; 62 + bool use_unordered = (xsub & XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS) != 0; 63 + bool use_depth = (xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0; 64 + bool use_transfer_src = (xsub & XRT_SWAPCHAIN_USAGE_TRANSFER_SRC) != 0; 65 + bool use_transfer_dst = (xsub & XRT_SWAPCHAIN_USAGE_TRANSFER_DST) != 0; 66 + bool use_mutable = (xsub & XRT_SWAPCHAIN_USAGE_MUTABLE_FORMAT) != 0; 67 + bool use_input_attachment = (xsub & XRT_SWAPCHAIN_USAGE_INPUT_ATTACHMENT) != 0; 68 + 69 + /* 70 + * When an application acquires a swapchain image by calling xrAcquireSwapchainImage in a session create using 71 + * XrGraphicsBindingD3D12KHR, the OpenXR runtime must guarantee that: 72 + * 73 + * The color rendering target image has a resource state match with D3D12_RESOURCE_STATE_RENDER_TARGET 74 + * 75 + * The depth rendering target image has a resource state match with D3D12_RESOURCE_STATE_DEPTH_WRITE 76 + */ 77 + 78 + if (use_color) { 65 79 // since we are treating these as mutually exclusive 66 - assert((xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) == 0); 67 - state |= D3D12_RESOURCE_STATE_RENDER_TARGET; 68 - } 69 - if ((xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0) { 70 - state |= D3D12_RESOURCE_STATE_DEPTH_WRITE; 80 + assert(!use_depth); 81 + state = D3D12_RESOURCE_STATE_RENDER_TARGET; 82 + } else if (use_depth) { 83 + state = D3D12_RESOURCE_STATE_DEPTH_WRITE; 84 + } else { 85 + //! @todo If neither color nor depth use is specified, we set an initial state that is not clearly 86 + //! defined in the spec, but most likely expected by the application. Note that the order here 87 + //! translates to precedence if multiple are set. 88 + if (use_unordered) { 89 + state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; 90 + } else if (use_transfer_src) { 91 + state = D3D12_RESOURCE_STATE_COPY_SOURCE; 92 + } else if (use_transfer_dst) { 93 + state = D3D12_RESOURCE_STATE_COPY_DEST; 94 + } else if (use_mutable) { 95 + state = D3D12_RESOURCE_STATE_COMMON; 96 + } else if (use_input_attachment) { 97 + state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; 98 + } else { 99 + //! @todo unspecified fallback 100 + state = D3D12_RESOURCE_STATE_RENDER_TARGET; 101 + } 71 102 } 103 + 72 104 return state; 73 105 } 74 106