radv: Handle VK_ATTACHMENT_UNUSED in color attachments.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 23 Jul 2017 19:59:01 +0000 (21:59 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 23 Jul 2017 23:50:52 +0000 (01:50 +0200)
This just sets them to INVALID COLOR,  instead of shifting the
attachments together.

This also fixes a number of cases where we use it first and only
then check if it is VK_ATTACHMENT_UNUSED.

Signed-off-by: Bas Nieuwenhuizen <basni@google.com>
Fixes: f4e499ec791 "radv: add initial non-conformant radv vulkan driver"
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_meta_clear.c
src/amd/vulkan/radv_meta_resolve.c
src/amd/vulkan/radv_meta_resolve_cs.c
src/amd/vulkan/radv_meta_resolve_fs.c
src/amd/vulkan/radv_pipeline.c

index 058770bcbfd10dfaf9d90b41c498c8b0707c8466..4b087811710a5345c8129035793c99187086ddaf 100644 (file)
@@ -1208,7 +1208,13 @@ radv_emit_framebuffer_state(struct radv_cmd_buffer *cmd_buffer)
        struct radv_framebuffer *framebuffer = cmd_buffer->state.framebuffer;
        const struct radv_subpass *subpass = cmd_buffer->state.subpass;
 
-       for (i = 0; i < subpass->color_count; ++i) {
+       for (i = 0; i < 8; ++i) {
+               if (i >= subpass->color_count || subpass->color_attachments[i].attachment == VK_ATTACHMENT_UNUSED) {
+                       radeon_set_context_reg(cmd_buffer->cs, R_028C70_CB_COLOR0_INFO + i * 0x3C,
+                                      S_028C70_FORMAT(V_028C70_COLOR_INVALID));
+                       continue;
+               }
+
                int idx = subpass->color_attachments[i].attachment;
                struct radv_attachment_info *att = &framebuffer->attachments[idx];
 
@@ -1220,10 +1226,6 @@ radv_emit_framebuffer_state(struct radv_cmd_buffer *cmd_buffer)
                radv_load_color_clear_regs(cmd_buffer, att->attachment->image, i);
        }
 
-       for (i = subpass->color_count; i < 8; i++)
-               radeon_set_context_reg(cmd_buffer->cs, R_028C70_CB_COLOR0_INFO + i * 0x3C,
-                                      S_028C70_FORMAT(V_028C70_COLOR_INVALID));
-
        if(subpass->depth_stencil_attachment.attachment != VK_ATTACHMENT_UNUSED) {
                int idx = subpass->depth_stencil_attachment.attachment;
                VkImageLayout layout = subpass->depth_stencil_attachment.layout;
@@ -1797,8 +1799,9 @@ radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
                radv_subpass_barrier(cmd_buffer, &subpass->start_barrier);
 
                for (unsigned i = 0; i < subpass->color_count; ++i) {
-                       radv_handle_subpass_image_transition(cmd_buffer,
-                                                       subpass->color_attachments[i]);
+                       if (subpass->color_attachments[i].attachment != VK_ATTACHMENT_UNUSED)
+                               radv_handle_subpass_image_transition(cmd_buffer,
+                                                                    subpass->color_attachments[i]);
                }
 
                for (unsigned i = 0; i < subpass->input_count; ++i) {
index 353e8382ca19892f5a5e554cfd2a4ea442810947..e9021915343bff11d8463bfaf9af905dbadfa969 100644 (file)
@@ -1080,7 +1080,8 @@ subpass_needs_clear(const struct radv_cmd_buffer *cmd_buffer)
        ds = cmd_state->subpass->depth_stencil_attachment.attachment;
        for (uint32_t i = 0; i < cmd_state->subpass->color_count; ++i) {
                uint32_t a = cmd_state->subpass->color_attachments[i].attachment;
-               if (cmd_state->attachments[a].pending_clear_aspects) {
+               if (a != VK_ATTACHMENT_UNUSED &&
+                   cmd_state->attachments[a].pending_clear_aspects) {
                        return true;
                }
        }
@@ -1120,7 +1121,8 @@ radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer)
        for (uint32_t i = 0; i < cmd_state->subpass->color_count; ++i) {
                uint32_t a = cmd_state->subpass->color_attachments[i].attachment;
 
-               if (!cmd_state->attachments[a].pending_clear_aspects)
+               if (a == VK_ATTACHMENT_UNUSED ||
+                   !cmd_state->attachments[a].pending_clear_aspects)
                        continue;
 
                assert(cmd_state->attachments[a].pending_clear_aspects ==
index a0edfb915cdce012223580d9b3c7a4315cc51d75..6cd0c381a54b043f2873980992331f6163fb4fb0 100644 (file)
@@ -560,6 +560,11 @@ radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer)
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference src_att = subpass->color_attachments[i];
                VkAttachmentReference dest_att = subpass->resolve_attachments[i];
+
+               if (src_att.attachment == VK_ATTACHMENT_UNUSED ||
+                   dest_att.attachment == VK_ATTACHMENT_UNUSED)
+                       continue;
+
                struct radv_image *dst_img = cmd_buffer->state.framebuffer->attachments[dest_att.attachment].attachment->image;
                struct radv_image *src_img = cmd_buffer->state.framebuffer->attachments[src_att.attachment].attachment->image;
 
@@ -582,10 +587,13 @@ radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer)
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference src_att = subpass->color_attachments[i];
                VkAttachmentReference dest_att = subpass->resolve_attachments[i];
-               struct radv_image *dst_img = cmd_buffer->state.framebuffer->attachments[dest_att.attachment].attachment->image;
-               if (dest_att.attachment == VK_ATTACHMENT_UNUSED)
+
+               if (src_att.attachment == VK_ATTACHMENT_UNUSED ||
+                   dest_att.attachment == VK_ATTACHMENT_UNUSED)
                        continue;
 
+               struct radv_image *dst_img = cmd_buffer->state.framebuffer->attachments[dest_att.attachment].attachment->image;
+
                if (dst_img->surface.dcc_size) {
                        radv_initialize_dcc(cmd_buffer, dst_img, 0xffffffff);
                        cmd_buffer->state.attachments[dest_att.attachment].current_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
index 5460fde2d5e69f62869400623187ce2a533f6799..1eef22ad7712f37be45a281f3dd0916bedcd8b75 100644 (file)
@@ -447,11 +447,14 @@ radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer)
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference src_att = subpass->color_attachments[i];
                VkAttachmentReference dest_att = subpass->resolve_attachments[i];
+
+               if (src_att.attachment == VK_ATTACHMENT_UNUSED ||
+                   dest_att.attachment == VK_ATTACHMENT_UNUSED)
+                       continue;
+
                struct radv_image *dst_img = cmd_buffer->state.framebuffer->attachments[dest_att.attachment].attachment->image;
                struct radv_image_view *src_iview = cmd_buffer->state.framebuffer->attachments[src_att.attachment].attachment;
 
-               if (dest_att.attachment == VK_ATTACHMENT_UNUSED)
-                       continue;
                if (dst_img->surface.dcc_size) {
                        radv_initialize_dcc(cmd_buffer, dst_img, 0xffffffff);
                        cmd_buffer->state.attachments[dest_att.attachment].current_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
index 97007d4ce6c716574a756cb8fad5fb2fe675cfcd..65c5075e2a1e1c5751e9c412aaeb3b64f2a71844 100644 (file)
@@ -618,11 +618,14 @@ radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer)
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference src_att = subpass->color_attachments[i];
                VkAttachmentReference dest_att = subpass->resolve_attachments[i];
+
+               if (src_att.attachment == VK_ATTACHMENT_UNUSED ||
+                   dest_att.attachment == VK_ATTACHMENT_UNUSED)
+                       continue;
+
                struct radv_image_view *dest_iview = cmd_buffer->state.framebuffer->attachments[dest_att.attachment].attachment;
                struct radv_image *dst_img = dest_iview->image;
                struct radv_image_view *src_iview = cmd_buffer->state.framebuffer->attachments[src_att.attachment].attachment;
-               if (dest_att.attachment == VK_ATTACHMENT_UNUSED)
-                       continue;
 
                if (dst_img->surface.dcc_size) {
                        radv_initialize_dcc(cmd_buffer, dst_img, 0xffffffff);
index c920cc35be14e1466652b89235b4d8b627fdf3fc..84494647c0225be0f383ab698eb76fe324ce66ee 100644 (file)
@@ -1035,14 +1035,17 @@ radv_pipeline_compute_spi_color_formats(struct radv_pipeline *pipeline,
        unsigned col_format = 0;
 
        for (unsigned i = 0; i < (single_cb_enable ? 1 : subpass->color_count); ++i) {
-               struct radv_render_pass_attachment *attachment;
                unsigned cf;
 
-               attachment = pass->attachments + subpass->color_attachments[i].attachment;
+               if (subpass->color_attachments[i].attachment == VK_ATTACHMENT_UNUSED) {
+                       cf = V_028714_SPI_SHADER_ZERO;
+               } else {
+                       struct radv_render_pass_attachment *attachment = pass->attachments + subpass->color_attachments[i].attachment;
 
-               cf = si_choose_spi_color_format(attachment->format,
-                                               blend_enable & (1 << i),
-                                               blend_need_alpha & (1 << i));
+                       cf = si_choose_spi_color_format(attachment->format,
+                                                       blend_enable & (1 << i),
+                                                       blend_need_alpha & (1 << i));
+               }
 
                col_format |= cf << (4 * i);
        }
@@ -1082,6 +1085,9 @@ radv_pipeline_compute_is_int8(const VkGraphicsPipelineCreateInfo *pCreateInfo)
        for (unsigned i = 0; i < subpass->color_count; ++i) {
                struct radv_render_pass_attachment *attachment;
 
+               if (subpass->color_attachments[i].attachment == VK_ATTACHMENT_UNUSED)
+                       continue;
+
                attachment = pass->attachments + subpass->color_attachments[i].attachment;
 
                if (format_is_int8(attachment->format))