| 1 |
/* |
| 2 |
* Copyright © 2022 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
* of this software and associated documentation files (the "Software"), to deal |
| 6 |
* in the Software without restriction, including without limitation the rights |
| 7 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 |
* copies of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
* SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include <assert.h> |
| 25 |
#include <stdbool.h> |
| 26 |
#include <stddef.h> |
| 27 |
#include <stdint.h> |
| 28 |
#include <vulkan/vulkan.h> |
| 29 |
|
| 30 |
#include "pvr_blit.h" |
| 31 |
#include "pvr_buffer.h" |
| 32 |
#include "pvr_clear.h" |
| 33 |
#include "pvr_cmd_buffer.h" |
| 34 |
#include "pvr_csb.h" |
| 35 |
#include "pvr_device.h" |
| 36 |
#include "pvr_entrypoints.h" |
| 37 |
#include "pvr_formats.h" |
| 38 |
#include "pvr_hw_pass.h" |
| 39 |
#include "pvr_image.h" |
| 40 |
#include "pvr_job_transfer.h" |
| 41 |
#include "pvr_pass.h" |
| 42 |
#include "pvr_physical_device.h" |
| 43 |
#include "pvr_types.h" |
| 44 |
#include "pvr_usc.h" |
| 45 |
#include "util/bitscan.h" |
| 46 |
#include "util/list.h" |
| 47 |
#include "util/macros.h" |
| 48 |
#include "util/u_dynarray.h" |
| 49 |
#include "util/u_math.h" |
| 50 |
#include "vk_alloc.h" |
| 51 |
#include "vk_command_buffer.h" |
| 52 |
#include "vk_command_pool.h" |
| 53 |
#include "vk_format.h" |
| 54 |
#include "vk_log.h" |
| 55 |
|
| 56 |
/* TODO: Investigate where this limit comes from. */ |
| 57 |
#define PVR_MAX_TRANSFER_SIZE_IN_TEXELS 2048U |
| 58 |
#define PVR_RESOLVE_DEFAULT PVR_RESOLVE_BLEND |
| 59 |
|
| 60 |
static inline void |
| 61 |
pvr_transfer_cmd_init_default(struct pvr_cmd_buffer *cmd_buffer, |
| 62 |
struct pvr_transfer_cmd *transfer_cmd) |
| 63 |
{ |
| 64 |
transfer_cmd->sources[0].filter = PVR_FILTER_POINT; |
| 65 |
transfer_cmd->sources[0].resolve_op = PVR_RESOLVE_DEFAULT; |
| 66 |
transfer_cmd->sources[0].addr_mode = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE; |
| 67 |
transfer_cmd->cmd_buffer = cmd_buffer; |
| 68 |
} |
| 69 |
|
| 70 |
static struct pvr_transfer_cmd * |
| 71 |
pvr_transfer_cmd_alloc(struct pvr_cmd_buffer *cmd_buffer) |
| 72 |
{ |
| 73 |
struct pvr_transfer_cmd *transfer_cmd; |
| 74 |
|
| 75 |
transfer_cmd = vk_zalloc(&cmd_buffer->vk.pool->alloc, |
| 76 |
sizeof(*transfer_cmd), |
| 77 |
8U, |
| 78 |
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
| 79 |
if (!transfer_cmd) { |
| 80 |
vk_command_buffer_set_error(&cmd_buffer->vk, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 81 |
return NULL; |
| 82 |
} |
| 83 |
|
| 84 |
/* transfer_cmd->mapping_count is already set to zero. */ |
| 85 |
pvr_transfer_cmd_init_default(cmd_buffer, transfer_cmd); |
| 86 |
|
| 87 |
return transfer_cmd; |
| 88 |
} |
| 89 |
|
| 90 |
static void pvr_setup_buffer_surface(struct pvr_transfer_cmd_surface *surface, |
| 91 |
VkRect2D *rect, |
| 92 |
pvr_dev_addr_t dev_addr, |
| 93 |
VkDeviceSize offset, |
| 94 |
VkFormat vk_format, |
| 95 |
VkFormat image_format, |
| 96 |
uint32_t width, |
| 97 |
uint32_t height, |
| 98 |
uint32_t stride) |
| 99 |
{ |
| 100 |
enum pipe_format pformat = vk_format_to_pipe_format(image_format); |
| 101 |
|
| 102 |
surface->dev_addr = PVR_DEV_ADDR_OFFSET(dev_addr, offset); |
| 103 |
surface->width = width; |
| 104 |
surface->height = height; |
| 105 |
surface->stride = stride; |
| 106 |
surface->vk_format = vk_format; |
| 107 |
surface->mem_layout = PVR_MEMLAYOUT_LINEAR; |
| 108 |
surface->sample_count = 1; |
| 109 |
|
| 110 |
/* Initialize rectangle extent. Also, rectangle.offset should be set to |
| 111 |
* zero, as the offset is already adjusted in the device address above. We |
| 112 |
* don't explicitly set offset to zero as transfer_cmd is zero allocated. |
| 113 |
*/ |
| 114 |
rect->extent.width = width; |
| 115 |
rect->extent.height = height; |
| 116 |
|
| 117 |
if (util_format_is_compressed(pformat)) { |
| 118 |
uint32_t block_width = util_format_get_blockwidth(pformat); |
| 119 |
uint32_t block_height = util_format_get_blockheight(pformat); |
| 120 |
|
| 121 |
surface->width = MAX2(1U, DIV_ROUND_UP(surface->width, block_width)); |
| 122 |
surface->height = MAX2(1U, DIV_ROUND_UP(surface->height, block_height)); |
| 123 |
surface->stride = MAX2(1U, DIV_ROUND_UP(surface->stride, block_width)); |
| 124 |
|
| 125 |
rect->offset.x /= block_width; |
| 126 |
rect->offset.y /= block_height; |
| 127 |
rect->extent.width = |
| 128 |
MAX2(1U, DIV_ROUND_UP(rect->extent.width, block_width)); |
| 129 |
rect->extent.height = |
| 130 |
MAX2(1U, DIV_ROUND_UP(rect->extent.height, block_height)); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
VkFormat pvr_get_raw_copy_format(VkFormat format) |
| 135 |
{ |
| 136 |
switch (vk_format_get_blocksize(format)) { |
| 137 |
case 1: |
| 138 |
return VK_FORMAT_R8_UINT; |
| 139 |
case 2: |
| 140 |
return VK_FORMAT_R8G8_UINT; |
| 141 |
case 3: |
| 142 |
return VK_FORMAT_R8G8B8_UINT; |
| 143 |
case 4: |
| 144 |
return VK_FORMAT_R32_UINT; |
| 145 |
case 6: |
| 146 |
return VK_FORMAT_R16G16B16_UINT; |
| 147 |
case 8: |
| 148 |
return VK_FORMAT_R32G32_UINT; |
| 149 |
case 12: |
| 150 |
return VK_FORMAT_R32G32B32_UINT; |
| 151 |
case 16: |
| 152 |
return VK_FORMAT_R32G32B32A32_UINT; |
| 153 |
default: |
| 154 |
UNREACHABLE("Unhandled copy block size."); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
static void pvr_setup_transfer_surface(struct pvr_device *device, |
| 159 |
struct pvr_transfer_cmd_surface *surface, |
| 160 |
VkRect2D *rect, |
| 161 |
const struct pvr_image *image, |
| 162 |
uint32_t array_layer, |
| 163 |
uint32_t mip_level, |
| 164 |
const VkOffset3D *offset, |
| 165 |
const VkExtent3D *extent, |
| 166 |
float fdepth, |
| 167 |
VkFormat format, |
| 168 |
VkImageAspectFlags aspect_mask) |
| 169 |
{ |
| 170 |
uint8_t plane; |
| 171 |
switch (aspect_mask) { |
| 172 |
case VK_IMAGE_ASPECT_PLANE_1_BIT: |
| 173 |
plane = 1; |
| 174 |
break; |
| 175 |
case VK_IMAGE_ASPECT_PLANE_2_BIT: |
| 176 |
plane = 2; |
| 177 |
break; |
| 178 |
default: |
| 179 |
plane = 0; |
| 180 |
break; |
| 181 |
}; |
| 182 |
|
| 183 |
const uint32_t height = |
| 184 |
MAX2(vk_format_get_plane_height(image->vk.format, |
| 185 |
plane, |
| 186 |
image->vk.extent.height) >> |
| 187 |
mip_level, |
| 188 |
1U); |
| 189 |
const uint32_t width = |
| 190 |
MAX2(vk_format_get_plane_width(image->vk.format, |
| 191 |
plane, |
| 192 |
image->vk.extent.width) >> |
| 193 |
mip_level, |
| 194 |
1U); |
| 195 |
enum pipe_format image_pformat = vk_format_to_pipe_format( |
| 196 |
vk_format_get_plane_aspect_format(image->vk.format, aspect_mask)); |
| 197 |
enum pipe_format pformat = vk_format_to_pipe_format(format); |
| 198 |
const VkImageSubresource sub_resource = { |
| 199 |
.aspectMask = aspect_mask, |
| 200 |
.mipLevel = mip_level, |
| 201 |
.arrayLayer = array_layer, |
| 202 |
}; |
| 203 |
VkSubresourceLayout info; |
| 204 |
uint32_t depth; |
| 205 |
|
| 206 |
if (image->memlayout == PVR_MEMLAYOUT_3DTWIDDLED) |
| 207 |
depth = MAX2(image->vk.extent.depth >> mip_level, 1U); |
| 208 |
else |
| 209 |
depth = 1U; |
| 210 |
|
| 211 |
pvr_get_image_subresource_layout(image, &sub_resource, &info); |
| 212 |
|
| 213 |
surface->dev_addr = PVR_DEV_ADDR_OFFSET(image->dev_addr, info.offset); |
| 214 |
surface->width = width; |
| 215 |
surface->height = height; |
| 216 |
surface->depth = depth; |
| 217 |
|
| 218 |
assert(info.rowPitch % vk_format_get_blocksize(format) == 0); |
| 219 |
surface->stride = info.rowPitch / vk_format_get_blocksize(format); |
| 220 |
|
| 221 |
surface->vk_format = format; |
| 222 |
surface->mem_layout = image->memlayout; |
| 223 |
surface->sample_count = image->vk.samples; |
| 224 |
|
| 225 |
if (image->memlayout == PVR_MEMLAYOUT_3DTWIDDLED) |
| 226 |
surface->z_position = fdepth; |
| 227 |
else |
| 228 |
surface->dev_addr.addr += info.depthPitch * ((uint32_t)fdepth); |
| 229 |
|
| 230 |
rect->offset.x = offset->x; |
| 231 |
rect->offset.y = offset->y; |
| 232 |
rect->extent.width = extent->width; |
| 233 |
rect->extent.height = extent->height; |
| 234 |
|
| 235 |
if (util_format_is_compressed(image_pformat) && |
| 236 |
!util_format_is_compressed(pformat)) { |
| 237 |
uint32_t block_width = util_format_get_blockwidth(image_pformat); |
| 238 |
uint32_t block_height = util_format_get_blockheight(image_pformat); |
| 239 |
|
| 240 |
surface->width = MAX2(1U, DIV_ROUND_UP(surface->width, block_width)); |
| 241 |
surface->height = MAX2(1U, DIV_ROUND_UP(surface->height, block_height)); |
| 242 |
surface->stride = MAX2(1U, DIV_ROUND_UP(surface->stride, block_width)); |
| 243 |
|
| 244 |
rect->offset.x /= block_width; |
| 245 |
rect->offset.y /= block_height; |
| 246 |
rect->extent.width = |
| 247 |
MAX2(1U, DIV_ROUND_UP(rect->extent.width, block_width)); |
| 248 |
rect->extent.height = |
| 249 |
MAX2(1U, DIV_ROUND_UP(rect->extent.height, block_height)); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
void pvr_rogue_CmdBlitImage2(VkCommandBuffer commandBuffer, |
| 254 |
const VkBlitImageInfo2 *pBlitImageInfo) |
| 255 |
{ |
| 256 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 257 |
VK_FROM_HANDLE(pvr_image, src, pBlitImageInfo->srcImage); |
| 258 |
VK_FROM_HANDLE(pvr_image, dst, pBlitImageInfo->dstImage); |
| 259 |
struct pvr_device *device = cmd_buffer->device; |
| 260 |
enum pvr_filter filter = PVR_FILTER_DONTCARE; |
| 261 |
|
| 262 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 263 |
|
| 264 |
if (pBlitImageInfo->filter == VK_FILTER_LINEAR) |
| 265 |
filter = PVR_FILTER_LINEAR; |
| 266 |
|
| 267 |
for (uint32_t i = 0U; i < pBlitImageInfo->regionCount; i++) { |
| 268 |
const VkImageBlit2 *region = &pBlitImageInfo->pRegions[i]; |
| 269 |
|
| 270 |
assert(region->srcSubresource.layerCount == |
| 271 |
region->dstSubresource.layerCount); |
| 272 |
const bool inverted_dst_z = |
| 273 |
(region->dstOffsets[1].z < region->dstOffsets[0].z); |
| 274 |
const bool inverted_src_z = |
| 275 |
(region->srcOffsets[1].z < region->srcOffsets[0].z); |
| 276 |
const uint32_t min_src_z = inverted_src_z ? region->srcOffsets[1].z |
| 277 |
: region->srcOffsets[0].z; |
| 278 |
const uint32_t max_src_z = inverted_src_z ? region->srcOffsets[0].z |
| 279 |
: region->srcOffsets[1].z; |
| 280 |
const uint32_t min_dst_z = inverted_dst_z ? region->dstOffsets[1].z |
| 281 |
: region->dstOffsets[0].z; |
| 282 |
const uint32_t max_dst_z = inverted_dst_z ? region->dstOffsets[0].z |
| 283 |
: region->dstOffsets[1].z; |
| 284 |
|
| 285 |
const uint32_t src_width = |
| 286 |
region->srcOffsets[1].x - region->srcOffsets[0].x; |
| 287 |
const uint32_t src_height = |
| 288 |
region->srcOffsets[1].y - region->srcOffsets[0].y; |
| 289 |
uint32_t dst_width; |
| 290 |
uint32_t dst_height; |
| 291 |
|
| 292 |
float initial_depth_offset; |
| 293 |
VkExtent3D src_extent; |
| 294 |
VkExtent3D dst_extent; |
| 295 |
VkOffset3D dst_offset = region->dstOffsets[0]; |
| 296 |
float z_slice_stride; |
| 297 |
bool flip_x; |
| 298 |
bool flip_y; |
| 299 |
|
| 300 |
if (region->dstOffsets[1].x > region->dstOffsets[0].x) { |
| 301 |
dst_width = region->dstOffsets[1].x - region->dstOffsets[0].x; |
| 302 |
flip_x = false; |
| 303 |
} else { |
| 304 |
dst_width = region->dstOffsets[0].x - region->dstOffsets[1].x; |
| 305 |
flip_x = true; |
| 306 |
dst_offset.x = region->dstOffsets[1].x; |
| 307 |
} |
| 308 |
|
| 309 |
if (region->dstOffsets[1].y > region->dstOffsets[0].y) { |
| 310 |
dst_height = region->dstOffsets[1].y - region->dstOffsets[0].y; |
| 311 |
flip_y = false; |
| 312 |
} else { |
| 313 |
dst_height = region->dstOffsets[0].y - region->dstOffsets[1].y; |
| 314 |
flip_y = true; |
| 315 |
dst_offset.y = region->dstOffsets[1].y; |
| 316 |
} |
| 317 |
|
| 318 |
/* If any of the extent regions is zero, then reject the blit and |
| 319 |
* continue. |
| 320 |
*/ |
| 321 |
if (!src_width || !src_height || !dst_width || !dst_height || |
| 322 |
!(max_dst_z - min_dst_z) || !(max_src_z - min_src_z)) { |
| 323 |
mesa_loge("BlitImage: Region %i has an area of zero", i); |
| 324 |
continue; |
| 325 |
} |
| 326 |
|
| 327 |
src_extent = (VkExtent3D){ |
| 328 |
.width = src_width, |
| 329 |
.height = src_height, |
| 330 |
.depth = 0U, |
| 331 |
}; |
| 332 |
|
| 333 |
dst_extent = (VkExtent3D){ |
| 334 |
.width = dst_width, |
| 335 |
.height = dst_height, |
| 336 |
.depth = 0U, |
| 337 |
}; |
| 338 |
|
| 339 |
/* The z_position of a transfer surface is intended to be in the range |
| 340 |
* of 0.0f <= z_position <= depth. It will be used as a texture coordinate |
| 341 |
* in the source surface for cases where linear filtering is enabled, so |
| 342 |
* the fractional part will need to represent the exact midpoint of a z |
| 343 |
* slice range in the source texture, as it maps to each destination |
| 344 |
* slice. |
| 345 |
* |
| 346 |
* For destination surfaces, the fractional part is discarded, so |
| 347 |
* we can safely pass the slice index. |
| 348 |
*/ |
| 349 |
|
| 350 |
/* Calculate the ratio of z slices in our source region to that of our |
| 351 |
* destination region, to get the number of z slices in our source region |
| 352 |
* to iterate over for each destination slice. |
| 353 |
* |
| 354 |
* If our destination region is inverted, we iterate backwards. |
| 355 |
*/ |
| 356 |
z_slice_stride = |
| 357 |
(inverted_dst_z ? -1.0f : 1.0f) * |
| 358 |
((float)(max_src_z - min_src_z) / (float)(max_dst_z - min_dst_z)); |
| 359 |
|
| 360 |
/* Offset the initial depth offset by half of the z slice stride, into the |
| 361 |
* blit region's z range. |
| 362 |
*/ |
| 363 |
initial_depth_offset = |
| 364 |
(inverted_dst_z ? max_src_z : min_src_z) + (0.5f * z_slice_stride); |
| 365 |
|
| 366 |
for (uint32_t j = 0U; j < region->srcSubresource.layerCount; j++) { |
| 367 |
struct pvr_transfer_cmd_surface src_surface = { 0 }; |
| 368 |
struct pvr_transfer_cmd_surface dst_surface = { 0 }; |
| 369 |
VkRect2D src_rect; |
| 370 |
VkRect2D dst_rect; |
| 371 |
|
| 372 |
/* Get the subresource info for the src and dst images, this is |
| 373 |
* required when incrementing the address of the depth slice used by |
| 374 |
* the transfer surface. |
| 375 |
*/ |
| 376 |
VkSubresourceLayout src_info, dst_info; |
| 377 |
const VkImageSubresource src_sub_resource = { |
| 378 |
.aspectMask = region->srcSubresource.aspectMask, |
| 379 |
.mipLevel = region->srcSubresource.mipLevel, |
| 380 |
.arrayLayer = region->srcSubresource.baseArrayLayer + j, |
| 381 |
}; |
| 382 |
const VkImageSubresource dst_sub_resource = { |
| 383 |
.aspectMask = region->dstSubresource.aspectMask, |
| 384 |
.mipLevel = region->dstSubresource.mipLevel, |
| 385 |
.arrayLayer = region->dstSubresource.baseArrayLayer + j, |
| 386 |
}; |
| 387 |
|
| 388 |
pvr_get_image_subresource_layout(src, &src_sub_resource, &src_info); |
| 389 |
pvr_get_image_subresource_layout(dst, &dst_sub_resource, &dst_info); |
| 390 |
|
| 391 |
/* Setup the transfer surfaces once per image layer, which saves us |
| 392 |
* from repeating subresource queries by manually incrementing the |
| 393 |
* depth slices. |
| 394 |
*/ |
| 395 |
pvr_setup_transfer_surface(device, |
| 396 |
&src_surface, |
| 397 |
&src_rect, |
| 398 |
src, |
| 399 |
region->srcSubresource.baseArrayLayer + j, |
| 400 |
region->srcSubresource.mipLevel, |
| 401 |
®ion->srcOffsets[0], |
| 402 |
&src_extent, |
| 403 |
initial_depth_offset, |
| 404 |
vk_format_get_plane_aspect_format( |
| 405 |
src->vk.format, |
| 406 |
region->srcSubresource.aspectMask), |
| 407 |
region->srcSubresource.aspectMask); |
| 408 |
|
| 409 |
pvr_setup_transfer_surface(device, |
| 410 |
&dst_surface, |
| 411 |
&dst_rect, |
| 412 |
dst, |
| 413 |
region->dstSubresource.baseArrayLayer + j, |
| 414 |
region->dstSubresource.mipLevel, |
| 415 |
&dst_offset, |
| 416 |
&dst_extent, |
| 417 |
min_dst_z, |
| 418 |
vk_format_get_plane_aspect_format( |
| 419 |
dst->vk.format, |
| 420 |
region->dstSubresource.aspectMask), |
| 421 |
region->dstSubresource.aspectMask); |
| 422 |
|
| 423 |
for (uint32_t dst_z = min_dst_z; dst_z < max_dst_z; dst_z++) { |
| 424 |
struct pvr_transfer_cmd *transfer_cmd; |
| 425 |
VkResult result; |
| 426 |
|
| 427 |
/* TODO: See if we can allocate all the transfer cmds in one go. */ |
| 428 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 429 |
if (!transfer_cmd) |
| 430 |
return; |
| 431 |
|
| 432 |
transfer_cmd->sources[0].mappings[0].src_rect = src_rect; |
| 433 |
transfer_cmd->sources[0].mappings[0].dst_rect = dst_rect; |
| 434 |
transfer_cmd->sources[0].mappings[0].flip_x = flip_x; |
| 435 |
transfer_cmd->sources[0].mappings[0].flip_y = flip_y; |
| 436 |
transfer_cmd->sources[0].mapping_count++; |
| 437 |
|
| 438 |
transfer_cmd->sources[0].surface = src_surface; |
| 439 |
transfer_cmd->sources[0].filter = filter; |
| 440 |
transfer_cmd->source_count = 1; |
| 441 |
|
| 442 |
transfer_cmd->dst = dst_surface; |
| 443 |
transfer_cmd->scissor = dst_rect; |
| 444 |
|
| 445 |
result = |
| 446 |
pvr_arch_cmd_buffer_add_transfer_cmd(cmd_buffer, transfer_cmd); |
| 447 |
if (result != VK_SUCCESS) { |
| 448 |
vk_free(&cmd_buffer->vk.pool->alloc, transfer_cmd); |
| 449 |
return; |
| 450 |
} |
| 451 |
|
| 452 |
if (src_surface.mem_layout == PVR_MEMLAYOUT_3DTWIDDLED) { |
| 453 |
src_surface.z_position += z_slice_stride; |
| 454 |
} else { |
| 455 |
src_surface.dev_addr.addr += |
| 456 |
src_info.depthPitch * ((uint32_t)z_slice_stride); |
| 457 |
} |
| 458 |
|
| 459 |
if (dst_surface.mem_layout == PVR_MEMLAYOUT_3DTWIDDLED) |
| 460 |
dst_surface.z_position += 1.0f; |
| 461 |
else |
| 462 |
dst_surface.dev_addr.addr += dst_info.depthPitch; |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
static VkFormat pvr_get_copy_format(VkFormat format, |
| 469 |
VkImageAspectFlagBits aspect) |
| 470 |
{ |
| 471 |
format = vk_format_get_plane_aspect_format(format, aspect); |
| 472 |
|
| 473 |
switch (format) { |
| 474 |
case VK_FORMAT_R8_SNORM: |
| 475 |
return VK_FORMAT_R8_SINT; |
| 476 |
case VK_FORMAT_R8G8_SNORM: |
| 477 |
case VK_FORMAT_R8G8_SSCALED: |
| 478 |
return VK_FORMAT_R8G8_SINT; |
| 479 |
case VK_FORMAT_R8G8B8_SNORM: |
| 480 |
return VK_FORMAT_R8G8B8_SINT; |
| 481 |
case VK_FORMAT_R8G8B8A8_SNORM: |
| 482 |
return VK_FORMAT_R8G8B8A8_SINT; |
| 483 |
case VK_FORMAT_B8G8R8A8_SNORM: |
| 484 |
return VK_FORMAT_B8G8R8A8_SINT; |
| 485 |
default: |
| 486 |
return format; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
static void |
| 491 |
pvr_setup_surface_for_image(struct pvr_device *device, |
| 492 |
struct pvr_transfer_cmd_surface *surface, |
| 493 |
VkRect2D *rect, |
| 494 |
const struct pvr_image *image, |
| 495 |
uint32_t array_layer, |
| 496 |
uint32_t array_offset, |
| 497 |
uint32_t mip_level, |
| 498 |
const VkOffset3D *offset, |
| 499 |
const VkExtent3D *extent, |
| 500 |
uint32_t depth, |
| 501 |
VkFormat format, |
| 502 |
const VkImageAspectFlags aspect_mask) |
| 503 |
{ |
| 504 |
if (image->vk.image_type != VK_IMAGE_TYPE_3D) { |
| 505 |
pvr_setup_transfer_surface(device, |
| 506 |
surface, |
| 507 |
rect, |
| 508 |
image, |
| 509 |
array_layer + array_offset, |
| 510 |
mip_level, |
| 511 |
offset, |
| 512 |
extent, |
| 513 |
0.0f, |
| 514 |
format, |
| 515 |
aspect_mask); |
| 516 |
} else { |
| 517 |
pvr_setup_transfer_surface(device, |
| 518 |
surface, |
| 519 |
rect, |
| 520 |
image, |
| 521 |
array_layer, |
| 522 |
mip_level, |
| 523 |
offset, |
| 524 |
extent, |
| 525 |
(float)depth, |
| 526 |
format, |
| 527 |
aspect_mask); |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
static VkFormat pvr_get_copy_or_resolve_format(VkFormat format, |
| 532 |
VkImageAspectFlags aspects, |
| 533 |
bool do_resolve) |
| 534 |
{ |
| 535 |
/* Resolve does filtering, never convert to SINT. */ |
| 536 |
if (do_resolve) |
| 537 |
return vk_format_get_plane_aspect_format(format, aspects); |
| 538 |
|
| 539 |
return pvr_get_copy_format(format, aspects); |
| 540 |
} |
| 541 |
|
| 542 |
static VkResult |
| 543 |
pvr_copy_or_resolve_image_region(struct pvr_cmd_buffer *cmd_buffer, |
| 544 |
enum pvr_resolve_op resolve_op, |
| 545 |
const struct pvr_image *src, |
| 546 |
const struct pvr_image *dst, |
| 547 |
const VkImageCopy2 *region, |
| 548 |
struct pvr_transfer_cmd *ds_transfer_cmd) |
| 549 |
{ |
| 550 |
enum pipe_format src_pformat = vk_format_to_pipe_format( |
| 551 |
vk_format_get_plane_aspect_format(src->vk.format, |
| 552 |
region->srcSubresource.aspectMask)); |
| 553 |
enum pipe_format dst_pformat = vk_format_to_pipe_format( |
| 554 |
vk_format_get_plane_aspect_format(dst->vk.format, |
| 555 |
region->dstSubresource.aspectMask)); |
| 556 |
const bool do_resolve = src->vk.samples > 1U && dst->vk.samples < 2U; |
| 557 |
bool src_block_compressed = util_format_is_compressed(src_pformat); |
| 558 |
bool dst_block_compressed = util_format_is_compressed(dst_pformat); |
| 559 |
VkExtent3D src_extent; |
| 560 |
VkExtent3D dst_extent; |
| 561 |
VkFormat dst_format; |
| 562 |
VkFormat src_format; |
| 563 |
uint32_t dst_layers; |
| 564 |
uint32_t src_layers; |
| 565 |
uint32_t max_slices; |
| 566 |
uint32_t flags = 0U; |
| 567 |
|
| 568 |
src_extent = region->extent; |
| 569 |
dst_extent = region->extent; |
| 570 |
|
| 571 |
if (src_block_compressed && !dst_block_compressed) { |
| 572 |
uint32_t block_width = util_format_get_blockwidth(src_pformat); |
| 573 |
uint32_t block_height = util_format_get_blockheight(src_pformat); |
| 574 |
|
| 575 |
dst_extent.width = MAX2(1U, DIV_ROUND_UP(src_extent.width, block_width)); |
| 576 |
dst_extent.height = |
| 577 |
MAX2(1U, DIV_ROUND_UP(src_extent.height, block_height)); |
| 578 |
} else if (!src_block_compressed && dst_block_compressed) { |
| 579 |
uint32_t block_width = util_format_get_blockwidth(dst_pformat); |
| 580 |
uint32_t block_height = util_format_get_blockheight(dst_pformat); |
| 581 |
|
| 582 |
dst_extent.width = MAX2(1U, src_extent.width * block_width); |
| 583 |
dst_extent.height = MAX2(1U, src_extent.height * block_height); |
| 584 |
} |
| 585 |
|
| 586 |
src_format = pvr_get_copy_or_resolve_format(src->vk.format, |
| 587 |
region->srcSubresource.aspectMask, |
| 588 |
do_resolve); |
| 589 |
if (pvr_vk_format_is_combined_ds(src->vk.format)) { |
| 590 |
dst_format = dst->vk.format; |
| 591 |
} else if (src_block_compressed && !dst_block_compressed) { |
| 592 |
src_format = dst_format = |
| 593 |
pvr_get_copy_or_resolve_format(dst->vk.format, |
| 594 |
region->srcSubresource.aspectMask, |
| 595 |
do_resolve); |
| 596 |
} else if (dst->vk.image_type == VK_IMAGE_TYPE_3D && |
| 597 |
dst_block_compressed) { |
| 598 |
src_format = dst_format = |
| 599 |
pvr_get_copy_or_resolve_format(dst->vk.format, |
| 600 |
region->dstSubresource.aspectMask, |
| 601 |
do_resolve); |
| 602 |
} else if (src_block_compressed && dst_block_compressed) { |
| 603 |
/* For compressed copies, only retain the size from the original |
| 604 |
* source image format. |
| 605 |
*/ |
| 606 |
src_format = dst_format = pvr_get_raw_copy_format(src->vk.format); |
| 607 |
} else { |
| 608 |
/* We don't care what format dst is as it's guaranteed to be size |
| 609 |
* compatible with src. |
| 610 |
*/ |
| 611 |
dst_format = src_format; |
| 612 |
} |
| 613 |
|
| 614 |
if (pvr_vk_format_is_combined_ds(src_format) && |
| 615 |
pvr_vk_format_is_combined_ds(dst_format) && |
| 616 |
region->srcSubresource.aspectMask != |
| 617 |
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 618 |
/* Takes the stencil of the source and the depth of the destination and |
| 619 |
* combines the two interleaved. |
| 620 |
*/ |
| 621 |
flags |= PVR_TRANSFER_CMD_FLAGS_DSMERGE; |
| 622 |
|
| 623 |
if (region->srcSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 624 |
/* Takes the depth of the source and the stencil of the destination and |
| 625 |
* combines the two interleaved. |
| 626 |
*/ |
| 627 |
flags |= PVR_TRANSFER_CMD_FLAGS_PICKD; |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
if (do_resolve) { |
| 632 |
/* Blend is not defined for integer formats */ |
| 633 |
if (resolve_op == PVR_RESOLVE_BLEND && vk_format_is_int(src_format)) { |
| 634 |
/* Override for either color or DS */ |
| 635 |
resolve_op = PVR_RESOLVE_SAMPLE0; |
| 636 |
} |
| 637 |
} else { |
| 638 |
assert(!ds_transfer_cmd || |
| 639 |
ds_transfer_cmd->sources[0].resolve_op == PVR_RESOLVE_DEFAULT); |
| 640 |
/* Override for either color or DS */ |
| 641 |
resolve_op = PVR_RESOLVE_DEFAULT; |
| 642 |
} |
| 643 |
|
| 644 |
src_layers = |
| 645 |
vk_image_subresource_layer_count(&src->vk, ®ion->srcSubresource); |
| 646 |
dst_layers = |
| 647 |
vk_image_subresource_layer_count(&dst->vk, ®ion->dstSubresource); |
| 648 |
|
| 649 |
/* srcSubresource.layerCount must match layerCount of dstSubresource in |
| 650 |
* copies not involving 3D images. In copies involving 3D images, if there is |
| 651 |
* a 2D image it's layerCount. |
| 652 |
*/ |
| 653 |
max_slices = MAX3(src_layers, dst_layers, region->extent.depth); |
| 654 |
|
| 655 |
for (uint32_t i = 0U; i < max_slices; i++) { |
| 656 |
struct pvr_transfer_cmd *transfer_cmd; |
| 657 |
VkResult result; |
| 658 |
|
| 659 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 660 |
if (!transfer_cmd) |
| 661 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 662 |
|
| 663 |
if (ds_transfer_cmd) |
| 664 |
memcpy(transfer_cmd, ds_transfer_cmd, sizeof(*transfer_cmd)); |
| 665 |
|
| 666 |
transfer_cmd->sources[0].resolve_op = resolve_op; |
| 667 |
transfer_cmd->flags |= flags; |
| 668 |
|
| 669 |
pvr_setup_surface_for_image( |
| 670 |
cmd_buffer->device, |
| 671 |
&transfer_cmd->sources[0].surface, |
| 672 |
&transfer_cmd->sources[0].mappings[0U].src_rect, |
| 673 |
src, |
| 674 |
region->srcSubresource.baseArrayLayer, |
| 675 |
i, |
| 676 |
region->srcSubresource.mipLevel, |
| 677 |
®ion->srcOffset, |
| 678 |
&src_extent, |
| 679 |
region->srcOffset.z + i, |
| 680 |
src_format, |
| 681 |
region->srcSubresource.aspectMask); |
| 682 |
|
| 683 |
pvr_setup_surface_for_image(cmd_buffer->device, |
| 684 |
&transfer_cmd->dst, |
| 685 |
&transfer_cmd->scissor, |
| 686 |
dst, |
| 687 |
region->dstSubresource.baseArrayLayer, |
| 688 |
i, |
| 689 |
region->dstSubresource.mipLevel, |
| 690 |
®ion->dstOffset, |
| 691 |
&dst_extent, |
| 692 |
region->dstOffset.z + i, |
| 693 |
dst_format, |
| 694 |
region->dstSubresource.aspectMask); |
| 695 |
|
| 696 |
transfer_cmd->sources[0].mappings[0U].dst_rect = transfer_cmd->scissor; |
| 697 |
transfer_cmd->sources[0].mapping_count++; |
| 698 |
transfer_cmd->source_count = 1; |
| 699 |
|
| 700 |
result = pvr_arch_cmd_buffer_add_transfer_cmd(cmd_buffer, transfer_cmd); |
| 701 |
if (result != VK_SUCCESS) { |
| 702 |
vk_free(&cmd_buffer->vk.pool->alloc, transfer_cmd); |
| 703 |
return result; |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
return VK_SUCCESS; |
| 708 |
} |
| 709 |
|
| 710 |
VkResult |
| 711 |
pvr_copy_or_resolve_color_image_region(struct pvr_cmd_buffer *cmd_buffer, |
| 712 |
const struct pvr_image *src, |
| 713 |
const struct pvr_image *dst, |
| 714 |
const VkImageCopy2 *region) |
| 715 |
{ |
| 716 |
return pvr_copy_or_resolve_image_region(cmd_buffer, |
| 717 |
PVR_RESOLVE_DEFAULT, |
| 718 |
src, |
| 719 |
dst, |
| 720 |
region, |
| 721 |
NULL); |
| 722 |
} |
| 723 |
|
| 724 |
VkResult pvr_copy_or_resolve_depth_stencil_region( |
| 725 |
struct pvr_cmd_buffer *cmd_buffer, |
| 726 |
const struct pvr_image *src_image, |
| 727 |
const struct pvr_image *dst_image, |
| 728 |
int resolve_op, |
| 729 |
bool clear_complement, |
| 730 |
const VkClearDepthStencilValue *ds_clear_values, |
| 731 |
const VkImageCopy2 *region) |
| 732 |
{ |
| 733 |
struct pvr_transfer_cmd transfer_cmd = { 0 }; |
| 734 |
|
| 735 |
pvr_transfer_cmd_init_default(cmd_buffer, &transfer_cmd); |
| 736 |
|
| 737 |
if (clear_complement) { |
| 738 |
transfer_cmd.clear_color[1].ui = ds_clear_values->stencil; |
| 739 |
transfer_cmd.clear_color[0].f = ds_clear_values->depth; |
| 740 |
transfer_cmd.flags |= PVR_TRANSFER_CMD_FLAGS_FILL; |
| 741 |
} |
| 742 |
|
| 743 |
return pvr_copy_or_resolve_image_region(cmd_buffer, |
| 744 |
resolve_op, |
| 745 |
src_image, |
| 746 |
dst_image, |
| 747 |
region, |
| 748 |
&transfer_cmd); |
| 749 |
} |
| 750 |
|
| 751 |
static bool pvr_can_merge_ds_regions(const VkImageCopy2 *pRegionA, |
| 752 |
const VkImageCopy2 *pRegionB) |
| 753 |
{ |
| 754 |
assert(pRegionA->srcSubresource.aspectMask != 0U); |
| 755 |
assert(pRegionB->srcSubresource.aspectMask != 0U); |
| 756 |
|
| 757 |
if (!((pRegionA->srcSubresource.aspectMask ^ |
| 758 |
pRegionB->srcSubresource.aspectMask) & |
| 759 |
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 760 |
return false; |
| 761 |
} |
| 762 |
|
| 763 |
/* Assert if aspectMask mismatch between src and dst, given it's a depth and |
| 764 |
* stencil image so not multi-planar and from the Vulkan 1.0.223 spec: |
| 765 |
* |
| 766 |
* If neither srcImage nor dstImage has a multi-planar image format then |
| 767 |
* for each element of pRegions, srcSubresource.aspectMask and |
| 768 |
* dstSubresource.aspectMask must match. |
| 769 |
*/ |
| 770 |
assert(pRegionA->srcSubresource.aspectMask == |
| 771 |
pRegionA->dstSubresource.aspectMask); |
| 772 |
assert(pRegionB->srcSubresource.aspectMask == |
| 773 |
pRegionB->dstSubresource.aspectMask); |
| 774 |
|
| 775 |
if (!(pRegionA->srcSubresource.mipLevel == |
| 776 |
pRegionB->srcSubresource.mipLevel && |
| 777 |
pRegionA->srcSubresource.baseArrayLayer == |
| 778 |
pRegionB->srcSubresource.baseArrayLayer && |
| 779 |
pRegionA->srcSubresource.layerCount == |
| 780 |
pRegionB->srcSubresource.layerCount)) { |
| 781 |
return false; |
| 782 |
} |
| 783 |
|
| 784 |
if (!(pRegionA->dstSubresource.mipLevel == |
| 785 |
pRegionB->dstSubresource.mipLevel && |
| 786 |
pRegionA->dstSubresource.baseArrayLayer == |
| 787 |
pRegionB->dstSubresource.baseArrayLayer && |
| 788 |
pRegionA->dstSubresource.layerCount == |
| 789 |
pRegionB->dstSubresource.layerCount)) { |
| 790 |
return false; |
| 791 |
} |
| 792 |
|
| 793 |
if (!(pRegionA->srcOffset.x == pRegionB->srcOffset.x && |
| 794 |
pRegionA->srcOffset.y == pRegionB->srcOffset.y && |
| 795 |
pRegionA->srcOffset.z == pRegionB->srcOffset.z)) { |
| 796 |
return false; |
| 797 |
} |
| 798 |
|
| 799 |
if (!(pRegionA->dstOffset.x == pRegionB->dstOffset.x && |
| 800 |
pRegionA->dstOffset.y == pRegionB->dstOffset.y && |
| 801 |
pRegionA->dstOffset.z == pRegionB->dstOffset.z)) { |
| 802 |
return false; |
| 803 |
} |
| 804 |
|
| 805 |
if (!(pRegionA->extent.width == pRegionB->extent.width && |
| 806 |
pRegionA->extent.height == pRegionB->extent.height && |
| 807 |
pRegionA->extent.depth == pRegionB->extent.depth)) { |
| 808 |
return false; |
| 809 |
} |
| 810 |
|
| 811 |
return true; |
| 812 |
} |
| 813 |
|
| 814 |
void pvr_rogue_CmdCopyImage2(VkCommandBuffer commandBuffer, |
| 815 |
const VkCopyImageInfo2 *pCopyImageInfo) |
| 816 |
{ |
| 817 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 818 |
VK_FROM_HANDLE(pvr_image, src, pCopyImageInfo->srcImage); |
| 819 |
VK_FROM_HANDLE(pvr_image, dst, pCopyImageInfo->dstImage); |
| 820 |
|
| 821 |
const bool can_merge_ds = pvr_vk_format_is_combined_ds(src->vk.format) && |
| 822 |
pvr_vk_format_is_combined_ds(dst->vk.format); |
| 823 |
|
| 824 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 825 |
|
| 826 |
for (uint32_t i = 0U; i < pCopyImageInfo->regionCount; i++) { |
| 827 |
VkResult result; |
| 828 |
|
| 829 |
/* If an application has split a copy between D24S8 images into two |
| 830 |
* separate copy regions (one for the depth aspect and one for the |
| 831 |
* stencil aspect) attempt to merge the two regions back into one blit. |
| 832 |
* |
| 833 |
* This can only be merged if both regions are identical apart from the |
| 834 |
* aspectMask, one of which has to be depth and the other has to be |
| 835 |
* stencil. |
| 836 |
* |
| 837 |
* Only attempt to merge consecutive regions, ignore the case of merging |
| 838 |
* non-consecutive regions. |
| 839 |
*/ |
| 840 |
if (can_merge_ds && i != (pCopyImageInfo->regionCount - 1)) { |
| 841 |
const bool ret = |
| 842 |
pvr_can_merge_ds_regions(&pCopyImageInfo->pRegions[i], |
| 843 |
&pCopyImageInfo->pRegions[i + 1]); |
| 844 |
if (ret) { |
| 845 |
VkImageCopy2 region = pCopyImageInfo->pRegions[i]; |
| 846 |
|
| 847 |
region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | |
| 848 |
VK_IMAGE_ASPECT_STENCIL_BIT; |
| 849 |
region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | |
| 850 |
VK_IMAGE_ASPECT_STENCIL_BIT; |
| 851 |
|
| 852 |
result = pvr_copy_or_resolve_color_image_region(cmd_buffer, |
| 853 |
src, |
| 854 |
dst, |
| 855 |
®ion); |
| 856 |
if (result != VK_SUCCESS) |
| 857 |
return; |
| 858 |
|
| 859 |
/* Skip the next region as it has been processed with the last |
| 860 |
* region. |
| 861 |
*/ |
| 862 |
i++; |
| 863 |
|
| 864 |
continue; |
| 865 |
} |
| 866 |
} |
| 867 |
|
| 868 |
result = |
| 869 |
pvr_copy_or_resolve_color_image_region(cmd_buffer, |
| 870 |
src, |
| 871 |
dst, |
| 872 |
&pCopyImageInfo->pRegions[i]); |
| 873 |
if (result != VK_SUCCESS) |
| 874 |
return; |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
VkResult |
| 879 |
pvr_copy_buffer_to_image_region_format(struct pvr_cmd_buffer *const cmd_buffer, |
| 880 |
const pvr_dev_addr_t buffer_dev_addr, |
| 881 |
const struct pvr_image *const image, |
| 882 |
const VkBufferImageCopy2 *const region, |
| 883 |
const VkFormat src_format, |
| 884 |
const VkFormat dst_format, |
| 885 |
const uint32_t flags) |
| 886 |
{ |
| 887 |
enum pipe_format pformat = vk_format_to_pipe_format(dst_format); |
| 888 |
uint32_t row_length_in_texels; |
| 889 |
uint32_t buffer_slice_size; |
| 890 |
uint32_t buffer_layer_size; |
| 891 |
uint32_t height_in_blks; |
| 892 |
uint32_t row_length; |
| 893 |
|
| 894 |
if (region->bufferRowLength == 0) |
| 895 |
row_length_in_texels = region->imageExtent.width; |
| 896 |
else |
| 897 |
row_length_in_texels = region->bufferRowLength; |
| 898 |
|
| 899 |
if (region->bufferImageHeight == 0) |
| 900 |
height_in_blks = region->imageExtent.height; |
| 901 |
else |
| 902 |
height_in_blks = region->bufferImageHeight; |
| 903 |
|
| 904 |
if (util_format_is_compressed(pformat)) { |
| 905 |
uint32_t block_width = util_format_get_blockwidth(pformat); |
| 906 |
uint32_t block_height = util_format_get_blockheight(pformat); |
| 907 |
uint32_t block_size = util_format_get_blocksize(pformat); |
| 908 |
|
| 909 |
height_in_blks = DIV_ROUND_UP(height_in_blks, block_height); |
| 910 |
row_length_in_texels = |
| 911 |
DIV_ROUND_UP(row_length_in_texels, block_width) * block_size; |
| 912 |
} |
| 913 |
|
| 914 |
row_length = row_length_in_texels * vk_format_get_blocksize(src_format); |
| 915 |
|
| 916 |
buffer_slice_size = height_in_blks * row_length; |
| 917 |
buffer_layer_size = buffer_slice_size * region->imageExtent.depth; |
| 918 |
|
| 919 |
for (uint32_t i = 0; i < region->imageExtent.depth; i++) { |
| 920 |
const uint32_t depth = i + (uint32_t)region->imageOffset.z; |
| 921 |
|
| 922 |
for (uint32_t j = 0; j < region->imageSubresource.layerCount; j++) { |
| 923 |
const VkDeviceSize buffer_offset = region->bufferOffset + |
| 924 |
(j * buffer_layer_size) + |
| 925 |
(i * buffer_slice_size); |
| 926 |
struct pvr_transfer_cmd *transfer_cmd; |
| 927 |
VkResult result; |
| 928 |
|
| 929 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 930 |
if (!transfer_cmd) |
| 931 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 932 |
|
| 933 |
transfer_cmd->flags = flags; |
| 934 |
|
| 935 |
pvr_setup_buffer_surface( |
| 936 |
&transfer_cmd->sources[0].surface, |
| 937 |
&transfer_cmd->sources[0].mappings[0].src_rect, |
| 938 |
buffer_dev_addr, |
| 939 |
buffer_offset, |
| 940 |
src_format, |
| 941 |
vk_format_get_plane_aspect_format( |
| 942 |
image->vk.format, |
| 943 |
region->imageSubresource.aspectMask), |
| 944 |
region->imageExtent.width, |
| 945 |
region->imageExtent.height, |
| 946 |
row_length_in_texels); |
| 947 |
|
| 948 |
transfer_cmd->sources[0].surface.sample_count = image->vk.samples; |
| 949 |
transfer_cmd->sources[0].surface.depth = 1; |
| 950 |
transfer_cmd->source_count = 1; |
| 951 |
|
| 952 |
pvr_setup_transfer_surface(cmd_buffer->device, |
| 953 |
&transfer_cmd->dst, |
| 954 |
&transfer_cmd->scissor, |
| 955 |
image, |
| 956 |
region->imageSubresource.baseArrayLayer + j, |
| 957 |
region->imageSubresource.mipLevel, |
| 958 |
®ion->imageOffset, |
| 959 |
®ion->imageExtent, |
| 960 |
depth, |
| 961 |
dst_format, |
| 962 |
region->imageSubresource.aspectMask); |
| 963 |
|
| 964 |
transfer_cmd->sources[0].mappings[0].dst_rect = transfer_cmd->scissor; |
| 965 |
transfer_cmd->sources[0].mapping_count++; |
| 966 |
|
| 967 |
result = |
| 968 |
pvr_arch_cmd_buffer_add_transfer_cmd(cmd_buffer, transfer_cmd); |
| 969 |
if (result != VK_SUCCESS) { |
| 970 |
vk_free(&cmd_buffer->vk.pool->alloc, transfer_cmd); |
| 971 |
return result; |
| 972 |
} |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
return VK_SUCCESS; |
| 977 |
} |
| 978 |
|
| 979 |
static VkResult |
| 980 |
pvr_copy_buffer_to_image_region(struct pvr_cmd_buffer *const cmd_buffer, |
| 981 |
const pvr_dev_addr_t buffer_dev_addr, |
| 982 |
const struct pvr_image *const image, |
| 983 |
const VkBufferImageCopy2 *const region) |
| 984 |
{ |
| 985 |
const VkImageAspectFlags aspect_mask = region->imageSubresource.aspectMask; |
| 986 |
VkFormat src_format; |
| 987 |
VkFormat dst_format; |
| 988 |
uint32_t flags = 0; |
| 989 |
|
| 990 |
/* From the Vulkan spec: |
| 991 |
* |
| 992 |
* dstImage must have a sample count equal to VK_SAMPLE_COUNT_1_BIT |
| 993 |
*/ |
| 994 |
assert(image->vk.samples == VK_SAMPLE_COUNT_1_BIT); |
| 995 |
|
| 996 |
if (vk_format_has_depth(image->vk.format) && |
| 997 |
vk_format_has_stencil(image->vk.format)) { |
| 998 |
flags |= PVR_TRANSFER_CMD_FLAGS_DSMERGE; |
| 999 |
|
| 1000 |
if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) { |
| 1001 |
src_format = vk_format_stencil_only(image->vk.format); |
| 1002 |
} else { |
| 1003 |
src_format = vk_format_depth_only(image->vk.format); |
| 1004 |
flags |= PVR_TRANSFER_CMD_FLAGS_PICKD; |
| 1005 |
} |
| 1006 |
|
| 1007 |
dst_format = image->vk.format; |
| 1008 |
} else { |
| 1009 |
src_format = pvr_get_raw_copy_format( |
| 1010 |
vk_format_get_plane_aspect_format(image->vk.format, aspect_mask)); |
| 1011 |
dst_format = src_format; |
| 1012 |
} |
| 1013 |
|
| 1014 |
return pvr_copy_buffer_to_image_region_format(cmd_buffer, |
| 1015 |
buffer_dev_addr, |
| 1016 |
image, |
| 1017 |
region, |
| 1018 |
src_format, |
| 1019 |
dst_format, |
| 1020 |
flags); |
| 1021 |
} |
| 1022 |
|
| 1023 |
void pvr_rogue_CmdCopyBufferToImage2( |
| 1024 |
VkCommandBuffer commandBuffer, |
| 1025 |
const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) |
| 1026 |
{ |
| 1027 |
VK_FROM_HANDLE(pvr_buffer, src, pCopyBufferToImageInfo->srcBuffer); |
| 1028 |
VK_FROM_HANDLE(pvr_image, dst, pCopyBufferToImageInfo->dstImage); |
| 1029 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 1030 |
|
| 1031 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 1032 |
|
| 1033 |
for (uint32_t i = 0; i < pCopyBufferToImageInfo->regionCount; i++) { |
| 1034 |
const VkResult result = |
| 1035 |
pvr_copy_buffer_to_image_region(cmd_buffer, |
| 1036 |
src->dev_addr, |
| 1037 |
dst, |
| 1038 |
&pCopyBufferToImageInfo->pRegions[i]); |
| 1039 |
if (result != VK_SUCCESS) |
| 1040 |
return; |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
VkResult |
| 1045 |
pvr_copy_image_to_buffer_region_format(struct pvr_cmd_buffer *const cmd_buffer, |
| 1046 |
const struct pvr_image *const image, |
| 1047 |
const pvr_dev_addr_t buffer_dev_addr, |
| 1048 |
const VkBufferImageCopy2 *const region, |
| 1049 |
const VkFormat src_format, |
| 1050 |
const VkFormat dst_format) |
| 1051 |
{ |
| 1052 |
enum pipe_format pformat = vk_format_to_pipe_format( |
| 1053 |
vk_format_get_plane_aspect_format(image->vk.format, |
| 1054 |
region->imageSubresource.aspectMask)); |
| 1055 |
struct pvr_transfer_cmd_surface dst_surface = { 0 }; |
| 1056 |
VkImageSubresource sub_resource; |
| 1057 |
uint32_t buffer_image_height; |
| 1058 |
uint32_t buffer_row_length; |
| 1059 |
uint32_t buffer_slice_size; |
| 1060 |
uint32_t max_array_layers; |
| 1061 |
VkRect2D dst_rect = { 0 }; |
| 1062 |
uint32_t max_depth_slice; |
| 1063 |
VkSubresourceLayout info; |
| 1064 |
|
| 1065 |
if (region->bufferRowLength == 0) |
| 1066 |
buffer_row_length = region->imageExtent.width; |
| 1067 |
else |
| 1068 |
buffer_row_length = region->bufferRowLength; |
| 1069 |
|
| 1070 |
if (region->bufferImageHeight == 0) |
| 1071 |
buffer_image_height = region->imageExtent.height; |
| 1072 |
else |
| 1073 |
buffer_image_height = region->bufferImageHeight; |
| 1074 |
|
| 1075 |
max_array_layers = |
| 1076 |
region->imageSubresource.baseArrayLayer + |
| 1077 |
vk_image_subresource_layer_count(&image->vk, ®ion->imageSubresource); |
| 1078 |
|
| 1079 |
buffer_slice_size = buffer_image_height * buffer_row_length * |
| 1080 |
vk_format_get_blocksize(dst_format); |
| 1081 |
|
| 1082 |
max_depth_slice = region->imageExtent.depth + region->imageOffset.z; |
| 1083 |
|
| 1084 |
pvr_setup_buffer_surface( |
| 1085 |
&dst_surface, |
| 1086 |
&dst_rect, |
| 1087 |
buffer_dev_addr, |
| 1088 |
region->bufferOffset, |
| 1089 |
dst_format, |
| 1090 |
vk_format_get_plane_aspect_format(image->vk.format, |
| 1091 |
region->imageSubresource.aspectMask), |
| 1092 |
buffer_row_length, |
| 1093 |
buffer_image_height, |
| 1094 |
buffer_row_length); |
| 1095 |
|
| 1096 |
dst_rect.extent.width = region->imageExtent.width; |
| 1097 |
dst_rect.extent.height = region->imageExtent.height; |
| 1098 |
dst_surface.sample_count = image->vk.samples; |
| 1099 |
|
| 1100 |
if (util_format_is_compressed(pformat)) { |
| 1101 |
uint32_t block_width = util_format_get_blockwidth(pformat); |
| 1102 |
uint32_t block_height = util_format_get_blockheight(pformat); |
| 1103 |
|
| 1104 |
dst_rect.extent.width = |
| 1105 |
MAX2(1U, DIV_ROUND_UP(dst_rect.extent.width, block_width)); |
| 1106 |
dst_rect.extent.height = |
| 1107 |
MAX2(1U, DIV_ROUND_UP(dst_rect.extent.height, block_height)); |
| 1108 |
} |
| 1109 |
|
| 1110 |
sub_resource = (VkImageSubresource){ |
| 1111 |
.aspectMask = region->imageSubresource.aspectMask, |
| 1112 |
.mipLevel = region->imageSubresource.mipLevel, |
| 1113 |
.arrayLayer = region->imageSubresource.baseArrayLayer, |
| 1114 |
}; |
| 1115 |
|
| 1116 |
pvr_get_image_subresource_layout(image, &sub_resource, &info); |
| 1117 |
|
| 1118 |
for (uint32_t i = region->imageSubresource.baseArrayLayer; |
| 1119 |
i < max_array_layers; |
| 1120 |
i++) { |
| 1121 |
struct pvr_transfer_cmd_surface src_surface = { 0 }; |
| 1122 |
VkRect2D src_rect = { 0 }; |
| 1123 |
|
| 1124 |
/* Note: Set the depth to the initial depth offset, the memory address (or |
| 1125 |
* the z_position) for the depth slice will be incremented manually in the |
| 1126 |
* loop below. |
| 1127 |
*/ |
| 1128 |
pvr_setup_transfer_surface(cmd_buffer->device, |
| 1129 |
&src_surface, |
| 1130 |
&src_rect, |
| 1131 |
image, |
| 1132 |
i, |
| 1133 |
region->imageSubresource.mipLevel, |
| 1134 |
®ion->imageOffset, |
| 1135 |
®ion->imageExtent, |
| 1136 |
region->imageOffset.z, |
| 1137 |
src_format, |
| 1138 |
region->imageSubresource.aspectMask); |
| 1139 |
|
| 1140 |
for (uint32_t j = region->imageOffset.z; j < max_depth_slice; j++) { |
| 1141 |
struct pvr_transfer_cmd *transfer_cmd; |
| 1142 |
VkResult result; |
| 1143 |
|
| 1144 |
/* TODO: See if we can allocate all the transfer cmds in one go. */ |
| 1145 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 1146 |
if (!transfer_cmd) |
| 1147 |
return vk_error(cmd_buffer->device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1148 |
|
| 1149 |
transfer_cmd->sources[0].mappings[0].src_rect = src_rect; |
| 1150 |
transfer_cmd->sources[0].mappings[0].dst_rect = dst_rect; |
| 1151 |
transfer_cmd->sources[0].mapping_count++; |
| 1152 |
|
| 1153 |
transfer_cmd->sources[0].surface = src_surface; |
| 1154 |
transfer_cmd->source_count = 1; |
| 1155 |
|
| 1156 |
transfer_cmd->dst = dst_surface; |
| 1157 |
transfer_cmd->scissor = dst_rect; |
| 1158 |
|
| 1159 |
result = |
| 1160 |
pvr_arch_cmd_buffer_add_transfer_cmd(cmd_buffer, transfer_cmd); |
| 1161 |
if (result != VK_SUCCESS) { |
| 1162 |
vk_free(&cmd_buffer->vk.pool->alloc, transfer_cmd); |
| 1163 |
return result; |
| 1164 |
} |
| 1165 |
|
| 1166 |
dst_surface.dev_addr.addr += buffer_slice_size; |
| 1167 |
|
| 1168 |
if (src_surface.mem_layout == PVR_MEMLAYOUT_3DTWIDDLED) |
| 1169 |
src_surface.z_position += 1.0f; |
| 1170 |
else |
| 1171 |
src_surface.dev_addr.addr += info.depthPitch; |
| 1172 |
} |
| 1173 |
} |
| 1174 |
|
| 1175 |
return VK_SUCCESS; |
| 1176 |
} |
| 1177 |
|
| 1178 |
static VkResult |
| 1179 |
pvr_copy_image_to_buffer_region(struct pvr_cmd_buffer *const cmd_buffer, |
| 1180 |
const struct pvr_image *const image, |
| 1181 |
const pvr_dev_addr_t buffer_dev_addr, |
| 1182 |
const VkBufferImageCopy2 *const region) |
| 1183 |
{ |
| 1184 |
const VkImageAspectFlags aspect_mask = region->imageSubresource.aspectMask; |
| 1185 |
|
| 1186 |
VkFormat src_format = pvr_get_copy_format(image->vk.format, aspect_mask); |
| 1187 |
VkFormat dst_format; |
| 1188 |
|
| 1189 |
/* From the Vulkan spec: |
| 1190 |
* |
| 1191 |
* srcImage must have a sample count equal to VK_SAMPLE_COUNT_1_BIT |
| 1192 |
*/ |
| 1193 |
assert(image->vk.samples == VK_SAMPLE_COUNT_1_BIT); |
| 1194 |
|
| 1195 |
/* All but stencil aspect copies can nearly all be done using an appropriate |
| 1196 |
* raw format. |
| 1197 |
*/ |
| 1198 |
if (aspect_mask & (~VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1199 |
if (src_format == VK_FORMAT_D32_SFLOAT_S8_UINT) { |
| 1200 |
dst_format = VK_FORMAT_D32_SFLOAT; |
| 1201 |
} else { |
| 1202 |
src_format = pvr_get_raw_copy_format(src_format); |
| 1203 |
|
| 1204 |
dst_format = src_format; |
| 1205 |
} |
| 1206 |
} else if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1207 |
/* From the Vulkan spec: |
| 1208 |
* |
| 1209 |
* Data copied to or from the stencil aspect of any depth/stencil |
| 1210 |
* format is tightly packed with one VK_FORMAT_S8_UINT value per texel. |
| 1211 |
*/ |
| 1212 |
dst_format = VK_FORMAT_S8_UINT; |
| 1213 |
} else { |
| 1214 |
UNREACHABLE(""); |
| 1215 |
} |
| 1216 |
|
| 1217 |
return pvr_copy_image_to_buffer_region_format(cmd_buffer, |
| 1218 |
image, |
| 1219 |
buffer_dev_addr, |
| 1220 |
region, |
| 1221 |
src_format, |
| 1222 |
dst_format); |
| 1223 |
} |
| 1224 |
|
| 1225 |
void pvr_rogue_CmdCopyImageToBuffer2( |
| 1226 |
VkCommandBuffer commandBuffer, |
| 1227 |
const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) |
| 1228 |
{ |
| 1229 |
VK_FROM_HANDLE(pvr_buffer, dst, pCopyImageToBufferInfo->dstBuffer); |
| 1230 |
VK_FROM_HANDLE(pvr_image, src, pCopyImageToBufferInfo->srcImage); |
| 1231 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 1232 |
|
| 1233 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 1234 |
|
| 1235 |
for (uint32_t i = 0U; i < pCopyImageToBufferInfo->regionCount; i++) { |
| 1236 |
const VkBufferImageCopy2 *region = &pCopyImageToBufferInfo->pRegions[i]; |
| 1237 |
|
| 1238 |
const VkResult result = pvr_copy_image_to_buffer_region(cmd_buffer, |
| 1239 |
src, |
| 1240 |
dst->dev_addr, |
| 1241 |
region); |
| 1242 |
if (result != VK_SUCCESS) |
| 1243 |
return; |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
static void pvr_calc_mip_level_extents(const struct pvr_image *image, |
| 1248 |
uint16_t mip_level, |
| 1249 |
VkExtent3D *extent_out) |
| 1250 |
{ |
| 1251 |
/* 3D textures are clamped to 4x4x4. */ |
| 1252 |
const uint32_t clamp = (image->vk.image_type == VK_IMAGE_TYPE_3D) ? 4 : 1; |
| 1253 |
const VkExtent3D *extent = &image->vk.extent; |
| 1254 |
|
| 1255 |
extent_out->width = MAX2(extent->width >> mip_level, clamp); |
| 1256 |
extent_out->height = MAX2(extent->height >> mip_level, clamp); |
| 1257 |
extent_out->depth = MAX2(extent->depth >> mip_level, clamp); |
| 1258 |
} |
| 1259 |
|
| 1260 |
static VkResult pvr_clear_image_range(struct pvr_cmd_buffer *cmd_buffer, |
| 1261 |
const struct pvr_image *image, |
| 1262 |
const VkClearColorValue *pColor, |
| 1263 |
const VkImageSubresourceRange *psRange, |
| 1264 |
uint32_t flags) |
| 1265 |
{ |
| 1266 |
const uint32_t layer_count = |
| 1267 |
vk_image_subresource_layer_count(&image->vk, psRange); |
| 1268 |
const uint32_t max_layers = psRange->baseArrayLayer + layer_count; |
| 1269 |
VkFormat format = image->vk.format; |
| 1270 |
const VkOffset3D offset = { 0 }; |
| 1271 |
VkExtent3D mip_extent; |
| 1272 |
|
| 1273 |
assert((psRange->baseArrayLayer + layer_count) <= image->vk.array_layers); |
| 1274 |
|
| 1275 |
for (uint32_t layer = psRange->baseArrayLayer; layer < max_layers; layer++) { |
| 1276 |
const uint32_t level_count = |
| 1277 |
vk_image_subresource_level_count(&image->vk, psRange); |
| 1278 |
const uint32_t max_level = psRange->baseMipLevel + level_count; |
| 1279 |
|
| 1280 |
assert((psRange->baseMipLevel + level_count) <= image->vk.mip_levels); |
| 1281 |
|
| 1282 |
for (uint32_t level = psRange->baseMipLevel; level < max_level; level++) { |
| 1283 |
pvr_calc_mip_level_extents(image, level, &mip_extent); |
| 1284 |
|
| 1285 |
for (uint32_t depth = 0; depth < mip_extent.depth; depth++) { |
| 1286 |
struct pvr_transfer_cmd *transfer_cmd; |
| 1287 |
VkResult result; |
| 1288 |
|
| 1289 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 1290 |
if (!transfer_cmd) |
| 1291 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1292 |
|
| 1293 |
transfer_cmd->flags |= flags; |
| 1294 |
transfer_cmd->flags |= PVR_TRANSFER_CMD_FLAGS_FILL; |
| 1295 |
|
| 1296 |
for (uint32_t i = 0; i < ARRAY_SIZE(transfer_cmd->clear_color); i++) |
| 1297 |
transfer_cmd->clear_color[i].ui = pColor->uint32[i]; |
| 1298 |
|
| 1299 |
pvr_setup_transfer_surface(cmd_buffer->device, |
| 1300 |
&transfer_cmd->dst, |
| 1301 |
&transfer_cmd->scissor, |
| 1302 |
image, |
| 1303 |
layer, |
| 1304 |
level, |
| 1305 |
&offset, |
| 1306 |
&mip_extent, |
| 1307 |
depth, |
| 1308 |
format, |
| 1309 |
psRange->aspectMask); |
| 1310 |
|
| 1311 |
result = |
| 1312 |
pvr_arch_cmd_buffer_add_transfer_cmd(cmd_buffer, transfer_cmd); |
| 1313 |
if (result != VK_SUCCESS) { |
| 1314 |
vk_free(&cmd_buffer->vk.pool->alloc, transfer_cmd); |
| 1315 |
return result; |
| 1316 |
} |
| 1317 |
} |
| 1318 |
} |
| 1319 |
} |
| 1320 |
|
| 1321 |
return VK_SUCCESS; |
| 1322 |
} |
| 1323 |
|
| 1324 |
void pvr_rogue_CmdClearColorImage(VkCommandBuffer commandBuffer, |
| 1325 |
VkImage _image, |
| 1326 |
VkImageLayout imageLayout, |
| 1327 |
const VkClearColorValue *pColor, |
| 1328 |
uint32_t rangeCount, |
| 1329 |
const VkImageSubresourceRange *pRanges) |
| 1330 |
{ |
| 1331 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 1332 |
VK_FROM_HANDLE(pvr_image, image, _image); |
| 1333 |
|
| 1334 |
for (uint32_t i = 0; i < rangeCount; i++) { |
| 1335 |
const VkResult result = |
| 1336 |
pvr_clear_image_range(cmd_buffer, image, pColor, &pRanges[i], 0); |
| 1337 |
if (result != VK_SUCCESS) |
| 1338 |
return; |
| 1339 |
} |
| 1340 |
} |
| 1341 |
|
| 1342 |
void pvr_clear_depth_stencil_image(struct pvr_cmd_buffer *cmd_buffer, |
| 1343 |
const struct pvr_image *image, |
| 1344 |
const VkClearDepthStencilValue *pDepthStencil, |
| 1345 |
uint32_t rangeCount, |
| 1346 |
const VkImageSubresourceRange *pRanges) |
| 1347 |
{ |
| 1348 |
for (uint32_t i = 0; i < rangeCount; i++) { |
| 1349 |
const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | |
| 1350 |
VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1351 |
VkClearColorValue clear_ds = { 0 }; |
| 1352 |
uint32_t flags = 0U; |
| 1353 |
VkResult result; |
| 1354 |
|
| 1355 |
if (vk_format_aspects(image->vk.format) == ds_aspect && |
| 1356 |
pRanges[i].aspectMask != ds_aspect) { |
| 1357 |
/* A depth or stencil blit to a packed_depth_stencil requires a merge |
| 1358 |
* operation. |
| 1359 |
*/ |
| 1360 |
flags |= PVR_TRANSFER_CMD_FLAGS_DSMERGE; |
| 1361 |
|
| 1362 |
if (pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) |
| 1363 |
flags |= PVR_TRANSFER_CMD_FLAGS_PICKD; |
| 1364 |
} |
| 1365 |
|
| 1366 |
clear_ds.float32[0] = pDepthStencil->depth; |
| 1367 |
clear_ds.uint32[1] = pDepthStencil->stencil; |
| 1368 |
|
| 1369 |
result = |
| 1370 |
pvr_clear_image_range(cmd_buffer, image, &clear_ds, pRanges + i, flags); |
| 1371 |
if (result != VK_SUCCESS) |
| 1372 |
return; |
| 1373 |
} |
| 1374 |
} |
| 1375 |
|
| 1376 |
void pvr_rogue_CmdClearDepthStencilImage( |
| 1377 |
VkCommandBuffer commandBuffer, |
| 1378 |
VkImage _image, |
| 1379 |
VkImageLayout imageLayout, |
| 1380 |
const VkClearDepthStencilValue *pDepthStencil, |
| 1381 |
uint32_t rangeCount, |
| 1382 |
const VkImageSubresourceRange *pRanges) |
| 1383 |
{ |
| 1384 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 1385 |
VK_FROM_HANDLE(pvr_image, image, _image); |
| 1386 |
|
| 1387 |
pvr_clear_depth_stencil_image(cmd_buffer, |
| 1388 |
image, |
| 1389 |
pDepthStencil, |
| 1390 |
rangeCount, |
| 1391 |
pRanges); |
| 1392 |
} |
| 1393 |
|
| 1394 |
static VkResult pvr_cmd_copy_buffer_region(struct pvr_cmd_buffer *cmd_buffer, |
| 1395 |
pvr_dev_addr_t src_addr, |
| 1396 |
VkDeviceSize src_offset, |
| 1397 |
pvr_dev_addr_t dst_addr, |
| 1398 |
VkDeviceSize dst_offset, |
| 1399 |
VkDeviceSize size, |
| 1400 |
uint32_t fill_data, |
| 1401 |
bool is_fill) |
| 1402 |
{ |
| 1403 |
VkDeviceSize offset = 0; |
| 1404 |
|
| 1405 |
while (offset < size) { |
| 1406 |
const VkDeviceSize remaining_size = size - offset; |
| 1407 |
struct pvr_transfer_cmd *transfer_cmd; |
| 1408 |
uint32_t src_align = (src_addr.addr + offset + src_offset) & 0xF; |
| 1409 |
uint32_t dst_align = (dst_addr.addr + offset + src_offset) & 0xF; |
| 1410 |
uint32_t texel_width; |
| 1411 |
VkDeviceSize texels; |
| 1412 |
VkFormat vk_format; |
| 1413 |
VkResult result; |
| 1414 |
uint32_t height; |
| 1415 |
uint32_t width; |
| 1416 |
|
| 1417 |
if (is_fill) { |
| 1418 |
vk_format = VK_FORMAT_R32_UINT; |
| 1419 |
texel_width = 4U; |
| 1420 |
} else if (remaining_size >= 16U && (src_align % 16U) == 0 && |
| 1421 |
(dst_align % 16U) == 0) { |
| 1422 |
/* Only if address is 128bpp aligned */ |
| 1423 |
vk_format = VK_FORMAT_R32G32B32A32_UINT; |
| 1424 |
texel_width = 16U; |
| 1425 |
} else if (remaining_size >= 4U) { |
| 1426 |
vk_format = VK_FORMAT_R32_UINT; |
| 1427 |
texel_width = 4U; |
| 1428 |
} else { |
| 1429 |
vk_format = VK_FORMAT_R8_UINT; |
| 1430 |
texel_width = 1U; |
| 1431 |
} |
| 1432 |
|
| 1433 |
texels = remaining_size / texel_width; |
| 1434 |
|
| 1435 |
/* Try to do max-width rects, fall back to a 1-height rect for the |
| 1436 |
* remainder. |
| 1437 |
*/ |
| 1438 |
if (texels > PVR_MAX_TRANSFER_SIZE_IN_TEXELS) { |
| 1439 |
width = PVR_MAX_TRANSFER_SIZE_IN_TEXELS; |
| 1440 |
height = texels / PVR_MAX_TRANSFER_SIZE_IN_TEXELS; |
| 1441 |
height = MIN2(height, PVR_MAX_TRANSFER_SIZE_IN_TEXELS); |
| 1442 |
} else { |
| 1443 |
width = texels; |
| 1444 |
height = 1; |
| 1445 |
} |
| 1446 |
|
| 1447 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 1448 |
if (!transfer_cmd) |
| 1449 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1450 |
|
| 1451 |
if (!is_fill) { |
| 1452 |
pvr_setup_buffer_surface( |
| 1453 |
&transfer_cmd->sources[0].surface, |
| 1454 |
&transfer_cmd->sources[0].mappings[0].src_rect, |
| 1455 |
src_addr, |
| 1456 |
offset + src_offset, |
| 1457 |
vk_format, |
| 1458 |
vk_format, |
| 1459 |
width, |
| 1460 |
height, |
| 1461 |
width); |
| 1462 |
transfer_cmd->source_count = 1; |
| 1463 |
} else { |
| 1464 |
transfer_cmd->flags |= PVR_TRANSFER_CMD_FLAGS_FILL; |
| 1465 |
|
| 1466 |
for (uint32_t i = 0; i < ARRAY_SIZE(transfer_cmd->clear_color); i++) |
| 1467 |
transfer_cmd->clear_color[i].ui = fill_data; |
| 1468 |
} |
| 1469 |
|
| 1470 |
pvr_setup_buffer_surface(&transfer_cmd->dst, |
| 1471 |
&transfer_cmd->scissor, |
| 1472 |
dst_addr, |
| 1473 |
offset + dst_offset, |
| 1474 |
vk_format, |
| 1475 |
vk_format, |
| 1476 |
width, |
| 1477 |
height, |
| 1478 |
width); |
| 1479 |
|
| 1480 |
if (transfer_cmd->source_count > 0) { |
| 1481 |
transfer_cmd->sources[0].mappings[0].dst_rect = transfer_cmd->scissor; |
| 1482 |
|
| 1483 |
transfer_cmd->sources[0].mapping_count++; |
| 1484 |
} |
| 1485 |
|
| 1486 |
result = pvr_arch_cmd_buffer_add_transfer_cmd(cmd_buffer, transfer_cmd); |
| 1487 |
if (result != VK_SUCCESS) { |
| 1488 |
vk_free(&cmd_buffer->vk.pool->alloc, transfer_cmd); |
| 1489 |
return result; |
| 1490 |
} |
| 1491 |
|
| 1492 |
offset += width * height * texel_width; |
| 1493 |
} |
| 1494 |
|
| 1495 |
return VK_SUCCESS; |
| 1496 |
} |
| 1497 |
|
| 1498 |
void pvr_rogue_CmdUpdateBuffer(VkCommandBuffer commandBuffer, |
| 1499 |
VkBuffer dstBuffer, |
| 1500 |
VkDeviceSize dstOffset, |
| 1501 |
VkDeviceSize dataSize, |
| 1502 |
const void *pData) |
| 1503 |
{ |
| 1504 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 1505 |
VK_FROM_HANDLE(pvr_buffer, dst, dstBuffer); |
| 1506 |
struct pvr_suballoc_bo *pvr_bo; |
| 1507 |
VkResult result; |
| 1508 |
|
| 1509 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 1510 |
|
| 1511 |
result = |
| 1512 |
pvr_arch_cmd_buffer_upload_general(cmd_buffer, pData, dataSize, &pvr_bo); |
| 1513 |
if (result != VK_SUCCESS) |
| 1514 |
return; |
| 1515 |
|
| 1516 |
pvr_cmd_copy_buffer_region(cmd_buffer, |
| 1517 |
pvr_bo->dev_addr, |
| 1518 |
0, |
| 1519 |
dst->dev_addr, |
| 1520 |
dstOffset, |
| 1521 |
dataSize, |
| 1522 |
0U, |
| 1523 |
false); |
| 1524 |
} |
| 1525 |
|
| 1526 |
void pvr_rogue_CmdCopyBuffer2(VkCommandBuffer commandBuffer, |
| 1527 |
const VkCopyBufferInfo2 *pCopyBufferInfo) |
| 1528 |
{ |
| 1529 |
VK_FROM_HANDLE(pvr_buffer, src, pCopyBufferInfo->srcBuffer); |
| 1530 |
VK_FROM_HANDLE(pvr_buffer, dst, pCopyBufferInfo->dstBuffer); |
| 1531 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 1532 |
|
| 1533 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 1534 |
|
| 1535 |
for (uint32_t i = 0; i < pCopyBufferInfo->regionCount; i++) { |
| 1536 |
const VkResult result = |
| 1537 |
pvr_cmd_copy_buffer_region(cmd_buffer, |
| 1538 |
src->dev_addr, |
| 1539 |
pCopyBufferInfo->pRegions[i].srcOffset, |
| 1540 |
dst->dev_addr, |
| 1541 |
pCopyBufferInfo->pRegions[i].dstOffset, |
| 1542 |
pCopyBufferInfo->pRegions[i].size, |
| 1543 |
0U, |
| 1544 |
false); |
| 1545 |
if (result != VK_SUCCESS) |
| 1546 |
return; |
| 1547 |
} |
| 1548 |
} |
| 1549 |
|
| 1550 |
void pvr_rogue_CmdFillBuffer(VkCommandBuffer commandBuffer, |
| 1551 |
VkBuffer dstBuffer, |
| 1552 |
VkDeviceSize dstOffset, |
| 1553 |
VkDeviceSize fillSize, |
| 1554 |
uint32_t data) |
| 1555 |
{ |
| 1556 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 1557 |
VK_FROM_HANDLE(pvr_buffer, dst, dstBuffer); |
| 1558 |
|
| 1559 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 1560 |
|
| 1561 |
fillSize = vk_buffer_range(&dst->vk, dstOffset, fillSize); |
| 1562 |
|
| 1563 |
/* From the Vulkan spec: |
| 1564 |
* |
| 1565 |
* "size is the number of bytes to fill, and must be either a multiple |
| 1566 |
* of 4, or VK_WHOLE_SIZE to fill the range from offset to the end of |
| 1567 |
* the buffer. If VK_WHOLE_SIZE is used and the remaining size of the |
| 1568 |
* buffer is not a multiple of 4, then the nearest smaller multiple is |
| 1569 |
* used." |
| 1570 |
*/ |
| 1571 |
fillSize &= ~3ULL; |
| 1572 |
|
| 1573 |
pvr_cmd_copy_buffer_region(cmd_buffer, |
| 1574 |
PVR_DEV_ADDR_INVALID, |
| 1575 |
0, |
| 1576 |
dst->dev_addr, |
| 1577 |
dstOffset, |
| 1578 |
fillSize, |
| 1579 |
data, |
| 1580 |
true); |
| 1581 |
} |
| 1582 |
|
| 1583 |
/** |
| 1584 |
* \brief Returns the maximum number of layers to clear starting from base_layer |
| 1585 |
* that contain or match the target rectangle. |
| 1586 |
* |
| 1587 |
* \param[in] target_rect The region which the clear should contain or |
| 1588 |
* match. |
| 1589 |
* \param[in] base_layer The layer index to start at. |
| 1590 |
* \param[in] clear_rect_count Amount of clear_rects |
| 1591 |
* \param[in] clear_rects Array of clear rects. |
| 1592 |
* |
| 1593 |
* \return Max number of layers that cover or match the target region. |
| 1594 |
*/ |
| 1595 |
static uint32_t |
| 1596 |
pvr_get_max_layers_covering_target(VkRect2D target_rect, |
| 1597 |
uint32_t base_layer, |
| 1598 |
uint32_t clear_rect_count, |
| 1599 |
const VkClearRect *clear_rects) |
| 1600 |
{ |
| 1601 |
const int32_t target_x0 = target_rect.offset.x; |
| 1602 |
const int32_t target_x1 = target_x0 + (int32_t)target_rect.extent.width; |
| 1603 |
const int32_t target_y0 = target_rect.offset.y; |
| 1604 |
const int32_t target_y1 = target_y0 + (int32_t)target_rect.extent.height; |
| 1605 |
|
| 1606 |
uint32_t layer_count = 0; |
| 1607 |
|
| 1608 |
assert((int64_t)target_x0 + (int64_t)target_rect.extent.width <= INT32_MAX); |
| 1609 |
assert((int64_t)target_y0 + (int64_t)target_rect.extent.height <= INT32_MAX); |
| 1610 |
|
| 1611 |
for (uint32_t i = 0; i < clear_rect_count; i++) { |
| 1612 |
const VkClearRect *clear_rect = &clear_rects[i]; |
| 1613 |
const uint32_t max_layer = |
| 1614 |
clear_rect->baseArrayLayer + clear_rect->layerCount; |
| 1615 |
bool target_is_covered; |
| 1616 |
int32_t x0, x1; |
| 1617 |
int32_t y0, y1; |
| 1618 |
|
| 1619 |
if (clear_rect->baseArrayLayer == 0) |
| 1620 |
continue; |
| 1621 |
|
| 1622 |
assert((uint64_t)clear_rect->baseArrayLayer + clear_rect->layerCount <= |
| 1623 |
UINT32_MAX); |
| 1624 |
|
| 1625 |
/* Check for layer intersection. */ |
| 1626 |
if (clear_rect->baseArrayLayer > base_layer || max_layer <= base_layer) |
| 1627 |
continue; |
| 1628 |
|
| 1629 |
x0 = clear_rect->rect.offset.x; |
| 1630 |
x1 = x0 + (int32_t)clear_rect->rect.extent.width; |
| 1631 |
y0 = clear_rect->rect.offset.y; |
| 1632 |
y1 = y0 + (int32_t)clear_rect->rect.extent.height; |
| 1633 |
|
| 1634 |
assert((int64_t)x0 + (int64_t)clear_rect->rect.extent.width <= INT32_MAX); |
| 1635 |
assert((int64_t)y0 + (int64_t)clear_rect->rect.extent.height <= |
| 1636 |
INT32_MAX); |
| 1637 |
|
| 1638 |
target_is_covered = x0 <= target_x0 && x1 >= target_x1; |
| 1639 |
target_is_covered &= y0 <= target_y0 && y1 >= target_y1; |
| 1640 |
|
| 1641 |
if (target_is_covered) |
| 1642 |
layer_count = MAX2(layer_count, max_layer - base_layer); |
| 1643 |
} |
| 1644 |
|
| 1645 |
return layer_count; |
| 1646 |
} |
| 1647 |
|
| 1648 |
/* Return true if vertex shader is required to output render target id to pick |
| 1649 |
* the texture array layer. |
| 1650 |
*/ |
| 1651 |
static inline bool |
| 1652 |
pvr_clear_needs_rt_id_output(struct pvr_device_info *dev_info, |
| 1653 |
bool multiview_enabled, |
| 1654 |
uint32_t rect_count, |
| 1655 |
const VkClearRect *rects) |
| 1656 |
{ |
| 1657 |
if (!PVR_HAS_FEATURE(dev_info, gs_rta_support) || multiview_enabled) |
| 1658 |
return false; |
| 1659 |
|
| 1660 |
for (uint32_t i = 0; i < rect_count; i++) { |
| 1661 |
if (rects[i].baseArrayLayer != 0 || rects[i].layerCount > 1) |
| 1662 |
return true; |
| 1663 |
} |
| 1664 |
|
| 1665 |
return false; |
| 1666 |
} |
| 1667 |
|
| 1668 |
static VkResult pvr_clear_color_attachment_static_create_consts_buffer( |
| 1669 |
struct pvr_cmd_buffer *cmd_buffer, |
| 1670 |
const struct pvr_clear_attach_props *props, |
| 1671 |
const uint32_t clear_color[static const PVR_CLEAR_COLOR_ARRAY_SIZE], |
| 1672 |
bool uses_tile_buffer, |
| 1673 |
uint32_t tile_buffer_idx, |
| 1674 |
struct pvr_suballoc_bo **const const_shareds_buffer_out) |
| 1675 |
{ |
| 1676 |
struct pvr_device *device = cmd_buffer->device; |
| 1677 |
struct pvr_suballoc_bo *const_shareds_buffer; |
| 1678 |
struct pvr_bo *tile_buffer; |
| 1679 |
uint64_t tile_dev_addr = 0; |
| 1680 |
uint32_t *buffer; |
| 1681 |
VkResult result; |
| 1682 |
|
| 1683 |
/* TODO: This doesn't need to be aligned to slc size. Alignment to 4 is fine. |
| 1684 |
* Change pvr_arch_cmd_buffer_alloc_mem() to take in an alignment? |
| 1685 |
*/ |
| 1686 |
/* TODO: only allocate what's needed, not always |
| 1687 |
* _PVR_CLEAR_ATTACH_DATA_COUNT? */ |
| 1688 |
result = pvr_arch_cmd_buffer_alloc_mem(cmd_buffer, |
| 1689 |
device->heaps.general_heap, |
| 1690 |
_PVR_CLEAR_ATTACH_DATA_COUNT, |
| 1691 |
&const_shareds_buffer); |
| 1692 |
if (result != VK_SUCCESS) |
| 1693 |
return result; |
| 1694 |
|
| 1695 |
buffer = pvr_bo_suballoc_get_map_addr(const_shareds_buffer); |
| 1696 |
|
| 1697 |
buffer[PVR_CLEAR_ATTACH_DATA_DWORD0] = clear_color[0]; |
| 1698 |
buffer[PVR_CLEAR_ATTACH_DATA_DWORD1] = clear_color[1]; |
| 1699 |
buffer[PVR_CLEAR_ATTACH_DATA_DWORD2] = clear_color[2]; |
| 1700 |
buffer[PVR_CLEAR_ATTACH_DATA_DWORD3] = clear_color[3]; |
| 1701 |
|
| 1702 |
if (uses_tile_buffer) { |
| 1703 |
tile_buffer = device->tile_buffer_state.buffers[tile_buffer_idx]; |
| 1704 |
tile_dev_addr = tile_buffer->vma->dev_addr.addr; |
| 1705 |
} |
| 1706 |
|
| 1707 |
buffer[PVR_CLEAR_ATTACH_DATA_TILE_ADDR_LO] = tile_dev_addr & 0xffffffff; |
| 1708 |
buffer[PVR_CLEAR_ATTACH_DATA_TILE_ADDR_HI] = tile_dev_addr >> 32; |
| 1709 |
|
| 1710 |
*const_shareds_buffer_out = const_shareds_buffer; |
| 1711 |
|
| 1712 |
return VK_SUCCESS; |
| 1713 |
} |
| 1714 |
|
| 1715 |
static VkResult pvr_clear_color_attachment_static( |
| 1716 |
struct pvr_cmd_buffer *cmd_buffer, |
| 1717 |
const struct usc_mrt_resource *mrt_resource, |
| 1718 |
VkFormat format, |
| 1719 |
uint32_t clear_color[static const PVR_CLEAR_COLOR_ARRAY_SIZE], |
| 1720 |
uint32_t template_idx, |
| 1721 |
uint32_t stencil, |
| 1722 |
bool vs_has_rt_id_output) |
| 1723 |
{ |
| 1724 |
struct pvr_device *device = cmd_buffer->device; |
| 1725 |
ASSERTED const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 1726 |
ASSERTED const bool has_eight_output_registers = |
| 1727 |
PVR_HAS_FEATURE(dev_info, eight_output_registers); |
| 1728 |
const struct pvr_device_static_clear_state *dev_clear_state = |
| 1729 |
device->static_clear_state; |
| 1730 |
const bool uses_tile_buffer = mrt_resource->type == |
| 1731 |
USC_MRT_RESOURCE_TYPE_MEMORY; |
| 1732 |
const struct pvr_pds_clear_attachment_program_info *clear_attachment_program; |
| 1733 |
struct pvr_pds_pixel_shader_sa_program texture_program; |
| 1734 |
uint32_t pds_state[PVR_PDS_STATE_LENGTH]; |
| 1735 |
struct pvr_suballoc_bo *pds_texture_program_bo; |
| 1736 |
struct pvr_static_clear_ppp_template template; |
| 1737 |
struct pvr_suballoc_bo *const_shareds_buffer; |
| 1738 |
uint64_t pds_texture_program_addr; |
| 1739 |
struct pvr_suballoc_bo *pvr_bo; |
| 1740 |
uint32_t tile_buffer_idx = 0; |
| 1741 |
uint32_t out_reg_count; |
| 1742 |
uint32_t output_offset; |
| 1743 |
uint32_t program_idx; |
| 1744 |
uint32_t *buffer; |
| 1745 |
VkResult result; |
| 1746 |
|
| 1747 |
out_reg_count = |
| 1748 |
DIV_ROUND_UP(pvr_get_pbe_accum_format_size_in_bytes(format), 4U); |
| 1749 |
|
| 1750 |
if (uses_tile_buffer) { |
| 1751 |
tile_buffer_idx = mrt_resource->mem.tile_buffer; |
| 1752 |
output_offset = mrt_resource->mem.offset_dw; |
| 1753 |
} else { |
| 1754 |
output_offset = mrt_resource->reg.output_reg; |
| 1755 |
} |
| 1756 |
|
| 1757 |
assert(has_eight_output_registers || out_reg_count + output_offset <= 4); |
| 1758 |
|
| 1759 |
struct pvr_clear_attach_props props = { |
| 1760 |
.dword_count = out_reg_count, |
| 1761 |
.offset = output_offset, |
| 1762 |
.uses_tile_buffer = uses_tile_buffer, |
| 1763 |
}; |
| 1764 |
|
| 1765 |
program_idx = pvr_uscgen_clear_attach_index(&props); |
| 1766 |
|
| 1767 |
result = pvr_clear_color_attachment_static_create_consts_buffer( |
| 1768 |
cmd_buffer, |
| 1769 |
&props, |
| 1770 |
clear_color, |
| 1771 |
uses_tile_buffer, |
| 1772 |
tile_buffer_idx, |
| 1773 |
&const_shareds_buffer); |
| 1774 |
if (result != VK_SUCCESS) |
| 1775 |
return result; |
| 1776 |
|
| 1777 |
texture_program = |
| 1778 |
(struct pvr_pds_pixel_shader_sa_program){ .num_texture_dma_kicks = 1, |
| 1779 |
.texture_dma_address = { |
| 1780 |
[0] = const_shareds_buffer |
| 1781 |
->dev_addr.addr, |
| 1782 |
} }; |
| 1783 |
|
| 1784 |
pvr_csb_pack (&texture_program.texture_dma_control[0], |
| 1785 |
PDSINST_DOUT_FIELDS_DOUTD_SRC1, |
| 1786 |
doutd_src1) { |
| 1787 |
doutd_src1.dest = ROGUE_PDSINST_DOUTD_DEST_COMMON_STORE; |
| 1788 |
doutd_src1.bsize = _PVR_CLEAR_ATTACH_DATA_COUNT; |
| 1789 |
} |
| 1790 |
|
| 1791 |
clear_attachment_program = |
| 1792 |
&dev_clear_state->pds_clear_attachment_program_info[program_idx]; |
| 1793 |
|
| 1794 |
/* TODO: This doesn't need to be aligned to slc size. Alignment to 4 is fine. |
| 1795 |
* Change pvr_arch_cmd_buffer_alloc_mem() to take in an alignment? |
| 1796 |
*/ |
| 1797 |
result = pvr_arch_cmd_buffer_alloc_mem( |
| 1798 |
cmd_buffer, |
| 1799 |
device->heaps.pds_heap, |
| 1800 |
clear_attachment_program->texture_program_data_size, |
| 1801 |
&pds_texture_program_bo); |
| 1802 |
if (result != VK_SUCCESS) { |
| 1803 |
list_del(&const_shareds_buffer->link); |
| 1804 |
pvr_bo_suballoc_free(const_shareds_buffer); |
| 1805 |
|
| 1806 |
return result; |
| 1807 |
} |
| 1808 |
|
| 1809 |
buffer = pvr_bo_suballoc_get_map_addr(pds_texture_program_bo); |
| 1810 |
pds_texture_program_addr = pds_texture_program_bo->dev_addr.addr - |
| 1811 |
device->heaps.pds_heap->base_addr.addr; |
| 1812 |
|
| 1813 |
pvr_pds_generate_pixel_shader_sa_texture_state_data( |
| 1814 |
&texture_program, |
| 1815 |
buffer, |
| 1816 |
&device->pdevice->dev_info); |
| 1817 |
|
| 1818 |
pvr_csb_pack (&pds_state[PVR_STATIC_CLEAR_PPP_PDS_TYPE_SHADERBASE], |
| 1819 |
TA_STATE_PDS_SHADERBASE, |
| 1820 |
shaderbase) { |
| 1821 |
shaderbase.addr = clear_attachment_program->pixel_program_offset; |
| 1822 |
} |
| 1823 |
|
| 1824 |
pvr_csb_pack (&pds_state[PVR_STATIC_CLEAR_PPP_PDS_TYPE_TEXUNICODEBASE], |
| 1825 |
TA_STATE_PDS_TEXUNICODEBASE, |
| 1826 |
texunicodebase) { |
| 1827 |
texunicodebase.addr = clear_attachment_program->texture_program_offset; |
| 1828 |
} |
| 1829 |
|
| 1830 |
pvr_csb_pack (&pds_state[PVR_STATIC_CLEAR_PPP_PDS_TYPE_SIZEINFO1], |
| 1831 |
TA_STATE_PDS_SIZEINFO1, |
| 1832 |
sizeinfo1) { |
| 1833 |
sizeinfo1.pds_texturestatesize = DIV_ROUND_UP( |
| 1834 |
clear_attachment_program->texture_program_data_size, |
| 1835 |
ROGUE_TA_STATE_PDS_SIZEINFO1_PDS_TEXTURESTATESIZE_UNIT_SIZE); |
| 1836 |
|
| 1837 |
sizeinfo1.pds_tempsize = |
| 1838 |
DIV_ROUND_UP(clear_attachment_program->texture_program_pds_temps_count, |
| 1839 |
ROGUE_TA_STATE_PDS_SIZEINFO1_PDS_TEMPSIZE_UNIT_SIZE); |
| 1840 |
} |
| 1841 |
|
| 1842 |
pvr_csb_pack (&pds_state[PVR_STATIC_CLEAR_PPP_PDS_TYPE_SIZEINFO2], |
| 1843 |
TA_STATE_PDS_SIZEINFO2, |
| 1844 |
sizeinfo2) { |
| 1845 |
sizeinfo2.usc_sharedsize = |
| 1846 |
DIV_ROUND_UP(_PVR_CLEAR_ATTACH_DATA_COUNT, |
| 1847 |
ROGUE_TA_STATE_PDS_SIZEINFO2_USC_SHAREDSIZE_UNIT_SIZE); |
| 1848 |
} |
| 1849 |
|
| 1850 |
/* Dummy coefficient loading program. */ |
| 1851 |
pds_state[PVR_STATIC_CLEAR_PPP_PDS_TYPE_VARYINGBASE] = 0; |
| 1852 |
|
| 1853 |
pvr_csb_pack (&pds_state[PVR_STATIC_CLEAR_PPP_PDS_TYPE_TEXTUREDATABASE], |
| 1854 |
TA_STATE_PDS_TEXTUREDATABASE, |
| 1855 |
texturedatabase) { |
| 1856 |
texturedatabase.addr = PVR_DEV_ADDR(pds_texture_program_addr); |
| 1857 |
} |
| 1858 |
|
| 1859 |
assert(template_idx < PVR_STATIC_CLEAR_VARIANT_COUNT); |
| 1860 |
template = |
| 1861 |
cmd_buffer->device->static_clear_state->ppp_templates[template_idx]; |
| 1862 |
|
| 1863 |
template.config.pds_state = &pds_state; |
| 1864 |
|
| 1865 |
template.config.ispctl.upass = |
| 1866 |
cmd_buffer->state.render_pass_info.isp_userpass; |
| 1867 |
|
| 1868 |
if (template_idx & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1869 |
/* clang-format off */ |
| 1870 |
template.config.ispa.sref = stencil & ROGUE_TA_STATE_ISPA_SREF_SIZE_MAX; |
| 1871 |
/* clang-format on */ |
| 1872 |
} |
| 1873 |
|
| 1874 |
if (vs_has_rt_id_output) { |
| 1875 |
template.config.output_sel.rhw_pres = true; |
| 1876 |
template.config.output_sel.render_tgt_pres = true; |
| 1877 |
template.config.output_sel.vtxsize = 4 + 1; |
| 1878 |
} |
| 1879 |
|
| 1880 |
result = pvr_emit_ppp_from_template( |
| 1881 |
&cmd_buffer->state.current_sub_cmd->gfx.control_stream, |
| 1882 |
&template, |
| 1883 |
&pvr_bo); |
| 1884 |
if (result != VK_SUCCESS) { |
| 1885 |
list_del(&pds_texture_program_bo->link); |
| 1886 |
pvr_bo_suballoc_free(pds_texture_program_bo); |
| 1887 |
|
| 1888 |
list_del(&const_shareds_buffer->link); |
| 1889 |
pvr_bo_suballoc_free(const_shareds_buffer); |
| 1890 |
|
| 1891 |
return pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result); |
| 1892 |
} |
| 1893 |
|
| 1894 |
list_add(&pvr_bo->link, &cmd_buffer->bo_list); |
| 1895 |
|
| 1896 |
return VK_SUCCESS; |
| 1897 |
} |
| 1898 |
|
| 1899 |
static void |
| 1900 |
pvr_set_rta_clear_layer_depth(const struct pvr_image_view *image_view, |
| 1901 |
uint32_t view_layer, |
| 1902 |
uint32_t *image_layer, |
| 1903 |
float *image_depth) |
| 1904 |
{ |
| 1905 |
const struct pvr_image *image = vk_to_pvr_image(image_view->vk.image); |
| 1906 |
uint32_t view_image_layer = image_view->vk.base_array_layer + view_layer; |
| 1907 |
|
| 1908 |
/* Convert layer to depth for 2D array views of 3D images */ |
| 1909 |
if (image->memlayout == PVR_MEMLAYOUT_3DTWIDDLED) { |
| 1910 |
/* Vulkan does not have a 3D array image view type, so for RTAs the |
| 1911 |
* view must be a 2D array view of a 3D image. |
| 1912 |
*/ |
| 1913 |
assert(image_view->vk.view_type == VK_IMAGE_VIEW_TYPE_2D_ARRAY); |
| 1914 |
|
| 1915 |
*image_layer = 0; |
| 1916 |
*image_depth = (float) view_image_layer; |
| 1917 |
} else { |
| 1918 |
*image_layer = view_image_layer; |
| 1919 |
*image_depth = 0.0f; |
| 1920 |
} |
| 1921 |
} |
| 1922 |
|
| 1923 |
/** |
| 1924 |
* \brief Record a deferred clear operation into the command buffer. |
| 1925 |
* |
| 1926 |
* Devices which don't have gs_rta_support require extra handling for RTA |
| 1927 |
* clears. We setup a list of deferred clear transfer commands which will be |
| 1928 |
* processed at the end of the graphics sub command to account for the missing |
| 1929 |
* feature. |
| 1930 |
*/ |
| 1931 |
static VkResult pvr_add_deferred_rta_clear(struct pvr_cmd_buffer *cmd_buffer, |
| 1932 |
const VkClearAttachment *attachment, |
| 1933 |
const VkClearRect *rect, |
| 1934 |
bool is_render_init) |
| 1935 |
{ |
| 1936 |
struct pvr_render_pass_info *pass_info = &cmd_buffer->state.render_pass_info; |
| 1937 |
struct pvr_sub_cmd_gfx *sub_cmd = &cmd_buffer->state.current_sub_cmd->gfx; |
| 1938 |
const struct pvr_renderpass_hwsetup_render *hw_render = |
| 1939 |
pvr_arch_pass_info_get_hw_render(pass_info, sub_cmd->hw_render_idx); |
| 1940 |
const struct pvr_image_view *image_view = NULL; |
| 1941 |
const struct pvr_image *image = NULL; |
| 1942 |
uint32_t attachment_index; |
| 1943 |
|
| 1944 |
const VkOffset3D offset = { |
| 1945 |
.x = rect->rect.offset.x, |
| 1946 |
.y = rect->rect.offset.y, |
| 1947 |
.z = 1, |
| 1948 |
}; |
| 1949 |
const VkExtent3D extent = { |
| 1950 |
.width = rect->rect.extent.width, |
| 1951 |
.height = rect->rect.extent.height, |
| 1952 |
.depth = 1, |
| 1953 |
}; |
| 1954 |
|
| 1955 |
assert( |
| 1956 |
!PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, gs_rta_support)); |
| 1957 |
|
| 1958 |
/* From the Vulkan 1.3.229 spec VUID-VkClearAttachment-aspectMask-00019: |
| 1959 |
* |
| 1960 |
* "If aspectMask includes VK_IMAGE_ASPECT_COLOR_BIT, it must not |
| 1961 |
* include VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT" |
| 1962 |
* |
| 1963 |
*/ |
| 1964 |
if (attachment->aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 1965 |
assert(attachment->aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT || |
| 1966 |
attachment->aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT || |
| 1967 |
attachment->aspectMask == |
| 1968 |
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); |
| 1969 |
|
| 1970 |
attachment_index = hw_render->ds_attach_idx; |
| 1971 |
} else if (is_render_init) { |
| 1972 |
assert(attachment->colorAttachment < hw_render->color_init_count); |
| 1973 |
attachment_index = |
| 1974 |
hw_render->color_init[attachment->colorAttachment].index; |
| 1975 |
} else if (cmd_buffer->state.current_sub_cmd->is_dynamic_render) { |
| 1976 |
const struct pvr_dynamic_render_info *dr_info = pass_info->dr_info; |
| 1977 |
attachment_index = |
| 1978 |
dr_info->color_attachments[attachment->colorAttachment].index_color; |
| 1979 |
} else { |
| 1980 |
const struct pvr_renderpass_hwsetup_subpass *hw_pass = |
| 1981 |
pvr_arch_get_hw_subpass(pass_info->pass, pass_info->subpass_idx); |
| 1982 |
const struct pvr_render_subpass *sub_pass = |
| 1983 |
&pass_info->pass->subpasses[hw_pass->index]; |
| 1984 |
attachment_index = |
| 1985 |
sub_pass->color_attachments[attachment->colorAttachment]; |
| 1986 |
assert(attachment->colorAttachment < sub_pass->color_count); |
| 1987 |
} |
| 1988 |
|
| 1989 |
if (pass_info->attachments) { |
| 1990 |
image_view = pass_info->attachments[attachment_index]; |
| 1991 |
image = vk_to_pvr_image(image_view->vk.image); |
| 1992 |
} else { |
| 1993 |
assert(cmd_buffer->vk.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY && |
| 1994 |
(cmd_buffer->usage_flags & |
| 1995 |
VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)); |
| 1996 |
} |
| 1997 |
|
| 1998 |
for (uint32_t i = 0; i < rect->layerCount; i++) { |
| 1999 |
uint32_t rt_id = rect->baseArrayLayer + i; |
| 2000 |
/* Do not defer the clear of active render target */ |
| 2001 |
if (hw_render->view_mask & (1 << rt_id)) |
| 2002 |
continue; |
| 2003 |
|
| 2004 |
if (pass_info->attachments) { |
| 2005 |
struct pvr_transfer_cmd *transfer_cmd; |
| 2006 |
float depth = 0.0f; |
| 2007 |
uint32_t layer = 0; |
| 2008 |
|
| 2009 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 2010 |
if (!transfer_cmd) |
| 2011 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2012 |
|
| 2013 |
list_addtail(&transfer_cmd->link, &cmd_buffer->deferred_clears); |
| 2014 |
|
| 2015 |
transfer_cmd->flags = PVR_TRANSFER_CMD_FLAGS_FILL; |
| 2016 |
|
| 2017 |
if (attachment->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2018 |
for (uint32_t j = 0; j < ARRAY_SIZE(transfer_cmd->clear_color); |
| 2019 |
j++) { |
| 2020 |
transfer_cmd->clear_color[j].ui = |
| 2021 |
attachment->clearValue.color.uint32[j]; |
| 2022 |
} |
| 2023 |
} else { |
| 2024 |
transfer_cmd->clear_color[0].f = |
| 2025 |
attachment->clearValue.depthStencil.depth; |
| 2026 |
transfer_cmd->clear_color[1].ui = |
| 2027 |
attachment->clearValue.depthStencil.stencil; |
| 2028 |
} |
| 2029 |
|
| 2030 |
pvr_set_rta_clear_layer_depth(image_view, rt_id, &layer, &depth); |
| 2031 |
pvr_setup_transfer_surface(cmd_buffer->device, |
| 2032 |
&transfer_cmd->dst, |
| 2033 |
&transfer_cmd->scissor, |
| 2034 |
image, |
| 2035 |
layer, |
| 2036 |
0, |
| 2037 |
&offset, |
| 2038 |
&extent, |
| 2039 |
depth, |
| 2040 |
image->vk.format, |
| 2041 |
attachment->aspectMask); |
| 2042 |
} else { |
| 2043 |
struct pvr_unbound_deferred_clear recorded_clear; |
| 2044 |
|
| 2045 |
if (attachment->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2046 |
for (uint32_t j = 0; j < ARRAY_SIZE(recorded_clear.clear_color); |
| 2047 |
j++) { |
| 2048 |
recorded_clear.clear_color[j].ui = |
| 2049 |
attachment->clearValue.color.uint32[j]; |
| 2050 |
} |
| 2051 |
} else { |
| 2052 |
recorded_clear.clear_color[0].f = |
| 2053 |
attachment->clearValue.depthStencil.depth; |
| 2054 |
recorded_clear.clear_color[1].ui = |
| 2055 |
attachment->clearValue.depthStencil.stencil; |
| 2056 |
} |
| 2057 |
|
| 2058 |
recorded_clear.extent = extent; |
| 2059 |
recorded_clear.offset = offset; |
| 2060 |
recorded_clear.array_layer = rt_id; |
| 2061 |
recorded_clear.aspect_mask = attachment->aspectMask; |
| 2062 |
recorded_clear.attachment_index = attachment_index; |
| 2063 |
|
| 2064 |
util_dynarray_append(&sub_cmd->unbound_deferred_clears, |
| 2065 |
recorded_clear); |
| 2066 |
} |
| 2067 |
} |
| 2068 |
|
| 2069 |
return VK_SUCCESS; |
| 2070 |
} |
| 2071 |
|
| 2072 |
VkResult pvr_bind_unbound_deferred_clear( |
| 2073 |
struct pvr_cmd_buffer *cmd_buffer, |
| 2074 |
struct pvr_unbound_deferred_clear *recorded_clear) |
| 2075 |
{ |
| 2076 |
struct pvr_render_pass_info *pass_info = &cmd_buffer->state.render_pass_info; |
| 2077 |
const struct pvr_image_view *image_view; |
| 2078 |
struct pvr_transfer_cmd *transfer_cmd; |
| 2079 |
const struct pvr_image *image; |
| 2080 |
float depth = 0.0f; |
| 2081 |
uint32_t layer = 0; |
| 2082 |
|
| 2083 |
image_view = pass_info->attachments[recorded_clear->attachment_index]; |
| 2084 |
image = vk_to_pvr_image(image_view->vk.image); |
| 2085 |
|
| 2086 |
transfer_cmd = pvr_transfer_cmd_alloc(cmd_buffer); |
| 2087 |
if (!transfer_cmd) |
| 2088 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2089 |
|
| 2090 |
list_addtail(&transfer_cmd->link, &cmd_buffer->deferred_clears); |
| 2091 |
|
| 2092 |
transfer_cmd->flags = PVR_TRANSFER_CMD_FLAGS_FILL; |
| 2093 |
|
| 2094 |
if (recorded_clear->aspect_mask == VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2095 |
for (uint32_t i = 0; i < ARRAY_SIZE(transfer_cmd->clear_color); i++) |
| 2096 |
transfer_cmd->clear_color[i].ui = recorded_clear->clear_color[i].ui; |
| 2097 |
} else { |
| 2098 |
transfer_cmd->clear_color[0].f = recorded_clear->clear_color[0].f; |
| 2099 |
transfer_cmd->clear_color[1].ui = recorded_clear->clear_color[1].ui; |
| 2100 |
} |
| 2101 |
|
| 2102 |
pvr_set_rta_clear_layer_depth(image_view, |
| 2103 |
recorded_clear->array_layer, |
| 2104 |
&layer, |
| 2105 |
&depth); |
| 2106 |
pvr_setup_transfer_surface(cmd_buffer->device, |
| 2107 |
&transfer_cmd->dst, |
| 2108 |
&transfer_cmd->scissor, |
| 2109 |
image, |
| 2110 |
layer, |
| 2111 |
0, |
| 2112 |
&recorded_clear->offset, |
| 2113 |
&recorded_clear->extent, |
| 2114 |
depth, |
| 2115 |
image->vk.format, |
| 2116 |
recorded_clear->aspect_mask); |
| 2117 |
|
| 2118 |
return VK_SUCCESS; |
| 2119 |
} |
| 2120 |
|
| 2121 |
static void pvr_clear_attachments(struct pvr_cmd_buffer *cmd_buffer, |
| 2122 |
uint32_t attachment_count, |
| 2123 |
const VkClearAttachment *attachments, |
| 2124 |
uint32_t rect_count, |
| 2125 |
const VkClearRect *rects, |
| 2126 |
bool is_render_init) |
| 2127 |
{ |
| 2128 |
const struct pvr_render_pass *pass = cmd_buffer->state.render_pass_info.pass; |
| 2129 |
struct pvr_render_pass_info *pass_info = &cmd_buffer->state.render_pass_info; |
| 2130 |
struct pvr_sub_cmd_gfx *sub_cmd = &cmd_buffer->state.current_sub_cmd->gfx; |
| 2131 |
struct pvr_device_info *dev_info = &cmd_buffer->device->pdevice->dev_info; |
| 2132 |
const struct pvr_renderpass_hwsetup_subpass *hw_pass; |
| 2133 |
bool vs_has_rt_id_output, multiview_enabled; |
| 2134 |
uint32_t vs_output_size_in_bytes; |
| 2135 |
|
| 2136 |
/* TODO: This function can be optimized so that most of the device memory |
| 2137 |
* gets allocated together in one go and then filled as needed. There might |
| 2138 |
* also be opportunities to reuse pds code and data segments. |
| 2139 |
*/ |
| 2140 |
|
| 2141 |
if (pass) { |
| 2142 |
hw_pass = pvr_arch_get_hw_subpass(pass, pass_info->subpass_idx); |
| 2143 |
multiview_enabled = pass->multiview_enabled; |
| 2144 |
} else { |
| 2145 |
multiview_enabled = pass_info->dr_info->hw_render.multiview_enabled; |
| 2146 |
hw_pass = NULL; |
| 2147 |
} |
| 2148 |
|
| 2149 |
assert(cmd_buffer->state.current_sub_cmd->type == PVR_SUB_CMD_TYPE_GRAPHICS); |
| 2150 |
|
| 2151 |
pvr_arch_reset_graphics_dirty_state(cmd_buffer, false); |
| 2152 |
|
| 2153 |
/* We'll be emitting to the control stream. */ |
| 2154 |
sub_cmd->empty_cmd = false; |
| 2155 |
|
| 2156 |
vs_has_rt_id_output = pvr_clear_needs_rt_id_output(dev_info, |
| 2157 |
multiview_enabled, |
| 2158 |
rect_count, |
| 2159 |
rects); |
| 2160 |
|
| 2161 |
/* 4 because we're expecting the USC to output X, Y, Z, and W. */ |
| 2162 |
vs_output_size_in_bytes = PVR_DW_TO_BYTES(4); |
| 2163 |
if (vs_has_rt_id_output) |
| 2164 |
vs_output_size_in_bytes += PVR_DW_TO_BYTES(1); |
| 2165 |
|
| 2166 |
for (uint32_t i = 0; i < attachment_count; i++) { |
| 2167 |
const VkClearAttachment *attachment = &attachments[i]; |
| 2168 |
struct pvr_pds_vertex_shader_program pds_program; |
| 2169 |
struct pvr_pds_upload pds_program_upload = { 0 }; |
| 2170 |
uint64_t current_base_array_layer = ~0; |
| 2171 |
VkResult result; |
| 2172 |
float depth; |
| 2173 |
|
| 2174 |
if (attachment->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2175 |
uint32_t packed_clear_color[PVR_CLEAR_COLOR_ARRAY_SIZE]; |
| 2176 |
struct pvr_renderpass_hwsetup_render *hw_render; |
| 2177 |
const struct usc_mrt_resource *mrt_resource; |
| 2178 |
uint32_t global_attachment_idx; |
| 2179 |
uint32_t local_attachment_idx; |
| 2180 |
VkFormat format; |
| 2181 |
|
| 2182 |
local_attachment_idx = attachment->colorAttachment; |
| 2183 |
|
| 2184 |
assert(cmd_buffer->state.current_sub_cmd->is_dynamic_render || |
| 2185 |
pass->hw_setup->render_count > 0); |
| 2186 |
hw_render = pvr_arch_pass_info_get_hw_render( |
| 2187 |
&cmd_buffer->state.render_pass_info, |
| 2188 |
0); |
| 2189 |
|
| 2190 |
/* TODO: verify that the hw_render if is_render_init is true is |
| 2191 |
* exclusive to a non dynamic rendering path. |
| 2192 |
*/ |
| 2193 |
if (is_render_init) { |
| 2194 |
mrt_resource = |
| 2195 |
&hw_render->init_setup.mrt_resources[local_attachment_idx]; |
| 2196 |
|
| 2197 |
assert(local_attachment_idx < hw_render->color_init_count); |
| 2198 |
global_attachment_idx = |
| 2199 |
hw_render->color_init[local_attachment_idx].index; |
| 2200 |
} else if (cmd_buffer->state.current_sub_cmd->is_dynamic_render) { |
| 2201 |
const struct pvr_dynamic_render_info *dr_info = pass_info->dr_info; |
| 2202 |
|
| 2203 |
mrt_resource = |
| 2204 |
&dr_info->mrt_setup->mrt_resources[local_attachment_idx]; |
| 2205 |
global_attachment_idx = |
| 2206 |
dr_info->color_attachments[local_attachment_idx].index_color; |
| 2207 |
} else { |
| 2208 |
struct pvr_render_subpass *sub_pass = |
| 2209 |
&pass->subpasses[hw_pass->index]; |
| 2210 |
|
| 2211 |
mrt_resource = &hw_pass->setup.mrt_resources[local_attachment_idx]; |
| 2212 |
|
| 2213 |
assert(local_attachment_idx < sub_pass->color_count); |
| 2214 |
global_attachment_idx = |
| 2215 |
sub_pass->color_attachments[local_attachment_idx]; |
| 2216 |
} |
| 2217 |
|
| 2218 |
if (global_attachment_idx == VK_ATTACHMENT_UNUSED) |
| 2219 |
continue; |
| 2220 |
|
| 2221 |
if (cmd_buffer->state.current_sub_cmd->is_dynamic_render) { |
| 2222 |
const struct pvr_dynamic_render_info *dr_info = pass_info->dr_info; |
| 2223 |
|
| 2224 |
format = dr_info->attachments[global_attachment_idx].vk_format; |
| 2225 |
} else { |
| 2226 |
assert(global_attachment_idx < pass->attachment_count); |
| 2227 |
format = pass->attachments[global_attachment_idx].vk_format; |
| 2228 |
} |
| 2229 |
|
| 2230 |
assert(format != VK_FORMAT_UNDEFINED); |
| 2231 |
|
| 2232 |
pvr_get_hw_clear_color(format, |
| 2233 |
attachment->clearValue.color, |
| 2234 |
packed_clear_color); |
| 2235 |
|
| 2236 |
result = pvr_clear_color_attachment_static(cmd_buffer, |
| 2237 |
mrt_resource, |
| 2238 |
format, |
| 2239 |
packed_clear_color, |
| 2240 |
VK_IMAGE_ASPECT_COLOR_BIT, |
| 2241 |
0, |
| 2242 |
vs_has_rt_id_output); |
| 2243 |
if (result != VK_SUCCESS) |
| 2244 |
return; |
| 2245 |
} else if (pass && hw_pass->z_replicate != -1 && |
| 2246 |
attachment->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2247 |
const VkClearColorValue clear_color = { |
| 2248 |
.float32 = { [0] = attachment->clearValue.depthStencil.depth, }, |
| 2249 |
}; |
| 2250 |
const uint32_t template_idx = attachment->aspectMask | |
| 2251 |
VK_IMAGE_ASPECT_COLOR_BIT; |
| 2252 |
const uint32_t stencil = attachment->clearValue.depthStencil.stencil; |
| 2253 |
uint32_t packed_clear_color[PVR_CLEAR_COLOR_ARRAY_SIZE]; |
| 2254 |
const struct usc_mrt_resource *mrt_resource; |
| 2255 |
|
| 2256 |
mrt_resource = &hw_pass->setup.mrt_resources[hw_pass->z_replicate]; |
| 2257 |
|
| 2258 |
pvr_get_hw_clear_color(VK_FORMAT_R32_SFLOAT, |
| 2259 |
clear_color, |
| 2260 |
packed_clear_color); |
| 2261 |
|
| 2262 |
result = pvr_clear_color_attachment_static(cmd_buffer, |
| 2263 |
mrt_resource, |
| 2264 |
VK_FORMAT_R32_SFLOAT, |
| 2265 |
packed_clear_color, |
| 2266 |
template_idx, |
| 2267 |
stencil, |
| 2268 |
vs_has_rt_id_output); |
| 2269 |
if (result != VK_SUCCESS) |
| 2270 |
return; |
| 2271 |
} else { |
| 2272 |
const uint32_t template_idx = attachment->aspectMask; |
| 2273 |
struct pvr_static_clear_ppp_template template; |
| 2274 |
struct pvr_suballoc_bo *pvr_bo; |
| 2275 |
|
| 2276 |
assert(template_idx < PVR_STATIC_CLEAR_VARIANT_COUNT); |
| 2277 |
template = |
| 2278 |
cmd_buffer->device->static_clear_state->ppp_templates[template_idx]; |
| 2279 |
|
| 2280 |
if (attachment->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2281 |
/* clang-format off */ |
| 2282 |
template.config.ispa.sref = |
| 2283 |
attachment->clearValue.depthStencil.stencil & |
| 2284 |
ROGUE_TA_STATE_ISPA_SREF_SIZE_MAX; |
| 2285 |
/* clang-format on */ |
| 2286 |
} |
| 2287 |
|
| 2288 |
if (vs_has_rt_id_output) { |
| 2289 |
template.config.output_sel.rhw_pres = true; |
| 2290 |
template.config.output_sel.render_tgt_pres = true; |
| 2291 |
template.config.output_sel.vtxsize = 4 + 1; |
| 2292 |
} |
| 2293 |
|
| 2294 |
result = pvr_emit_ppp_from_template(&sub_cmd->control_stream, |
| 2295 |
&template, |
| 2296 |
&pvr_bo); |
| 2297 |
if (result != VK_SUCCESS) { |
| 2298 |
pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result); |
| 2299 |
return; |
| 2300 |
} |
| 2301 |
|
| 2302 |
list_add(&pvr_bo->link, &cmd_buffer->bo_list); |
| 2303 |
} |
| 2304 |
|
| 2305 |
if (attachment->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) |
| 2306 |
depth = attachment->clearValue.depthStencil.depth; |
| 2307 |
else |
| 2308 |
depth = 1.0f; |
| 2309 |
|
| 2310 |
if (vs_has_rt_id_output) { |
| 2311 |
const struct pvr_device_static_clear_state *dev_clear_state = |
| 2312 |
cmd_buffer->device->static_clear_state; |
| 2313 |
const struct pvr_suballoc_bo *multi_layer_vert_bo = |
| 2314 |
dev_clear_state->usc_multi_layer_vertex_shader_bo; |
| 2315 |
|
| 2316 |
/* We can't use the device's passthrough pds program since it doesn't |
| 2317 |
* have iterate_instance_id enabled. We'll be uploading code sections |
| 2318 |
* per each clear rect. |
| 2319 |
*/ |
| 2320 |
|
| 2321 |
/* TODO: See if we can allocate all the code section memory in one go. |
| 2322 |
* We'd need to make sure that changing instance_id_modifier doesn't |
| 2323 |
* change the code section size. |
| 2324 |
* Also check if we can reuse the same code segment for each rect. |
| 2325 |
* Seems like the instance_id_modifier is written into the data section |
| 2326 |
* and used by the pds ADD instruction that way instead of it being |
| 2327 |
* embedded into the code section. |
| 2328 |
*/ |
| 2329 |
|
| 2330 |
pvr_pds_clear_rta_vertex_shader_program_init_base(&pds_program, |
| 2331 |
multi_layer_vert_bo); |
| 2332 |
} else { |
| 2333 |
/* We can reuse the device's code section but we'll need to upload data |
| 2334 |
* sections so initialize the program. |
| 2335 |
*/ |
| 2336 |
pvr_pds_clear_vertex_shader_program_init_base( |
| 2337 |
&pds_program, |
| 2338 |
cmd_buffer->device->static_clear_state->usc_vertex_shader_bo); |
| 2339 |
|
| 2340 |
pds_program_upload.code_offset = |
| 2341 |
cmd_buffer->device->static_clear_state->pds.code_offset; |
| 2342 |
/* TODO: The code size doesn't get used by pvr_clear_vdm_state() maybe |
| 2343 |
* let's change its interface to make that clear and not set this? |
| 2344 |
*/ |
| 2345 |
pds_program_upload.code_size = |
| 2346 |
cmd_buffer->device->static_clear_state->pds.code_size; |
| 2347 |
} |
| 2348 |
|
| 2349 |
for (uint32_t j = 0; j < rect_count; j++) { |
| 2350 |
struct pvr_pds_upload pds_program_data_upload; |
| 2351 |
const VkClearRect *clear_rect = &rects[j]; |
| 2352 |
struct pvr_suballoc_bo *vertices_bo; |
| 2353 |
uint32_t vdm_cs_size_in_dw; |
| 2354 |
uint32_t *vdm_cs_buffer; |
| 2355 |
VkResult result; |
| 2356 |
|
| 2357 |
if (!PVR_HAS_FEATURE(dev_info, gs_rta_support) && |
| 2358 |
(clear_rect->baseArrayLayer != 0 || clear_rect->layerCount > 1)) { |
| 2359 |
result = pvr_add_deferred_rta_clear(cmd_buffer, |
| 2360 |
attachment, |
| 2361 |
clear_rect, |
| 2362 |
is_render_init); |
| 2363 |
if (result != VK_SUCCESS) |
| 2364 |
return; |
| 2365 |
|
| 2366 |
if (clear_rect->baseArrayLayer != 0) |
| 2367 |
continue; |
| 2368 |
} |
| 2369 |
|
| 2370 |
/* TODO: Allocate all the buffers in one go before the loop, and add |
| 2371 |
* support to multi-alloc bo. |
| 2372 |
*/ |
| 2373 |
result = pvr_clear_vertices_upload(cmd_buffer->device, |
| 2374 |
&clear_rect->rect, |
| 2375 |
depth, |
| 2376 |
&vertices_bo); |
| 2377 |
if (result != VK_SUCCESS) { |
| 2378 |
pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result); |
| 2379 |
return; |
| 2380 |
} |
| 2381 |
|
| 2382 |
list_add(&vertices_bo->link, &cmd_buffer->bo_list); |
| 2383 |
|
| 2384 |
if (vs_has_rt_id_output) { |
| 2385 |
if (current_base_array_layer != clear_rect->baseArrayLayer) { |
| 2386 |
const uint32_t base_array_layer = clear_rect->baseArrayLayer; |
| 2387 |
struct pvr_pds_upload pds_program_code_upload; |
| 2388 |
|
| 2389 |
result = |
| 2390 |
pvr_pds_clear_rta_vertex_shader_program_create_and_upload_code( |
| 2391 |
&pds_program, |
| 2392 |
cmd_buffer, |
| 2393 |
base_array_layer, |
| 2394 |
&pds_program_code_upload); |
| 2395 |
if (result != VK_SUCCESS) { |
| 2396 |
pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result); |
| 2397 |
return; |
| 2398 |
} |
| 2399 |
|
| 2400 |
pds_program_upload.code_offset = |
| 2401 |
pds_program_code_upload.code_offset; |
| 2402 |
/* TODO: The code size doesn't get used by pvr_clear_vdm_state() |
| 2403 |
* maybe let's change its interface to make that clear and not |
| 2404 |
* set this? |
| 2405 |
*/ |
| 2406 |
pds_program_upload.code_size = pds_program_code_upload.code_size; |
| 2407 |
|
| 2408 |
current_base_array_layer = base_array_layer; |
| 2409 |
} |
| 2410 |
|
| 2411 |
result = |
| 2412 |
pvr_pds_clear_rta_vertex_shader_program_create_and_upload_data( |
| 2413 |
&pds_program, |
| 2414 |
cmd_buffer, |
| 2415 |
vertices_bo, |
| 2416 |
&pds_program_data_upload); |
| 2417 |
if (result != VK_SUCCESS) |
| 2418 |
return; |
| 2419 |
} else { |
| 2420 |
result = pvr_pds_clear_vertex_shader_program_create_and_upload_data( |
| 2421 |
&pds_program, |
| 2422 |
cmd_buffer, |
| 2423 |
vertices_bo, |
| 2424 |
&pds_program_data_upload); |
| 2425 |
if (result != VK_SUCCESS) |
| 2426 |
return; |
| 2427 |
} |
| 2428 |
|
| 2429 |
pds_program_upload.data_offset = pds_program_data_upload.data_offset; |
| 2430 |
pds_program_upload.data_size = pds_program_data_upload.data_size; |
| 2431 |
|
| 2432 |
vdm_cs_size_in_dw = |
| 2433 |
pvr_clear_vdm_state_get_size_in_dw(dev_info, |
| 2434 |
clear_rect->layerCount); |
| 2435 |
|
| 2436 |
pvr_csb_set_relocation_mark(&sub_cmd->control_stream); |
| 2437 |
|
| 2438 |
vdm_cs_buffer = pvr_arch_csb_alloc_dwords(&sub_cmd->control_stream, |
| 2439 |
vdm_cs_size_in_dw); |
| 2440 |
if (!vdm_cs_buffer) { |
| 2441 |
pvr_cmd_buffer_set_error_unwarned(cmd_buffer, |
| 2442 |
sub_cmd->control_stream.status); |
| 2443 |
return; |
| 2444 |
} |
| 2445 |
|
| 2446 |
pvr_pack_clear_vdm_state(dev_info, |
| 2447 |
&pds_program_upload, |
| 2448 |
pds_program.temps_used, |
| 2449 |
4, |
| 2450 |
vs_output_size_in_bytes, |
| 2451 |
clear_rect->layerCount, |
| 2452 |
vdm_cs_buffer); |
| 2453 |
|
| 2454 |
pvr_csb_clear_relocation_mark(&sub_cmd->control_stream); |
| 2455 |
} |
| 2456 |
} |
| 2457 |
} |
| 2458 |
|
| 2459 |
void pvr_clear_attachments_render_init(struct pvr_cmd_buffer *cmd_buffer, |
| 2460 |
const VkClearAttachment *attachment, |
| 2461 |
const VkClearRect *rect) |
| 2462 |
{ |
| 2463 |
pvr_clear_attachments(cmd_buffer, 1, attachment, 1, rect, true); |
| 2464 |
} |
| 2465 |
|
| 2466 |
void pvr_rogue_CmdClearAttachments(VkCommandBuffer commandBuffer, |
| 2467 |
uint32_t attachmentCount, |
| 2468 |
const VkClearAttachment *pAttachments, |
| 2469 |
uint32_t rectCount, |
| 2470 |
const VkClearRect *pRects) |
| 2471 |
{ |
| 2472 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 2473 |
struct pvr_cmd_buffer_state *state = &cmd_buffer->state; |
| 2474 |
struct pvr_sub_cmd_gfx *sub_cmd = &state->current_sub_cmd->gfx; |
| 2475 |
|
| 2476 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 2477 |
assert(state->current_sub_cmd->type == PVR_SUB_CMD_TYPE_GRAPHICS); |
| 2478 |
|
| 2479 |
/* TODO: There are some optimizations that can be made here: |
| 2480 |
* - For a full screen clear, update the clear values for the corresponding |
| 2481 |
* attachment index. |
| 2482 |
* - For a full screen color attachment clear, add its index to a load op |
| 2483 |
* override to add it to the background shader. This will elide any load |
| 2484 |
* op loads currently in the background shader as well as the usual |
| 2485 |
* frag kick for geometry clear. |
| 2486 |
*/ |
| 2487 |
|
| 2488 |
/* If we have any depth/stencil clears, update the sub command depth/stencil |
| 2489 |
* modification and usage flags. |
| 2490 |
*/ |
| 2491 |
if (state->depth_format != VK_FORMAT_UNDEFINED) { |
| 2492 |
uint32_t full_screen_clear_count; |
| 2493 |
bool has_stencil_clear = false; |
| 2494 |
bool has_depth_clear = false; |
| 2495 |
|
| 2496 |
for (uint32_t i = 0; i < attachmentCount; i++) { |
| 2497 |
const VkImageAspectFlags aspect_mask = pAttachments[i].aspectMask; |
| 2498 |
|
| 2499 |
if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) |
| 2500 |
has_stencil_clear = true; |
| 2501 |
|
| 2502 |
if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) |
| 2503 |
has_depth_clear = true; |
| 2504 |
|
| 2505 |
if (has_stencil_clear && has_depth_clear) |
| 2506 |
break; |
| 2507 |
} |
| 2508 |
|
| 2509 |
sub_cmd->modifies_stencil |= has_stencil_clear; |
| 2510 |
sub_cmd->modifies_depth |= has_depth_clear; |
| 2511 |
|
| 2512 |
/* We only care about clears that have a baseArrayLayer of 0 as any |
| 2513 |
* attachment clears we move to the background shader must apply to all of |
| 2514 |
* the attachment's sub resources. |
| 2515 |
*/ |
| 2516 |
full_screen_clear_count = |
| 2517 |
pvr_get_max_layers_covering_target(state->render_pass_info.render_area, |
| 2518 |
0, |
| 2519 |
rectCount, |
| 2520 |
pRects); |
| 2521 |
|
| 2522 |
if (full_screen_clear_count > 0) { |
| 2523 |
if (has_stencil_clear && |
| 2524 |
sub_cmd->stencil_usage == PVR_DEPTH_STENCIL_USAGE_UNDEFINED) { |
| 2525 |
sub_cmd->stencil_usage = PVR_DEPTH_STENCIL_USAGE_NEVER; |
| 2526 |
} |
| 2527 |
|
| 2528 |
if (has_depth_clear && |
| 2529 |
sub_cmd->depth_usage == PVR_DEPTH_STENCIL_USAGE_UNDEFINED) { |
| 2530 |
sub_cmd->depth_usage = PVR_DEPTH_STENCIL_USAGE_NEVER; |
| 2531 |
} |
| 2532 |
} |
| 2533 |
} |
| 2534 |
|
| 2535 |
pvr_clear_attachments(cmd_buffer, |
| 2536 |
attachmentCount, |
| 2537 |
pAttachments, |
| 2538 |
rectCount, |
| 2539 |
pRects, |
| 2540 |
false); |
| 2541 |
} |
| 2542 |
|
| 2543 |
void pvr_rogue_CmdResolveImage2(VkCommandBuffer commandBuffer, |
| 2544 |
const VkResolveImageInfo2 *pResolveImageInfo) |
| 2545 |
{ |
| 2546 |
VK_FROM_HANDLE(pvr_image, src, pResolveImageInfo->srcImage); |
| 2547 |
VK_FROM_HANDLE(pvr_image, dst, pResolveImageInfo->dstImage); |
| 2548 |
VK_FROM_HANDLE(pvr_cmd_buffer, cmd_buffer, commandBuffer); |
| 2549 |
|
| 2550 |
PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); |
| 2551 |
|
| 2552 |
for (uint32_t i = 0U; i < pResolveImageInfo->regionCount; i++) { |
| 2553 |
VkImageCopy2 region = { |
| 2554 |
.sType = VK_STRUCTURE_TYPE_IMAGE_COPY_2, |
| 2555 |
.srcSubresource = pResolveImageInfo->pRegions[i].srcSubresource, |
| 2556 |
.srcOffset = pResolveImageInfo->pRegions[i].srcOffset, |
| 2557 |
.dstSubresource = pResolveImageInfo->pRegions[i].dstSubresource, |
| 2558 |
.dstOffset = pResolveImageInfo->pRegions[i].dstOffset, |
| 2559 |
.extent = pResolveImageInfo->pRegions[i].extent, |
| 2560 |
}; |
| 2561 |
|
| 2562 |
VkResult result = |
| 2563 |
pvr_copy_or_resolve_color_image_region(cmd_buffer, src, dst, ®ion); |
| 2564 |
if (result != VK_SUCCESS) |
| 2565 |
return; |
| 2566 |
} |
| 2567 |
} |