diff options
author | Marek Olšák <[email protected]> | 2020-05-04 07:43:44 -0400 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-05-07 20:13:41 +0000 |
commit | 441eaef6a9e5bb6d55bb3f875d60b35a5e70042b (patch) | |
tree | eab2378a0e90760c426b744d19a6e290ff14f262 /src/amd | |
parent | c164ea86e193c710d41de769ddfb169ab53ced51 (diff) |
amd: unify code for overriding offset and stride for imported buffers
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Reviewed-by: Samuel Pitoiset <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4863>
Diffstat (limited to 'src/amd')
-rw-r--r-- | src/amd/common/ac_surface.c | 26 | ||||
-rw-r--r-- | src/amd/common/ac_surface.h | 5 | ||||
-rw-r--r-- | src/amd/vulkan/radv_image.c | 24 |
3 files changed, 34 insertions, 21 deletions
diff --git a/src/amd/common/ac_surface.c b/src/amd/common/ac_surface.c index 5bfea4b5762..577b2d487eb 100644 --- a/src/amd/common/ac_surface.c +++ b/src/amd/common/ac_surface.c @@ -2189,3 +2189,29 @@ void ac_surface_get_umd_metadata(const struct radeon_info *info, *size_metadata += num_mipmap_levels * 4; } } + +void ac_surface_override_offset_stride(const struct radeon_info *info, + struct radeon_surf *surf, + unsigned num_mipmap_levels, + uint64_t offset, unsigned pitch) +{ + if (info->chip_class >= GFX9) { + if (pitch) { + surf->u.gfx9.surf_pitch = pitch; + if (num_mipmap_levels == 1) + surf->u.gfx9.surf.epitch = pitch - 1; + surf->u.gfx9.surf_slice_size = + (uint64_t)pitch * surf->u.gfx9.surf_height * surf->bpe; + } + surf->u.gfx9.surf_offset = offset; + } else { + surf->u.legacy.level[0].nblk_x = pitch; + surf->u.legacy.level[0].slice_size_dw = + ((uint64_t)pitch * surf->u.legacy.level[0].nblk_y * surf->bpe) / 4; + + if (offset) { + for (unsigned i = 0; i < ARRAY_SIZE(surf->u.legacy.level); ++i) + surf->u.legacy.level[i].offset += offset; + } + } +} diff --git a/src/amd/common/ac_surface.h b/src/amd/common/ac_surface.h index 11e92d12fc5..7405192d57c 100644 --- a/src/amd/common/ac_surface.h +++ b/src/amd/common/ac_surface.h @@ -309,6 +309,11 @@ void ac_surface_get_umd_metadata(const struct radeon_info *info, uint32_t desc[8], unsigned *size_metadata, uint32_t metadata[64]); +void ac_surface_override_offset_stride(const struct radeon_info *info, + struct radeon_surf *surf, + unsigned num_mipmap_levels, + uint64_t offset, unsigned pitch); + #ifdef __cplusplus } #endif diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c index 12cf6fb6eb7..29eb78c7c09 100644 --- a/src/amd/vulkan/radv_image.c +++ b/src/amd/vulkan/radv_image.c @@ -1178,27 +1178,9 @@ radv_image_override_offset_stride(struct radv_device *device, struct radv_image *image, uint64_t offset, uint32_t stride) { - struct radeon_surf *surface = &image->planes[0].surface; - unsigned bpe = vk_format_get_blocksizebits(image->vk_format) / 8; - - if (device->physical_device->rad_info.chip_class >= GFX9) { - if (stride) { - surface->u.gfx9.surf_pitch = stride; - surface->u.gfx9.surf_slice_size = - (uint64_t)stride * surface->u.gfx9.surf_height * bpe; - } - surface->u.gfx9.surf_offset = offset; - } else { - surface->u.legacy.level[0].nblk_x = stride; - surface->u.legacy.level[0].slice_size_dw = - ((uint64_t)stride * surface->u.legacy.level[0].nblk_y * bpe) / 4; - - if (offset) { - for (unsigned i = 0; i < ARRAY_SIZE(surface->u.legacy.level); ++i) - surface->u.legacy.level[i].offset += offset; - } - - } + ac_surface_override_offset_stride(&device->physical_device->rad_info, + &image->planes[0].surface, + image->info.levels, offset, stride); } static void |