[Mesa-dev] [PATCH 05/10] radv: introduce the concept of meta save flags
Samuel Pitoiset
samuel.pitoiset at gmail.com
Tue Oct 3 18:52:40 UTC 2017
This will allow us to save/restore the different states on-demand
based on the meta operation. For now, this saves/restores all
states. Compute will follow once the graphics part is done.
The main idea is to merge all save/restore helpers.
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
src/amd/vulkan/radv_meta.c | 99 +++++++++++++++++++++--------------
src/amd/vulkan/radv_meta.h | 12 ++++-
src/amd/vulkan/radv_meta_blit.c | 2 +-
src/amd/vulkan/radv_meta_clear.c | 8 +--
src/amd/vulkan/radv_meta_copy.c | 4 +-
src/amd/vulkan/radv_meta_decompress.c | 2 +-
src/amd/vulkan/radv_meta_fast_clear.c | 2 +-
src/amd/vulkan/radv_meta_resolve.c | 4 +-
src/amd/vulkan/radv_meta_resolve_fs.c | 4 +-
9 files changed, 85 insertions(+), 52 deletions(-)
diff --git a/src/amd/vulkan/radv_meta.c b/src/amd/vulkan/radv_meta.c
index 3ddbc2e9af..d6966ed516 100644
--- a/src/amd/vulkan/radv_meta.c
+++ b/src/amd/vulkan/radv_meta.c
@@ -32,53 +32,75 @@
static void
radv_meta_save_novertex(struct radv_meta_saved_state *state,
- const struct radv_cmd_buffer *cmd_buffer)
+ const struct radv_cmd_buffer *cmd_buffer,
+ uint32_t flags)
{
- state->old_pipeline = cmd_buffer->state.pipeline;
- state->old_descriptor_set0 = cmd_buffer->state.descriptors[0];
-
- /* Save all viewports. */
- state->viewport.count = cmd_buffer->state.dynamic.viewport.count;
- typed_memcpy(state->viewport.viewports,
- cmd_buffer->state.dynamic.viewport.viewports,
- MAX_VIEWPORTS);
+ state->flags = flags;
+
+ if (state->flags & RADV_META_SAVE_GRAPHICS) {
+ state->old_pipeline = cmd_buffer->state.pipeline;
+
+ /* Save all viewports. */
+ state->viewport.count = cmd_buffer->state.dynamic.viewport.count;
+ typed_memcpy(state->viewport.viewports,
+ cmd_buffer->state.dynamic.viewport.viewports,
+ MAX_VIEWPORTS);
+
+ /* Save all scissors. */
+ state->scissor.count = cmd_buffer->state.dynamic.scissor.count;
+ typed_memcpy(state->scissor.scissors,
+ cmd_buffer->state.dynamic.scissor.scissors,
+ MAX_SCISSORS);
+ }
- /* Save all scissors. */
- state->scissor.count = cmd_buffer->state.dynamic.scissor.count;
- typed_memcpy(state->scissor.scissors,
- cmd_buffer->state.dynamic.scissor.scissors,
- MAX_SCISSORS);
+ if (state->flags & RADV_META_SAVE_DESCRIPTORS) {
+ state->old_descriptor_set0 = cmd_buffer->state.descriptors[0];
+ }
- memcpy(state->push_constants, cmd_buffer->push_constants, MAX_PUSH_CONSTANTS_SIZE);
+ if (state->flags & RADV_META_SAVE_CONSTANTS) {
+ memcpy(state->push_constants, cmd_buffer->push_constants,
+ MAX_PUSH_CONSTANTS_SIZE);
+ }
}
void
radv_meta_restore(const struct radv_meta_saved_state *state,
struct radv_cmd_buffer *cmd_buffer)
{
- radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer), VK_PIPELINE_BIND_POINT_GRAPHICS,
- radv_pipeline_to_handle(state->old_pipeline));
- cmd_buffer->state.descriptors[0] = state->old_descriptor_set0;
-
- cmd_buffer->state.dirty |= RADV_CMD_DIRTY_PIPELINE;
-
- /* Restore all viewports. */
- cmd_buffer->state.dynamic.viewport.count = state->viewport.count;
- typed_memcpy(cmd_buffer->state.dynamic.viewport.viewports,
- state->viewport.viewports,
- MAX_VIEWPORTS);
-
- /* Restore all scissors. */
- cmd_buffer->state.dynamic.scissor.count = state->scissor.count;
- typed_memcpy(cmd_buffer->state.dynamic.scissor.scissors,
- state->scissor.scissors,
- MAX_SCISSORS);
+ if (state->flags & RADV_META_SAVE_GRAPHICS) {
+ radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer),
+ VK_PIPELINE_BIND_POINT_GRAPHICS,
+ radv_pipeline_to_handle(state->old_pipeline));
+
+ cmd_buffer->state.dirty |= RADV_CMD_DIRTY_PIPELINE;
+
+ /* Restore all viewports. */
+ cmd_buffer->state.dynamic.viewport.count = state->viewport.count;
+ typed_memcpy(cmd_buffer->state.dynamic.viewport.viewports,
+ state->viewport.viewports,
+ MAX_VIEWPORTS);
+
+ /* Restore all scissors. */
+ cmd_buffer->state.dynamic.scissor.count = state->scissor.count;
+ typed_memcpy(cmd_buffer->state.dynamic.scissor.scissors,
+ state->scissor.scissors,
+ MAX_SCISSORS);
+
+ cmd_buffer->state.dirty |= 1 << VK_DYNAMIC_STATE_VIEWPORT |
+ 1 << VK_DYNAMIC_STATE_SCISSOR;
+ }
- cmd_buffer->state.dirty |= 1 << VK_DYNAMIC_STATE_VIEWPORT |
- 1 << VK_DYNAMIC_STATE_SCISSOR;
+ if (state->flags & RADV_META_SAVE_DESCRIPTORS) {
+ cmd_buffer->state.descriptors[0] = state->old_descriptor_set0;
+ cmd_buffer->state.descriptors_dirty |= (1 << 0);
+ }
- memcpy(cmd_buffer->push_constants, state->push_constants, MAX_PUSH_CONSTANTS_SIZE);
- cmd_buffer->push_constant_stages |= VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_COMPUTE_BIT;
+ if (state->flags & RADV_META_SAVE_CONSTANTS) {
+ memcpy(cmd_buffer->push_constants, state->push_constants,
+ MAX_PUSH_CONSTANTS_SIZE);
+ cmd_buffer->push_constant_stages |= VK_SHADER_STAGE_ALL_GRAPHICS |
+ VK_SHADER_STAGE_COMPUTE_BIT;
+ }
}
void
@@ -410,9 +432,10 @@ radv_device_finish_meta(struct radv_device *device)
*/
void
radv_meta_save_graphics_reset_vport_scissor_novertex(struct radv_meta_saved_state *saved_state,
- struct radv_cmd_buffer *cmd_buffer)
+ struct radv_cmd_buffer *cmd_buffer,
+ uint32_t flags)
{
- radv_meta_save_novertex(saved_state, cmd_buffer);
+ radv_meta_save_novertex(saved_state, cmd_buffer, flags);
cmd_buffer->state.dynamic.viewport.count = 0;
cmd_buffer->state.dynamic.scissor.count = 0;
cmd_buffer->state.dirty |= 1 << VK_DYNAMIC_STATE_VIEWPORT |
diff --git a/src/amd/vulkan/radv_meta.h b/src/amd/vulkan/radv_meta.h
index 252514540e..0befecd043 100644
--- a/src/amd/vulkan/radv_meta.h
+++ b/src/amd/vulkan/radv_meta.h
@@ -33,7 +33,16 @@
extern "C" {
#endif
+enum radv_meta_save_flags {
+ RADV_META_SAVE_PASS = (1 << 0),
+ RADV_META_SAVE_CONSTANTS = (1 << 1),
+ RADV_META_SAVE_DESCRIPTORS = (1 << 2),
+ RADV_META_SAVE_GRAPHICS = (1 << 3),
+};
+
struct radv_meta_saved_state {
+ uint32_t flags;
+
struct radv_descriptor_set *old_descriptor_set0;
struct radv_pipeline *old_pipeline;
struct radv_viewport_state viewport;
@@ -182,7 +191,8 @@ void radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
const VkImageSubresourceRange *subresourceRange);
void radv_meta_save_graphics_reset_vport_scissor_novertex(struct radv_meta_saved_state *saved_state,
- struct radv_cmd_buffer *cmd_buffer);
+ struct radv_cmd_buffer *cmd_buffer,
+ uint32_t flags);
void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
struct radv_image *src_image,
diff --git a/src/amd/vulkan/radv_meta_blit.c b/src/amd/vulkan/radv_meta_blit.c
index a0be498de5..eb43b822e3 100644
--- a/src/amd/vulkan/radv_meta_blit.c
+++ b/src/amd/vulkan/radv_meta_blit.c
@@ -512,7 +512,7 @@ void radv_CmdBlitImage(
assert(src_image->info.samples == 1);
assert(dest_image->info.samples == 1);
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
for (unsigned r = 0; r < regionCount; r++) {
const VkImageSubresourceLayers *src_res = &pRegions[r].srcSubresource;
diff --git a/src/amd/vulkan/radv_meta_clear.c b/src/amd/vulkan/radv_meta_clear.c
index 1133024d58..47aef2098a 100644
--- a/src/amd/vulkan/radv_meta_clear.c
+++ b/src/amd/vulkan/radv_meta_clear.c
@@ -1139,7 +1139,7 @@ radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer)
if (!radv_subpass_needs_clear(cmd_buffer))
return;
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
for (uint32_t i = 0; i < cmd_state->subpass->color_count; ++i) {
uint32_t a = cmd_state->subpass->color_attachments[i].attachment;
@@ -1381,7 +1381,7 @@ void radv_CmdClearColorImage(
if (cs)
radv_meta_save_compute(&saved_state.compute, cmd_buffer, 16);
else
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state.gfx, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state.gfx, cmd_buffer, ~0);
radv_cmd_clear_image(cmd_buffer, image, imageLayout,
(const VkClearValue *) pColor,
@@ -1405,7 +1405,7 @@ void radv_CmdClearDepthStencilImage(
RADV_FROM_HANDLE(radv_image, image, image_h);
struct radv_meta_saved_state saved_state;
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
radv_cmd_clear_image(cmd_buffer, image, imageLayout,
(const VkClearValue *) pDepthStencil,
@@ -1429,7 +1429,7 @@ void radv_CmdClearAttachments(
if (!cmd_buffer->state.subpass)
return;
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
/* FINISHME: We can do better than this dumb loop. It thrashes too much
* state.
diff --git a/src/amd/vulkan/radv_meta_copy.c b/src/amd/vulkan/radv_meta_copy.c
index f3e41ff056..b5a14f6d9f 100644
--- a/src/amd/vulkan/radv_meta_copy.c
+++ b/src/amd/vulkan/radv_meta_copy.c
@@ -123,7 +123,7 @@ meta_copy_buffer_to_image(struct radv_cmd_buffer *cmd_buffer,
if (cs)
radv_meta_save_compute(&saved_state.compute, cmd_buffer, 12);
else
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state.gfx, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state.gfx, cmd_buffer, ~0);
for (unsigned r = 0; r < regionCount; r++) {
@@ -342,7 +342,7 @@ meta_copy_image(struct radv_cmd_buffer *cmd_buffer,
if (cs)
radv_meta_save_compute(&saved_state.compute, cmd_buffer, 16);
else
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state.gfx, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state.gfx, cmd_buffer, ~0);
for (unsigned r = 0; r < regionCount; r++) {
assert(pRegions[r].srcSubresource.aspectMask ==
diff --git a/src/amd/vulkan/radv_meta_decompress.c b/src/amd/vulkan/radv_meta_decompress.c
index 8abbcb6723..ba2133fabe 100644
--- a/src/amd/vulkan/radv_meta_decompress.c
+++ b/src/amd/vulkan/radv_meta_decompress.c
@@ -321,7 +321,7 @@ static void radv_process_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
return;
radv_meta_save_pass(&saved_pass_state, cmd_buffer);
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
switch (op) {
case DEPTH_DECOMPRESS:
diff --git a/src/amd/vulkan/radv_meta_fast_clear.c b/src/amd/vulkan/radv_meta_fast_clear.c
index a10630173e..7daa2ad015 100644
--- a/src/amd/vulkan/radv_meta_fast_clear.c
+++ b/src/amd/vulkan/radv_meta_fast_clear.c
@@ -346,7 +346,7 @@ radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer *cmd_buffer,
assert(cmd_buffer->queue_family_index == RADV_QUEUE_GENERAL);
radv_meta_save_pass(&saved_pass_state, cmd_buffer);
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
if (image->fmask.size > 0) {
pipeline = cmd_buffer->device->meta_state.fast_clear_flush.fmask_decompress_pipeline;
diff --git a/src/amd/vulkan/radv_meta_resolve.c b/src/amd/vulkan/radv_meta_resolve.c
index 5141ae3baa..b9020adcb6 100644
--- a/src/amd/vulkan/radv_meta_resolve.c
+++ b/src/amd/vulkan/radv_meta_resolve.c
@@ -370,7 +370,7 @@ void radv_CmdResolveImage(
return;
}
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
assert(src_image->info.samples > 1);
if (src_image->info.samples <= 1) {
@@ -578,7 +578,7 @@ radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer)
return;
}
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
for (uint32_t i = 0; i < subpass->color_count; ++i) {
VkAttachmentReference src_att = subpass->color_attachments[i];
diff --git a/src/amd/vulkan/radv_meta_resolve_fs.c b/src/amd/vulkan/radv_meta_resolve_fs.c
index 56b6e0c29a..c0c1ff4b6e 100644
--- a/src/amd/vulkan/radv_meta_resolve_fs.c
+++ b/src/amd/vulkan/radv_meta_resolve_fs.c
@@ -471,7 +471,7 @@ void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
}
rp = device->meta_state.resolve_fragment.rc[samples_log2].render_pass[fs_key];
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
for (uint32_t r = 0; r < region_count; ++r) {
const VkImageResolve *region = ®ions[r];
@@ -598,7 +598,7 @@ radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer)
if (!subpass->has_resolve)
return;
- radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer);
+ radv_meta_save_graphics_reset_vport_scissor_novertex(&saved_state, cmd_buffer, ~0);
for (uint32_t i = 0; i < subpass->color_count; ++i) {
VkAttachmentReference src_att = subpass->color_attachments[i];
--
2.14.2
More information about the mesa-dev
mailing list