very bad texture API
This commit is contained in:
@@ -14,6 +14,17 @@ VkBufferUsageFlags vkGryphnBufferType(gnBufferType type) {
|
||||
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 = gnTrue;
|
||||
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
|
||||
@@ -31,21 +42,12 @@ gnReturnCode VkCreateBuffer(
|
||||
VkMemoryRequirements bufferRequirements;
|
||||
vkGetBufferMemoryRequirements(device->outputDevice->device, buffer->buffer, &bufferRequirements);
|
||||
|
||||
gnBool foundMemory = gnFalse;
|
||||
VkMemoryAllocateInfo memoryAllocateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = bufferRequirements.size,
|
||||
.memoryTypeIndex = VkMemoryIndex(device->physicalDevice.physicalDevice->device, bufferRequirements.memoryTypeBits, flags, &foundMemory)
|
||||
};
|
||||
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
vkGetPhysicalDeviceMemoryProperties(device->physicalDevice.physicalDevice->device, &memoryProperties);
|
||||
|
||||
gnBool foundMemory = gnFalse;
|
||||
for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++) {
|
||||
if ((bufferRequirements.memoryTypeBits & (1 << i)) && (memoryProperties.memoryTypes[i].propertyFlags & flags) == flags) {
|
||||
memoryAllocateInfo.memoryTypeIndex = i;
|
||||
foundMemory = gnTrue;
|
||||
}
|
||||
} // this whole thing was adapted from vulkan-tutorial.com
|
||||
if (!foundMemory) return GN_FAILED_TO_ALLOCATE_MEMORY;
|
||||
|
||||
if (vkAllocateMemory(device->outputDevice->device, &memoryAllocateInfo, NULL, &buffer->memory) != VK_SUCCESS)
|
||||
|
@@ -20,3 +20,4 @@ gnReturnCode VkCreateBuffer(
|
||||
VkGryphnBuffer* buffer, size_t size, gnDevice device,
|
||||
VkMemoryPropertyFlags flags, VkBufferUsageFlags usage
|
||||
);
|
||||
uint32_t VkMemoryIndex(VkPhysicalDevice device, uint32_t memoryType, VkMemoryPropertyFlags flags, gnBool* foundMemory);
|
||||
|
@@ -7,5 +7,6 @@ typedef struct gnPlatformTexture_t {
|
||||
VkGryphnBuffer buffer;
|
||||
|
||||
VkImage image;
|
||||
VkDeviceMemory memory;
|
||||
VkImageView imageView;
|
||||
} gnPlatformTexture;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "vulkan_surface/vulkan_surface.h"
|
||||
#include "vulkan_texture.h"
|
||||
#include "output_device/vulkan_output_devices.h"
|
||||
#include "output_device/vulkan_physical_device.h"
|
||||
|
||||
VkImageType vkGryphnTextureType(gnTextureType type) {
|
||||
switch(type) {
|
||||
@@ -32,5 +33,21 @@ gnReturnCode gnCreateTextureFn(gnTexture texture, gnDevice device, const gnTextu
|
||||
if (vkCreateImage(device->outputDevice->device, &imageInfo, NULL, &texture->texture->image) != VK_SUCCESS)
|
||||
return GN_FAILED_TO_CREATE_IMAGE;
|
||||
|
||||
VkMemoryRequirements memRequirements;
|
||||
vkGetImageMemoryRequirements(device->outputDevice->device, texture->texture->image, &memRequirements);
|
||||
|
||||
gnBool foundMemory = gnFalse;
|
||||
VkMemoryAllocateInfo allocInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = memRequirements.size,
|
||||
.memoryTypeIndex = VkMemoryIndex(device->physicalDevice.physicalDevice->device, memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &foundMemory)
|
||||
};
|
||||
if (!foundMemory) return GN_FAILED_TO_ALLOCATE_MEMORY;
|
||||
|
||||
if (vkAllocateMemory(device->outputDevice->device, &allocInfo, NULL, &texture->texture->memory) != VK_SUCCESS)
|
||||
return GN_FAILED_TO_ALLOCATE_MEMORY;
|
||||
|
||||
vkBindImageMemory(device->outputDevice->device, texture->texture->image, texture->texture->memory, 0);
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user