Remove redundant explicit clears in the Vulkan RD
(cherry picked from commit 4964d9a083
)
This commit is contained in:
parent
307a6eba6b
commit
4b71c38e47
|
@ -6713,24 +6713,24 @@ Error RenderingDeviceVulkan::_draw_list_setup_framebuffer(Framebuffer *p_framebu
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error RenderingDeviceVulkan::_draw_list_render_pass_begin(Framebuffer *framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_colors, float p_clear_depth, uint32_t p_clear_stencil, Point2i viewport_offset, Point2i viewport_size, VkFramebuffer vkframebuffer, VkRenderPass render_pass, VkCommandBuffer command_buffer, VkSubpassContents subpass_contents, const Vector<RID> &p_storage_textures) {
|
Error RenderingDeviceVulkan::_draw_list_render_pass_begin(Framebuffer *framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_colors, float p_clear_depth, uint32_t p_clear_stencil, Point2i viewport_offset, Point2i viewport_size, VkFramebuffer vkframebuffer, VkRenderPass render_pass, VkCommandBuffer command_buffer, VkSubpassContents subpass_contents, const Vector<RID> &p_storage_textures, bool p_constrained_to_region) {
|
||||||
VkRenderPassBeginInfo render_pass_begin;
|
VkRenderPassBeginInfo render_pass_begin;
|
||||||
render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
render_pass_begin.pNext = nullptr;
|
render_pass_begin.pNext = nullptr;
|
||||||
render_pass_begin.renderPass = render_pass;
|
render_pass_begin.renderPass = render_pass;
|
||||||
render_pass_begin.framebuffer = vkframebuffer;
|
render_pass_begin.framebuffer = vkframebuffer;
|
||||||
/*
|
|
||||||
* Given how API works, it makes sense to always fully operate on the whole framebuffer.
|
if (p_constrained_to_region) {
|
||||||
* This allows better continue operations for operations like shadowmapping.
|
|
||||||
render_pass_begin.renderArea.extent.width = viewport_size.width;
|
render_pass_begin.renderArea.extent.width = viewport_size.width;
|
||||||
render_pass_begin.renderArea.extent.height = viewport_size.height;
|
render_pass_begin.renderArea.extent.height = viewport_size.height;
|
||||||
render_pass_begin.renderArea.offset.x = viewport_offset.x;
|
render_pass_begin.renderArea.offset.x = viewport_offset.x;
|
||||||
render_pass_begin.renderArea.offset.y = viewport_offset.y;
|
render_pass_begin.renderArea.offset.y = viewport_offset.y;
|
||||||
*/
|
} else {
|
||||||
render_pass_begin.renderArea.extent.width = framebuffer->size.width;
|
render_pass_begin.renderArea.extent.width = framebuffer->size.width;
|
||||||
render_pass_begin.renderArea.extent.height = framebuffer->size.height;
|
render_pass_begin.renderArea.extent.height = framebuffer->size.height;
|
||||||
render_pass_begin.renderArea.offset.x = 0;
|
render_pass_begin.renderArea.offset.x = 0;
|
||||||
render_pass_begin.renderArea.offset.y = 0;
|
render_pass_begin.renderArea.offset.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Vector<VkClearValue> clear_values;
|
Vector<VkClearValue> clear_values;
|
||||||
clear_values.resize(framebuffer->texture_ids.size());
|
clear_values.resize(framebuffer->texture_ids.size());
|
||||||
|
@ -6880,6 +6880,7 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu
|
||||||
|
|
||||||
Point2i viewport_offset;
|
Point2i viewport_offset;
|
||||||
Point2i viewport_size = framebuffer->size;
|
Point2i viewport_size = framebuffer->size;
|
||||||
|
bool constrained_to_region = false;
|
||||||
bool needs_clear_color = false;
|
bool needs_clear_color = false;
|
||||||
bool needs_clear_depth = false;
|
bool needs_clear_depth = false;
|
||||||
|
|
||||||
|
@ -6894,6 +6895,14 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu
|
||||||
|
|
||||||
viewport_offset = regioni.position;
|
viewport_offset = regioni.position;
|
||||||
viewport_size = regioni.size;
|
viewport_size = regioni.size;
|
||||||
|
|
||||||
|
// If clearing regions both in color and depth, we can switch to a fast path where we let Vulkan to the clears
|
||||||
|
// and we constrain the render area to the region.
|
||||||
|
if (p_initial_color_action == INITIAL_ACTION_CLEAR_REGION && p_initial_depth_action == INITIAL_ACTION_CLEAR_REGION) {
|
||||||
|
constrained_to_region = true;
|
||||||
|
p_initial_color_action = INITIAL_ACTION_CLEAR;
|
||||||
|
p_initial_depth_action = INITIAL_ACTION_CLEAR;
|
||||||
|
} else {
|
||||||
if (p_initial_color_action == INITIAL_ACTION_CLEAR_REGION_CONTINUE) {
|
if (p_initial_color_action == INITIAL_ACTION_CLEAR_REGION_CONTINUE) {
|
||||||
needs_clear_color = true;
|
needs_clear_color = true;
|
||||||
p_initial_color_action = INITIAL_ACTION_CONTINUE;
|
p_initial_color_action = INITIAL_ACTION_CONTINUE;
|
||||||
|
@ -6911,6 +6920,7 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu
|
||||||
p_initial_depth_action = INITIAL_ACTION_KEEP;
|
p_initial_depth_action = INITIAL_ACTION_KEEP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (p_initial_color_action == INITIAL_ACTION_CLEAR || needs_clear_color) { // Check clear values.
|
if (p_initial_color_action == INITIAL_ACTION_CLEAR || needs_clear_color) { // Check clear values.
|
||||||
int color_count = 0;
|
int color_count = 0;
|
||||||
|
@ -6935,7 +6945,7 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu
|
||||||
ERR_FAIL_COND_V(err != OK, INVALID_ID);
|
ERR_FAIL_COND_V(err != OK, INVALID_ID);
|
||||||
|
|
||||||
VkCommandBuffer command_buffer = frames[frame].draw_command_buffer;
|
VkCommandBuffer command_buffer = frames[frame].draw_command_buffer;
|
||||||
err = _draw_list_render_pass_begin(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, p_clear_color_values, p_clear_depth, p_clear_stencil, viewport_offset, viewport_size, vkframebuffer, render_pass, command_buffer, VK_SUBPASS_CONTENTS_INLINE, p_storage_textures);
|
err = _draw_list_render_pass_begin(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, p_clear_color_values, p_clear_depth, p_clear_stencil, viewport_offset, viewport_size, vkframebuffer, render_pass, command_buffer, VK_SUBPASS_CONTENTS_INLINE, p_storage_textures, constrained_to_region);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
return INVALID_ID;
|
return INVALID_ID;
|
||||||
|
@ -6951,6 +6961,7 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu
|
||||||
draw_list_current_subpass = 0;
|
draw_list_current_subpass = 0;
|
||||||
|
|
||||||
if (needs_clear_color || needs_clear_depth) {
|
if (needs_clear_color || needs_clear_depth) {
|
||||||
|
DEV_ASSERT(!constrained_to_region);
|
||||||
_draw_list_insert_clear_region(draw_list, framebuffer, viewport_offset, viewport_size, needs_clear_color, p_clear_color_values, needs_clear_depth, p_clear_depth, p_clear_stencil);
|
_draw_list_insert_clear_region(draw_list, framebuffer, viewport_offset, viewport_size, needs_clear_color, p_clear_color_values, needs_clear_depth, p_clear_depth, p_clear_stencil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6989,6 +7000,7 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p
|
||||||
Point2i viewport_offset;
|
Point2i viewport_offset;
|
||||||
Point2i viewport_size = framebuffer->size;
|
Point2i viewport_size = framebuffer->size;
|
||||||
|
|
||||||
|
bool constrained_to_region = false;
|
||||||
bool needs_clear_color = false;
|
bool needs_clear_color = false;
|
||||||
bool needs_clear_depth = false;
|
bool needs_clear_depth = false;
|
||||||
|
|
||||||
|
@ -7004,6 +7016,21 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p
|
||||||
viewport_offset = regioni.position;
|
viewport_offset = regioni.position;
|
||||||
viewport_size = regioni.size;
|
viewport_size = regioni.size;
|
||||||
|
|
||||||
|
// If clearing regions both in color and depth, we can switch to a fast path where we let Vulkan to the clears
|
||||||
|
// and we constrain the render area to the region.
|
||||||
|
if (p_initial_color_action == INITIAL_ACTION_CLEAR_REGION && p_initial_depth_action == INITIAL_ACTION_CLEAR_REGION) {
|
||||||
|
constrained_to_region = true;
|
||||||
|
p_initial_color_action = INITIAL_ACTION_CLEAR;
|
||||||
|
p_initial_depth_action = INITIAL_ACTION_CLEAR;
|
||||||
|
} else {
|
||||||
|
if (p_initial_color_action == INITIAL_ACTION_CLEAR_REGION_CONTINUE) {
|
||||||
|
needs_clear_color = true;
|
||||||
|
p_initial_color_action = INITIAL_ACTION_CONTINUE;
|
||||||
|
}
|
||||||
|
if (p_initial_depth_action == INITIAL_ACTION_CLEAR_REGION_CONTINUE) {
|
||||||
|
needs_clear_depth = true;
|
||||||
|
p_initial_depth_action = INITIAL_ACTION_CONTINUE;
|
||||||
|
}
|
||||||
if (p_initial_color_action == INITIAL_ACTION_CLEAR_REGION) {
|
if (p_initial_color_action == INITIAL_ACTION_CLEAR_REGION) {
|
||||||
needs_clear_color = true;
|
needs_clear_color = true;
|
||||||
p_initial_color_action = INITIAL_ACTION_KEEP;
|
p_initial_color_action = INITIAL_ACTION_KEEP;
|
||||||
|
@ -7013,6 +7040,7 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p
|
||||||
p_initial_depth_action = INITIAL_ACTION_KEEP;
|
p_initial_depth_action = INITIAL_ACTION_KEEP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (p_initial_color_action == INITIAL_ACTION_CLEAR || needs_clear_color) { // Check clear values.
|
if (p_initial_color_action == INITIAL_ACTION_CLEAR || needs_clear_color) { // Check clear values.
|
||||||
|
|
||||||
|
@ -7036,7 +7064,7 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p
|
||||||
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
|
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
|
||||||
|
|
||||||
VkCommandBuffer frame_command_buffer = frames[frame].draw_command_buffer;
|
VkCommandBuffer frame_command_buffer = frames[frame].draw_command_buffer;
|
||||||
err = _draw_list_render_pass_begin(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, p_clear_color_values, p_clear_depth, p_clear_stencil, viewport_offset, viewport_size, vkframebuffer, render_pass, frame_command_buffer, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, p_storage_textures);
|
err = _draw_list_render_pass_begin(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, p_clear_color_values, p_clear_depth, p_clear_stencil, viewport_offset, viewport_size, vkframebuffer, render_pass, frame_command_buffer, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, p_storage_textures, constrained_to_region);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
return ERR_CANT_CREATE;
|
return ERR_CANT_CREATE;
|
||||||
|
@ -7056,6 +7084,7 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needs_clear_color || needs_clear_depth) {
|
if (needs_clear_color || needs_clear_depth) {
|
||||||
|
DEV_ASSERT(!constrained_to_region);
|
||||||
_draw_list_insert_clear_region(&draw_list[0], framebuffer, viewport_offset, viewport_size, needs_clear_color, p_clear_color_values, needs_clear_depth, p_clear_depth, p_clear_stencil);
|
_draw_list_insert_clear_region(&draw_list[0], framebuffer, viewport_offset, viewport_size, needs_clear_color, p_clear_color_values, needs_clear_depth, p_clear_depth, p_clear_stencil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -929,7 +929,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
|
||||||
|
|
||||||
void _draw_list_insert_clear_region(DrawList *p_draw_list, Framebuffer *p_framebuffer, Point2i p_viewport_offset, Point2i p_viewport_size, bool p_clear_color, const Vector<Color> &p_clear_colors, bool p_clear_depth, float p_depth, uint32_t p_stencil);
|
void _draw_list_insert_clear_region(DrawList *p_draw_list, Framebuffer *p_framebuffer, Point2i p_viewport_offset, Point2i p_viewport_size, bool p_clear_color, const Vector<Color> &p_clear_colors, bool p_clear_depth, float p_depth, uint32_t p_stencil);
|
||||||
Error _draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass, uint32_t *r_subpass_count);
|
Error _draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass, uint32_t *r_subpass_count);
|
||||||
Error _draw_list_render_pass_begin(Framebuffer *framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_colors, float p_clear_depth, uint32_t p_clear_stencil, Point2i viewport_offset, Point2i viewport_size, VkFramebuffer vkframebuffer, VkRenderPass render_pass, VkCommandBuffer command_buffer, VkSubpassContents subpass_contents, const Vector<RID> &p_storage_textures);
|
Error _draw_list_render_pass_begin(Framebuffer *framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_colors, float p_clear_depth, uint32_t p_clear_stencil, Point2i viewport_offset, Point2i viewport_size, VkFramebuffer vkframebuffer, VkRenderPass render_pass, VkCommandBuffer command_buffer, VkSubpassContents subpass_contents, const Vector<RID> &p_storage_textures, bool p_constrained_to_region);
|
||||||
_FORCE_INLINE_ DrawList *_get_draw_list_ptr(DrawListID p_id);
|
_FORCE_INLINE_ DrawList *_get_draw_list_ptr(DrawListID p_id);
|
||||||
Buffer *_get_buffer_from_owner(RID p_buffer, VkPipelineStageFlags &dst_stage_mask, VkAccessFlags &dst_access, BitField<BarrierMask> p_post_barrier);
|
Buffer *_get_buffer_from_owner(RID p_buffer, VkPipelineStageFlags &dst_stage_mask, VkAccessFlags &dst_access, BitField<BarrierMask> p_post_barrier);
|
||||||
Error _draw_list_allocate(const Rect2i &p_viewport, uint32_t p_splits, uint32_t p_subpass);
|
Error _draw_list_allocate(const Rect2i &p_viewport, uint32_t p_splits, uint32_t p_subpass);
|
||||||
|
|
Loading…
Reference in New Issue