From 3639703ab90cbfa6083e8d5dce8af02e1127c096 Mon Sep 17 00:00:00 2001 From: Unknown <0.tamas.marton@gmail.com> Date: Thu, 18 Oct 2018 21:17:02 +0100 Subject: [PATCH] added some resource stuff --- driver/common.h | 8 +++ driver/resource.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) diff --git a/driver/common.h b/driver/common.h index 7e2b2e5..30a7f3f 100644 --- a/driver/common.h +++ b/driver/common.h @@ -269,6 +269,14 @@ typedef struct VkFence_T uint32_t signaled; } _fence; +typedef struct VkBufferView_T +{ + _buffer* buffer; + VkFormat format; + VkDeviceSize offset; + VkDeviceSize range; +} _bufferView; + uint32_t getFormatBpp(VkFormat f); uint32_t packVec4IntoABGR8(const float rgba[4]); void createImageBO(_image* i); diff --git a/driver/resource.c b/driver/resource.c index 7a57ce9..14cb387 100644 --- a/driver/resource.c +++ b/driver/resource.c @@ -124,3 +124,152 @@ void vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocati _imageView* view = imageView; free(view); } + + +/* + * https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateBufferView + */ +VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView( + VkDevice device, + const VkBufferViewCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkBufferView* pView) +{ + assert(device); + assert(pCreateInfo); + assert(pView); + + assert(pAllocator == 0); //TODO + + _bufferView* bv = malloc(sizeof(_bufferView)); + + bv->buffer = pCreateInfo->buffer; + bv->format = pCreateInfo->format; + bv->offset = pCreateInfo->offset; + bv->range = pCreateInfo->range; + + *pView = bv; +} + +/* + * https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkDestroyBufferView + */ +VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView( + VkDevice device, + VkBufferView bufferView, + const VkAllocationCallbacks* pAllocator) +{ + assert(device); + assert(bufferView); + + assert(pAllocator == 0); //TODO + + _bufferView* bv = bufferView; + free(bv); +} + +/* + * https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateImage + */ +VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage( + VkDevice device, + const VkImageCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkImage* pImage) +{ + assert(device); + assert(pCreateInfo); + assert(pImage); + + assert(pAllocator == 0); + + _image* i = malloc(sizeof(_image)); + if(!i) + { + return VK_ERROR_OUT_OF_HOST_MEMORY; + } + + //TODO flags? + //TODO? pCreateInfo->imageType + i->format = pCreateInfo->format; + i->width = pCreateInfo->extent.width; + i->height = pCreateInfo->extent.height; + i->depth = pCreateInfo->extent.depth; + i->miplevels = pCreateInfo->mipLevels; + i->layers = pCreateInfo->arrayLayers; + i->samples = pCreateInfo->samples; //TODO? + i->tiling = pCreateInfo->tiling; //TODO? + i->usageBits = pCreateInfo->usage; + i->concurrentAccess = pCreateInfo->sharingMode; //TODO? + i->numQueueFamiliesWithAccess = pCreateInfo->queueFamilyIndexCount; + if(i->numQueueFamiliesWithAccess > 0) + { + i->queueFamiliesWithAccess = malloc(sizeof(uint32_t) * i->numQueueFamiliesWithAccess); + if(!i->queueFamiliesWithAccess) + return VK_ERROR_OUT_OF_HOST_MEMORY; + memcpy(i->queueFamiliesWithAccess, pCreateInfo->pQueueFamilyIndices, sizeof(uint32_t) * i->numQueueFamiliesWithAccess); + } + i->layout = pCreateInfo->initialLayout; + + //TODO what else memory allocation, buffer object creation etc? + + *pImage = i; + + return VK_SUCCESS; +} + +/* + * https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkDestroyImage + */ +VKAPI_ATTR void VKAPI_CALL vkDestroyImage( + VkDevice device, + VkImage image, + const VkAllocationCallbacks* pAllocator) +{ + assert(device); + assert(image); + + assert(pAllocator == 0); //TODO + + _image* i = image; + + if(i->numQueueFamiliesWithAccess > 0); + free(i->queueFamiliesWithAccess); + + free(i); +} + +/* + * https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkGetImageMemoryRequirements + */ +VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements( + VkDevice device, + VkImage image, + VkMemoryRequirements* pMemoryRequirements) +{ + assert(device); + assert(image); + assert(pMemoryRequirements); + + _image* i = image; + + //TODO?? +} + +/* + * https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkBindImageMemory + */ +VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory( + VkDevice device, + VkImage image, + VkDeviceMemory memory, + VkDeviceSize memoryOffset) +{ + assert(device); + assert(image); + assert(memory); + + //TODO + + return VK_SUCCESS; +}