···5858{
5959 D3D12_RESOURCE_STATES state = D3D12_RESOURCE_STATES(0);
60606161- if ((xsub & XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS) != 0) {
6262- state |= D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
6363- }
6464- if ((xsub & XRT_SWAPCHAIN_USAGE_COLOR) != 0) {
6161+ bool use_color = (xsub & XRT_SWAPCHAIN_USAGE_COLOR) != 0;
6262+ bool use_unordered = (xsub & XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS) != 0;
6363+ bool use_depth = (xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0;
6464+ bool use_transfer_src = (xsub & XRT_SWAPCHAIN_USAGE_TRANSFER_SRC) != 0;
6565+ bool use_transfer_dst = (xsub & XRT_SWAPCHAIN_USAGE_TRANSFER_DST) != 0;
6666+ bool use_mutable = (xsub & XRT_SWAPCHAIN_USAGE_MUTABLE_FORMAT) != 0;
6767+ bool use_input_attachment = (xsub & XRT_SWAPCHAIN_USAGE_INPUT_ATTACHMENT) != 0;
6868+6969+ /*
7070+ * When an application acquires a swapchain image by calling xrAcquireSwapchainImage in a session create using
7171+ * XrGraphicsBindingD3D12KHR, the OpenXR runtime must guarantee that:
7272+ *
7373+ * The color rendering target image has a resource state match with D3D12_RESOURCE_STATE_RENDER_TARGET
7474+ *
7575+ * The depth rendering target image has a resource state match with D3D12_RESOURCE_STATE_DEPTH_WRITE
7676+ */
7777+7878+ if (use_color) {
6579 // since we are treating these as mutually exclusive
6666- assert((xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) == 0);
6767- state |= D3D12_RESOURCE_STATE_RENDER_TARGET;
6868- }
6969- if ((xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0) {
7070- state |= D3D12_RESOURCE_STATE_DEPTH_WRITE;
8080+ assert(!use_depth);
8181+ state = D3D12_RESOURCE_STATE_RENDER_TARGET;
8282+ } else if (use_depth) {
8383+ state = D3D12_RESOURCE_STATE_DEPTH_WRITE;
8484+ } else {
8585+ //! @todo If neither color nor depth use is specified, we set an initial state that is not clearly
8686+ //! defined in the spec, but most likely expected by the application. Note that the order here
8787+ //! translates to precedence if multiple are set.
8888+ if (use_unordered) {
8989+ state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
9090+ } else if (use_transfer_src) {
9191+ state = D3D12_RESOURCE_STATE_COPY_SOURCE;
9292+ } else if (use_transfer_dst) {
9393+ state = D3D12_RESOURCE_STATE_COPY_DEST;
9494+ } else if (use_mutable) {
9595+ state = D3D12_RESOURCE_STATE_COMMON;
9696+ } else if (use_input_attachment) {
9797+ state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
9898+ } else {
9999+ //! @todo unspecified fallback
100100+ state = D3D12_RESOURCE_STATE_RENDER_TARGET;
101101+ }
71102 }
103103+72104 return state;
73105}
74106