1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2024-11-29 11:24:14 +01:00

allocators are now supported, more CTS fixes.

This commit is contained in:
Unknown 2018-11-17 15:53:13 +00:00
parent fb2af568b2
commit ce9668b992
12 changed files with 109 additions and 150 deletions

View File

@ -20,9 +20,6 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(
assert(device);
assert(pCreateInfo);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
//VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
//specifies that command buffers allocated from the pool will be short-lived, meaning that they will be reset or freed in a relatively short timeframe.
//This flag may be used by the implementation to control memory allocation behavior within the pool.
@ -34,7 +31,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(
//TODO pool family ignored for now
_commandPool* cp = malloc(sizeof(_commandPool));
_commandPool* cp = ALLOCATE(sizeof(_commandPool), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!cp)
{
@ -43,26 +40,39 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(
cp->queueFamilyIndex = pCreateInfo->queueFamilyIndex;
//TODO CTS fails as we can't allocate enough memory for some reason
//tweak system allocation as root using:
//make sure kernel denies memory allocation that it won't be able to serve
//sysctl -w vm.overcommit_memory="2"
//specify after how much memory used the kernel will start denying requests
//sysctl -w vm.overcommit_ratio="80"
//
//initial number of command buffers to hold
int numCommandBufs = 100;
int controlListSize = ARM_PAGE_SIZE * 100;
int numCommandBufs = 128;
int consecutivePoolSize = ARM_PAGE_SIZE*128;
int consecutiveBlockSize = ARM_PAGE_SIZE>>2;
static int counter = 0;
//if(pCreateInfo->flags & VK_COMMAND_POOL_CREATE_TRANSIENT_BIT)
{
//use pool allocator
void* pamem = malloc(numCommandBufs * sizeof(_commandBuffer));
void* pamem = ALLOCATE(numCommandBufs * sizeof(_commandBuffer), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pamem)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
cp->pa = createPoolAllocator(pamem, sizeof(_commandBuffer), numCommandBufs * sizeof(_commandBuffer));
void* cpamem = malloc(controlListSize);
void* cpamem = ALLOCATE(consecutivePoolSize, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!cpamem)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
cp->cpa = createConsecutivePoolAllocator(cpamem, ARM_PAGE_SIZE, controlListSize);
cp->cpa = createConsecutivePoolAllocator(cpamem, consecutiveBlockSize, consecutivePoolSize);
}
*pCommandPool = (VkCommandPool)cp;
@ -394,20 +404,17 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(
assert(device);
assert(commandPool);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
_commandPool* cp = (_commandPool*)commandPool;
//if(cp->usePoolAllocator)
{
free(cp->pa.buf);
free(cp->cpa.buf);
FREE(cp->pa.buf);
FREE(cp->cpa.buf);
destroyPoolAllocator(&cp->pa);
destroyConsecutivePoolAllocator(&cp->cpa);
}
free(cp);
FREE(cp);
}
/*

View File

@ -20,11 +20,13 @@ uint32_t getFormatBpp(VkFormat f)
case VK_FORMAT_R8G8_UNORM:
case VK_FORMAT_R16_SFLOAT:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_D16_UNORM:
return 16;
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R8_SINT:
return 8;
default:
default://
printf("format %i\n", f);
assert(0);
return 0;
}

View File

@ -34,6 +34,18 @@
#include "vkCaps.h"
/**
//scope
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
VK_SYSTEM_ALLOCATION_SCOPE_CACHE
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
**/
#define ALLOCATE(size, alignment, scope) (pAllocator == 0) ? malloc(size) : pAllocator->pfnAllocation(pAllocator->pUserData, size, alignment, scope);
#define FREE(memory) (pAllocator == 0) ? free(memory) : pAllocator->pfnFree(pAllocator->pUserData, memory);
typedef struct VkDevice_T _device;
typedef struct VkQueue_T

View File

@ -196,9 +196,6 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(
assert(pDevice);
assert(pCreateInfo);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
//check for enabled extensions
for(int c = 0; c < pCreateInfo->enabledExtensionCount; ++c)
{
@ -224,8 +221,8 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(
}
}
*pDevice = malloc(sizeof(_device));
if(!pDevice)
*pDevice = ALLOCATE(sizeof(_device), 1, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
if(!*pDevice)
{
return VK_ERROR_TOO_MANY_OBJECTS;
}
@ -273,7 +270,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(
{
for(int c = 0; c < pCreateInfo->queueCreateInfoCount; ++c)
{
(*pDevice)->queues[pCreateInfo->pQueueCreateInfos[c].queueFamilyIndex] = malloc(sizeof(_queue)*pCreateInfo->pQueueCreateInfos[c].queueCount);
(*pDevice)->queues[pCreateInfo->pQueueCreateInfos[c].queueFamilyIndex] = ALLOCATE(sizeof(_queue)*pCreateInfo->pQueueCreateInfos[c].queueCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!(*pDevice)->queues[pCreateInfo->pQueueCreateInfos[c].queueFamilyIndex])
{
@ -325,19 +322,16 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(
{
assert(device);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
_device* dev = device;
for(int c = 0; c < numQueueFamilies; ++c)
{
for(int d = 0; d < dev->numQueues[c]; ++d)
{
free(dev->queues[d]);
FREE(dev->queues[d]);
}
}
free(dev);
FREE(dev);
}
/*

View File

@ -55,7 +55,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
assert(pInstance);
assert(pCreateInfo);
*pInstance = malloc(sizeof(_instance));
*pInstance = ALLOCATE(sizeof(_instance), 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if(!*pInstance)
{
@ -64,9 +64,6 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
(*pInstance)->numEnabledExtensions = 0;
//TODO: allocator is ignored for now
assert(pAllocator == 0);
//TODO: possibly we need to load layers here
//and store them in pInstance
assert(pCreateInfo->enabledLayerCount == 0);
@ -123,12 +120,9 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(
{
assert(instance);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
closeIoctl();
free(instance);
FREE(instance);
}
/*

View File

@ -65,15 +65,13 @@ VkResult vkAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocate
assert(pAllocateInfo);
assert(pMemory);
assert(pAllocator == 0); //TODO
uint32_t bo = vc4_bo_alloc(device->dev->instance->controlFd, pAllocateInfo->allocationSize, "vkAllocateMemory");
if(!bo)
{
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
_deviceMemory* mem = malloc(sizeof(_deviceMemory));
_deviceMemory* mem = ALLOCATE(sizeof(_deviceMemory), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!mem)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -143,11 +141,9 @@ void vkFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCall
assert(device);
assert(memory);
assert(pAllocator == 0); //TODO
_deviceMemory* mem = memory;
vc4_bo_free(device->dev->instance->controlFd, mem->bo, mem->mappedPtr, mem->size);
free(mem);
FREE(mem);
}
/*

View File

@ -31,11 +31,10 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
assert(pPipelines);
assert(pipelineCache == 0); //TODO not supported right now
assert(pAllocator == 0); //TODO
for(int c = 0; c < createInfoCount; ++c)
{
_pipeline* pip = malloc(sizeof(_pipeline));
_pipeline* pip = ALLOCATE(sizeof(_pipeline), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -46,7 +45,7 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
uint32_t idx = ulog2(pCreateInfos->pStages[d].stage);
pip->modules[idx] = pCreateInfos->pStages[d].module;
pip->names[idx] = malloc(strlen(pCreateInfos->pStages[d].pName)+1);
pip->names[idx] = ALLOCATE(strlen(pCreateInfos->pStages[d].pName)+1, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip->names[idx])
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -56,7 +55,7 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
}
pip->vertexAttributeDescriptionCount = pCreateInfos->pVertexInputState->vertexAttributeDescriptionCount;
pip->vertexAttributeDescriptions = malloc(sizeof(VkVertexInputAttributeDescription) * pip->vertexAttributeDescriptionCount);
pip->vertexAttributeDescriptions = ALLOCATE(sizeof(VkVertexInputAttributeDescription) * pip->vertexAttributeDescriptionCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip->vertexAttributeDescriptions)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -65,7 +64,7 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
memcpy(pip->vertexAttributeDescriptions, pCreateInfos->pVertexInputState->pVertexAttributeDescriptions, sizeof(VkVertexInputAttributeDescription) * pip->vertexAttributeDescriptionCount);
pip->vertexBindingDescriptionCount = pCreateInfos->pVertexInputState->vertexBindingDescriptionCount;
pip->vertexBindingDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * pip->vertexBindingDescriptionCount);
pip->vertexBindingDescriptions = ALLOCATE(sizeof(VkVertexInputBindingDescription) * pip->vertexBindingDescriptionCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip->vertexBindingDescriptions)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -79,7 +78,7 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
//TODO tessellation ignored
pip->viewportCount = pCreateInfos->pViewportState->viewportCount;
pip->viewports = malloc(sizeof(VkViewport) * pip->viewportCount);
pip->viewports = ALLOCATE(sizeof(VkViewport) * pip->viewportCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip->viewports)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -89,7 +88,7 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
pip->scissorCount = pCreateInfos->pViewportState->scissorCount;
pip->scissors = malloc(sizeof(VkRect2D) * pip->viewportCount);
pip->scissors = ALLOCATE(sizeof(VkRect2D) * pip->viewportCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip->scissors)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -135,7 +134,7 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
pip->logicOpEnable = pCreateInfos->pColorBlendState->logicOpEnable;
pip->logicOp = pCreateInfos->pColorBlendState->logicOp;
pip->attachmentCount = pCreateInfos->pColorBlendState->attachmentCount;
pip->attachmentBlendStates = malloc(sizeof(VkPipelineColorBlendAttachmentState) * pip->attachmentCount);
pip->attachmentBlendStates = ALLOCATE(sizeof(VkPipelineColorBlendAttachmentState) * pip->attachmentCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip->attachmentBlendStates)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -149,7 +148,7 @@ VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCach
if(pCreateInfos->pDynamicState)
{
pip->dynamicStateCount = pCreateInfos->pDynamicState->dynamicStateCount;
pip->dynamicStates = malloc(sizeof(VkDynamicState)*pip->dynamicStateCount);
pip->dynamicStates = ALLOCATE(sizeof(VkDynamicState)*pip->dynamicStateCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!pip->dynamicStates)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -180,21 +179,19 @@ void vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationC
assert(device);
assert(pipeline);
assert(pAllocator == 0); //TODO
_pipeline* pip = pipeline;
free(pip->dynamicStates);
free(pip->attachmentBlendStates);
free(pip->scissors);
free(pip->viewports);
free(pip->vertexBindingDescriptions);
free(pip->vertexAttributeDescriptions);
FREE(pip->dynamicStates);
FREE(pip->attachmentBlendStates);
FREE(pip->scissors);
FREE(pip->viewports);
FREE(pip->vertexBindingDescriptions);
FREE(pip->vertexAttributeDescriptions);
for(int c = 0; c < 6; ++c)
{
free(pip->names[c]);
FREE(pip->names[c]);
}
free(pip);
FREE(pip);
}

View File

@ -58,19 +58,17 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
assert(pCreateInfo);
assert(pRenderPass);
assert(pAllocator == 0); //TODO allocators not supported yet
//just copy all data from create info
//we'll later need to bake the control list based on this
_renderpass* rp = malloc(sizeof(_renderpass));
_renderpass* rp = ALLOCATE(sizeof(_renderpass), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
rp->numAttachments = pCreateInfo->attachmentCount;
rp->attachments = malloc(sizeof(VkAttachmentDescription)*rp->numAttachments);
rp->attachments = ALLOCATE(sizeof(VkAttachmentDescription)*rp->numAttachments, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->attachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -79,7 +77,7 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
memcpy(rp->attachments, pCreateInfo->pAttachments, sizeof(VkAttachmentDescription)*rp->numAttachments);
rp->numSubpasses = pCreateInfo->subpassCount;
rp->subpasses = malloc(sizeof(VkSubpassDescription)*rp->numSubpasses);
rp->subpasses = ALLOCATE(sizeof(VkSubpassDescription)*rp->numSubpasses, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->subpasses)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -95,7 +93,7 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
if(rp->subpasses[c].inputAttachmentCount)
{
rp->subpasses[c].pInputAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].inputAttachmentCount);
rp->subpasses[c].pInputAttachments = ALLOCATE(sizeof(VkAttachmentReference)*rp->subpasses[c].inputAttachmentCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->subpasses[c].pInputAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -110,7 +108,7 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
if(rp->subpasses[c].colorAttachmentCount)
{
rp->subpasses[c].pColorAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
rp->subpasses[c].pColorAttachments = ALLOCATE(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->subpasses[c].pColorAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -125,7 +123,7 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
if(rp->subpasses[c].colorAttachmentCount && pCreateInfo->pSubpasses[c].pResolveAttachments)
{
rp->subpasses[c].pResolveAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
rp->subpasses[c].pResolveAttachments = ALLOCATE(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->subpasses[c].pResolveAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -140,7 +138,7 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
if(pCreateInfo->pSubpasses[c].pDepthStencilAttachment)
{
rp->subpasses[c].pDepthStencilAttachment = malloc(sizeof(VkAttachmentReference));
rp->subpasses[c].pDepthStencilAttachment = ALLOCATE(sizeof(VkAttachmentReference), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->subpasses[c].pDepthStencilAttachment)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -155,7 +153,7 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
if(rp->subpasses[c].preserveAttachmentCount)
{
rp->subpasses[c].pPreserveAttachments = malloc(sizeof(uint32_t)*rp->subpasses[c].preserveAttachmentCount);
rp->subpasses[c].pPreserveAttachments = ALLOCATE(sizeof(uint32_t)*rp->subpasses[c].preserveAttachmentCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->subpasses[c].pPreserveAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -170,7 +168,7 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
}
rp->numSubpassDependencies = pCreateInfo->dependencyCount;
rp->subpassDependencies = malloc(sizeof(VkSubpassDependency)*rp->numSubpassDependencies);
rp->subpassDependencies = ALLOCATE(sizeof(VkSubpassDependency)*rp->numSubpassDependencies, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!rp->subpassDependencies)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -188,26 +186,24 @@ void vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAlloc
assert(device);
assert(renderPass);
assert(pAllocator == 0); //TODO
_renderpass* rp = renderPass;
free(rp->subpassDependencies);
FREE(rp->subpassDependencies);
for(int c = 0; c < rp->numSubpasses; ++c)
{
free(rp->subpasses[c].pInputAttachments);
free(rp->subpasses[c].pColorAttachments);
free(rp->subpasses[c].pResolveAttachments);
free(rp->subpasses[c].pDepthStencilAttachment);
free(rp->subpasses[c].pPreserveAttachments);
FREE(rp->subpasses[c].pInputAttachments);
FREE(rp->subpasses[c].pColorAttachments);
FREE(rp->subpasses[c].pResolveAttachments);
FREE(rp->subpasses[c].pDepthStencilAttachment);
FREE(rp->subpasses[c].pPreserveAttachments);
}
free(rp->subpasses);
FREE(rp->subpasses);
free(rp->attachments);
FREE(rp->attachments);
free(rp);
FREE(rp);
}
/*
@ -219,9 +215,7 @@ VkResult vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCr
assert(pCreateInfo);
assert(pFramebuffer);
assert(pAllocator == 0); //TODO
_framebuffer* fb = malloc(sizeof(_framebuffer));
_framebuffer* fb = ALLOCATE(sizeof(_framebuffer), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!fb)
{
@ -231,7 +225,7 @@ VkResult vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCr
fb->renderpass = pCreateInfo->renderPass;
fb->numAttachmentViews = pCreateInfo->attachmentCount;
fb->attachmentViews = malloc(sizeof(_imageView) * fb->numAttachmentViews);
fb->attachmentViews = ALLOCATE(sizeof(_imageView) * fb->numAttachmentViews, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!fb->attachmentViews)
{
@ -259,11 +253,9 @@ void vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAl
assert(device);
assert(framebuffer);
assert(pAllocator == 0); //TODO
_framebuffer* fb = framebuffer;
free(fb->attachmentViews);
free(fb);
FREE(fb->attachmentViews);
FREE(fb);
}
/*

View File

@ -11,9 +11,7 @@ VkResult vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreate
assert(pCreateInfo);
assert(pView);
assert(pAllocator == 0); //TODO
_imageView* view = malloc(sizeof(_imageView));
_imageView* view = ALLOCATE(sizeof(_imageView), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!view)
{
@ -42,9 +40,7 @@ VkResult vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo,
assert(pCreateInfo);
assert(pBuffer);
assert(pAllocator == 0); //TODO
_buffer* buf = malloc(sizeof(_buffer));
_buffer* buf = ALLOCATE(sizeof(_buffer), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!buf)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -103,10 +99,8 @@ void vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbac
assert(device);
assert(buffer);
assert(pAllocator == 0); //TODO
_buffer* buf = buffer;
free(buf);
FREE(buf);
}
void vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
@ -114,10 +108,8 @@ void vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocati
assert(device);
assert(imageView);
assert(pAllocator == 0); //TODO
_imageView* view = imageView;
free(view);
FREE(view);
}
@ -134,9 +126,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(
assert(pCreateInfo);
assert(pView);
assert(pAllocator == 0); //TODO
_bufferView* bv = malloc(sizeof(_bufferView));
_bufferView* bv = ALLOCATE(sizeof(_bufferView), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
bv->buffer = pCreateInfo->buffer;
bv->format = pCreateInfo->format;
@ -157,10 +147,8 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(
assert(device);
assert(bufferView);
assert(pAllocator == 0); //TODO
_bufferView* bv = bufferView;
free(bv);
FREE(bv);
}
/*
@ -176,9 +164,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(
assert(pCreateInfo);
assert(pImage);
assert(pAllocator == 0);
_image* i = malloc(sizeof(_image));
_image* i = ALLOCATE(sizeof(_image), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!i)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -212,7 +198,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(
i->numQueueFamiliesWithAccess = pCreateInfo->queueFamilyIndexCount;
if(i->numQueueFamiliesWithAccess > 0)
{
i->queueFamiliesWithAccess = malloc(sizeof(uint32_t) * i->numQueueFamiliesWithAccess);
i->queueFamiliesWithAccess = ALLOCATE(sizeof(uint32_t) * i->numQueueFamiliesWithAccess, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!i->queueFamiliesWithAccess)
return VK_ERROR_OUT_OF_HOST_MEMORY;
memcpy(i->queueFamiliesWithAccess, pCreateInfo->pQueueFamilyIndices, sizeof(uint32_t) * i->numQueueFamiliesWithAccess);
@ -239,14 +225,12 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyImage(
assert(device);
assert(image);
assert(pAllocator == 0); //TODO
_image* i = image;
if(i->numQueueFamiliesWithAccess > 0);
free(i->queueFamiliesWithAccess);
FREE(i->queueFamiliesWithAccess);
free(i);
FREE(i);
}
/*

View File

@ -10,9 +10,7 @@ VkResult vkCreateShaderModuleFromRpiAssemblyKHR(VkDevice device, VkRpiShaderModu
assert(pCreateInfo->byteStreamArray);
assert(pCreateInfo->numBytesArray);
assert(pAllocator == 0); //TODO
_shaderModule* shader = malloc(sizeof(_shaderModule));
_shaderModule* shader = ALLOCATE(sizeof(_shaderModule), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!shader)
{
@ -52,8 +50,6 @@ void vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const V
assert(device);
assert(shaderModule);
assert(pAllocator == 0);
_shaderModule* shader = shaderModule;
for(int c = 0; c < VK_RPI_ASSEMBLY_TYPE_MAX; ++c)
@ -64,5 +60,5 @@ void vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const V
}
}
free(shader);
FREE(shader);
}

View File

@ -24,11 +24,8 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
assert(device);
assert(pSemaphore);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
//we'll probably just use an IOCTL to wait for a GPU sequence number to complete.
sem_t* s = malloc(sizeof(sem_t));
sem_t* s = ALLOCATE(sizeof(sem_t), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!s)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -281,10 +278,9 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(
assert(device);
assert(semaphore);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
sem_destroy((sem_t*)semaphore);
FREE(semaphore);
}
/*
@ -300,9 +296,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence(
assert(pCreateInfo);
assert(pFence);
assert(pAllocator == 0);
_fence* f = malloc(sizeof(_fence));
_fence* f = ALLOCATE(sizeof(_fence), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
f->seqno = 0;
f->signaled = pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT;
@ -321,9 +315,7 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyFence(
assert(device);
assert(fence);
assert(pAllocator == 0);
free(fence);
FREE(fence);
}
/*

View File

@ -15,8 +15,8 @@ VkResult vkCreateRpiSurfaceKHR(
assert(instance);
//assert(pCreateInfo); //ignored for now
assert(pSurface);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
//TODO use allocator!
*pSurface = (VkSurfaceKHR)modeset_create(instance->controlFd);
@ -37,8 +37,7 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
assert(instance);
assert(surface);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
//TODO use allocator
modeset_destroy(instance->controlFd, (modeset_dev*)surface);
}
@ -183,10 +182,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
assert(pCreateInfo);
assert(pSwapchain);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
*pSwapchain = malloc(sizeof(_swapchain));
*pSwapchain = ALLOCATE(sizeof(_swapchain), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!*pSwapchain)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -197,7 +193,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
//TODO flags, layers, queue sharing, pretransform, composite alpha, present mode..., clipped, oldswapchain
//TODO external sync on surface, oldswapchain
s->images = malloc(sizeof(_image) * pCreateInfo->minImageCount);
s->images = ALLOCATE(sizeof(_image) * pCreateInfo->minImageCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!s->images)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
@ -222,7 +218,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
s->images[c].numQueueFamiliesWithAccess = pCreateInfo->queueFamilyIndexCount;
if(s->images[c].concurrentAccess)
{
s->images[c].queueFamiliesWithAccess = malloc(sizeof(uint32_t)*s->images[c].numQueueFamiliesWithAccess);
s->images[c].queueFamiliesWithAccess = ALLOCATE(sizeof(uint32_t)*s->images[c].numQueueFamiliesWithAccess, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
memcpy(s->images[c].queueFamiliesWithAccess, pCreateInfo->pQueueFamilyIndices, sizeof(uint32_t)*s->images[c].numQueueFamiliesWithAccess);
}
s->images[c].preTransformMode = pCreateInfo->preTransform;
@ -395,9 +391,6 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
assert(device);
assert(swapchain);
//TODO: allocator is ignored for now
assert(pAllocator == 0);
//TODO flush all ops
_swapchain* s = swapchain;
@ -408,7 +401,7 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
modeset_destroy_fb(device->dev->instance->controlFd, &s->images[c]);
}
free(s->images);
free(s);
FREE(s->images);
FREE(s);
}