pvr: Implement vkCreateBufferView and vkDestroyBufferView.

Signed-off-by: Rajnesh Kanwal <rajnesh.kanwal@imgtec.com>
Reviewed-by: Karmjit Mahil <Karmjit.Mahil@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17719>
This commit is contained in:
Rajnesh Kanwal 2022-07-04 12:34:27 +01:00
parent 8ef42c25a6
commit f044676dbb
2 changed files with 87 additions and 3 deletions

View File

@ -22,7 +22,9 @@
*/
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "pvr_csb.h"
#include "pvr_device_info.h"
@ -34,6 +36,7 @@
#include "vk_format.h"
#include "vk_image.h"
#include "vk_log.h"
#include "vk_object.h"
#include "vk_util.h"
#include "wsi_common.h"
@ -366,13 +369,78 @@ VkResult pvr_CreateBufferView(VkDevice _device,
const VkAllocationCallbacks *pAllocator,
VkBufferView *pView)
{
assert(!"Unimplemented");
PVR_FROM_HANDLE(pvr_buffer, buffer, pCreateInfo->buffer);
PVR_FROM_HANDLE(pvr_device, device, _device);
struct pvr_texture_state_info info;
const uint8_t *format_swizzle;
struct pvr_buffer_view *bview;
VkResult result;
bview = vk_object_alloc(&device->vk,
pAllocator,
sizeof(*bview),
VK_OBJECT_TYPE_BUFFER_VIEW);
if (!bview)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
bview->format = pCreateInfo->format;
bview->range =
vk_buffer_range(&buffer->vk, pCreateInfo->offset, pCreateInfo->range);
/* If the remaining size of the buffer is not a multiple of the element
* size of the format, the nearest smaller multiple is used.
*/
bview->range -= bview->range % vk_format_get_blocksize(bview->format);
/* The range of the buffer view shouldn't be smaller than one texel. */
assert(bview->range >= vk_format_get_blocksize(bview->format));
info.base_level = 0U;
info.mip_levels = 1U;
info.mipmaps_present = false;
info.extent.width = 8192U;
info.extent.height = bview->range / vk_format_get_blocksize(bview->format);
info.extent.height = DIV_ROUND_UP(info.extent.height, info.extent.width);
info.extent.depth = 0U;
info.sample_count = 1U;
info.stride = info.extent.width;
info.offset = 0U;
info.addr = PVR_DEV_ADDR_OFFSET(buffer->dev_addr, pCreateInfo->offset);
info.mem_layout = PVR_MEMLAYOUT_LINEAR;
info.is_cube = false;
info.tex_state_type = PVR_TEXTURE_STATE_SAMPLE;
info.format = bview->format;
info.flags = PVR_TEXFLAGS_INDEX_LOOKUP;
if (PVR_HAS_FEATURE(&device->pdevice->dev_info, tpu_array_textures))
info.array_size = 1U;
format_swizzle = pvr_get_format_swizzle(info.format);
memcpy(info.swizzle, format_swizzle, sizeof(info.swizzle));
result = pvr_pack_tex_state(device, &info, bview->texture_state);
if (result != VK_SUCCESS)
goto err_vk_buffer_view_destroy;
*pView = pvr_buffer_view_to_handle(bview);
return VK_SUCCESS;
err_vk_buffer_view_destroy:
vk_object_free(&device->vk, pAllocator, bview);
return result;
}
void pvr_DestroyBufferView(VkDevice _device,
VkBufferView bufferView,
const VkAllocationCallbacks *pAllocator)
{
assert(!"Unimplemented");
PVR_FROM_HANDLE(pvr_buffer_view, bview, bufferView);
PVR_FROM_HANDLE(pvr_device, device, _device);
if (!bview)
return;
vk_object_free(&device->vk, pAllocator, bview);
}

View File

@ -340,7 +340,7 @@ struct pvr_image_view {
const struct pvr_image *image;
/* Prepacked Texture Image dword 0 and 1. It will be copied to the
* descriptor info during pvr_UpdateDescriptorSets.
* descriptor info during pvr_UpdateDescriptorSets().
*
* We create separate texture states for sampling, storage and input
* attachment cases.
@ -348,6 +348,18 @@ struct pvr_image_view {
uint64_t texture_state[PVR_TEXTURE_STATE_MAX_ENUM][2];
};
struct pvr_buffer_view {
struct vk_object_base base;
uint64_t range;
VkFormat format;
/* Prepacked Texture dword 0 and 1. It will be copied to the descriptor
* during pvr_UpdateDescriptorSets().
*/
uint64_t texture_state[2];
};
union pvr_sampler_descriptor {
uint32_t words[PVR_SAMPLER_DESCRIPTOR_SIZE];
@ -1367,6 +1379,10 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(pvr_image_view,
vk.base,
VkImageView,
VK_OBJECT_TYPE_IMAGE_VIEW)
VK_DEFINE_NONDISP_HANDLE_CASTS(pvr_buffer_view,
base,
VkBufferView,
VK_OBJECT_TYPE_BUFFER_VIEW)
VK_DEFINE_NONDISP_HANDLE_CASTS(pvr_descriptor_set_layout,
base,
VkDescriptorSetLayout,