From: Faith Ekstrand Date: Tue, 31 Jan 2023 02:11:49 +0000 (-0600) Subject: nvk: Move Fill/UpdateBuffer to nvk_cmd_copy X-Git-Tag: upstream/23.3.3~4498 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e706a974ef65e82e380f91714bf1558603b7177;p=platform%2Fupstream%2Fmesa.git nvk: Move Fill/UpdateBuffer to nvk_cmd_copy Even if they technically use blit-like HW commands, they're much more a copy operation than a blit since there's no scaling going on. Part-of: --- diff --git a/src/nouveau/vulkan/nvk_cmd_blit.c b/src/nouveau/vulkan/nvk_cmd_blit.c index e62200c..5da50b6 100644 --- a/src/nouveau/vulkan/nvk_cmd_blit.c +++ b/src/nouveau/vulkan/nvk_cmd_blit.c @@ -185,136 +185,6 @@ nvk_CmdBlitImage2(VkCommandBuffer commandBuffer, } VKAPI_ATTR void VKAPI_CALL -nvk_CmdFillBuffer(VkCommandBuffer commandBuffer, - VkBuffer dstBuffer, - VkDeviceSize dstOffset, - VkDeviceSize fillSize, - uint32_t data) -{ - VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer); - VK_FROM_HANDLE(nvk_buffer, dst, dstBuffer); - struct nouveau_ws_push *push = cmd->push; - fillSize = vk_buffer_range(&dst->vk, dstOffset, fillSize); - - VkDeviceSize dst_addr = nvk_buffer_address(dst, 0); - VkDeviceSize start = dstOffset / 4; - VkDeviceSize end = start + fillSize / 4; - - /* can't go higher for whatever reason */ - uint32_t pitch = 1 << 19; - uint32_t line = pitch / 4; - - nvk_push_buffer_ref(push, dst, NOUVEAU_WS_BO_WR); - - P_IMMD(push, NV902D, SET_OPERATION, V_SRCCOPY); - - P_MTHD(push, NV902D, SET_DST_FORMAT); - P_NV902D_SET_DST_FORMAT(push, V_A8B8G8R8); - P_NV902D_SET_DST_MEMORY_LAYOUT(push, V_PITCH); - - P_MTHD(push, NV902D, SET_DST_PITCH); - P_NV902D_SET_DST_PITCH(push, pitch); - - P_MTHD(push, NV902D, SET_DST_OFFSET_UPPER); - P_NV902D_SET_DST_OFFSET_UPPER(push, dst_addr >> 32); - P_NV902D_SET_DST_OFFSET_LOWER(push, dst_addr & 0xffffffff); - - P_MTHD(push, NV902D, RENDER_SOLID_PRIM_MODE); - P_NV902D_RENDER_SOLID_PRIM_MODE(push, V_LINES); - P_NV902D_SET_RENDER_SOLID_PRIM_COLOR_FORMAT(push, V_A8B8G8R8); - P_NV902D_SET_RENDER_SOLID_PRIM_COLOR(push, data); - - /* - * In order to support CPU efficient fills, we'll draw up to three primitives: - * 1. rest of the first line - * 2. a rect filling up the space between the start and end - * 3. begining of last line - */ - - uint32_t y_0 = start / line; - uint32_t y_1 = end / line; - - uint32_t x_0 = start % line; - uint32_t x_1 = end % line; - - P_MTHD(push, NV902D, RENDER_SOLID_PRIM_POINT_SET_X(0)); - P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 0, x_0); - P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 0, y_0); - P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 1, y_0 == y_1 ? x_1 : line); - P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 1, y_0); - - if (y_0 + 1 < y_1) { - P_IMMD(push, NV902D, RENDER_SOLID_PRIM_MODE, V_RECTS); - - P_MTHD(push, NV902D, RENDER_SOLID_PRIM_POINT_SET_X(0)); - P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 0, 0); - P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 0, y_0 + 1); - P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 1, line); - P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 1, y_1); - - P_IMMD(push, NV902D, RENDER_SOLID_PRIM_MODE, V_LINES); - } - - if (y_0 < y_1) { - P_MTHD(push, NV902D, RENDER_SOLID_PRIM_POINT_SET_X(0)); - P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 0, 0); - P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 0, y_1); - P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 1, x_1); - P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 1, y_1); - } -} - -VKAPI_ATTR void VKAPI_CALL -nvk_CmdUpdateBuffer(VkCommandBuffer commandBuffer, - VkBuffer dstBuffer, - VkDeviceSize dstOffset, - VkDeviceSize dataSize, - const void *pData) -{ - VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer); - VK_FROM_HANDLE(nvk_buffer, dst, dstBuffer); - struct nouveau_ws_push *push = cmd->push; - uint32_t pitch = 65536; - - assert(dataSize <= 65536); - - VkDeviceSize dst_addr = nvk_buffer_address(dst, 0); - - nvk_push_buffer_ref(push, dst, NOUVEAU_WS_BO_WR); - - P_IMMD(push, NV902D, SET_OPERATION, V_SRCCOPY); - - P_MTHD(push, NV902D, SET_DST_OFFSET_UPPER); - P_NV902D_SET_DST_OFFSET_UPPER(push, dst_addr >> 32); - P_NV902D_SET_DST_OFFSET_LOWER(push, dst_addr & 0xffffffff); - - P_MTHD(push, NV902D, SET_DST_FORMAT); - P_NV902D_SET_DST_FORMAT(push, V_A8B8G8R8); - P_NV902D_SET_DST_MEMORY_LAYOUT(push, V_PITCH); - - P_MTHD(push, NV902D, SET_DST_PITCH); - P_NV902D_SET_DST_PITCH(push, pitch); - - P_IMMD(push, NV902D, SET_PIXELS_FROM_CPU_DATA_TYPE, V_COLOR); - P_IMMD(push, NV902D, SET_PIXELS_FROM_CPU_COLOR_FORMAT, V_A8B8G8R8); - - P_MTHD(push, NV902D, SET_PIXELS_FROM_CPU_SRC_WIDTH); - P_NV902D_SET_PIXELS_FROM_CPU_SRC_WIDTH(push, dataSize / 4); - P_NV902D_SET_PIXELS_FROM_CPU_SRC_HEIGHT(push, 1); - P_NV902D_SET_PIXELS_FROM_CPU_DX_DU_FRAC(push, 0); - P_NV902D_SET_PIXELS_FROM_CPU_DX_DU_INT(push, 1); - P_NV902D_SET_PIXELS_FROM_CPU_DY_DV_FRAC(push, 0); - P_NV902D_SET_PIXELS_FROM_CPU_DY_DV_INT(push, 1); - P_NV902D_SET_PIXELS_FROM_CPU_DST_X0_FRAC(push, 0); - P_NV902D_SET_PIXELS_FROM_CPU_DST_X0_INT(push, (dstOffset % pitch) / 4); - P_NV902D_SET_PIXELS_FROM_CPU_DST_Y0_FRAC(push, 0); - P_NV902D_SET_PIXELS_FROM_CPU_DST_Y0_INT(push, (dstOffset / pitch) / 4); - - P_0INC(push, NV902D, PIXELS_FROM_CPU_DATA); - P_INLINE_ARRAY(push, pData, dataSize / 4); -} - -VKAPI_ATTR void VKAPI_CALL nvk_CmdClearColorImage(VkCommandBuffer commandBuffer, VkImage _image, VkImageLayout imageLayout, diff --git a/src/nouveau/vulkan/nvk_cmd_copy.c b/src/nouveau/vulkan/nvk_cmd_copy.c index 37190c7..c98035f 100644 --- a/src/nouveau/vulkan/nvk_cmd_copy.c +++ b/src/nouveau/vulkan/nvk_cmd_copy.c @@ -12,6 +12,7 @@ #include "nouveau_push.h" #include "nvtypes.h" +#include "nvk_cl902d.h" #include "nvk_cl90b5.h" #include "nvk_clc1b5.h" @@ -342,3 +343,133 @@ nvk_CmdCopyImage2(VkCommandBuffer commandBuffer, nouveau_copy_rect(cmd, ©); } } + +VKAPI_ATTR void VKAPI_CALL +nvk_CmdFillBuffer(VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize fillSize, + uint32_t data) +{ + VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer); + VK_FROM_HANDLE(nvk_buffer, dst, dstBuffer); + struct nouveau_ws_push *push = cmd->push; + fillSize = vk_buffer_range(&dst->vk, dstOffset, fillSize); + + VkDeviceSize dst_addr = nvk_buffer_address(dst, 0); + VkDeviceSize start = dstOffset / 4; + VkDeviceSize end = start + fillSize / 4; + + /* can't go higher for whatever reason */ + uint32_t pitch = 1 << 19; + uint32_t line = pitch / 4; + + nvk_push_buffer_ref(push, dst, NOUVEAU_WS_BO_WR); + + P_IMMD(push, NV902D, SET_OPERATION, V_SRCCOPY); + + P_MTHD(push, NV902D, SET_DST_FORMAT); + P_NV902D_SET_DST_FORMAT(push, V_A8B8G8R8); + P_NV902D_SET_DST_MEMORY_LAYOUT(push, V_PITCH); + + P_MTHD(push, NV902D, SET_DST_PITCH); + P_NV902D_SET_DST_PITCH(push, pitch); + + P_MTHD(push, NV902D, SET_DST_OFFSET_UPPER); + P_NV902D_SET_DST_OFFSET_UPPER(push, dst_addr >> 32); + P_NV902D_SET_DST_OFFSET_LOWER(push, dst_addr & 0xffffffff); + + P_MTHD(push, NV902D, RENDER_SOLID_PRIM_MODE); + P_NV902D_RENDER_SOLID_PRIM_MODE(push, V_LINES); + P_NV902D_SET_RENDER_SOLID_PRIM_COLOR_FORMAT(push, V_A8B8G8R8); + P_NV902D_SET_RENDER_SOLID_PRIM_COLOR(push, data); + + /* + * In order to support CPU efficient fills, we'll draw up to three primitives: + * 1. rest of the first line + * 2. a rect filling up the space between the start and end + * 3. begining of last line + */ + + uint32_t y_0 = start / line; + uint32_t y_1 = end / line; + + uint32_t x_0 = start % line; + uint32_t x_1 = end % line; + + P_MTHD(push, NV902D, RENDER_SOLID_PRIM_POINT_SET_X(0)); + P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 0, x_0); + P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 0, y_0); + P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 1, y_0 == y_1 ? x_1 : line); + P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 1, y_0); + + if (y_0 + 1 < y_1) { + P_IMMD(push, NV902D, RENDER_SOLID_PRIM_MODE, V_RECTS); + + P_MTHD(push, NV902D, RENDER_SOLID_PRIM_POINT_SET_X(0)); + P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 0, 0); + P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 0, y_0 + 1); + P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 1, line); + P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 1, y_1); + + P_IMMD(push, NV902D, RENDER_SOLID_PRIM_MODE, V_LINES); + } + + if (y_0 < y_1) { + P_MTHD(push, NV902D, RENDER_SOLID_PRIM_POINT_SET_X(0)); + P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 0, 0); + P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 0, y_1); + P_NV902D_RENDER_SOLID_PRIM_POINT_SET_X(push, 1, x_1); + P_NV902D_RENDER_SOLID_PRIM_POINT_Y(push, 1, y_1); + } +} + +VKAPI_ATTR void VKAPI_CALL +nvk_CmdUpdateBuffer(VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize dataSize, + const void *pData) +{ + VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer); + VK_FROM_HANDLE(nvk_buffer, dst, dstBuffer); + struct nouveau_ws_push *push = cmd->push; + uint32_t pitch = 65536; + + assert(dataSize <= 65536); + + VkDeviceSize dst_addr = nvk_buffer_address(dst, 0); + + nvk_push_buffer_ref(push, dst, NOUVEAU_WS_BO_WR); + + P_IMMD(push, NV902D, SET_OPERATION, V_SRCCOPY); + + P_MTHD(push, NV902D, SET_DST_OFFSET_UPPER); + P_NV902D_SET_DST_OFFSET_UPPER(push, dst_addr >> 32); + P_NV902D_SET_DST_OFFSET_LOWER(push, dst_addr & 0xffffffff); + + P_MTHD(push, NV902D, SET_DST_FORMAT); + P_NV902D_SET_DST_FORMAT(push, V_A8B8G8R8); + P_NV902D_SET_DST_MEMORY_LAYOUT(push, V_PITCH); + + P_MTHD(push, NV902D, SET_DST_PITCH); + P_NV902D_SET_DST_PITCH(push, pitch); + + P_IMMD(push, NV902D, SET_PIXELS_FROM_CPU_DATA_TYPE, V_COLOR); + P_IMMD(push, NV902D, SET_PIXELS_FROM_CPU_COLOR_FORMAT, V_A8B8G8R8); + + P_MTHD(push, NV902D, SET_PIXELS_FROM_CPU_SRC_WIDTH); + P_NV902D_SET_PIXELS_FROM_CPU_SRC_WIDTH(push, dataSize / 4); + P_NV902D_SET_PIXELS_FROM_CPU_SRC_HEIGHT(push, 1); + P_NV902D_SET_PIXELS_FROM_CPU_DX_DU_FRAC(push, 0); + P_NV902D_SET_PIXELS_FROM_CPU_DX_DU_INT(push, 1); + P_NV902D_SET_PIXELS_FROM_CPU_DY_DV_FRAC(push, 0); + P_NV902D_SET_PIXELS_FROM_CPU_DY_DV_INT(push, 1); + P_NV902D_SET_PIXELS_FROM_CPU_DST_X0_FRAC(push, 0); + P_NV902D_SET_PIXELS_FROM_CPU_DST_X0_INT(push, (dstOffset % pitch) / 4); + P_NV902D_SET_PIXELS_FROM_CPU_DST_Y0_FRAC(push, 0); + P_NV902D_SET_PIXELS_FROM_CPU_DST_Y0_INT(push, (dstOffset / pitch) / 4); + + P_0INC(push, NV902D, PIXELS_FROM_CPU_DATA); + P_INLINE_ARRAY(push, pData, dataSize / 4); +}