diff --git a/src/gallium/drivers/d3d12/d3d12_bufmgr.h b/src/gallium/drivers/d3d12/d3d12_bufmgr.h index 7008563ad4b..2678d2bb4ed 100644 --- a/src/gallium/drivers/d3d12/d3d12_bufmgr.h +++ b/src/gallium/drivers/d3d12/d3d12_bufmgr.h @@ -60,6 +60,10 @@ struct d3d12_bo { */ uint64_t unique_id; +#ifndef NDEBUG + bool is_front_buffer; +#endif + struct list_head residency_list_entry; uint64_t estimated_size; int64_t last_used_timestamp; diff --git a/src/gallium/drivers/d3d12/d3d12_resource_state.cpp b/src/gallium/drivers/d3d12/d3d12_resource_state.cpp index 29fca0021bc..caad8661fc2 100644 --- a/src/gallium/drivers/d3d12/d3d12_resource_state.cpp +++ b/src/gallium/drivers/d3d12/d3d12_resource_state.cpp @@ -324,7 +324,7 @@ transition_required(D3D12_RESOURCE_STATES current_state, D3D12_RESOURCE_STATES * } static void -resolve_global_state(struct d3d12_context *ctx, ID3D12Resource *res, d3d12_resource_state *batch_state, d3d12_resource_state *res_state) +resolve_global_state(struct d3d12_context *ctx, struct d3d12_bo *bo, d3d12_resource_state *batch_state, d3d12_resource_state *res_state) { assert(batch_state->num_subresources == res_state->num_subresources); unsigned num_subresources = batch_state->homogenous && res_state->homogenous ? 1 : batch_state->num_subresources; @@ -340,10 +340,11 @@ resolve_global_state(struct d3d12_context *ctx, ID3D12Resource *res, d3d12_resou continue; D3D12_RESOURCE_BARRIER barrier = { D3D12_RESOURCE_BARRIER_TYPE_TRANSITION }; - barrier.Transition.pResource = res; + barrier.Transition.pResource = bo->res; barrier.Transition.StateBefore = current_state->state; barrier.Transition.StateAfter = after; barrier.Transition.Subresource = num_subresources == 1 ? D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES : i; + assert(!bo->is_front_buffer); // No explicit barriers against front buffers util_dynarray_append(&ctx->barrier_scratch, barrier); } } @@ -355,7 +356,7 @@ context_state_resolve_submission(struct d3d12_context *ctx, d3d12_bo *bo) if (!bo_state->batch_end.supports_simultaneous_access) { assert(bo->res && bo->global_state.subresource_states); - resolve_global_state(ctx, bo->res, &bo_state->batch_begin, &bo->global_state); + resolve_global_state(ctx, bo, &bo_state->batch_begin, &bo->global_state); copy_resource_state(&bo_state->batch_begin, &bo_state->batch_end); copy_resource_state(&bo->global_state, &bo_state->batch_end); @@ -470,6 +471,8 @@ append_barrier(struct d3d12_context *ctx, is_promotion = true; } + assert(!bo->is_front_buffer || (is_promotion && may_decay)); + d3d12_subresource_state new_subresource_state { after, ctx->submit_id, is_promotion, may_decay }; if (subresource == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES) set_resource_state(current_state, &new_subresource_state); diff --git a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp index decfc5c29b8..8de3d6b5247 100644 --- a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp +++ b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp @@ -291,6 +291,11 @@ d3d12_wgl_framebuffer_resize(stw_winsys_framebuffer *fb, pipe_resource_reference(&framebuffer->buffers[i], screen->base.base.resource_from_handle(&screen->base.base, &templ, &handle, PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE)); + +#ifndef NDEBUG + struct d3d12_bo *bo = d3d12_resource(framebuffer->buffers[i])->bo; + bo->is_front_buffer = i != 0; +#endif } if (framebuffer->single_buffered) { @@ -334,6 +339,14 @@ d3d12_wgl_framebuffer_present(stw_winsys_framebuffer *fb, int interval) hr = framebuffer->swapchain->Present(interval, 0); assert(SUCCEEDED(hr)); +#ifndef NDEBUG + uint32_t back_buffer_idx = framebuffer->swapchain->GetCurrentBackBufferIndex(); + for (uint32_t i = 0; i < num_buffers; ++i) { + struct d3d12_bo *bo = d3d12_resource(framebuffer->buffers[i])->bo; + bo->is_front_buffer = i != back_buffer_idx; + } +#endif + if (SUCCEEDED(hr)) (void)WaitForSingleObject(framebuffer->waitable_object, 2000); return SUCCEEDED(hr);