Use VulkanDevice
This commit is contained in:
parent
27aa3ad1b2
commit
d414849e23
2 changed files with 58 additions and 81 deletions
|
|
@ -154,7 +154,7 @@ public:
|
||||||
// Pool
|
// Pool
|
||||||
VkCommandPoolCreateInfo cmdPoolInfo = {};
|
VkCommandPoolCreateInfo cmdPoolInfo = {};
|
||||||
cmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
cmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||||
cmdPoolInfo.queueFamilyIndex = 0; // todo : pass from example base / swap chain
|
cmdPoolInfo.queueFamilyIndex = vulkanDevice->queueFamilyIndices.graphics;
|
||||||
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||||
VK_CHECK_RESULT(vkCreateCommandPool(vulkanDevice->logicalDevice, &cmdPoolInfo, nullptr, &commandPool));
|
VK_CHECK_RESULT(vkCreateCommandPool(vulkanDevice->logicalDevice, &cmdPoolInfo, nullptr, &commandPool));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
#include "vulkanexamplebase.h"
|
#include "vulkanexamplebase.h"
|
||||||
|
#include "vulkandevice.hpp"
|
||||||
|
|
||||||
#include "../external/stb/stb_font_consolas_24_latin1.inl"
|
#include "../external/stb/stb_font_consolas_24_latin1.inl"
|
||||||
|
|
||||||
#define VERTEX_BUFFER_BIND_ID 0
|
#define VERTEX_BUFFER_BIND_ID 0
|
||||||
|
|
@ -53,9 +55,8 @@ std::vector<vkMeshLoader::VertexLayout> vertexLayout =
|
||||||
class TextOverlay
|
class TextOverlay
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
VkPhysicalDevice physicalDevice;
|
vk::VulkanDevice *vulkanDevice;
|
||||||
VkDevice device;
|
|
||||||
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
|
|
||||||
VkQueue queue;
|
VkQueue queue;
|
||||||
VkFormat colorFormat;
|
VkFormat colorFormat;
|
||||||
VkFormat depthFormat;
|
VkFormat depthFormat;
|
||||||
|
|
@ -86,22 +87,6 @@ private:
|
||||||
|
|
||||||
stb_fontchar stbFontData[STB_NUM_CHARS];
|
stb_fontchar stbFontData[STB_NUM_CHARS];
|
||||||
uint32_t numLetters;
|
uint32_t numLetters;
|
||||||
|
|
||||||
// Try to find appropriate memory type for a memory allocation
|
|
||||||
VkBool32 getMemoryType(uint32_t typeBits, VkFlags properties, uint32_t *typeIndex)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 32; i++) {
|
|
||||||
if ((typeBits & 1) == 1) {
|
|
||||||
if ((deviceMemoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
|
|
||||||
{
|
|
||||||
*typeIndex = i;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
typeBits >>= 1;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum TextAlign { alignLeft, alignCenter, alignRight };
|
enum TextAlign { alignLeft, alignCenter, alignRight };
|
||||||
|
|
@ -109,8 +94,7 @@ public:
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
|
|
||||||
TextOverlay(
|
TextOverlay(
|
||||||
VkPhysicalDevice physicalDevice,
|
vk::VulkanDevice *vulkanDevice,
|
||||||
VkDevice device,
|
|
||||||
VkQueue queue,
|
VkQueue queue,
|
||||||
std::vector<VkFramebuffer> &framebuffers,
|
std::vector<VkFramebuffer> &framebuffers,
|
||||||
VkFormat colorformat,
|
VkFormat colorformat,
|
||||||
|
|
@ -119,8 +103,7 @@ public:
|
||||||
uint32_t *framebufferheight,
|
uint32_t *framebufferheight,
|
||||||
std::vector<VkPipelineShaderStageCreateInfo> shaderstages)
|
std::vector<VkPipelineShaderStageCreateInfo> shaderstages)
|
||||||
{
|
{
|
||||||
this->physicalDevice = physicalDevice;
|
this->vulkanDevice = vulkanDevice;
|
||||||
this->device = device;
|
|
||||||
this->queue = queue;
|
this->queue = queue;
|
||||||
this->colorFormat = colorformat;
|
this->colorFormat = colorformat;
|
||||||
this->depthFormat = depthformat;
|
this->depthFormat = depthformat;
|
||||||
|
|
@ -136,7 +119,6 @@ public:
|
||||||
this->frameBufferWidth = framebufferwidth;
|
this->frameBufferWidth = framebufferwidth;
|
||||||
this->frameBufferHeight = framebufferheight;
|
this->frameBufferHeight = framebufferheight;
|
||||||
|
|
||||||
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &deviceMemoryProperties);
|
|
||||||
cmdBuffers.resize(framebuffers.size());
|
cmdBuffers.resize(framebuffers.size());
|
||||||
prepareResources();
|
prepareResources();
|
||||||
prepareRenderPass();
|
prepareRenderPass();
|
||||||
|
|
@ -146,20 +128,20 @@ public:
|
||||||
~TextOverlay()
|
~TextOverlay()
|
||||||
{
|
{
|
||||||
// Free up all Vulkan resources requested by the text overlay
|
// Free up all Vulkan resources requested by the text overlay
|
||||||
vkDestroySampler(device, sampler, nullptr);
|
vkDestroySampler(vulkanDevice->logicalDevice, sampler, nullptr);
|
||||||
vkDestroyImage(device, image, nullptr);
|
vkDestroyImage(vulkanDevice->logicalDevice, image, nullptr);
|
||||||
vkDestroyImageView(device, view, nullptr);
|
vkDestroyImageView(vulkanDevice->logicalDevice, view, nullptr);
|
||||||
vkDestroyBuffer(device, buffer, nullptr);
|
vkDestroyBuffer(vulkanDevice->logicalDevice, buffer, nullptr);
|
||||||
vkFreeMemory(device, memory, nullptr);
|
vkFreeMemory(vulkanDevice->logicalDevice, memory, nullptr);
|
||||||
vkFreeMemory(device, imageMemory, nullptr);
|
vkFreeMemory(vulkanDevice->logicalDevice, imageMemory, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
vkDestroyDescriptorSetLayout(vulkanDevice->logicalDevice, descriptorSetLayout, nullptr);
|
||||||
vkDestroyDescriptorPool(device, descriptorPool, nullptr);
|
vkDestroyDescriptorPool(vulkanDevice->logicalDevice, descriptorPool, nullptr);
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(vulkanDevice->logicalDevice, pipelineLayout, nullptr);
|
||||||
vkDestroyPipelineCache(device, pipelineCache, nullptr);
|
vkDestroyPipelineCache(vulkanDevice->logicalDevice, pipelineCache, nullptr);
|
||||||
vkDestroyPipeline(device, pipeline, nullptr);
|
vkDestroyPipeline(vulkanDevice->logicalDevice, pipeline, nullptr);
|
||||||
vkDestroyRenderPass(device, renderPass, nullptr);
|
vkDestroyRenderPass(vulkanDevice->logicalDevice, renderPass, nullptr);
|
||||||
vkFreeCommandBuffers(device, commandPool, cmdBuffers.size(), cmdBuffers.data());
|
vkFreeCommandBuffers(vulkanDevice->logicalDevice, commandPool, cmdBuffers.size(), cmdBuffers.data());
|
||||||
vkDestroyCommandPool(device, commandPool, nullptr);
|
vkDestroyCommandPool(vulkanDevice->logicalDevice, commandPool, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare all vulkan resources required to render the font
|
// Prepare all vulkan resources required to render the font
|
||||||
|
|
@ -174,9 +156,9 @@ public:
|
||||||
// Pool
|
// Pool
|
||||||
VkCommandPoolCreateInfo cmdPoolInfo = {};
|
VkCommandPoolCreateInfo cmdPoolInfo = {};
|
||||||
cmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
cmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||||
cmdPoolInfo.queueFamilyIndex = 0; // todo : pass from example base / swap chain
|
cmdPoolInfo.queueFamilyIndex = vulkanDevice->queueFamilyIndices.graphics;
|
||||||
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||||
VK_CHECK_RESULT(vkCreateCommandPool(device, &cmdPoolInfo, nullptr, &commandPool));
|
VK_CHECK_RESULT(vkCreateCommandPool(vulkanDevice->logicalDevice, &cmdPoolInfo, nullptr, &commandPool));
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo cmdBufAllocateInfo =
|
VkCommandBufferAllocateInfo cmdBufAllocateInfo =
|
||||||
vkTools::initializers::commandBufferAllocateInfo(
|
vkTools::initializers::commandBufferAllocateInfo(
|
||||||
|
|
@ -184,23 +166,23 @@ public:
|
||||||
VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||||
(uint32_t)cmdBuffers.size());
|
(uint32_t)cmdBuffers.size());
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, cmdBuffers.data()));
|
VK_CHECK_RESULT(vkAllocateCommandBuffers(vulkanDevice->logicalDevice, &cmdBufAllocateInfo, cmdBuffers.data()));
|
||||||
|
|
||||||
// Vertex buffer
|
// Vertex buffer
|
||||||
VkDeviceSize bufferSize = MAX_CHAR_COUNT * sizeof(glm::vec4);
|
VkDeviceSize bufferSize = MAX_CHAR_COUNT * sizeof(glm::vec4);
|
||||||
|
|
||||||
VkBufferCreateInfo bufferInfo = vkTools::initializers::bufferCreateInfo(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, bufferSize);
|
VkBufferCreateInfo bufferInfo = vkTools::initializers::bufferCreateInfo(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, bufferSize);
|
||||||
VK_CHECK_RESULT(vkCreateBuffer(device, &bufferInfo, nullptr, &buffer));
|
VK_CHECK_RESULT(vkCreateBuffer(vulkanDevice->logicalDevice, &bufferInfo, nullptr, &buffer));
|
||||||
|
|
||||||
VkMemoryRequirements memReqs;
|
VkMemoryRequirements memReqs;
|
||||||
VkMemoryAllocateInfo allocInfo = vkTools::initializers::memoryAllocateInfo();
|
VkMemoryAllocateInfo allocInfo = vkTools::initializers::memoryAllocateInfo();
|
||||||
|
|
||||||
vkGetBufferMemoryRequirements(device, buffer, &memReqs);
|
vkGetBufferMemoryRequirements(vulkanDevice->logicalDevice, buffer, &memReqs);
|
||||||
allocInfo.allocationSize = memReqs.size;
|
allocInfo.allocationSize = memReqs.size;
|
||||||
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &allocInfo.memoryTypeIndex);
|
allocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkAllocateMemory(device, &allocInfo, nullptr, &memory));
|
VK_CHECK_RESULT(vkAllocateMemory(vulkanDevice->logicalDevice, &allocInfo, nullptr, &memory));
|
||||||
VK_CHECK_RESULT(vkBindBufferMemory(device, buffer, memory, 0));
|
VK_CHECK_RESULT(vkBindBufferMemory(vulkanDevice->logicalDevice, buffer, memory, 0));
|
||||||
|
|
||||||
// Font texture
|
// Font texture
|
||||||
VkImageCreateInfo imageInfo = vkTools::initializers::imageCreateInfo();
|
VkImageCreateInfo imageInfo = vkTools::initializers::imageCreateInfo();
|
||||||
|
|
@ -217,14 +199,14 @@ public:
|
||||||
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateImage(device, &imageInfo, nullptr, &image));
|
VK_CHECK_RESULT(vkCreateImage(vulkanDevice->logicalDevice, &imageInfo, nullptr, &image));
|
||||||
|
|
||||||
vkGetImageMemoryRequirements(device, image, &memReqs);
|
vkGetImageMemoryRequirements(vulkanDevice->logicalDevice, image, &memReqs);
|
||||||
allocInfo.allocationSize = memReqs.size;
|
allocInfo.allocationSize = memReqs.size;
|
||||||
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &allocInfo.memoryTypeIndex);
|
allocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory));
|
VK_CHECK_RESULT(vkAllocateMemory(vulkanDevice->logicalDevice, &allocInfo, nullptr, &imageMemory));
|
||||||
VK_CHECK_RESULT(vkBindImageMemory(device, image, imageMemory, 0));
|
VK_CHECK_RESULT(vkBindImageMemory(vulkanDevice->logicalDevice, image, imageMemory, 0));
|
||||||
|
|
||||||
// Staging
|
// Staging
|
||||||
|
|
||||||
|
|
@ -238,28 +220,28 @@ public:
|
||||||
bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||||
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateBuffer(device, &bufferCreateInfo, nullptr, &stagingBuffer.buffer));
|
VK_CHECK_RESULT(vkCreateBuffer(vulkanDevice->logicalDevice, &bufferCreateInfo, nullptr, &stagingBuffer.buffer));
|
||||||
|
|
||||||
// Get memory requirements for the staging buffer (alignment, memory type bits)
|
// Get memory requirements for the staging buffer (alignment, memory type bits)
|
||||||
vkGetBufferMemoryRequirements(device, stagingBuffer.buffer, &memReqs);
|
vkGetBufferMemoryRequirements(vulkanDevice->logicalDevice, stagingBuffer.buffer, &memReqs);
|
||||||
|
|
||||||
allocInfo.allocationSize = memReqs.size;
|
allocInfo.allocationSize = memReqs.size;
|
||||||
// Get memory type index for a host visible buffer
|
// Get memory type index for a host visible buffer
|
||||||
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &allocInfo.memoryTypeIndex);
|
allocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkAllocateMemory(device, &allocInfo, nullptr, &stagingBuffer.memory));
|
VK_CHECK_RESULT(vkAllocateMemory(vulkanDevice->logicalDevice, &allocInfo, nullptr, &stagingBuffer.memory));
|
||||||
VK_CHECK_RESULT(vkBindBufferMemory(device, stagingBuffer.buffer, stagingBuffer.memory, 0));
|
VK_CHECK_RESULT(vkBindBufferMemory(vulkanDevice->logicalDevice, stagingBuffer.buffer, stagingBuffer.memory, 0));
|
||||||
|
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, stagingBuffer.memory, 0, allocInfo.allocationSize, 0, (void **)&data));
|
VK_CHECK_RESULT(vkMapMemory(vulkanDevice->logicalDevice, stagingBuffer.memory, 0, allocInfo.allocationSize, 0, (void **)&data));
|
||||||
memcpy(data, &font24pixels[0][0], STB_FONT_WIDTH * STB_FONT_HEIGHT);
|
memcpy(data, &font24pixels[0][0], STB_FONT_WIDTH * STB_FONT_HEIGHT);
|
||||||
vkUnmapMemory(device, stagingBuffer.memory);
|
vkUnmapMemory(vulkanDevice->logicalDevice, stagingBuffer.memory);
|
||||||
|
|
||||||
// Copy to image
|
// Copy to image
|
||||||
|
|
||||||
VkCommandBuffer copyCmd;
|
VkCommandBuffer copyCmd;
|
||||||
cmdBufAllocateInfo.commandBufferCount = 1;
|
cmdBufAllocateInfo.commandBufferCount = 1;
|
||||||
VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, ©Cmd));
|
VK_CHECK_RESULT(vkAllocateCommandBuffers(vulkanDevice->logicalDevice, &cmdBufAllocateInfo, ©Cmd));
|
||||||
|
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
||||||
VK_CHECK_RESULT(vkBeginCommandBuffer(copyCmd, &cmdBufInfo));
|
VK_CHECK_RESULT(vkBeginCommandBuffer(copyCmd, &cmdBufInfo));
|
||||||
|
|
@ -306,10 +288,9 @@ public:
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||||
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
||||||
|
|
||||||
vkFreeCommandBuffers(device, commandPool, 1, ©Cmd);
|
vkFreeCommandBuffers(vulkanDevice->logicalDevice, commandPool, 1, ©Cmd);
|
||||||
vkFreeMemory(device, stagingBuffer.memory, nullptr);
|
vkFreeMemory(vulkanDevice->logicalDevice, stagingBuffer.memory, nullptr);
|
||||||
vkDestroyBuffer(device, stagingBuffer.buffer, nullptr);
|
vkDestroyBuffer(vulkanDevice->logicalDevice, stagingBuffer.buffer, nullptr);
|
||||||
|
|
||||||
|
|
||||||
VkImageViewCreateInfo imageViewInfo = vkTools::initializers::imageViewCreateInfo();
|
VkImageViewCreateInfo imageViewInfo = vkTools::initializers::imageViewCreateInfo();
|
||||||
imageViewInfo.image = image;
|
imageViewInfo.image = image;
|
||||||
|
|
@ -317,8 +298,7 @@ public:
|
||||||
imageViewInfo.format = imageInfo.format;
|
imageViewInfo.format = imageInfo.format;
|
||||||
imageViewInfo.components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
|
imageViewInfo.components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
|
||||||
imageViewInfo.subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 };
|
imageViewInfo.subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 };
|
||||||
|
VK_CHECK_RESULT(vkCreateImageView(vulkanDevice->logicalDevice, &imageViewInfo, nullptr, &view));
|
||||||
VK_CHECK_RESULT(vkCreateImageView(device, &imageViewInfo, nullptr, &view));
|
|
||||||
|
|
||||||
// Sampler
|
// Sampler
|
||||||
VkSamplerCreateInfo samplerInfo = vkTools::initializers::samplerCreateInfo();
|
VkSamplerCreateInfo samplerInfo = vkTools::initializers::samplerCreateInfo();
|
||||||
|
|
@ -333,7 +313,7 @@ public:
|
||||||
samplerInfo.minLod = 0.0f;
|
samplerInfo.minLod = 0.0f;
|
||||||
samplerInfo.maxLod = 1.0f;
|
samplerInfo.maxLod = 1.0f;
|
||||||
samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
||||||
VK_CHECK_RESULT(vkCreateSampler(device, &samplerInfo, nullptr, &sampler));
|
VK_CHECK_RESULT(vkCreateSampler(vulkanDevice->logicalDevice, &samplerInfo, nullptr, &sampler));
|
||||||
|
|
||||||
// Descriptor
|
// Descriptor
|
||||||
// Font uses a separate descriptor pool
|
// Font uses a separate descriptor pool
|
||||||
|
|
@ -346,7 +326,7 @@ public:
|
||||||
poolSizes.data(),
|
poolSizes.data(),
|
||||||
1);
|
1);
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
VK_CHECK_RESULT(vkCreateDescriptorPool(vulkanDevice->logicalDevice, &descriptorPoolInfo, nullptr, &descriptorPool));
|
||||||
|
|
||||||
// Descriptor set layout
|
// Descriptor set layout
|
||||||
std::array<VkDescriptorSetLayoutBinding, 1> setLayoutBindings;
|
std::array<VkDescriptorSetLayoutBinding, 1> setLayoutBindings;
|
||||||
|
|
@ -356,16 +336,14 @@ public:
|
||||||
vkTools::initializers::descriptorSetLayoutCreateInfo(
|
vkTools::initializers::descriptorSetLayoutCreateInfo(
|
||||||
setLayoutBindings.data(),
|
setLayoutBindings.data(),
|
||||||
setLayoutBindings.size());
|
setLayoutBindings.size());
|
||||||
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(vulkanDevice->logicalDevice, &descriptorSetLayoutInfo, nullptr, &descriptorSetLayout));
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutInfo, nullptr, &descriptorSetLayout));
|
|
||||||
|
|
||||||
// Pipeline layout
|
// Pipeline layout
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo =
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo =
|
||||||
vkTools::initializers::pipelineLayoutCreateInfo(
|
vkTools::initializers::pipelineLayoutCreateInfo(
|
||||||
&descriptorSetLayout,
|
&descriptorSetLayout,
|
||||||
1);
|
1);
|
||||||
|
VK_CHECK_RESULT(vkCreatePipelineLayout(vulkanDevice->logicalDevice, &pipelineLayoutInfo, nullptr, &pipelineLayout));
|
||||||
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &pipelineLayout));
|
|
||||||
|
|
||||||
// Descriptor set
|
// Descriptor set
|
||||||
VkDescriptorSetAllocateInfo descriptorSetAllocInfo =
|
VkDescriptorSetAllocateInfo descriptorSetAllocInfo =
|
||||||
|
|
@ -374,7 +352,7 @@ public:
|
||||||
&descriptorSetLayout,
|
&descriptorSetLayout,
|
||||||
1);
|
1);
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSet));
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(vulkanDevice->logicalDevice, &descriptorSetAllocInfo, &descriptorSet));
|
||||||
|
|
||||||
VkDescriptorImageInfo texDescriptor =
|
VkDescriptorImageInfo texDescriptor =
|
||||||
vkTools::initializers::descriptorImageInfo(
|
vkTools::initializers::descriptorImageInfo(
|
||||||
|
|
@ -384,12 +362,12 @@ public:
|
||||||
|
|
||||||
std::array<VkWriteDescriptorSet, 1> writeDescriptorSets;
|
std::array<VkWriteDescriptorSet, 1> writeDescriptorSets;
|
||||||
writeDescriptorSets[0] = vkTools::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &texDescriptor);
|
writeDescriptorSets[0] = vkTools::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &texDescriptor);
|
||||||
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
vkUpdateDescriptorSets(vulkanDevice->logicalDevice, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
||||||
|
|
||||||
// Pipeline cache
|
// Pipeline cache
|
||||||
VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {};
|
VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {};
|
||||||
pipelineCacheCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
|
pipelineCacheCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
|
||||||
VK_CHECK_RESULT(vkCreatePipelineCache(device, &pipelineCacheCreateInfo, nullptr, &pipelineCache));
|
VK_CHECK_RESULT(vkCreatePipelineCache(vulkanDevice->logicalDevice, &pipelineCacheCreateInfo, nullptr, &pipelineCache));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare a separate pipeline for the font rendering decoupled from the main application
|
// Prepare a separate pipeline for the font rendering decoupled from the main application
|
||||||
|
|
@ -483,7 +461,7 @@ public:
|
||||||
pipelineCreateInfo.stageCount = shaderStages.size();
|
pipelineCreateInfo.stageCount = shaderStages.size();
|
||||||
pipelineCreateInfo.pStages = shaderStages.data();
|
pipelineCreateInfo.pStages = shaderStages.data();
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(vulkanDevice->logicalDevice, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare a separate render pass for rendering the text as an overlay
|
// Prepare a separate render pass for rendering the text as an overlay
|
||||||
|
|
@ -542,13 +520,13 @@ public:
|
||||||
renderPassInfo.dependencyCount = 0;
|
renderPassInfo.dependencyCount = 0;
|
||||||
renderPassInfo.pDependencies = NULL;
|
renderPassInfo.pDependencies = NULL;
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass));
|
VK_CHECK_RESULT(vkCreateRenderPass(vulkanDevice->logicalDevice, &renderPassInfo, nullptr, &renderPass));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map buffer
|
// Map buffer
|
||||||
void beginTextUpdate()
|
void beginTextUpdate()
|
||||||
{
|
{
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, memory, 0, VK_WHOLE_SIZE, 0, (void **)&mapped));
|
VK_CHECK_RESULT(vkMapMemory(vulkanDevice->logicalDevice, memory, 0, VK_WHOLE_SIZE, 0, (void **)&mapped));
|
||||||
numLetters = 0;
|
numLetters = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -622,7 +600,7 @@ public:
|
||||||
// Unmap buffer and update command buffers
|
// Unmap buffer and update command buffers
|
||||||
void endTextUpdate()
|
void endTextUpdate()
|
||||||
{
|
{
|
||||||
vkUnmapMemory(device, memory);
|
vkUnmapMemory(vulkanDevice->logicalDevice, memory);
|
||||||
mapped = nullptr;
|
mapped = nullptr;
|
||||||
updateCommandBuffers();
|
updateCommandBuffers();
|
||||||
}
|
}
|
||||||
|
|
@ -1147,8 +1125,7 @@ public:
|
||||||
shaderStages.push_back(loadShader(getAssetPath() + "shaders/textoverlay/text.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT));
|
shaderStages.push_back(loadShader(getAssetPath() + "shaders/textoverlay/text.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT));
|
||||||
|
|
||||||
textOverlay = new TextOverlay(
|
textOverlay = new TextOverlay(
|
||||||
physicalDevice,
|
vulkanDevice,
|
||||||
device,
|
|
||||||
queue,
|
queue,
|
||||||
frameBuffers,
|
frameBuffers,
|
||||||
colorformat,
|
colorformat,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue