From: Jonathan Marek Date: Mon, 14 Oct 2019 16:46:37 +0000 (-0400) Subject: turnip: basic msaa working X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f1efc9a1c89e3b8f1b5faad4238035ebe8a8f217;p=mesa.git turnip: basic msaa working Not perfect but gets through some tests. Signed-off-by: Jonathan Marek Reviewed-by: Kristian H. Kristensen --- diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index 3043740626f..9e8889a45b2 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -34,6 +34,7 @@ #include "vk_format.h" #include "tu_cs.h" +#include "tu_blit.h" void tu_bo_list_init(struct tu_bo_list *list) @@ -515,28 +516,22 @@ tu6_emit_msaa(struct tu_cmd_buffer *cmd, struct tu_cs *cs) { const struct tu_subpass *subpass = cmd->state.subpass; const enum a3xx_msaa_samples samples = - tu6_msaa_samples(subpass->max_sample_count); + tu_msaa_samples(subpass->max_sample_count); tu_cs_emit_pkt4(cs, REG_A6XX_SP_TP_RAS_MSAA_CNTL, 2); tu_cs_emit(cs, A6XX_SP_TP_RAS_MSAA_CNTL_SAMPLES(samples)); - tu_cs_emit( - cs, A6XX_SP_TP_DEST_MSAA_CNTL_SAMPLES(samples) | - ((samples == MSAA_ONE) ? A6XX_SP_TP_DEST_MSAA_CNTL_MSAA_DISABLE - : 0)); + tu_cs_emit(cs, A6XX_SP_TP_DEST_MSAA_CNTL_SAMPLES(samples) | + COND(samples == MSAA_ONE, A6XX_SP_TP_DEST_MSAA_CNTL_MSAA_DISABLE)); tu_cs_emit_pkt4(cs, REG_A6XX_GRAS_RAS_MSAA_CNTL, 2); tu_cs_emit(cs, A6XX_GRAS_RAS_MSAA_CNTL_SAMPLES(samples)); - tu_cs_emit( - cs, - A6XX_GRAS_DEST_MSAA_CNTL_SAMPLES(samples) | - ((samples == MSAA_ONE) ? A6XX_GRAS_DEST_MSAA_CNTL_MSAA_DISABLE : 0)); + tu_cs_emit(cs, A6XX_GRAS_DEST_MSAA_CNTL_SAMPLES(samples) | + COND(samples == MSAA_ONE, A6XX_GRAS_DEST_MSAA_CNTL_MSAA_DISABLE)); tu_cs_emit_pkt4(cs, REG_A6XX_RB_RAS_MSAA_CNTL, 2); tu_cs_emit(cs, A6XX_RB_RAS_MSAA_CNTL_SAMPLES(samples)); - tu_cs_emit( - cs, - A6XX_RB_DEST_MSAA_CNTL_SAMPLES(samples) | - ((samples == MSAA_ONE) ? A6XX_RB_DEST_MSAA_CNTL_MSAA_DISABLE : 0)); + tu_cs_emit(cs, A6XX_RB_DEST_MSAA_CNTL_SAMPLES(samples) | + COND(samples == MSAA_ONE, A6XX_RB_DEST_MSAA_CNTL_MSAA_DISABLE)); tu_cs_emit_pkt4(cs, REG_A6XX_RB_MSAA_CNTL, 1); tu_cs_emit(cs, A6XX_RB_MSAA_CNTL_SAMPLES(samples)); @@ -606,7 +601,6 @@ tu6_emit_blit_info(struct tu_cmd_buffer *cmd, &iview->image->levels[iview->base_mip]; const uint32_t offset = slice->offset + slice->size * iview->base_layer; const uint32_t stride = slice->pitch * iview->image->cpp; - const enum a3xx_msaa_samples samples = tu6_msaa_samples(1); tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_INFO, 1); tu_cs_emit(cs, blit_info); @@ -619,7 +613,7 @@ tu6_emit_blit_info(struct tu_cmd_buffer *cmd, tu6_get_image_tile_mode(iview->image, iview->base_mip); tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 5); tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_TILE_MODE(tile_mode) | - A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) | + A6XX_RB_BLIT_DST_INFO_SAMPLES(tu_msaa_samples(iview->image->samples)) | A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format->rb) | A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(format->swap)); tu_cs_emit_qw(cs, @@ -638,8 +632,6 @@ tu6_emit_blit_clear(struct tu_cmd_buffer *cmd, uint32_t gmem_offset, const VkClearValue *clear_value) { - const enum a3xx_msaa_samples samples = tu6_msaa_samples(1); - const struct tu_native_format *format = tu6_get_native_format(iview->vk_format); assert(format && format->rb >= 0); @@ -648,7 +640,7 @@ tu6_emit_blit_clear(struct tu_cmd_buffer *cmd, tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 1); tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR) | - A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) | + A6XX_RB_BLIT_DST_INFO_SAMPLES(tu_msaa_samples(iview->image->samples)) | A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format->rb) | A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(swap)); @@ -1074,6 +1066,9 @@ tu6_render_tile(struct tu_cmd_buffer *cmd, static void tu6_render_end(struct tu_cmd_buffer *cmd, struct tu_cs *cs) { + const struct tu_subpass *subpass = cmd->state.subpass; + const struct tu_framebuffer *fb = cmd->state.framebuffer; + VkResult result = tu_cs_reserve_space(cmd->device, cs, 16); if (result != VK_SUCCESS) { cmd->record_result = result; @@ -1087,6 +1082,31 @@ tu6_render_end(struct tu_cmd_buffer *cmd, struct tu_cs *cs) tu6_emit_event_write(cmd, cs, CACHE_FLUSH_TS, true); + if (subpass->has_resolve) { + for (uint32_t i = 0; i < subpass->color_count; ++i) { + struct tu_subpass_attachment src_att = subpass->color_attachments[i]; + struct tu_subpass_attachment dst_att = subpass->resolve_attachments[i]; + + if (dst_att.attachment == VK_ATTACHMENT_UNUSED) + continue; + + struct tu_image *src_img = fb->attachments[src_att.attachment].attachment->image; + struct tu_image *dst_img = fb->attachments[dst_att.attachment].attachment->image; + + assert(src_img->extent.width == dst_img->extent.width); + assert(src_img->extent.height == dst_img->extent.height); + + tu_bo_list_add(&cmd->bo_list, src_img->bo, MSM_SUBMIT_BO_READ); + tu_bo_list_add(&cmd->bo_list, dst_img->bo, MSM_SUBMIT_BO_WRITE); + + tu_blit(cmd, &(struct tu_blit) { + .dst = tu_blit_surf_whole(dst_img), + .src = tu_blit_surf_whole(src_img), + .layers = 1, + }, false); + } + } + tu_cs_sanity_check(cs); } diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index 6f76a69b632..1635bfddb49 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -703,7 +703,8 @@ tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice); - VkSampleCountFlags sample_counts = 0xf; + VkSampleCountFlags sample_counts = VK_SAMPLE_COUNT_1_BIT | + VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT | VK_SAMPLE_COUNT_8_BIT; /* make sure that the entire descriptor set is addressable with a signed * 32-bit int. So the sum of all limits scaled by descriptor size has to diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c index 50bd1dbbb19..6c774de9f53 100644 --- a/src/freedreno/vulkan/tu_image.c +++ b/src/freedreno/vulkan/tu_image.c @@ -335,7 +335,7 @@ tu_image_view_init(struct tu_image_view *iview, A6XX_TEX_CONST_0_TILE_MODE(tile_mode) | COND(vk_format_is_srgb(iview->vk_format), A6XX_TEX_CONST_0_SRGB) | A6XX_TEX_CONST_0_FMT(fmt->tex) | - A6XX_TEX_CONST_0_SAMPLES(0) | + A6XX_TEX_CONST_0_SAMPLES(tu_msaa_samples(image->samples)) | A6XX_TEX_CONST_0_SWAP(image->tile_mode ? WZYX : fmt->swap) | tu6_texswiz(&pCreateInfo->components, vk_format_description(iview->vk_format)->swizzle) | A6XX_TEX_CONST_0_MIPLVLS(iview->level_count - 1); diff --git a/src/freedreno/vulkan/tu_meta_resolve.c b/src/freedreno/vulkan/tu_meta_resolve.c index 4a9ebedfdab..74ce766aacf 100644 --- a/src/freedreno/vulkan/tu_meta_resolve.c +++ b/src/freedreno/vulkan/tu_meta_resolve.c @@ -29,6 +29,23 @@ #include "nir/nir_builder.h" #include "vk_format.h" +#include "tu_blit.h" + +static void +tu_resolve_image(struct tu_cmd_buffer *cmdbuf, + struct tu_image *src_image, + struct tu_image *dst_image, + const VkImageResolve *info) +{ + assert(info->dstSubresource.layerCount == info->srcSubresource.layerCount); + + tu_blit(cmdbuf, &(struct tu_blit) { + .dst = tu_blit_surf_ext(dst_image, info->dstSubresource, info->dstOffset, info->extent), + .src = tu_blit_surf_ext(src_image, info->srcSubresource, info->srcOffset, info->extent), + .layers = MAX2(info->extent.depth, info->dstSubresource.layerCount) + }, false); +} + void tu_CmdResolveImage(VkCommandBuffer cmd_buffer_h, VkImage src_image_h, @@ -38,4 +55,13 @@ tu_CmdResolveImage(VkCommandBuffer cmd_buffer_h, uint32_t region_count, const VkImageResolve *regions) { + TU_FROM_HANDLE(tu_cmd_buffer, cmdbuf, cmd_buffer_h); + TU_FROM_HANDLE(tu_image, src_image, src_image_h); + TU_FROM_HANDLE(tu_image, dst_image, dest_image_h); + + tu_bo_list_add(&cmdbuf->bo_list, src_image->bo, MSM_SUBMIT_BO_READ); + tu_bo_list_add(&cmdbuf->bo_list, dst_image->bo, MSM_SUBMIT_BO_WRITE); + + for (uint32_t i = 0; i < region_count; ++i) + tu_resolve_image(cmdbuf, src_image, dst_image, regions + i); }