2020-05-28 20:27:40 +02:00
|
|
|
#include "common.h"
|
2018-10-15 23:37:09 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
#include "declarations.h"
|
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
#include "kernel/vc4_packet.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateImageView
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VkResult RPIFUNC(vkCreateImageView)(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCreateImageView));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pCreateInfo);
|
|
|
|
assert(pView);
|
|
|
|
|
2018-11-17 16:53:13 +01:00
|
|
|
_imageView* view = ALLOCATE(sizeof(_imageView), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2018-10-15 23:37:09 +02:00
|
|
|
|
|
|
|
if(!view)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateImageView));
|
2018-10-15 23:37:09 +02:00
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->image = pCreateInfo->image;
|
|
|
|
view->viewType = pCreateInfo->viewType;
|
|
|
|
view->interpretedFormat = pCreateInfo->format;
|
|
|
|
view->swizzle = pCreateInfo->components;
|
|
|
|
view->subresourceRange = pCreateInfo->subresourceRange;
|
|
|
|
|
|
|
|
*pView = view;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateImageView));
|
2018-10-15 23:37:09 +02:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateBuffer
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VkResult RPIFUNC(vkCreateBuffer)(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCreateBuffer));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pCreateInfo);
|
|
|
|
assert(pBuffer);
|
|
|
|
|
2018-11-17 16:53:13 +01:00
|
|
|
_buffer* buf = ALLOCATE(sizeof(_buffer), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2018-10-15 23:37:09 +02:00
|
|
|
if(!buf)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateBuffer));
|
2018-10-15 23:37:09 +02:00
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf->size = pCreateInfo->size;
|
|
|
|
buf->usage = pCreateInfo->usage;
|
|
|
|
buf->boundMem = 0;
|
2020-04-26 21:21:18 +02:00
|
|
|
buf->alignment = ARM_PAGE_SIZE;
|
2019-09-08 00:30:52 +02:00
|
|
|
buf->alignedSize = getBOAlignedSize(buf->size, ARM_PAGE_SIZE);
|
2018-10-15 23:37:09 +02:00
|
|
|
|
|
|
|
*pBuffer = buf;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateBuffer));
|
2018-10-15 23:37:09 +02:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkGetBufferMemoryRequirements
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
void RPIFUNC(vkGetBufferMemoryRequirements)(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkGetBufferMemoryRequirements));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(device);
|
|
|
|
assert(buffer);
|
|
|
|
assert(pMemoryRequirements);
|
|
|
|
|
|
|
|
pMemoryRequirements->alignment = ((_buffer*)buffer)->alignment;
|
2019-09-08 00:30:52 +02:00
|
|
|
pMemoryRequirements->size = getBOAlignedSize(((_buffer*)buffer)->size, ARM_PAGE_SIZE);
|
|
|
|
//there's only one memory type so that's gonna be it...
|
|
|
|
pMemoryRequirements->memoryTypeBits = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkGetBufferMemoryRequirements));
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkGetBufferMemoryRequirements2)(
|
2019-04-22 15:58:27 +02:00
|
|
|
VkDevice device,
|
|
|
|
const VkBufferMemoryRequirementsInfo2* pInfo,
|
|
|
|
VkMemoryRequirements2* pMemoryRequirements)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkGetBufferMemoryRequirements2));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2019-04-22 15:58:27 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pInfo);
|
|
|
|
assert(pMemoryRequirements);
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkGetBufferMemoryRequirements)(device, pInfo->buffer, &pMemoryRequirements->memoryRequirements);
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkGetBufferMemoryRequirements2));
|
2019-04-22 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkBindBufferMemory
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VkResult RPIFUNC(vkBindBufferMemory)(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkBindBufferMemory));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(device);
|
|
|
|
assert(buffer);
|
|
|
|
assert(memory);
|
|
|
|
|
|
|
|
_buffer* buf = buffer;
|
|
|
|
_deviceMemory* mem = memory;
|
|
|
|
|
|
|
|
assert(!buf->boundMem);
|
|
|
|
assert(memoryOffset < mem->size);
|
2020-05-27 00:34:07 +02:00
|
|
|
//assert(memoryOffset % buf->alignment == 0);
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(buf->alignedSize <= mem->size - memoryOffset);
|
|
|
|
|
|
|
|
buf->boundMem = mem;
|
|
|
|
buf->boundOffset = memoryOffset;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkBindBufferMemory));
|
2018-10-15 23:37:09 +02:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
void RPIFUNC(vkDestroyBuffer)(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkDestroyBuffer));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(device);
|
|
|
|
|
|
|
|
_buffer* buf = buffer;
|
2019-02-10 00:53:32 +01:00
|
|
|
if(buf)
|
|
|
|
{
|
|
|
|
FREE(buf);
|
|
|
|
}
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkDestroyBuffer));
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
void RPIFUNC(vkDestroyImageView)(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkDestroyImageView));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(device);
|
|
|
|
|
|
|
|
_imageView* view = imageView;
|
2019-02-10 00:53:32 +01:00
|
|
|
if(view)
|
|
|
|
{
|
|
|
|
FREE(view);
|
|
|
|
}
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkDestroyImageView));
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
2018-10-18 22:17:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateBufferView
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateBufferView)(
|
2018-10-18 22:17:02 +02:00
|
|
|
VkDevice device,
|
|
|
|
const VkBufferViewCreateInfo* pCreateInfo,
|
|
|
|
const VkAllocationCallbacks* pAllocator,
|
|
|
|
VkBufferView* pView)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCreateBufferView));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pCreateInfo);
|
|
|
|
assert(pView);
|
|
|
|
|
2018-11-17 16:53:13 +01:00
|
|
|
_bufferView* bv = ALLOCATE(sizeof(_bufferView), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2018-10-18 22:17:02 +02:00
|
|
|
|
2019-02-08 01:33:51 +01:00
|
|
|
if(!bv)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateBufferView));
|
2019-02-08 01:33:51 +01:00
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
bv->buffer = pCreateInfo->buffer;
|
|
|
|
bv->format = pCreateInfo->format;
|
|
|
|
bv->offset = pCreateInfo->offset;
|
|
|
|
bv->range = pCreateInfo->range;
|
|
|
|
|
|
|
|
*pView = bv;
|
2019-02-08 01:33:51 +01:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateBufferView));
|
2019-02-08 01:33:51 +01:00
|
|
|
return VK_SUCCESS;
|
2018-10-18 22:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkDestroyBufferView
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkDestroyBufferView)(
|
2018-10-18 22:17:02 +02:00
|
|
|
VkDevice device,
|
|
|
|
VkBufferView bufferView,
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkDestroyBufferView));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
assert(device);
|
|
|
|
|
|
|
|
_bufferView* bv = bufferView;
|
2019-02-10 00:53:32 +01:00
|
|
|
if(bv)
|
|
|
|
{
|
|
|
|
FREE(bv);
|
|
|
|
}
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkDestroyBufferView));
|
2018-10-18 22:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateImage
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateImage)(
|
2018-10-18 22:17:02 +02:00
|
|
|
VkDevice device,
|
|
|
|
const VkImageCreateInfo* pCreateInfo,
|
|
|
|
const VkAllocationCallbacks* pAllocator,
|
|
|
|
VkImage* pImage)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCreateImage));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pCreateInfo);
|
|
|
|
assert(pImage);
|
|
|
|
|
2018-11-17 16:53:13 +01:00
|
|
|
_image* i = ALLOCATE(sizeof(_image), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2018-10-18 22:17:02 +02:00
|
|
|
if(!i)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateImage));
|
2018-10-18 22:17:02 +02:00
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
|
2020-04-14 19:31:58 +02:00
|
|
|
i->flags = pCreateInfo->flags;
|
2018-10-20 16:46:12 +02:00
|
|
|
i->type = pCreateInfo->imageType;
|
|
|
|
i->fb = 0; //needed for modeset
|
2018-10-18 22:17:02 +02:00
|
|
|
i->width = pCreateInfo->extent.width;
|
|
|
|
i->height = pCreateInfo->extent.height;
|
|
|
|
i->depth = pCreateInfo->extent.depth;
|
|
|
|
i->miplevels = pCreateInfo->mipLevels;
|
2020-03-01 20:11:31 +01:00
|
|
|
memset(i->levelOffsets, 0, sizeof(uint32_t) * 11);
|
2020-05-16 15:49:09 +02:00
|
|
|
memset(i->levelTiling, 0, sizeof(uint32_t) * 11);
|
2018-10-20 16:46:12 +02:00
|
|
|
i->samples = pCreateInfo->samples;
|
2018-10-18 22:17:02 +02:00
|
|
|
i->layers = pCreateInfo->arrayLayers;
|
2018-10-20 16:46:12 +02:00
|
|
|
i->size = 0;
|
|
|
|
i->stride = 0;
|
2018-10-18 22:17:02 +02:00
|
|
|
i->usageBits = pCreateInfo->usage;
|
2018-10-20 16:46:12 +02:00
|
|
|
i->format = pCreateInfo->format;
|
|
|
|
i->imageSpace = 0;
|
2020-03-02 00:28:27 +01:00
|
|
|
i->tiling = 0;
|
|
|
|
if(pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR)
|
|
|
|
{
|
|
|
|
i->tiling = VC4_TILING_FORMAT_LINEAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-15 19:58:21 +02:00
|
|
|
uint32_t isLT = isLTformat(getFormatBpp(i->format), i->width, i->height);
|
|
|
|
if(!isLT)
|
2020-03-02 00:28:27 +01:00
|
|
|
{
|
|
|
|
i->tiling = VC4_TILING_FORMAT_T;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i->tiling = VC4_TILING_FORMAT_LT;
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 16:46:12 +02:00
|
|
|
i->layout = pCreateInfo->initialLayout;
|
|
|
|
i->boundMem = 0;
|
|
|
|
i->boundOffset = 0;
|
2020-04-26 21:21:18 +02:00
|
|
|
i->alignment = ARM_PAGE_SIZE;
|
2018-10-20 16:46:12 +02:00
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
i->concurrentAccess = pCreateInfo->sharingMode; //TODO?
|
|
|
|
i->numQueueFamiliesWithAccess = pCreateInfo->queueFamilyIndexCount;
|
|
|
|
if(i->numQueueFamiliesWithAccess > 0)
|
|
|
|
{
|
2018-11-17 16:53:13 +01:00
|
|
|
i->queueFamiliesWithAccess = ALLOCATE(sizeof(uint32_t) * i->numQueueFamiliesWithAccess, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2018-10-18 22:17:02 +02:00
|
|
|
if(!i->queueFamiliesWithAccess)
|
2019-02-08 01:33:51 +01:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateImage));
|
2018-10-18 22:17:02 +02:00
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
2019-02-08 01:33:51 +01:00
|
|
|
}
|
2018-10-18 22:17:02 +02:00
|
|
|
memcpy(i->queueFamiliesWithAccess, pCreateInfo->pQueueFamilyIndices, sizeof(uint32_t) * i->numQueueFamiliesWithAccess);
|
|
|
|
}
|
|
|
|
|
2018-10-20 16:46:12 +02:00
|
|
|
i->preTransformMode = 0;
|
|
|
|
i->compositeAlpha = 0;
|
|
|
|
i->presentMode = 0;
|
|
|
|
i->clipped = 0;
|
2018-10-18 22:17:02 +02:00
|
|
|
|
|
|
|
*pImage = i;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCreateImage));
|
2018-10-18 22:17:02 +02:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkDestroyImage
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkDestroyImage)(
|
2018-10-18 22:17:02 +02:00
|
|
|
VkDevice device,
|
|
|
|
VkImage image,
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkDestroyImage));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
assert(device);
|
|
|
|
|
|
|
|
_image* i = image;
|
|
|
|
|
2019-02-09 17:18:15 +01:00
|
|
|
if(i)
|
|
|
|
{
|
|
|
|
if(i->numQueueFamiliesWithAccess > 0)
|
|
|
|
{
|
|
|
|
FREE(i->queueFamiliesWithAccess);
|
|
|
|
}
|
2019-02-10 00:53:32 +01:00
|
|
|
FREE(i);
|
2019-02-09 17:18:15 +01:00
|
|
|
}
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkDestroyImage));
|
2018-10-18 22:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkGetImageMemoryRequirements
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkGetImageMemoryRequirements)(
|
2018-10-18 22:17:02 +02:00
|
|
|
VkDevice device,
|
|
|
|
VkImage image,
|
|
|
|
VkMemoryRequirements* pMemoryRequirements)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkGetImageMemoryRequirements));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
assert(device);
|
|
|
|
assert(image);
|
|
|
|
assert(pMemoryRequirements);
|
|
|
|
|
|
|
|
_image* i = image;
|
|
|
|
|
2018-10-20 16:46:12 +02:00
|
|
|
uint32_t bpp = getFormatBpp(i->format);
|
2020-03-02 00:28:27 +01:00
|
|
|
uint32_t utileW, utileH;
|
|
|
|
getUTileDimensions(bpp, &utileW, &utileH);
|
2018-10-20 16:46:12 +02:00
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
uint32_t w = i->width;
|
|
|
|
uint32_t h = i->height;
|
|
|
|
|
|
|
|
if(i->format == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)
|
|
|
|
{
|
|
|
|
w = (w + 3) >> 2;
|
|
|
|
h = (h + 3) >> 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t potW = getPow2Pad(w);
|
|
|
|
uint32_t potH = getPow2Pad(h);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
uint32_t sizes[11];
|
|
|
|
uint32_t strides[11];
|
|
|
|
|
|
|
|
for(int c = i->miplevels - 1; c >= 0; c--)
|
2018-10-20 16:46:12 +02:00
|
|
|
{
|
2020-05-16 15:49:09 +02:00
|
|
|
i->levelTiling[c] = i->tiling;
|
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
uint32_t mipW, mipH;
|
|
|
|
if(!c)
|
2020-03-02 00:28:27 +01:00
|
|
|
{
|
2020-05-15 20:55:27 +02:00
|
|
|
mipW = w;
|
|
|
|
mipH = h;
|
2020-03-02 00:28:27 +01:00
|
|
|
}
|
2020-05-15 20:55:27 +02:00
|
|
|
else
|
2020-03-02 00:28:27 +01:00
|
|
|
{
|
2020-05-15 20:55:27 +02:00
|
|
|
mipW = max(potW >> c, 1);
|
|
|
|
mipH = max(potH >> c, 1);
|
2020-03-02 00:28:27 +01:00
|
|
|
}
|
2020-05-15 20:55:27 +02:00
|
|
|
|
|
|
|
if(i->tiling == VC4_TILING_FORMAT_LINEAR)
|
2020-03-02 00:28:27 +01:00
|
|
|
{
|
2020-05-15 20:55:27 +02:00
|
|
|
if(i->samples > 1)
|
|
|
|
{
|
|
|
|
mipW = roundUp(mipW, 32);
|
|
|
|
mipH = roundUp(mipH, 32);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mipW = roundUp(mipW, utileW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint32_t isMipLT = isLTformat(bpp, mipW, mipH);
|
|
|
|
if(isMipLT)
|
|
|
|
{
|
2020-05-16 15:49:09 +02:00
|
|
|
i->levelTiling[c] = VC4_TILING_FORMAT_LT;
|
2020-05-15 20:55:27 +02:00
|
|
|
mipW = roundUp(mipW, utileW);
|
|
|
|
mipH = roundUp(mipH, utileH);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mipW = roundUp(mipW, utileW * 8);
|
|
|
|
mipH = roundUp(mipH, utileH * 8);
|
|
|
|
}
|
2020-03-02 00:28:27 +01:00
|
|
|
}
|
2020-03-01 20:11:31 +01:00
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
i->levelOffsets[c] = offset;
|
2020-03-02 00:28:27 +01:00
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
strides[c] = (mipW * bpp * max(i->samples, 1)) >> 3;
|
|
|
|
sizes[c] = mipH * strides[c];
|
2020-03-02 00:28:27 +01:00
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
offset += sizes[c];
|
2020-03-01 20:11:31 +01:00
|
|
|
}
|
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
uint32_t levelZeroOffset = roundUp(i->levelOffsets[0], ARM_PAGE_SIZE) - i->levelOffsets[0];
|
2018-10-20 16:46:12 +02:00
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
if(levelZeroOffset)
|
2020-03-11 10:32:26 +01:00
|
|
|
{
|
2020-05-15 20:55:27 +02:00
|
|
|
for(uint32_t c = 0; c < i->miplevels; ++c)
|
|
|
|
{
|
|
|
|
i->levelOffsets[c] += levelZeroOffset;
|
|
|
|
}
|
2020-03-11 10:32:26 +01:00
|
|
|
}
|
|
|
|
|
2020-05-15 20:55:27 +02:00
|
|
|
i->size = getBOAlignedSize(sizes[0] + i->levelOffsets[0], ARM_PAGE_SIZE) * i->layers;
|
|
|
|
i->stride = strides[0];
|
2020-03-01 20:11:31 +01:00
|
|
|
|
2018-10-20 16:46:12 +02:00
|
|
|
pMemoryRequirements->alignment = ARM_PAGE_SIZE;
|
2020-03-01 20:11:31 +01:00
|
|
|
pMemoryRequirements->memoryTypeBits = memoryTypes[0].propertyFlags; //TODO
|
2018-10-20 16:46:12 +02:00
|
|
|
pMemoryRequirements->size = i->size;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkGetImageMemoryRequirements));
|
2018-10-18 22:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkBindImageMemory
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkBindImageMemory)(
|
2018-10-18 22:17:02 +02:00
|
|
|
VkDevice device,
|
|
|
|
VkImage image,
|
|
|
|
VkDeviceMemory memory,
|
|
|
|
VkDeviceSize memoryOffset)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkBindImageMemory));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-18 22:17:02 +02:00
|
|
|
assert(device);
|
|
|
|
assert(image);
|
|
|
|
assert(memory);
|
|
|
|
|
2018-10-20 16:46:12 +02:00
|
|
|
_image* i = image;
|
|
|
|
_deviceMemory* m = memory;
|
|
|
|
|
|
|
|
assert(!i->boundMem);
|
|
|
|
assert(memoryOffset < m->size);
|
2020-05-27 00:34:07 +02:00
|
|
|
//assert(memoryOffset % i->alignment == 0);
|
2018-10-20 16:46:12 +02:00
|
|
|
assert(i->size <= m->size - memoryOffset);
|
|
|
|
|
|
|
|
i->boundMem = m;
|
|
|
|
i->boundOffset = memoryOffset;
|
2018-10-18 22:17:02 +02:00
|
|
|
|
2020-04-26 21:21:18 +02:00
|
|
|
//TODO this is necessary, but maybe don't do it here?
|
2020-03-02 00:28:27 +01:00
|
|
|
if(i->tiling == VC4_TILING_FORMAT_LINEAR)
|
|
|
|
{
|
|
|
|
int ret = vc4_bo_set_tiling(controlFd, i->boundMem->bo, DRM_FORMAT_MOD_LINEAR); assert(ret);
|
|
|
|
}
|
2020-05-06 01:10:40 +02:00
|
|
|
else if(i->tiling == VC4_TILING_FORMAT_T || i->tiling == VC4_TILING_FORMAT_LT)
|
2020-03-02 00:28:27 +01:00
|
|
|
{
|
|
|
|
int ret = vc4_bo_set_tiling(controlFd, i->boundMem->bo, DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED); assert(ret);
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkBindImageMemory));
|
2018-10-18 22:17:02 +02:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
2019-04-22 15:58:27 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkBindBufferMemory2)(
|
2019-04-22 15:58:27 +02:00
|
|
|
VkDevice device,
|
|
|
|
uint32_t bindInfoCount,
|
|
|
|
const VkBindBufferMemoryInfo* pBindInfos)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkBindBufferMemory2));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2019-09-08 00:30:52 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pBindInfos);
|
|
|
|
|
|
|
|
VkResult ret = VK_SUCCESS;
|
|
|
|
|
|
|
|
for(uint32_t c = 0; c < bindInfoCount; ++c)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
VkResult res = RPIFUNC(vkBindBufferMemory)(device, pBindInfos[c].buffer, pBindInfos[c].memory, pBindInfos[c].memoryOffset);
|
2019-09-08 00:30:52 +02:00
|
|
|
if(res != VK_SUCCESS)
|
|
|
|
{
|
|
|
|
ret = res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkBindBufferMemory2));
|
2019-09-08 00:30:52 +02:00
|
|
|
return ret;
|
2019-04-22 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkGetImageMemoryRequirements2)(
|
2019-04-22 15:58:27 +02:00
|
|
|
VkDevice device,
|
|
|
|
const VkImageMemoryRequirementsInfo2* pInfo,
|
|
|
|
VkMemoryRequirements2* pMemoryRequirements)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkGetImageMemoryRequirements2));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2019-09-08 00:30:52 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pInfo);
|
|
|
|
assert(pMemoryRequirements);
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkGetImageMemoryRequirements)(device, pInfo->image, pMemoryRequirements);
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkGetImageMemoryRequirements2));
|
2019-04-22 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkBindImageMemory2)(
|
2019-04-22 15:58:27 +02:00
|
|
|
VkDevice device,
|
|
|
|
uint32_t bindInfoCount,
|
|
|
|
const VkBindImageMemoryInfo* pBindInfos)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkBindImageMemory2));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2019-09-08 00:30:52 +02:00
|
|
|
assert(device);
|
|
|
|
assert(pBindInfos);
|
|
|
|
|
|
|
|
VkResult ret = VK_SUCCESS;
|
|
|
|
|
|
|
|
for(uint32_t c = 0; c < bindInfoCount; ++c)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
VkResult res = RPIFUNC(vkBindImageMemory)(device, pBindInfos[c].image, pBindInfos[c].memory, pBindInfos[c].memoryOffset);
|
2019-09-08 00:30:52 +02:00
|
|
|
if(res != VK_SUCCESS)
|
|
|
|
{
|
|
|
|
ret = res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkBindImageMemory2));
|
2019-09-08 00:30:52 +02:00
|
|
|
return ret;
|
2019-04-22 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdPushConstants)(
|
2019-04-22 15:58:27 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkPipelineLayout layout,
|
|
|
|
VkShaderStageFlags stageFlags,
|
|
|
|
uint32_t offset,
|
|
|
|
uint32_t size,
|
|
|
|
const void* pValues)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdPushConstants));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2019-07-27 22:57:13 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
assert(layout);
|
2019-04-22 15:58:27 +02:00
|
|
|
|
2019-07-27 22:57:13 +02:00
|
|
|
_pipelineLayout* pl = layout;
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
|
|
|
|
if(stageFlags & VK_SHADER_STAGE_VERTEX_BIT)
|
|
|
|
{
|
|
|
|
memcpy(cb->pushConstantBufferVertex + offset, pValues, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stageFlags & VK_SHADER_STAGE_FRAGMENT_BIT)
|
|
|
|
{
|
|
|
|
memcpy(cb->pushConstantBufferPixel + offset, pValues, size);
|
|
|
|
}
|
2019-09-02 23:37:42 +02:00
|
|
|
|
|
|
|
cb->pushConstantDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdPushConstants));
|
2019-04-22 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkGetImageSubresourceLayout)(
|
2019-04-22 15:58:27 +02:00
|
|
|
VkDevice device,
|
|
|
|
VkImage image,
|
|
|
|
const VkImageSubresource* pSubresource,
|
|
|
|
VkSubresourceLayout* pLayout)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkGetImageSubresourceLayout));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2019-09-08 00:30:52 +02:00
|
|
|
//TODO
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkGetImageSubresourceLayout));
|
2019-04-22 15:58:27 +02:00
|
|
|
}
|