From: Józef Kucia jkucia@codeweavers.com
A lot of Vulkan commands must be recorded outside a render pass.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- libs/vkd3d/command.c | 64 +++++++++++++++++++++++++++++++++++++++------- libs/vkd3d/vkd3d_private.h | 1 + 2 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 7989401600b2..ce5f60fb6824 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -1143,6 +1143,21 @@ static void d3d12_command_list_invalidate_current_pipeline(struct d3d12_command_ list->current_pipeline = VK_NULL_HANDLE; }
+static void d3d12_command_list_end_current_render_pass(struct d3d12_command_list *list, + const struct vkd3d_vk_device_procs *vk_procs) +{ + if (list->current_render_pass) + VK_CALL(vkCmdEndRenderPass(list->vk_command_buffer)); + + list->current_render_pass = VK_NULL_HANDLE; +} + +static void d3d12_command_list_invalidate_current_render_pass(struct d3d12_command_list *list) +{ + const struct vkd3d_vk_device_procs *vk_procs = &list->device->vk_procs; + d3d12_command_list_end_current_render_pass(list, vk_procs); +} + static void d3d12_command_list_invalidate_bindings(struct d3d12_command_list *list, struct d3d12_pipeline_state *state) { @@ -1396,6 +1411,9 @@ static void d3d12_command_list_track_resource_usage(struct d3d12_command_list *l { if (resource->flags & VKD3D_RESOURCE_INITIAL_STATE_TRANSITION) { + const struct vkd3d_vk_device_procs *vk_procs = &list->device->vk_procs; + d3d12_command_list_end_current_render_pass(list, vk_procs); + d3d12_command_list_transition_resource_to_initial_state(list, resource); resource->flags &= ~VKD3D_RESOURCE_INITIAL_STATE_TRANSITION; } @@ -1523,6 +1541,9 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_list_Close(ID3D12GraphicsCommandL }
vk_procs = &list->device->vk_procs; + + d3d12_command_list_end_current_render_pass(list, vk_procs); + if ((vr = VK_CALL(vkEndCommandBuffer(list->vk_command_buffer))) < 0) { WARN("Failed to end command buffer, vr %d.\n", vr); @@ -2202,6 +2223,7 @@ static bool d3d12_command_list_begin_render_pass(struct d3d12_command_list *list const struct vkd3d_vk_device_procs *vk_procs) { struct VkRenderPassBeginInfo begin_desc; + VkRenderPass vk_render_pass;
if (!list->state) { @@ -2216,9 +2238,14 @@ static bool d3d12_command_list_begin_render_pass(struct d3d12_command_list *list
d3d12_command_list_update_descriptors(list, VK_PIPELINE_BIND_POINT_GRAPHICS);
+ if (list->current_render_pass != VK_NULL_HANDLE) + return true; + + vk_render_pass = list->state->u.graphics.render_pass; + begin_desc.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; begin_desc.pNext = NULL; - begin_desc.renderPass = list->state->u.graphics.render_pass; + begin_desc.renderPass = vk_render_pass; begin_desc.framebuffer = list->current_framebuffer; begin_desc.renderArea.offset.x = 0; begin_desc.renderArea.offset.y = 0; @@ -2228,6 +2255,8 @@ static bool d3d12_command_list_begin_render_pass(struct d3d12_command_list *list begin_desc.pClearValues = NULL; VK_CALL(vkCmdBeginRenderPass(list->vk_command_buffer, &begin_desc, VK_SUBPASS_CONTENTS_INLINE));
+ list->current_render_pass = vk_render_pass; + return true; }
@@ -2245,7 +2274,6 @@ static void STDMETHODCALLTYPE d3d12_command_list_DrawInstanced(ID3D12GraphicsCom
vk_procs = &list->device->vk_procs;
- /* FIXME: We probably don't want to begin a render pass for each draw. */ if (!d3d12_command_list_begin_render_pass(list, vk_procs)) { WARN("Failed to begin render pass, ignoring draw call.\n"); @@ -2254,8 +2282,6 @@ static void STDMETHODCALLTYPE d3d12_command_list_DrawInstanced(ID3D12GraphicsCom
VK_CALL(vkCmdDraw(list->vk_command_buffer, vertex_count_per_instance, instance_count, start_vertex_location, start_instance_location)); - - VK_CALL(vkCmdEndRenderPass(list->vk_command_buffer)); }
static void STDMETHODCALLTYPE d3d12_command_list_DrawIndexedInstanced(ID3D12GraphicsCommandList *iface, @@ -2272,7 +2298,6 @@ static void STDMETHODCALLTYPE d3d12_command_list_DrawIndexedInstanced(ID3D12Grap
vk_procs = &list->device->vk_procs;
- /* FIXME: We probably don't want to begin a render pass for each draw. */ if (!d3d12_command_list_begin_render_pass(list, vk_procs)) { WARN("Failed to begin render pass, ignoring draw call.\n"); @@ -2281,8 +2306,6 @@ static void STDMETHODCALLTYPE d3d12_command_list_DrawIndexedInstanced(ID3D12Grap
VK_CALL(vkCmdDrawIndexed(list->vk_command_buffer, index_count_per_instance, instance_count, start_vertex_location, base_vertex_location, start_instance_location)); - - VK_CALL(vkCmdEndRenderPass(list->vk_command_buffer)); }
static void STDMETHODCALLTYPE d3d12_command_list_Dispatch(ID3D12GraphicsCommandList *iface, @@ -2301,6 +2324,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_Dispatch(ID3D12GraphicsCommandL
vk_procs = &list->device->vk_procs;
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + d3d12_command_list_update_descriptors(list, VK_PIPELINE_BIND_POINT_COMPUTE);
VK_CALL(vkCmdDispatch(list->vk_command_buffer, x, y, z)); @@ -2328,6 +2353,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_CopyBufferRegion(ID3D12Graphics d3d12_command_list_track_resource_usage(list, dst_resource); d3d12_command_list_track_resource_usage(list, src_resource);
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + buffer_copy.srcOffset = src_offset; buffer_copy.dstOffset = dst_offset; buffer_copy.size = byte_count; @@ -2548,6 +2575,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_CopyTextureRegion(ID3D12Graphic d3d12_command_list_track_resource_usage(list, dst_resource); d3d12_command_list_track_resource_usage(list, src_resource);
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + if (src->Type == D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX && dst->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { @@ -2661,6 +2690,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_CopyResource(ID3D12GraphicsComm d3d12_command_list_track_resource_usage(list, dst_resource); d3d12_command_list_track_resource_usage(list, src_resource);
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + if (d3d12_resource_is_buffer(dst_resource)) { assert(d3d12_resource_is_buffer(src_resource)); @@ -2850,6 +2881,7 @@ static void STDMETHODCALLTYPE d3d12_command_list_SetPipelineState(ID3D12Graphics if (!d3d12_pipeline_state_is_render_pass_compatible(list->state, state)) { d3d12_command_list_invalidate_current_framebuffer(list); + d3d12_command_list_invalidate_current_render_pass(list); } d3d12_command_list_invalidate_current_pipeline(list); } @@ -2869,6 +2901,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_ResourceBarrier(ID3D12GraphicsC
vk_procs = &list->device->vk_procs;
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + for (i = 0; i < barrier_count; ++i) { unsigned int sub_resource_idx = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; @@ -3486,6 +3520,7 @@ static void STDMETHODCALLTYPE d3d12_command_list_OMSetRenderTargets(ID3D12Graphi }
d3d12_command_list_invalidate_current_framebuffer(list); + d3d12_command_list_invalidate_current_render_pass(list); }
static void d3d12_command_list_clear(struct d3d12_command_list *list, @@ -3504,6 +3539,8 @@ static void d3d12_command_list_clear(struct d3d12_command_list *list, unsigned int i; VkResult vr;
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + if (!rect_count) { full_rect.top = 0; @@ -3695,6 +3732,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearUnorderedAccessViewUint(ID return; }
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + cpu_descriptor = d3d12_desc_from_cpu_handle(cpu_handle); if (!cpu_descriptor->view_size) { @@ -3737,6 +3776,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_BeginQuery(ID3D12GraphicsComman
TRACE("iface %p, heap %p, type %#x, index %u.\n", iface, heap, type, index);
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + if (type == D3D12_QUERY_TYPE_OCCLUSION) flags = VK_QUERY_CONTROL_PRECISE_BIT;
@@ -3753,6 +3794,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_EndQuery(ID3D12GraphicsCommandL
TRACE("iface %p, heap %p, type %#x, index %u.\n", iface, heap, type, index);
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + d3d12_query_heap_mark_result_as_available(query_heap, index);
if (type == D3D12_QUERY_TYPE_TIMESTAMP) @@ -3798,6 +3841,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_ResolveQueryData(ID3D12Graphics return; }
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + if (type == D3D12_QUERY_TYPE_PIPELINE_STATISTICS) stride = sizeof(struct D3D12_QUERY_DATA_PIPELINE_STATISTICS);
@@ -3887,8 +3932,6 @@ static void STDMETHODCALLTYPE d3d12_command_list_ExecuteIndirect(ID3D12GraphicsC
VK_CALL(vkCmdDrawIndirect(list->vk_command_buffer, arg_impl->u.vk_buffer, arg_buffer_offset, max_command_count, signature_desc->ByteStride)); - - VK_CALL(vkCmdEndRenderPass(list->vk_command_buffer)); break;
case D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH: @@ -3902,6 +3945,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_ExecuteIndirect(ID3D12GraphicsC break; }
+ d3d12_command_list_end_current_render_pass(list, vk_procs); + d3d12_command_list_update_descriptors(list, VK_PIPELINE_BIND_POINT_COMPUTE);
VK_CALL(vkCmdDispatchIndirect(list->vk_command_buffer, @@ -4022,6 +4067,7 @@ static HRESULT d3d12_command_list_init(struct d3d12_command_list *list, struct d
list->current_framebuffer = VK_NULL_HANDLE; list->current_pipeline = VK_NULL_HANDLE; + list->current_render_pass = VK_NULL_HANDLE; memset(list->pipeline_bindings, 0, sizeof(list->pipeline_bindings));
list->state = NULL; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 9fa29fb59774..f9a2f5a18f0c 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -617,6 +617,7 @@ struct d3d12_command_list
VkFramebuffer current_framebuffer; VkPipeline current_pipeline; + VkRenderPass current_render_pass; struct vkd3d_pipeline_bindings pipeline_bindings[VK_PIPELINE_BIND_POINT_RANGE_SIZE];
struct d3d12_pipeline_state *state;