Merge branch 'master' of https://github.com/GregoryWells2007/Gryphn
This commit is contained in:
@@ -33,8 +33,15 @@ add_subdirectory(projects/loader) # build gryphn loader
|
|||||||
add_subdirectory(projects/core) # build gryphn core
|
add_subdirectory(projects/core) # build gryphn core
|
||||||
add_subdirectory(projects/extensions)
|
add_subdirectory(projects/extensions)
|
||||||
add_subdirectory(projects/platform) # build gryphn platform
|
add_subdirectory(projects/platform) # build gryphn platform
|
||||||
|
|
||||||
add_subdirectory(projects/validation_layers/function_loader/)
|
add_subdirectory(projects/validation_layers/function_loader/)
|
||||||
|
<<<<<<< HEAD
|
||||||
target_link_libraries(Gryphn INTERFACE GryphnCore GryphnLoader GryphnPlatform GryphnFunctionValidator GryphnExtensions)
|
target_link_libraries(Gryphn INTERFACE GryphnCore GryphnLoader GryphnPlatform GryphnFunctionValidator GryphnExtensions)
|
||||||
|
=======
|
||||||
|
add_subdirectory(projects/validation_layers/allocators/)
|
||||||
|
|
||||||
|
target_link_libraries(Gryphn INTERFACE GryphnUtils GryphnCore GryphnLoader GryphnPlatform GryphnFunctionValidator GryphnAllocatorChecker GryphnExtensions)
|
||||||
|
>>>>>>> acf2f8c22860b57d65172e2356704813fa2e18f0
|
||||||
|
|
||||||
if (VULKAN_BUILT)
|
if (VULKAN_BUILT)
|
||||||
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl)
|
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl)
|
||||||
|
@@ -7,5 +7,5 @@ typedef struct gnPlatformInstance_t {
|
|||||||
NSView* metalContentView;
|
NSView* metalContentView;
|
||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next);
|
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next);
|
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
#include "metal_instance.h"
|
#include "metal_instance.h"
|
||||||
|
|
||||||
// metal instances are kinda useless
|
// metal instances are kinda useless
|
||||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next) {
|
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||||
if (next != NULL) return GN_SUCCESS;
|
if (next != NULL) return GN_SUCCESS;
|
||||||
|
|
||||||
if (instanceInfo == NULL) return GN_INCOMPLETE;
|
if (instanceInfo == NULL) return GN_INCOMPLETE;
|
||||||
instance->instance = malloc(sizeof(gnPlatformInstance));
|
instance->instance = allocators->malloc(sizeof(gnPlatformInstance), allocators->userData);
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next) {
|
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||||
if (next != NULL) return;
|
if (next != NULL) return;
|
||||||
free(instance->instance);
|
allocators->free(instance->instance, allocators->userData);
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,7 @@ gnReturnCode createMetalGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gn
|
|||||||
mtlSubpass subpass = info.renderPassDescriptor->renderPassDescriptor->subpasses[info.subpassIndex];
|
mtlSubpass subpass = info.renderPassDescriptor->renderPassDescriptor->subpasses[info.subpassIndex];
|
||||||
mtlSubpassCopyInfo copyInfo = info.renderPassDescriptor->renderPassDescriptor->copyInfos[info.subpassIndex];
|
mtlSubpassCopyInfo copyInfo = info.renderPassDescriptor->renderPassDescriptor->copyInfos[info.subpassIndex];
|
||||||
for (uint32_t i = 0; i < copyInfo.colorAttachmentCount; i++) {
|
for (uint32_t i = 0; i < copyInfo.colorAttachmentCount; i++) {
|
||||||
descriptor.colorAttachments[i].pixelFormat = copyInfo.colorAttachments[i].format;
|
[descriptor.colorAttachments objectAtIndexedSubscript:i].pixelFormat = copyInfo.colorAttachments[i].format;
|
||||||
if (info.colorBlending.enable == GN_TRUE) {
|
if (info.colorBlending.enable == GN_TRUE) {
|
||||||
[descriptor.colorAttachments objectAtIndexedSubscript:i].blendingEnabled = YES;
|
[descriptor.colorAttachments objectAtIndexedSubscript:i].blendingEnabled = YES;
|
||||||
[descriptor.colorAttachments objectAtIndexedSubscript:i].rgbBlendOperation = mtlGryphnBlendOperation(info.colorBlending.colorBlendOperation);
|
[descriptor.colorAttachments objectAtIndexedSubscript:i].rgbBlendOperation = mtlGryphnBlendOperation(info.colorBlending.colorBlendOperation);
|
||||||
@@ -85,7 +85,6 @@ gnReturnCode createMetalGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gn
|
|||||||
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
|
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
|
||||||
.message = gnCombineStrings(gnCreateString("Failed to compile metal library "), errorString)
|
.message = gnCombineStrings(gnCreateString("Failed to compile metal library "), errorString)
|
||||||
});
|
});
|
||||||
[shaderLib release];
|
|
||||||
free((void*)shaderCode);
|
free((void*)shaderCode);
|
||||||
return GN_FAILED_CREATE_OBJECT;
|
return GN_FAILED_CREATE_OBJECT;
|
||||||
}
|
}
|
||||||
@@ -134,7 +133,6 @@ gnReturnCode createMetalGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gn
|
|||||||
graphicsPipeline->graphicsPipeline->graphicsPipeline = [device->outputDevice->device newRenderPipelineStateWithDescriptor:descriptor error:&error];
|
graphicsPipeline->graphicsPipeline->graphicsPipeline = [device->outputDevice->device newRenderPipelineStateWithDescriptor:descriptor error:&error];
|
||||||
[descriptor release];
|
[descriptor release];
|
||||||
[vertexDescriptor release];
|
[vertexDescriptor release];
|
||||||
[error release];
|
|
||||||
if (graphicsPipeline->graphicsPipeline->graphicsPipeline == nil) return GN_FAILED_CREATE_OBJECT;
|
if (graphicsPipeline->graphicsPipeline->graphicsPipeline == nil) return GN_FAILED_CREATE_OBJECT;
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
|
||||||
project(GryphnVulkanImpl)
|
project(GryphnVulkanImpl)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
add_compile_definitions(GN_REVEAL_IMPL)
|
add_compile_definitions(GN_REVEAL_IMPL)
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS "src/*.c" "src/*.h")
|
file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS "src/*.c" "src/*.h")
|
||||||
@@ -9,9 +11,11 @@ if (APPLE)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
add_library(GryphnVulkanImpl STATIC ${SOURCE_FILES} ${METAL_FILES} ${LOADER_FILES})
|
add_library(GryphnVulkanImpl STATIC ${SOURCE_FILES} ${METAL_FILES} ${LOADER_FILES} depends/memory_allocator/vk_mem_alloc.cpp)
|
||||||
target_link_libraries(GryphnVulkanImpl ${Vulkan_LIBRARY})
|
target_link_libraries(GryphnVulkanImpl ${Vulkan_LIBRARY})
|
||||||
|
|
||||||
|
target_compile_options(GryphnVulkanImpl PRIVATE -Wno-nullability-completeness)
|
||||||
|
|
||||||
target_include_directories(GryphnVulkanImpl PUBLIC
|
target_include_directories(GryphnVulkanImpl PUBLIC
|
||||||
${Vulkan_INCLUDE_DIRS}
|
${Vulkan_INCLUDE_DIRS}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/
|
${CMAKE_CURRENT_SOURCE_DIR}/src/
|
||||||
@@ -23,6 +27,7 @@ target_include_directories(GryphnVulkanImpl PUBLIC
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../
|
${CMAKE_CURRENT_SOURCE_DIR}/../../
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../depends/
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../depends/
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/depends/
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
@@ -0,0 +1,2 @@
|
|||||||
|
#define VMA_IMPLEMENTATION
|
||||||
|
#include "vk_mem_alloc.h"
|
19535
projects/apis/vulkan/depends/memory_allocator/vk_mem_alloc.h
Normal file
19535
projects/apis/vulkan/depends/memory_allocator/vk_mem_alloc.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,8 @@ gnDeviceFunctions loadVulkanDeviceFunctions(void) {
|
|||||||
._gnCreateBuffer = createBuffer,
|
._gnCreateBuffer = createBuffer,
|
||||||
._gnBufferData = vulkanBufferData,
|
._gnBufferData = vulkanBufferData,
|
||||||
._gnBufferSubData = vulkanBufferSubData,
|
._gnBufferSubData = vulkanBufferSubData,
|
||||||
._gnMapBuffer = mapBuffer,
|
._gnMapBuffer = vulkanMapBuffer,
|
||||||
|
._gnUnmapBuffer = vulkanUnmapBuffer,
|
||||||
._gnDestroyBuffer = destroyBuffer,
|
._gnDestroyBuffer = destroyBuffer,
|
||||||
|
|
||||||
._gnCreateUniformPool = createUniformPool,
|
._gnCreateUniformPool = createUniformPool,
|
||||||
|
@@ -7,57 +7,13 @@
|
|||||||
|
|
||||||
VkBufferUsageFlags vkGryphnBufferType(gnBufferType type) {
|
VkBufferUsageFlags vkGryphnBufferType(gnBufferType type) {
|
||||||
VkBufferUsageFlags usageFlags = 0;
|
VkBufferUsageFlags usageFlags = 0;
|
||||||
switch (type) {
|
if ((type & GN_VERTEX_BUFFER) == GN_VERTEX_BUFFER) usageFlags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
|
||||||
case GN_VERTEX_BUFFER: usageFlags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; break;
|
if ((type & GN_INDEX_BUFFER) == GN_INDEX_BUFFER) usageFlags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
|
||||||
case GN_INDEX_BUFFER: usageFlags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; break;
|
if ((type & GN_UNIFORM_BUFFER) == GN_UNIFORM_BUFFER) usageFlags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
|
||||||
case GN_UNIFORM_BUFFER: usageFlags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; break;
|
if ((type & GN_STORAGE_BUFFER) == GN_STORAGE_BUFFER) usageFlags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||||
case GN_STORAGE_BUFFER: usageFlags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; break;
|
|
||||||
}
|
|
||||||
return usageFlags;
|
return usageFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t VkMemoryIndex(VkPhysicalDevice device, uint32_t memoryType, VkMemoryPropertyFlags flags, gnBool* foundMemory) {
|
|
||||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
|
||||||
vkGetPhysicalDeviceMemoryProperties(device, &memoryProperties);
|
|
||||||
for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++) {
|
|
||||||
if ((memoryType & (1 << i)) && (memoryProperties.memoryTypes[i].propertyFlags & flags) == flags) {
|
|
||||||
*foundMemory = GN_TRUE;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
} // this whole thing was adapted from vulkan-tutorial.com
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
gnReturnCode VkCreateBuffer(
|
|
||||||
VkGryphnBuffer* buffer, size_t size, gnDevice device,
|
|
||||||
VkMemoryPropertyFlags flags, VkBufferUsageFlags usage
|
|
||||||
) {
|
|
||||||
VkBufferCreateInfo bufferInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
||||||
.size = size,
|
|
||||||
.usage = usage,
|
|
||||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE
|
|
||||||
};
|
|
||||||
|
|
||||||
VkResult created_buffer = vkCreateBuffer(device->outputDevice->device, &bufferInfo, NULL, &buffer->buffer);
|
|
||||||
if (created_buffer != VK_SUCCESS)
|
|
||||||
return VkResultToGnReturnCode(created_buffer);
|
|
||||||
|
|
||||||
VkMemoryRequirements bufferRequirements;
|
|
||||||
vkGetBufferMemoryRequirements(device->outputDevice->device, buffer->buffer, &bufferRequirements);
|
|
||||||
|
|
||||||
gnBool foundMemory = GN_FALSE;
|
|
||||||
VkMemoryAllocateInfo memoryAllocateInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
|
||||||
.allocationSize = bufferRequirements.size,
|
|
||||||
.memoryTypeIndex = VkMemoryIndex(device->outputDevice->physicalDevice, bufferRequirements.memoryTypeBits, flags, &foundMemory)
|
|
||||||
};
|
|
||||||
if (!foundMemory) return GN_FAILED_TO_ALLOCATE_MEMORY;
|
|
||||||
|
|
||||||
VkResult memoryFound = vkAllocateMemory(device->outputDevice->device, &memoryAllocateInfo, NULL, &buffer->memory);
|
|
||||||
if (memoryFound == VK_SUCCESS) vkBindBufferMemory(device->outputDevice->device, buffer->buffer, buffer->memory, 0);
|
|
||||||
return VkResultToGnReturnCode(memoryFound);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VkCopyBuffer(gnDevice device, VkBuffer source, VkBuffer destination, VkBufferCopy copy) {
|
void VkCopyBuffer(gnDevice device, VkBuffer source, VkBuffer destination, VkBufferCopy copy) {
|
||||||
VkCommandBuffer transferBuffer = gnBeginVulkanTransferOperation(device);
|
VkCommandBuffer transferBuffer = gnBeginVulkanTransferOperation(device);
|
||||||
vkCmdCopyBuffer(transferBuffer, source, destination, 1, ©);
|
vkCmdCopyBuffer(transferBuffer, source, destination, 1, ©);
|
||||||
@@ -68,19 +24,41 @@ gnReturnCode createBuffer(gnBufferHandle buffer, gnOutputDeviceHandle device, gn
|
|||||||
buffer->buffer = malloc(sizeof(struct gnPlatformBuffer_t));
|
buffer->buffer = malloc(sizeof(struct gnPlatformBuffer_t));
|
||||||
buffer->buffer->useStagingBuffer = (info.usage == GN_STATIC_DRAW);
|
buffer->buffer->useStagingBuffer = (info.usage == GN_STATIC_DRAW);
|
||||||
if (info.usage == GN_STATIC_DRAW) {
|
if (info.usage == GN_STATIC_DRAW) {
|
||||||
return VkCreateBuffer(
|
VkBufferCreateInfo bufferCreateInfo = {
|
||||||
&buffer->buffer->buffer,
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
info.size, device,
|
.pNext = NULL,
|
||||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
.flags = 0,
|
||||||
vkGryphnBufferType(info.type) | VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
.queueFamilyIndexCount = 0,
|
||||||
);
|
.size = info.size,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.usage = vkGryphnBufferType(info.type) | VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo bufferAllocationInfo = {
|
||||||
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
|
.flags = 0,
|
||||||
|
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||||
|
};
|
||||||
|
|
||||||
|
return VkResultToGnReturnCode(vmaCreateBuffer(device->outputDevice->allocator, &bufferCreateInfo, &bufferAllocationInfo, &buffer->buffer->buffer.buffer, &buffer->buffer->buffer.allocation, NULL));
|
||||||
} else {
|
} else {
|
||||||
return VkCreateBuffer(
|
VkBufferCreateInfo bufferCreateInfo = {
|
||||||
&buffer->buffer->buffer,
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
info.size, device,
|
.pNext = NULL,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
.flags = 0,
|
||||||
vkGryphnBufferType(info.type)
|
.queueFamilyIndexCount = 0,
|
||||||
);
|
.size = info.size,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.usage = vkGryphnBufferType(info.type)
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo bufferAllocationInfo = {
|
||||||
|
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||||
|
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
|
};
|
||||||
|
|
||||||
|
return VkResultToGnReturnCode(vmaCreateBuffer(device->outputDevice->allocator, &bufferCreateInfo, &bufferAllocationInfo, &buffer->buffer->buffer.buffer, &buffer->buffer->buffer.allocation, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
@@ -95,9 +73,9 @@ void vulkanBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize,
|
|||||||
VkDeviceSize sizeLeft = dataSize;
|
VkDeviceSize sizeLeft = dataSize;
|
||||||
while (sizeLeft > 0) {
|
while (sizeLeft > 0) {
|
||||||
VkDeviceSize chunkSize = (buffer->device->outputDevice->stagingBufferSize < sizeLeft) ? buffer->device->outputDevice->stagingBufferSize : sizeLeft;
|
VkDeviceSize chunkSize = (buffer->device->outputDevice->stagingBufferSize < sizeLeft) ? buffer->device->outputDevice->stagingBufferSize : sizeLeft;
|
||||||
vkMapMemory(buffer->device->outputDevice->device, stagingBuffer->memory, 0, chunkSize, 0, &bufferData);
|
vulkanMapBufferInternal(buffer->device, *stagingBuffer, &bufferData);
|
||||||
memcpy(bufferData, (char*)data + (dataSize - sizeLeft), chunkSize);
|
memcpy(bufferData, (char*)data + (dataSize - sizeLeft), chunkSize);
|
||||||
vkUnmapMemory(buffer->device->outputDevice->device, stagingBuffer->memory);
|
vulkanUnmapBufferInternal(buffer->device, *stagingBuffer);
|
||||||
|
|
||||||
VkBufferCopy copyRegion = {
|
VkBufferCopy copyRegion = {
|
||||||
.srcOffset = 0,
|
.srcOffset = 0,
|
||||||
@@ -108,24 +86,35 @@ void vulkanBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize,
|
|||||||
sizeLeft -= chunkSize;
|
sizeLeft -= chunkSize;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vkMapMemory(buffer->device->outputDevice->device, buffer->buffer->buffer.memory, 0, dataSize, 0, &bufferData);
|
bufferData = vulkanMapBuffer(buffer);
|
||||||
memcpy((char*)bufferData + offset, data, dataSize);
|
memcpy((char*)bufferData + offset, data, dataSize);
|
||||||
vkUnmapMemory(buffer->device->outputDevice->device, buffer->buffer->buffer.memory);
|
vulkanUnmapBuffer(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void* mapBuffer(gnBufferHandle buffer) {
|
|
||||||
|
|
||||||
|
void vulkanMapBufferInternal(gnDevice device, VkGryphnBuffer buffer, void* data) {
|
||||||
|
vmaMapMemory(device->outputDevice->allocator, buffer.allocation, data);
|
||||||
|
}
|
||||||
|
void vulkanUnmapBufferInternal(gnDevice device, VkGryphnBuffer buffer) {
|
||||||
|
vmaUnmapMemory(device->outputDevice->allocator, buffer.allocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* vulkanMapBuffer(gnBufferHandle buffer) {
|
||||||
void* data;
|
void* data;
|
||||||
vkMapMemory(buffer->device->outputDevice->device, buffer->buffer->buffer.memory, 0, buffer->info.size, 0, &data);
|
vulkanMapBufferInternal(buffer->device, buffer->buffer->buffer, &data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyVulkanBuffer(VkGryphnBuffer* buffer, VkDevice device) {
|
void vulkanUnmapBuffer(gnBufferHandle buffer) {
|
||||||
vkDestroyBuffer(device, buffer->buffer, NULL);
|
vulkanUnmapBufferInternal(buffer->device, buffer->buffer->buffer);
|
||||||
vkFreeMemory(device, buffer->memory, NULL);
|
}
|
||||||
|
|
||||||
|
void gnDestroyVulkanBuffer(VkGryphnBuffer* buffer, gnDevice device) {
|
||||||
|
vmaDestroyBuffer(device->outputDevice->allocator, buffer->buffer, buffer->allocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyBuffer(gnBufferHandle buffer) {
|
void destroyBuffer(gnBufferHandle buffer) {
|
||||||
// if (buffer->buffer->useStagingBuffer == gnTrue) gnDestroyVulkanBuffer(&buffer->buffer->stagingBuffer, buffer->device->outputDevice->device);
|
gnDestroyVulkanBuffer(&buffer->buffer->buffer, buffer->device);
|
||||||
gnDestroyVulkanBuffer(&buffer->buffer->buffer, buffer->device->outputDevice->device);
|
|
||||||
free(buffer->buffer);
|
free(buffer->buffer);
|
||||||
}
|
}
|
||||||
|
@@ -2,27 +2,32 @@
|
|||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include "utils/gryphn_bool.h"
|
#include "utils/gryphn_bool.h"
|
||||||
#include <buffers/gryphn_buffer.h>
|
#include <buffers/gryphn_buffer.h>
|
||||||
|
#include <memory_allocator/vk_mem_alloc.h>
|
||||||
|
|
||||||
typedef struct VkGryphnBuffer {
|
typedef struct VkGryphnBuffer {
|
||||||
VkBuffer buffer;
|
VkBuffer buffer;
|
||||||
VkDeviceMemory memory;
|
VmaAllocation allocation;
|
||||||
} VkGryphnBuffer;
|
} VkGryphnBuffer;
|
||||||
void gnDestroyVulkanBuffer(VkGryphnBuffer* buffer, VkDevice device);
|
|
||||||
|
|
||||||
struct gnPlatformBuffer_t {
|
struct gnPlatformBuffer_t {
|
||||||
VkGryphnBuffer buffer;
|
VkGryphnBuffer buffer;
|
||||||
gnBool useStagingBuffer;
|
gnBool useStagingBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
gnReturnCode VkCreateBuffer(
|
// gnReturnCode VkCreateBuffer(
|
||||||
VkGryphnBuffer* buffer, size_t size, gnDevice device,
|
// VkGryphnBuffer* buffer, size_t size, gnDevice device,
|
||||||
VkMemoryPropertyFlags flags, VkBufferUsageFlags usage
|
// VkMemoryPropertyFlags flags, VkBufferUsageFlags usage
|
||||||
);
|
// );
|
||||||
void gnDestroyVulkanBuffer(VkGryphnBuffer* buffer, VkDevice device);
|
// void gnDestroyVulkanBuffer(VkGryphnBuffer* buffer, gnDevice device);
|
||||||
uint32_t VkMemoryIndex(VkPhysicalDevice device, uint32_t memoryType, VkMemoryPropertyFlags flags, gnBool* foundMemory);
|
// uint32_t VkMemoryIndex(VkPhysicalDevice device, uint32_t memoryType, VkMemoryPropertyFlags flags, gnBool* foundMemory);
|
||||||
|
|
||||||
gnReturnCode createBuffer(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info);
|
gnReturnCode createBuffer(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info);
|
||||||
void vulkanBufferData(gnBufferHandle buffer, size_t dataSize, void* data);
|
void vulkanBufferData(gnBufferHandle buffer, size_t dataSize, void* data);
|
||||||
void vulkanBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, void* data);
|
void vulkanBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, void* data);
|
||||||
void* mapBuffer(gnBufferHandle buffer);
|
|
||||||
|
void vulkanMapBufferInternal(gnDevice device, VkGryphnBuffer buffer, void* data);
|
||||||
|
void vulkanUnmapBufferInternal(gnDevice device, VkGryphnBuffer buffer);
|
||||||
|
void* vulkanMapBuffer(gnBufferHandle buffer);
|
||||||
|
void vulkanUnmapBuffer(gnBufferHandle buffer);
|
||||||
|
|
||||||
void destroyBuffer(gnBufferHandle buffer);
|
void destroyBuffer(gnBufferHandle buffer);
|
||||||
|
@@ -43,9 +43,9 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
|
|||||||
return VK_TRUE;
|
return VK_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next) {
|
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||||
if (next != NULL) { return GN_SUCCESS; }
|
if (next != NULL) { return GN_SUCCESS; }
|
||||||
instance->instance = malloc(sizeof(gnPlatformInstance));
|
instance->instance = alloctors->malloc(sizeof(gnPlatformInstance), alloctors->userData);
|
||||||
|
|
||||||
vkStringArrayList extensions = vkStringArrayListCreate();
|
vkStringArrayList extensions = vkStringArrayListCreate();
|
||||||
vkStringArrayListAdd(extensions, "VK_KHR_surface");
|
vkStringArrayListAdd(extensions, "VK_KHR_surface");
|
||||||
@@ -109,7 +109,8 @@ gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInf
|
|||||||
return VkResultToGnReturnCode(vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance));
|
return VkResultToGnReturnCode(vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next) {
|
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||||
if (next != NULL) { return; }
|
if (next != NULL) { return; }
|
||||||
vkDestroyInstance(instance->instance->vk_instance, NULL);
|
vkDestroyInstance(instance->instance->vk_instance, NULL);
|
||||||
|
alloctors->free(instance->instance, alloctors->userData);
|
||||||
}
|
}
|
||||||
|
@@ -14,8 +14,8 @@ typedef struct gnPlatformInstance_t {
|
|||||||
vkUserData userData;
|
vkUserData userData;
|
||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next);
|
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
|
|
||||||
typedef const char* vkString;
|
typedef const char* vkString;
|
||||||
GN_ARRAY_LIST_HEADER(vkString);
|
GN_ARRAY_LIST_HEADER(vkString);
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "vulkan_device_extensions.h"
|
#include "vulkan_device_extensions.h"
|
||||||
#include "instance/gryphn_instance.h"
|
#include "instance/gryphn_instance.h"
|
||||||
#include "commands/command_buffer/vulkan_command_buffer.h"
|
#include "commands/command_buffer/vulkan_command_buffer.h"
|
||||||
|
#include "instance/vulkan_instance.h"
|
||||||
#include "vulkan_result_converter.h"
|
#include "vulkan_result_converter.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
@@ -95,15 +96,34 @@ gnReturnCode createVulkanOutputDevice(gnInstanceHandle instance, gnOutputDeviceH
|
|||||||
VkResult fence_result = vkCreateFence(device->outputDevice->device, &fenceInfo, NULL, &device->outputDevice->barrierFence);
|
VkResult fence_result = vkCreateFence(device->outputDevice->device, &fenceInfo, NULL, &device->outputDevice->barrierFence);
|
||||||
if (fence_result != VK_SUCCESS) VkResultToGnReturnCode(fence_result);
|
if (fence_result != VK_SUCCESS) VkResultToGnReturnCode(fence_result);
|
||||||
|
|
||||||
|
VmaAllocatorCreateInfo allocatorCreateInfo = {
|
||||||
|
.device = device->outputDevice->device,
|
||||||
|
.physicalDevice = device->outputDevice->physicalDevice,
|
||||||
|
.instance = instance->instance->vk_instance,
|
||||||
|
};
|
||||||
|
if (vmaCreateAllocator(&allocatorCreateInfo, &device->outputDevice->allocator) != VK_SUCCESS)
|
||||||
|
return GN_FAILED_CREATE_ALLOCATOR;
|
||||||
|
|
||||||
// create the massive staging buffer
|
// create the massive staging buffer
|
||||||
device->outputDevice->stagingBufferSize = 128 * 1024 * 1024;
|
device->outputDevice->stagingBufferSize = 128 * 1024 * 1024;
|
||||||
gnReturnCode code = VkCreateBuffer(
|
|
||||||
&device->outputDevice->stagingBuffer,
|
VkBufferCreateInfo bufferCreateInfo = {
|
||||||
device->outputDevice->stagingBufferSize, device,
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
.pNext = NULL,
|
||||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
.flags = 0,
|
||||||
);
|
.queueFamilyIndexCount = 0,
|
||||||
return code; // lowkey is a hack
|
.size = device->outputDevice->stagingBufferSize,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo bufferAllocationInfo = {
|
||||||
|
.usage = VMA_MEMORY_USAGE_CPU_ONLY,
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||||
|
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
|
};
|
||||||
|
|
||||||
|
return VkResultToGnReturnCode(vmaCreateBuffer(device->outputDevice->allocator, &bufferCreateInfo, &bufferAllocationInfo, &device->outputDevice->stagingBuffer.buffer, &device->outputDevice->stagingBuffer.allocation, NULL)); // lowkey is a hack
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForDevice(const gnOutputDeviceHandle device) {
|
void waitForDevice(const gnOutputDeviceHandle device) {
|
||||||
@@ -112,8 +132,9 @@ void waitForDevice(const gnOutputDeviceHandle device) {
|
|||||||
|
|
||||||
void destroyVulkanOutputDevice(gnOutputDeviceHandle device) {
|
void destroyVulkanOutputDevice(gnOutputDeviceHandle device) {
|
||||||
vkDestroyFence(device->outputDevice->device, device->outputDevice->barrierFence, NULL);
|
vkDestroyFence(device->outputDevice->device, device->outputDevice->barrierFence, NULL);
|
||||||
gnDestroyVulkanBuffer(&device->outputDevice->stagingBuffer, device->outputDevice->device);
|
|
||||||
vkDestroyCommandPool(device->outputDevice->device, device->outputDevice->transferCommandPool, NULL);
|
vkDestroyCommandPool(device->outputDevice->device, device->outputDevice->transferCommandPool, NULL);
|
||||||
|
vmaDestroyBuffer(device->outputDevice->allocator, device->outputDevice->stagingBuffer.buffer, device->outputDevice->stagingBuffer.allocation);
|
||||||
|
vmaDestroyAllocator(device->outputDevice->allocator);
|
||||||
vkDestroyDevice(device->outputDevice->device, NULL);
|
vkDestroyDevice(device->outputDevice->device, NULL);
|
||||||
free(device->outputDevice);
|
free(device->outputDevice);
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include <output_device/gryphn_output_device.h>
|
#include <output_device/gryphn_output_device.h>
|
||||||
#include "buffers/vulkan_buffer.h"
|
#include "buffers/vulkan_buffer.h"
|
||||||
#include "vulkan_physical_device.h"
|
#include "vulkan_physical_device.h"
|
||||||
|
#include <memory_allocator/vk_mem_alloc.h>
|
||||||
|
|
||||||
typedef struct vulkanQueue {
|
typedef struct vulkanQueue {
|
||||||
VkQueue queue;
|
VkQueue queue;
|
||||||
@@ -24,6 +25,8 @@ typedef struct gnPlatformOutputDevice_t {
|
|||||||
|
|
||||||
VkFence barrierFence;
|
VkFence barrierFence;
|
||||||
gnBool enabledOversizedDescriptorPools;
|
gnBool enabledOversizedDescriptorPools;
|
||||||
|
|
||||||
|
VmaAllocator allocator;
|
||||||
} gnPlatformOutputDevice;
|
} gnPlatformOutputDevice;
|
||||||
|
|
||||||
VkCommandBuffer gnBeginVulkanTransferOperation(gnDevice device);
|
VkCommandBuffer gnBeginVulkanTransferOperation(gnDevice device);
|
||||||
|
@@ -143,18 +143,10 @@ void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, gnExtent3D
|
|||||||
|
|
||||||
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
|
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
|
||||||
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
|
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
|
||||||
|
|
||||||
size_t imageSize = info.extent.width * info.extent.height;
|
size_t imageSize = info.extent.width * info.extent.height;
|
||||||
if (info.format == GN_FORMAT_BGRA8_SRGB) { imageSize *= 4; }
|
if (info.format == GN_FORMAT_BGRA8_SRGB) { imageSize *= 4; }
|
||||||
if (info.format == GN_FORMAT_RGBA8_SRGB) { imageSize *= 4; }
|
if (info.format == GN_FORMAT_RGBA8_SRGB) { imageSize *= 4; }
|
||||||
|
|
||||||
gnReturnCode staginBufferCreateCode = VkCreateBuffer(
|
|
||||||
&texture->texture->buffer, imageSize, device,
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
|
||||||
);
|
|
||||||
if (staginBufferCreateCode != GN_SUCCESS) return staginBufferCreateCode;
|
|
||||||
texture->texture->size = imageSize;
|
texture->texture->size = imageSize;
|
||||||
|
|
||||||
VkImageCreateInfo imageInfo = {
|
VkImageCreateInfo imageInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
@@ -172,27 +164,14 @@ gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureIn
|
|||||||
.imageType = vkGryphnTextureType(info.type),
|
.imageType = vkGryphnTextureType(info.type),
|
||||||
.format = vkGryphnFormatToVulkanFormat(info.format)
|
.format = vkGryphnFormatToVulkanFormat(info.format)
|
||||||
};
|
};
|
||||||
|
VmaAllocationCreateInfo allocationInfo = {
|
||||||
VkResult res = vkCreateImage(device->outputDevice->device, &imageInfo, NULL, &texture->texture->image.image);
|
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
|
||||||
if (res != VK_SUCCESS) return VkResultToGnReturnCode(res);
|
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
||||||
|
|
||||||
VkMemoryRequirements memRequirements;
|
|
||||||
vkGetImageMemoryRequirements(device->outputDevice->device, texture->texture->image.image, &memRequirements);
|
|
||||||
|
|
||||||
gnBool foundMemory = GN_FALSE;
|
|
||||||
VkMemoryAllocateInfo allocInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
|
||||||
.allocationSize = memRequirements.size,
|
|
||||||
.memoryTypeIndex = VkMemoryIndex(device->outputDevice->physicalDevice, memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &foundMemory)
|
|
||||||
};
|
};
|
||||||
if (!foundMemory) return GN_FAILED_TO_ALLOCATE_MEMORY;
|
VkResult imageCreateInfo = vmaCreateImage(device->outputDevice->allocator, &imageInfo, &allocationInfo, &texture->texture->image.image, &texture->texture->image.allocation, NULL);
|
||||||
|
if (imageCreateInfo != VK_SUCCESS) return VkResultToGnReturnCode(imageCreateInfo);
|
||||||
VkResult allocationRes = vkAllocateMemory(device->outputDevice->device, &allocInfo, NULL, &texture->texture->image.memory);
|
|
||||||
if (allocationRes != VK_SUCCESS) return VkResultToGnReturnCode(allocationRes);
|
|
||||||
vkBindImageMemory(device->outputDevice->device, texture->texture->image.image, texture->texture->image.memory, 0);
|
|
||||||
|
|
||||||
texture->texture->beenWrittenToo = GN_FALSE;
|
texture->texture->beenWrittenToo = GN_FALSE;
|
||||||
|
|
||||||
VkImageViewCreateInfo viewInfo = {
|
VkImageViewCreateInfo viewInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
.image = texture->texture->image.image,
|
.image = texture->texture->image.image,
|
||||||
@@ -242,28 +221,37 @@ gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
void textureData(gnTextureHandle texture, void* pixelData) {
|
void textureData(gnTextureHandle texture, void* pixelData) {
|
||||||
void* data;
|
|
||||||
vkMapMemory(texture->device->outputDevice->device, texture->texture->buffer.memory, 0, texture->texture->size, 0, &data);
|
|
||||||
memcpy(data, pixelData, texture->texture->size);
|
|
||||||
vkUnmapMemory(texture->device->outputDevice->device, texture->texture->buffer.memory);
|
|
||||||
|
|
||||||
//gnDevice device, VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout
|
|
||||||
VkTransitionImageLayout(texture->device, texture->texture->image.image, texture->info.format, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
VkTransitionImageLayout(texture->device, texture->texture->image.image, texture->info.format, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||||
VkCopyBufferToImage(texture->texture->buffer, texture->texture->image, texture->info.extent, texture->device);
|
|
||||||
VkTransitionImageLayout(texture->device, texture->texture->image.image, texture->info.format, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
||||||
|
|
||||||
|
void* textureData;
|
||||||
|
VkGryphnBuffer* stagingBuffer = &texture->device->outputDevice->stagingBuffer;
|
||||||
|
VkDeviceSize sizeLeft = texture->texture->size, dataSize = texture->texture->size;
|
||||||
|
while (sizeLeft > 0) {
|
||||||
|
VkDeviceSize chunkSize = (texture->device->outputDevice->stagingBufferSize < sizeLeft) ? texture->device->outputDevice->stagingBufferSize : sizeLeft;
|
||||||
|
vulkanMapBufferInternal(texture->device, *stagingBuffer, &textureData);
|
||||||
|
memcpy(textureData, (char*)pixelData + (dataSize - sizeLeft), chunkSize);
|
||||||
|
vulkanUnmapBufferInternal(texture->device, *stagingBuffer);
|
||||||
|
|
||||||
|
VkBufferCopy copyRegion = {
|
||||||
|
.srcOffset = 0,
|
||||||
|
.dstOffset = dataSize - sizeLeft,
|
||||||
|
.size = chunkSize
|
||||||
|
};
|
||||||
|
sizeLeft -= chunkSize;
|
||||||
|
|
||||||
|
VkCopyBufferToImage(texture->device->outputDevice->stagingBuffer, texture->texture->image, texture->info.extent, texture->device);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkTransitionImageLayout(texture->device, texture->texture->image.image, texture->info.format, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||||
texture->texture->beenWrittenToo = GN_TRUE;
|
texture->texture->beenWrittenToo = GN_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyVulkanImage(VkGryphnImage* image, VkDevice device) {
|
void gnDestroyVulkanImage(VkGryphnImage* image, gnDevice device) {
|
||||||
vkDestroyImage(device, image->image, NULL);
|
vmaDestroyImage(device->outputDevice->allocator, image->image, image->allocation);
|
||||||
vkDestroyImageView(device, image->imageView, NULL);
|
vkDestroyImageView(device->outputDevice->device, image->imageView, NULL);
|
||||||
vkFreeMemory(device, image->memory, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyTexture(gnTexture texture) {
|
void destroyTexture(gnTexture texture) {
|
||||||
vkDestroySampler(texture->device->outputDevice->device, texture->texture->sampler, NULL);
|
vkDestroySampler(texture->device->outputDevice->device, texture->texture->sampler, NULL);
|
||||||
|
gnDestroyVulkanImage(&texture->texture->image, texture->device);
|
||||||
gnDestroyVulkanBuffer(&texture->texture->buffer, texture->device->outputDevice->device);
|
|
||||||
gnDestroyVulkanImage(&texture->texture->image, texture->device->outputDevice->device);
|
|
||||||
}
|
}
|
||||||
|
@@ -2,21 +2,22 @@
|
|||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include "textures/gryphn_texture.h"
|
#include "textures/gryphn_texture.h"
|
||||||
#include "buffers/vulkan_buffer.h"
|
#include "buffers/vulkan_buffer.h"
|
||||||
|
#include "memory_allocator/vk_mem_alloc.h"
|
||||||
|
|
||||||
typedef struct VkGryphnImage {
|
typedef struct VkGryphnImage {
|
||||||
VkImage image;
|
VkImage image;
|
||||||
VkDeviceMemory memory;
|
VmaAllocation allocation;
|
||||||
VkImageView imageView;
|
VkImageView imageView;
|
||||||
} VkGryphnImage;
|
} VkGryphnImage;
|
||||||
void gnDestroyVulkanImage(VkGryphnImage* image, VkDevice device);
|
void gnDestroyVulkanImage(VkGryphnImage* image, gnDevice device);
|
||||||
|
|
||||||
typedef struct gnPlatformTexture_t {
|
typedef struct gnPlatformTexture_t {
|
||||||
VkGryphnBuffer buffer;
|
|
||||||
VkGryphnImage image;
|
VkGryphnImage image;
|
||||||
VkSampler sampler;
|
VkSampler sampler;
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
gnBool beenWrittenToo;
|
gnBool beenWrittenToo;
|
||||||
|
|
||||||
|
VkImageLayout currentLayout;
|
||||||
} gnPlatformTexture;
|
} gnPlatformTexture;
|
||||||
|
|
||||||
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info);
|
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info);
|
||||||
|
15
projects/core/gryphn_allocators.h
Normal file
15
projects/core/gryphn_allocators.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef void* (*PFN_gnMalloc) (size_t size, void* userData);
|
||||||
|
typedef void* (*PFN_gnCalloc) (int cnt, size_t size, void* userData);
|
||||||
|
typedef void* (*PFN_gnRealloc) (void* ptr, size_t size, void* userData);
|
||||||
|
typedef void (*PFN_gnFree) (void* ptr, void* userData);
|
||||||
|
|
||||||
|
typedef struct gnAllocators {
|
||||||
|
void* userData;
|
||||||
|
PFN_gnMalloc malloc;
|
||||||
|
PFN_gnCalloc calloc;
|
||||||
|
PFN_gnRealloc realloc;
|
||||||
|
PFN_gnFree free;
|
||||||
|
} gnAllocators;
|
@@ -12,7 +12,7 @@ typedef enum gnReturnCode {
|
|||||||
GN_FAILED_TO_FIND_ENTRY_POINT, GN_FAILED_TO_LOAD_FUNCTION, GN_INCOMPLETE,
|
GN_FAILED_TO_FIND_ENTRY_POINT, GN_FAILED_TO_LOAD_FUNCTION, GN_INCOMPLETE,
|
||||||
GN_NOT_READY, GN_TIMEOUT, GN_DEVICE_LOST, GN_FAILED_MEMORY_MAP, GN_UNSUPPORTED_FEATURE,
|
GN_NOT_READY, GN_TIMEOUT, GN_DEVICE_LOST, GN_FAILED_MEMORY_MAP, GN_UNSUPPORTED_FEATURE,
|
||||||
GN_OVERALLOCATION, GN_FRAGMENTATION, GN_INVALID_HANDLE, GN_SURFACE_LOST, GN_WINDOW_IN_USE,
|
GN_OVERALLOCATION, GN_FRAGMENTATION, GN_INVALID_HANDLE, GN_SURFACE_LOST, GN_WINDOW_IN_USE,
|
||||||
GN_INCOMPATIBLE_DISPLAY, GN_UNSUPPORTED_IMAGE_USE,
|
GN_INCOMPATIBLE_DISPLAY, GN_UNSUPPORTED_IMAGE_USE, GN_FAILED_CREATE_ALLOCATOR,
|
||||||
|
|
||||||
GN_UNLOADED_EXTENSION = -1,
|
GN_UNLOADED_EXTENSION = -1,
|
||||||
GN_UNLOADED_LAYER = -2,
|
GN_UNLOADED_LAYER = -2,
|
||||||
|
@@ -21,6 +21,9 @@ void* gnMapBuffer(gnBufferHandle buffer) {
|
|||||||
if (buffer->info.usage == GN_STATIC_DRAW) return NULL;
|
if (buffer->info.usage == GN_STATIC_DRAW) return NULL;
|
||||||
return buffer->device->instance->callingLayer->deviceFunctions._gnMapBuffer(buffer);
|
return buffer->device->instance->callingLayer->deviceFunctions._gnMapBuffer(buffer);
|
||||||
}
|
}
|
||||||
|
void gnUnmapBuffer(gnBufferHandle buffer) {
|
||||||
|
buffer->device->instance->callingLayer->deviceFunctions._gnUnmapBuffer(buffer);
|
||||||
|
}
|
||||||
void gnDestroyBuffer(gnBufferHandle buffer) {
|
void gnDestroyBuffer(gnBufferHandle buffer) {
|
||||||
buffer->device->instance->callingLayer->deviceFunctions._gnDestroyBuffer(buffer);
|
buffer->device->instance->callingLayer->deviceFunctions._gnDestroyBuffer(buffer);
|
||||||
}
|
}
|
||||||
|
@@ -9,10 +9,10 @@ typedef enum gnIndexType {
|
|||||||
} gnIndexType;
|
} gnIndexType;
|
||||||
|
|
||||||
typedef enum gnBufferType {
|
typedef enum gnBufferType {
|
||||||
GN_VERTEX_BUFFER = 0x00000001,
|
GN_VERTEX_BUFFER = 1 << 0,
|
||||||
GN_INDEX_BUFFER = 0x00000002,
|
GN_INDEX_BUFFER = 1 << 2,
|
||||||
GN_UNIFORM_BUFFER = 0x00000004,
|
GN_UNIFORM_BUFFER = 1 << 3,
|
||||||
GN_STORAGE_BUFFER = 0x00000008
|
GN_STORAGE_BUFFER = 1 << 4
|
||||||
} gnBufferType; // I need to support more buffer types
|
} gnBufferType; // I need to support more buffer types
|
||||||
|
|
||||||
// i love that OpenGL does this so im stealing it
|
// i love that OpenGL does this so im stealing it
|
||||||
@@ -44,4 +44,5 @@ gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device,
|
|||||||
void gnBufferData(gnBufferHandle buffer, size_t dataSize, gnBufferMemory data);
|
void gnBufferData(gnBufferHandle buffer, size_t dataSize, gnBufferMemory data);
|
||||||
void gnBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, gnBufferMemory data);
|
void gnBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, gnBufferMemory data);
|
||||||
gnBufferMemory gnMapBuffer(gnBufferHandle buffer);
|
gnBufferMemory gnMapBuffer(gnBufferHandle buffer);
|
||||||
|
void gnUnmapBuffer(gnBufferHandle buffer);
|
||||||
void gnDestroyBuffer(gnBufferHandle buffer);
|
void gnDestroyBuffer(gnBufferHandle buffer);
|
||||||
|
10
projects/core/src/instance/gryphn_debugger.c
Normal file
10
projects/core/src/instance/gryphn_debugger.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "gryphn_debugger.h"
|
||||||
|
|
||||||
|
void gnDebuggerSetVerboseMessage(gnDebuggerCreateInfo* debugger, gnMessageData data) {
|
||||||
|
debugger->callback(
|
||||||
|
GN_MESSAGE_VERBOSE,
|
||||||
|
GN_DEBUG_MESSAGE_GENERAL,
|
||||||
|
data,
|
||||||
|
debugger->userData
|
||||||
|
);
|
||||||
|
}
|
@@ -29,7 +29,8 @@ typedef gnBool (*gnDebuggerCallback)(
|
|||||||
|
|
||||||
typedef enum gnDebuggerLayer {
|
typedef enum gnDebuggerLayer {
|
||||||
GN_DEBUGGER_LAYER_PLATFORM, // enable platform (vulkan validation) layers
|
GN_DEBUGGER_LAYER_PLATFORM, // enable platform (vulkan validation) layers
|
||||||
GN_DEBUGGER_LAYER_FUNCTIONS, // enable the checks on every function
|
GN_DEBUGGER_LAYER_FUNCTIONS, // enable the checks on every function,
|
||||||
|
GN_DEBUGGER_LAYER_ALLOCATORS, // enable the layer which debugs all allocations within Gryphn
|
||||||
|
|
||||||
GN_LAYER_MAX
|
GN_LAYER_MAX
|
||||||
} gnDebuggerLayer;
|
} gnDebuggerLayer;
|
||||||
@@ -42,6 +43,7 @@ typedef struct gnDebuggerCreateInfo {
|
|||||||
} gnDebuggerCreateInfo;
|
} gnDebuggerCreateInfo;
|
||||||
|
|
||||||
#ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
|
void gnDebuggerSetVerboseMessage(gnDebuggerCreateInfo* debugger, gnMessageData data);
|
||||||
static inline void gnDebuggerSetErrorMessage(gnDebuggerCreateInfo debugger, gnMessageData data) {
|
static inline void gnDebuggerSetErrorMessage(gnDebuggerCreateInfo debugger, gnMessageData data) {
|
||||||
if (debugger.callback == 0) return;
|
if (debugger.callback == 0) return;
|
||||||
debugger.callback(
|
debugger.callback(
|
||||||
|
@@ -4,12 +4,30 @@
|
|||||||
#include "loader/src/gryphn_extension_loader.h"
|
#include "loader/src/gryphn_extension_loader.h"
|
||||||
#include "loader/src/gryphn_loader.h"
|
#include "loader/src/gryphn_loader.h"
|
||||||
#include "loader/src/gryphn_loader.h"
|
#include "loader/src/gryphn_loader.h"
|
||||||
#include "stdio.h"
|
|
||||||
#include "validation_layers/function_loader/loader/function_loader.h"
|
#include "validation_layers/function_loader/loader/function_loader.h"
|
||||||
|
#include "validation_layers/allocators/allocator_checker.h"
|
||||||
|
|
||||||
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
||||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
||||||
*instance = malloc(sizeof(struct gnInstance_t));
|
*instance = GN_NULL_HANDLE;
|
||||||
|
gnAllocators tmpAllocators = {
|
||||||
|
.userData = &info->debuggerInfo,
|
||||||
|
.malloc = (PFN_gnMalloc)malloc,
|
||||||
|
.calloc = (PFN_gnCalloc)calloc,
|
||||||
|
.realloc = (PFN_gnRealloc)realloc,
|
||||||
|
.free = (PFN_gnFree)free
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < info->debuggerInfo.layerCount; i++) {
|
||||||
|
if (info->debuggerInfo.layers[i] == GN_DEBUGGER_LAYER_ALLOCATORS) {
|
||||||
|
tmpAllocators.malloc = gnMallocFunc;
|
||||||
|
tmpAllocators.calloc = gnCallocFunc;
|
||||||
|
tmpAllocators.realloc = gnReallocFunc;
|
||||||
|
tmpAllocators.free = gnFreeFunc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*instance = tmpAllocators.malloc(sizeof(struct gnInstance_t), tmpAllocators.userData);
|
||||||
(*instance)->hasDebugger = GN_FALSE;
|
(*instance)->hasDebugger = GN_FALSE;
|
||||||
(*instance)->layers = loaderLayerArrayListCreate();
|
(*instance)->layers = loaderLayerArrayListCreate();
|
||||||
|
|
||||||
@@ -61,11 +79,14 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
|
|||||||
for (uint32_t i = 0; i < loaderLayerArrayListCount((*instance)->layers); i++) loaderLayerArrayListRefAt((*instance)->layers, i)->layerIndex = i;
|
for (uint32_t i = 0; i < loaderLayerArrayListCount((*instance)->layers); i++) loaderLayerArrayListRefAt((*instance)->layers, i)->layerIndex = i;
|
||||||
(*instance)->callingLayer = loaderLayerArrayListRefAt((*instance)->layers, (*instance)->currentLayer);
|
(*instance)->callingLayer = loaderLayerArrayListRefAt((*instance)->layers, (*instance)->currentLayer);
|
||||||
if (unsupportedExtension) return GN_UNLOADED_EXTENSION;
|
if (unsupportedExtension) return GN_UNLOADED_EXTENSION;
|
||||||
return (*instance)->functions->createInstance(*instance, info, (*instance)->functions->next);
|
(*instance)->allocators = tmpAllocators;
|
||||||
|
(*instance)->allocators.userData = &(*instance)->debugger;
|
||||||
|
return (*instance)->functions->createInstance(*instance, info, (*instance)->functions->next, &(*instance)->allocators);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyInstance(gnInstanceHandle* instance) {
|
void gnDestroyInstance(gnInstanceHandle* instance) {
|
||||||
if (instance == GN_NULL_HANDLE) return;
|
if (instance == GN_NULL_HANDLE) return;
|
||||||
(*instance)->functions->destroyInstance(*instance, (*instance)->functions->next);
|
(*instance)->functions->destroyInstance(*instance, (*instance)->functions->next, &(*instance)->allocators);
|
||||||
|
(*instance)->allocators.free(*instance, (*instance)->allocators.userData);
|
||||||
*instance = GN_NULL_HANDLE;
|
*instance = GN_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,10 @@
|
|||||||
#include "utils/gryphn_version.h"
|
#include "utils/gryphn_version.h"
|
||||||
#include "core/gryphn_return_code.h"
|
#include "core/gryphn_return_code.h"
|
||||||
#include "core/src/instance/gryphn_debugger.h"
|
#include "core/src/instance/gryphn_debugger.h"
|
||||||
|
#include "gryphn_allocators.h"
|
||||||
#include <gryphn_extensions.h>
|
#include <gryphn_extensions.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct gnApplicationInfo {
|
typedef struct gnApplicationInfo {
|
||||||
gnString applicationName;
|
gnString applicationName;
|
||||||
gnVersion applicationVersion;
|
gnVersion applicationVersion;
|
||||||
@@ -32,12 +34,14 @@ struct gnInstance_t {
|
|||||||
int enabledLayerCounts[GN_LAYER_MAX];
|
int enabledLayerCounts[GN_LAYER_MAX];
|
||||||
gryphnInstanceFunctionLayers* allLayers;
|
gryphnInstanceFunctionLayers* allLayers;
|
||||||
gryphnInstanceFunctionLayers* functions;
|
gryphnInstanceFunctionLayers* functions;
|
||||||
|
gnAllocators allocators;
|
||||||
|
|
||||||
loaderLayerArrayList layers;
|
loaderLayerArrayList layers;
|
||||||
loaderLayer* callingLayer;
|
loaderLayer* callingLayer;
|
||||||
uint32_t currentLayer;
|
uint32_t currentLayer;
|
||||||
gnBool hasDebugger;
|
gnBool hasDebugger;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info);
|
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info);
|
||||||
|
@@ -42,6 +42,7 @@ typedef struct gnDeviceFunctions {
|
|||||||
void (*_gnBufferData)(gnBufferHandle buffer, size_t size, void* data);
|
void (*_gnBufferData)(gnBufferHandle buffer, size_t size, void* data);
|
||||||
void (*_gnBufferSubData)(gnBufferHandle buffer, size_t offset, size_t dataSize, void* data);
|
void (*_gnBufferSubData)(gnBufferHandle buffer, size_t offset, size_t dataSize, void* data);
|
||||||
void* (*_gnMapBuffer)(gnBufferHandle buffer);
|
void* (*_gnMapBuffer)(gnBufferHandle buffer);
|
||||||
|
void (*_gnUnmapBuffer)(gnBufferHandle buffer);
|
||||||
void (*_gnDestroyBuffer)(gnBufferHandle buffer);
|
void (*_gnDestroyBuffer)(gnBufferHandle buffer);
|
||||||
|
|
||||||
gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device);
|
gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device);
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include "core/gryphn_return_code.h"
|
#include "core/gryphn_return_code.h"
|
||||||
#include "utils/gryphn_bool.h"
|
#include "utils/gryphn_bool.h"
|
||||||
#include "gryphn_handles.h"
|
#include "gryphn_handles.h"
|
||||||
|
#include "gryphn_allocators.h"
|
||||||
|
|
||||||
typedef struct gnInstanceCreateInfo gnInstanceCreateInfo;
|
typedef struct gnInstanceCreateInfo gnInstanceCreateInfo;
|
||||||
typedef struct gnSurfaceDetails gnSurfaceDetails;
|
typedef struct gnSurfaceDetails gnSurfaceDetails;
|
||||||
@@ -19,8 +20,8 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers;
|
typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers;
|
||||||
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next);
|
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
|
|
||||||
typedef struct gnInstanceFunctions {
|
typedef struct gnInstanceFunctions {
|
||||||
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
||||||
|
10
projects/validation_layers/allocators/CMakeLists.txt
Normal file
10
projects/validation_layers/allocators/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
|
||||||
|
project(GryphnAllocatorChecker)
|
||||||
|
add_library(GryphnAllocatorChecker STATIC allocator_checker.c)
|
||||||
|
target_include_directories(GryphnAllocatorChecker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/)
|
||||||
|
target_include_directories(GryphnAllocatorChecker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../)
|
||||||
|
target_include_directories(GryphnAllocatorChecker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../core/src/)
|
||||||
|
target_include_directories(GryphnAllocatorChecker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../platform/)
|
||||||
|
target_include_directories(GryphnAllocatorChecker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../utils)
|
||||||
|
target_include_directories(GryphnAllocatorChecker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../core/)
|
||||||
|
target_include_directories(GryphnAllocatorChecker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../extensions/)
|
39
projects/validation_layers/allocators/allocator_checker.c
Normal file
39
projects/validation_layers/allocators/allocator_checker.c
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include "allocator_checker.h"
|
||||||
|
#include <core/src/gryphn_handles.h>
|
||||||
|
#include "core/src/instance/gryphn_debugger.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void* gnMallocFunc (size_t size, void* userData) {
|
||||||
|
char outBuffer[500];
|
||||||
|
snprintf(outBuffer, sizeof(outBuffer), "Allocating %lu bytes with malloc", size);
|
||||||
|
|
||||||
|
gnDebuggerSetVerboseMessage(userData, (gnMessageData) {
|
||||||
|
.message = gnCreateString(outBuffer)
|
||||||
|
});
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
void* gnCallocFunc (int cnt, size_t size, void* userData) {
|
||||||
|
char outBuffer[500];
|
||||||
|
snprintf(outBuffer, sizeof(outBuffer), "Allocating %i items of %lu bytes with calloc", cnt, size);
|
||||||
|
gnDebuggerSetVerboseMessage(userData, (gnMessageData){
|
||||||
|
.message = gnCreateString(outBuffer)
|
||||||
|
});
|
||||||
|
return calloc(cnt, size);
|
||||||
|
}
|
||||||
|
void* gnReallocFunc (void* ptr, size_t size, void* userData) {
|
||||||
|
char outBuffer[500];
|
||||||
|
snprintf(outBuffer, sizeof(outBuffer), "Reallocating %p with new size %lu", ptr, size);
|
||||||
|
gnDebuggerSetVerboseMessage(userData, (gnMessageData){
|
||||||
|
.message = gnCreateString(outBuffer)
|
||||||
|
});
|
||||||
|
return realloc(ptr, size);
|
||||||
|
}
|
||||||
|
void gnFreeFunc (void* ptr, void* userData) {
|
||||||
|
char outBuffer[500];
|
||||||
|
snprintf(outBuffer, sizeof(outBuffer), "Freeing %p", ptr);
|
||||||
|
gnDebuggerSetVerboseMessage(userData, (gnMessageData){
|
||||||
|
.message = gnCreateString(outBuffer)
|
||||||
|
});
|
||||||
|
free(ptr);
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
void* gnMallocFunc (size_t size, void* userData);
|
||||||
|
void* gnCallocFunc (int cnt, size_t size, void* userData);
|
||||||
|
void* gnReallocFunc (void* ptr, size_t size, void* userData);
|
||||||
|
void gnFreeFunc (void* ptr, void* userData);
|
@@ -68,6 +68,7 @@ gnDeviceFunctions loadFunctionLoaderDeviceFunctions(void) {
|
|||||||
._gnBufferData = checkBufferData,
|
._gnBufferData = checkBufferData,
|
||||||
._gnBufferSubData = checkBufferSubData,
|
._gnBufferSubData = checkBufferSubData,
|
||||||
._gnMapBuffer = checkMapBuffer,
|
._gnMapBuffer = checkMapBuffer,
|
||||||
|
._gnUnmapBuffer = checkUnmapBuffer,
|
||||||
._gnDestroyBuffer = checkDestroyBuffer,
|
._gnDestroyBuffer = checkDestroyBuffer,
|
||||||
|
|
||||||
._gnCreateUniformPool = checkCreateUniformPool,
|
._gnCreateUniformPool = checkCreateUniformPool,
|
||||||
|
@@ -70,6 +70,9 @@ void checkBufferSubData(gnBufferHandle buffer, size_t offset, size_t size, void*
|
|||||||
void* checkMapBuffer(gnBufferHandle buffer) {
|
void* checkMapBuffer(gnBufferHandle buffer) {
|
||||||
CHECK_RETURNED_FUNCTION(buffer->device->instance, _gnMapBuffer, deviceFunctions, NULL, buffer);
|
CHECK_RETURNED_FUNCTION(buffer->device->instance, _gnMapBuffer, deviceFunctions, NULL, buffer);
|
||||||
}
|
}
|
||||||
|
void checkUnmapBuffer(gnBufferHandle buffer) {
|
||||||
|
CHECK_VOID_FUNCTION(buffer->device->instance, _gnUnmapBuffer, deviceFunctions, buffer);
|
||||||
|
}
|
||||||
void checkDestroyBuffer(gnBufferHandle buffer) {
|
void checkDestroyBuffer(gnBufferHandle buffer) {
|
||||||
CHECK_VOID_FUNCTION(buffer->device->instance, _gnDestroyBuffer, deviceFunctions, buffer);
|
CHECK_VOID_FUNCTION(buffer->device->instance, _gnDestroyBuffer, deviceFunctions, buffer);
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ gnReturnCode checkCreateBuffer(gnBufferHandle buffer, gnDeviceHandle device, gnB
|
|||||||
void checkBufferData(gnBufferHandle buffer, size_t size, void* data);
|
void checkBufferData(gnBufferHandle buffer, size_t size, void* data);
|
||||||
void checkBufferSubData(gnBufferHandle buffer, size_t offset, size_t size, void* data);
|
void checkBufferSubData(gnBufferHandle buffer, size_t offset, size_t size, void* data);
|
||||||
void* checkMapBuffer(gnBufferHandle buffer);
|
void* checkMapBuffer(gnBufferHandle buffer);
|
||||||
|
void checkUnmapBuffer(gnBufferHandle buffer);
|
||||||
void checkDestroyBuffer(gnBufferHandle buffer);
|
void checkDestroyBuffer(gnBufferHandle buffer);
|
||||||
|
|
||||||
gnReturnCode checkCreateUniformPool(gnUniformPool pool, gnDeviceHandle device);
|
gnReturnCode checkCreateUniformPool(gnUniformPool pool, gnDeviceHandle device);
|
||||||
|
@@ -4,24 +4,24 @@
|
|||||||
#include "core/src/output_device/gryphn_output_device.h"
|
#include "core/src/output_device/gryphn_output_device.h"
|
||||||
#include "core/src/window_surface/gryphn_surface.h"
|
#include "core/src/window_surface/gryphn_surface.h"
|
||||||
|
|
||||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next) {
|
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||||
if (next == NULL || next->createInstance == NULL) {
|
if (next == NULL || next->createInstance == NULL) {
|
||||||
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
||||||
.message = gnCreateString("Failed to load gnCreateInstance this indicates a bug within gryphn")
|
.message = gnCreateString("Failed to load gnCreateInstance this indicates a bug within gryphn")
|
||||||
});
|
});
|
||||||
return GN_FAILED_TO_LOAD_FUNCTION;
|
return GN_FAILED_TO_LOAD_FUNCTION;
|
||||||
}
|
}
|
||||||
return next->createInstance(instance, info, next->next);
|
return next->createInstance(instance, info, next->next, alloctors);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next) {
|
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||||
if (next == NULL || next->destroyInstance == NULL) {
|
if (next == NULL || next->destroyInstance == NULL) {
|
||||||
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
||||||
.message = gnCreateString("Failed to load gnDestroyInstance this indicates a bug within gryphn")
|
.message = gnCreateString("Failed to load gnDestroyInstance this indicates a bug within gryphn")
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
next->destroyInstance(instance, next->next);
|
next->destroyInstance(instance, next->next, alloctors);
|
||||||
}
|
}
|
||||||
|
|
||||||
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count) {
|
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count) {
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
#include "core/src/instance/gryphn_instance.h"
|
#include "core/src/instance/gryphn_instance.h"
|
||||||
#include <core/src/window_surface/gryphn_surface_create_functions.h>
|
#include <core/src/window_surface/gryphn_surface_create_functions.h>
|
||||||
|
|
||||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next);
|
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
|
|
||||||
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count);
|
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count);
|
||||||
gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
|
gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
|
||||||
|
Reference in New Issue
Block a user