parent
dbd8a5e504
commit
60abe8c9f2
1 changed files with 21 additions and 21 deletions
|
|
@ -25,11 +25,6 @@
|
||||||
#include "vulkanexamplebase.h"
|
#include "vulkanexamplebase.h"
|
||||||
|
|
||||||
#define VERTEX_BUFFER_BIND_ID 0
|
#define VERTEX_BUFFER_BIND_ID 0
|
||||||
// Note :
|
|
||||||
// Enabling this define will feed GLSL directly to the driver
|
|
||||||
// Unlike the SDK samples that convert it to SPIR-V
|
|
||||||
// This may or may not be supported depending on your ISV
|
|
||||||
//#define USE_GLSL
|
|
||||||
// Set to "true" to enable Vulkan's validation layers
|
// Set to "true" to enable Vulkan's validation layers
|
||||||
// See vulkandebug.cpp for details
|
// See vulkandebug.cpp for details
|
||||||
#define ENABLE_VALIDATION false
|
#define ENABLE_VALIDATION false
|
||||||
|
|
@ -71,6 +66,8 @@ public:
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet;
|
||||||
VkDescriptorSetLayout descriptorSetLayout;
|
VkDescriptorSetLayout descriptorSetLayout;
|
||||||
|
|
||||||
|
VkSemaphore presentCompleteSemaphore;
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||||
{
|
{
|
||||||
width = 1280;
|
width = 1280;
|
||||||
|
|
@ -95,6 +92,8 @@ public:
|
||||||
vkDestroyBuffer(device, indices.buf, nullptr);
|
vkDestroyBuffer(device, indices.buf, nullptr);
|
||||||
vkFreeMemory(device, indices.mem, nullptr);
|
vkFreeMemory(device, indices.mem, nullptr);
|
||||||
|
|
||||||
|
vkDestroySemaphore(device, presentCompleteSemaphore, nullptr);
|
||||||
|
|
||||||
vkDestroyBuffer(device, uniformDataVS.buffer, nullptr);
|
vkDestroyBuffer(device, uniformDataVS.buffer, nullptr);
|
||||||
vkFreeMemory(device, uniformDataVS.memory, nullptr);
|
vkFreeMemory(device, uniformDataVS.memory, nullptr);
|
||||||
}
|
}
|
||||||
|
|
@ -202,14 +201,6 @@ public:
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
VkSemaphore presentCompleteSemaphore;
|
|
||||||
VkSemaphoreCreateInfo presentCompleteSemaphoreCreateInfo = {};
|
|
||||||
presentCompleteSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
|
||||||
presentCompleteSemaphoreCreateInfo.pNext = NULL;
|
|
||||||
|
|
||||||
err = vkCreateSemaphore(device, &presentCompleteSemaphoreCreateInfo, nullptr, &presentCompleteSemaphore);
|
|
||||||
assert(!err);
|
|
||||||
|
|
||||||
// Get next image in the swap chain (back/front buffer)
|
// Get next image in the swap chain (back/front buffer)
|
||||||
err = swapChain.acquireNextImage(presentCompleteSemaphore, ¤tBuffer);
|
err = swapChain.acquireNextImage(presentCompleteSemaphore, ¤tBuffer);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
@ -221,6 +212,7 @@ public:
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submitInfo.waitSemaphoreCount = 1;
|
submitInfo.waitSemaphoreCount = 1;
|
||||||
submitInfo.pWaitSemaphores = &presentCompleteSemaphore;
|
submitInfo.pWaitSemaphores = &presentCompleteSemaphore;
|
||||||
|
// Submit the currently active command buffer
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||||
|
|
||||||
|
|
@ -233,8 +225,6 @@ public:
|
||||||
err = swapChain.queuePresent(queue, currentBuffer);
|
err = swapChain.queuePresent(queue, currentBuffer);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
||||||
vkDestroySemaphore(device, presentCompleteSemaphore, nullptr);
|
|
||||||
|
|
||||||
// Add a post present image memory barrier
|
// Add a post present image memory barrier
|
||||||
// This will transform the frame buffer color attachment back
|
// This will transform the frame buffer color attachment back
|
||||||
// to it's initial layout after it has been presented to the
|
// to it's initial layout after it has been presented to the
|
||||||
|
|
@ -286,6 +276,20 @@ public:
|
||||||
assert(!err);
|
assert(!err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a semaphore used to make sure that the image isn't rendered
|
||||||
|
// until all commands have been submitted
|
||||||
|
// This is used to ensure that the image isn't presented until
|
||||||
|
// it's ready for presentation
|
||||||
|
void prepareSemaphore()
|
||||||
|
{
|
||||||
|
VkSemaphoreCreateInfo presentCompleteSemaphoreCreateInfo = {};
|
||||||
|
presentCompleteSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||||
|
presentCompleteSemaphoreCreateInfo.pNext = NULL;
|
||||||
|
|
||||||
|
VkResult err = vkCreateSemaphore(device, &presentCompleteSemaphoreCreateInfo, nullptr, &presentCompleteSemaphore);
|
||||||
|
assert(!err);
|
||||||
|
}
|
||||||
|
|
||||||
// Setups vertex and index buffers for an indexed triangle,
|
// Setups vertex and index buffers for an indexed triangle,
|
||||||
// uploads them to the VRAM and sets binding points and attribute
|
// uploads them to the VRAM and sets binding points and attribute
|
||||||
// descriptions to match locations inside the shaders
|
// descriptions to match locations inside the shaders
|
||||||
|
|
@ -596,15 +600,10 @@ public:
|
||||||
multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
// Load shaders
|
// Load shaders
|
||||||
|
// Shaders are loaded from the SPIR-V format, which can be generated from glsl
|
||||||
VkPipelineShaderStageCreateInfo shaderStages[2] = { {},{} };
|
VkPipelineShaderStageCreateInfo shaderStages[2] = { {},{} };
|
||||||
|
|
||||||
#ifdef USE_GLSL
|
|
||||||
shaderStages[0] = loadShaderGLSL("./../data/shaders/_test/test.vert", VK_SHADER_STAGE_VERTEX_BIT);
|
|
||||||
shaderStages[1] = loadShaderGLSL("./../data/shaders/_test/test.frag", VK_SHADER_STAGE_FRAGMENT_BIT);
|
|
||||||
#else
|
|
||||||
shaderStages[0] = loadShader("./../data/shaders/triangle.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
shaderStages[0] = loadShader("./../data/shaders/triangle.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
shaderStages[1] = loadShader("./../data/shaders/triangle.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
shaderStages[1] = loadShader("./../data/shaders/triangle.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Assign states
|
// Assign states
|
||||||
// Two shader stages
|
// Two shader stages
|
||||||
|
|
@ -692,6 +691,7 @@ public:
|
||||||
void prepare()
|
void prepare()
|
||||||
{
|
{
|
||||||
VulkanExampleBase::prepare();
|
VulkanExampleBase::prepare();
|
||||||
|
prepareSemaphore();
|
||||||
prepareVertices();
|
prepareVertices();
|
||||||
prepareUniformBuffers();
|
prepareUniformBuffers();
|
||||||
setupDescriptorSetLayout();
|
setupDescriptorSetLayout();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue