parent
dbd8a5e504
commit
60abe8c9f2
1 changed files with 21 additions and 21 deletions
|
|
@ -25,11 +25,6 @@
|
|||
#include "vulkanexamplebase.h"
|
||||
|
||||
#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
|
||||
// See vulkandebug.cpp for details
|
||||
#define ENABLE_VALIDATION false
|
||||
|
|
@ -71,6 +66,8 @@ public:
|
|||
VkDescriptorSet descriptorSet;
|
||||
VkDescriptorSetLayout descriptorSetLayout;
|
||||
|
||||
VkSemaphore presentCompleteSemaphore;
|
||||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
width = 1280;
|
||||
|
|
@ -95,6 +92,8 @@ public:
|
|||
vkDestroyBuffer(device, indices.buf, nullptr);
|
||||
vkFreeMemory(device, indices.mem, nullptr);
|
||||
|
||||
vkDestroySemaphore(device, presentCompleteSemaphore, nullptr);
|
||||
|
||||
vkDestroyBuffer(device, uniformDataVS.buffer, nullptr);
|
||||
vkFreeMemory(device, uniformDataVS.memory, nullptr);
|
||||
}
|
||||
|
|
@ -202,14 +201,6 @@ public:
|
|||
void draw()
|
||||
{
|
||||
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)
|
||||
err = swapChain.acquireNextImage(presentCompleteSemaphore, ¤tBuffer);
|
||||
assert(!err);
|
||||
|
|
@ -221,6 +212,7 @@ public:
|
|||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.pWaitSemaphores = &presentCompleteSemaphore;
|
||||
// Submit the currently active command buffer
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||
|
||||
|
|
@ -233,8 +225,6 @@ public:
|
|||
err = swapChain.queuePresent(queue, currentBuffer);
|
||||
assert(!err);
|
||||
|
||||
vkDestroySemaphore(device, presentCompleteSemaphore, nullptr);
|
||||
|
||||
// Add a post present image memory barrier
|
||||
// This will transform the frame buffer color attachment back
|
||||
// to it's initial layout after it has been presented to the
|
||||
|
|
@ -286,6 +276,20 @@ public:
|
|||
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,
|
||||
// uploads them to the VRAM and sets binding points and attribute
|
||||
// descriptions to match locations inside the shaders
|
||||
|
|
@ -596,15 +600,10 @@ public:
|
|||
multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
// Load shaders
|
||||
// Shaders are loaded from the SPIR-V format, which can be generated from glsl
|
||||
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[1] = loadShader("./../data/shaders/triangle.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
#endif
|
||||
|
||||
// Assign states
|
||||
// Two shader stages
|
||||
|
|
@ -692,6 +691,7 @@ public:
|
|||
void prepare()
|
||||
{
|
||||
VulkanExampleBase::prepare();
|
||||
prepareSemaphore();
|
||||
prepareVertices();
|
||||
prepareUniformBuffers();
|
||||
setupDescriptorSetLayout();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue