Code cleanup

This commit is contained in:
Sascha Willems 2020-04-20 22:13:51 +02:00
parent 4b9f10d644
commit 53846d8b1d
23 changed files with 54 additions and 104 deletions

View file

@ -129,51 +129,6 @@ void VulkanExampleBase::destroyCommandBuffers()
vkFreeCommandBuffers(device, cmdPool, static_cast<uint32_t>(drawCmdBuffers.size()), drawCmdBuffers.data()); vkFreeCommandBuffers(device, cmdPool, static_cast<uint32_t>(drawCmdBuffers.size()), drawCmdBuffers.data());
} }
VkCommandBuffer VulkanExampleBase::createCommandBuffer(VkCommandBufferLevel level, bool begin)
{
VkCommandBuffer cmdBuffer;
VkCommandBufferAllocateInfo cmdBufAllocateInfo =
vks::initializers::commandBufferAllocateInfo(
cmdPool,
level,
1);
VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, &cmdBuffer));
// If requested, also start the new command buffer
if (begin)
{
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
VK_CHECK_RESULT(vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo));
}
return cmdBuffer;
}
void VulkanExampleBase::flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, bool free)
{
if (commandBuffer == VK_NULL_HANDLE)
{
return;
}
VK_CHECK_RESULT(vkEndCommandBuffer(commandBuffer));
VkSubmitInfo submitInfo = {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffer;
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
if (free)
{
vkFreeCommandBuffers(device, cmdPool, 1, &commandBuffer);
}
}
void VulkanExampleBase::createPipelineCache() void VulkanExampleBase::createPipelineCache()
{ {
VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {}; VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {};

View file

@ -334,11 +334,6 @@ public:
/** @brief (Virtual) Called after the physical device features have been read, can be used to set features to enable on the device */ /** @brief (Virtual) Called after the physical device features have been read, can be used to set features to enable on the device */
virtual void getEnabledFeatures(); virtual void getEnabledFeatures();
/** @brief Creates and returns a new command buffer */
VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin);
/** @brief End the command buffer, submit it to the queue and free (if requested) */
void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, bool free);
/** @brief Prepares all Vulkan resources and functions required to run the sample */ /** @brief Prepares all Vulkan resources and functions required to run the sample */
virtual void prepare(); virtual void prepare();

View file

@ -410,7 +410,7 @@ public:
storageBufferSize); storageBufferSize);
// Copy from staging buffer // Copy from staging buffer
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = {}; VkBufferCopy copyRegion = {};
copyRegion.size = storageBufferSize; copyRegion.size = storageBufferSize;
vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.input.buffer, 1, &copyRegion); vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.input.buffer, 1, &copyRegion);
@ -419,7 +419,7 @@ public:
// so that when the compute command buffer executes for the first time // so that when the compute command buffer executes for the first time
// it doesn't complain about a lack of a corresponding "release" to its "acquire" // it doesn't complain about a lack of a corresponding "release" to its "acquire"
addGraphicsToComputeBarriers(copyCmd); addGraphicsToComputeBarriers(copyCmd);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
stagingBuffer.destroy(); stagingBuffer.destroy();
@ -450,11 +450,11 @@ public:
indexBufferSize); indexBufferSize);
// Copy from staging buffer // Copy from staging buffer
copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
copyRegion = {}; copyRegion = {};
copyRegion.size = indexBufferSize; copyRegion.size = indexBufferSize;
vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, graphics.indices.buffer, 1, &copyRegion); vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, graphics.indices.buffer, 1, &copyRegion);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
stagingBuffer.destroy(); stagingBuffer.destroy();
} }

View file

@ -409,7 +409,7 @@ public:
storageBufferSize); storageBufferSize);
// Copy from staging buffer to storage buffer // Copy from staging buffer to storage buffer
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = {}; VkBufferCopy copyRegion = {};
copyRegion.size = storageBufferSize; copyRegion.size = storageBufferSize;
vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffer.buffer, 1, &copyRegion); vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffer.buffer, 1, &copyRegion);
@ -438,7 +438,7 @@ public:
1, &buffer_barrier, 1, &buffer_barrier,
0, nullptr); 0, nullptr);
} }
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
stagingBuffer.destroy(); stagingBuffer.destroy();

View file

@ -327,7 +327,7 @@ public:
storageBufferSize); storageBufferSize);
// Copy from staging buffer to storage buffer // Copy from staging buffer to storage buffer
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = {}; VkBufferCopy copyRegion = {};
copyRegion.size = storageBufferSize; copyRegion.size = storageBufferSize;
vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffer.buffer, 1, &copyRegion); vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffer.buffer, 1, &copyRegion);
@ -356,7 +356,7 @@ public:
1, &buffer_barrier, 1, &buffer_barrier,
0, nullptr); 0, nullptr);
} }
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
stagingBuffer.destroy(); stagingBuffer.destroy();

View file

@ -162,7 +162,7 @@ public:
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &tex->deviceMemory)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &tex->deviceMemory));
VK_CHECK_RESULT(vkBindImageMemory(device, tex->image, tex->deviceMemory, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, tex->image, tex->deviceMemory, 0));
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
tex->imageLayout = VK_IMAGE_LAYOUT_GENERAL; tex->imageLayout = VK_IMAGE_LAYOUT_GENERAL;
vks::tools::setImageLayout( vks::tools::setImageLayout(
@ -172,7 +172,7 @@ public:
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
tex->imageLayout); tex->imageLayout);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
// Create sampler // Create sampler
VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo();
@ -337,11 +337,11 @@ public:
storageBufferSize); storageBufferSize);
// Copy to staging buffer // Copy to staging buffer
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = {}; VkBufferCopy copyRegion = {};
copyRegion.size = storageBufferSize; copyRegion.size = storageBufferSize;
vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.spheres.buffer, 1, &copyRegion); vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.spheres.buffer, 1, &copyRegion);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
stagingBuffer.destroy(); stagingBuffer.destroy();
@ -372,10 +372,10 @@ public:
storageBufferSize); storageBufferSize);
// Copy to staging buffer // Copy to staging buffer
copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
copyRegion.size = storageBufferSize; copyRegion.size = storageBufferSize;
vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.planes.buffer, 1, &copyRegion); vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.planes.buffer, 1, &copyRegion);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
stagingBuffer.destroy(); stagingBuffer.destroy();
} }

View file

@ -152,7 +152,7 @@ public:
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &tex->deviceMemory)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &tex->deviceMemory));
VK_CHECK_RESULT(vkBindImageMemory(device, tex->image, tex->deviceMemory, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, tex->image, tex->deviceMemory, 0));
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
tex->imageLayout = VK_IMAGE_LAYOUT_GENERAL; tex->imageLayout = VK_IMAGE_LAYOUT_GENERAL;
vks::tools::setImageLayout( vks::tools::setImageLayout(
@ -161,7 +161,7 @@ public:
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
tex->imageLayout); tex->imageLayout);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
// Create sampler // Create sampler
VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo();

View file

@ -438,7 +438,7 @@ public:
{ {
if (offScreenCmdBuffer == VK_NULL_HANDLE) if (offScreenCmdBuffer == VK_NULL_HANDLE)
{ {
offScreenCmdBuffer = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false); offScreenCmdBuffer = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
} }
// Create a semaphore used to synchronize offscreen rendering and usage // Create a semaphore used to synchronize offscreen rendering and usage

View file

@ -450,7 +450,7 @@ public:
void buildDeferredCommandBuffer() void buildDeferredCommandBuffer()
{ {
if (offScreenCmdBuffer == VK_NULL_HANDLE) { if (offScreenCmdBuffer == VK_NULL_HANDLE) {
offScreenCmdBuffer = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false); offScreenCmdBuffer = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
} }
// Create a semaphore used to synchronize offscreen rendering and usage // Create a semaphore used to synchronize offscreen rendering and usage

View file

@ -354,7 +354,7 @@ public:
{ {
if (commandBuffers.deferred == VK_NULL_HANDLE) if (commandBuffers.deferred == VK_NULL_HANDLE)
{ {
commandBuffers.deferred = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false); commandBuffers.deferred = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
} }
// Create a semaphore used to synchronize offscreen rendering and usage // Create a semaphore used to synchronize offscreen rendering and usage

View file

@ -569,7 +569,7 @@ public:
&glTFModel.indices.memory)); &glTFModel.indices.memory));
// Copy data from staging buffers (host) do device local buffer (gpu) // Copy data from staging buffers (host) do device local buffer (gpu)
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = {}; VkBufferCopy copyRegion = {};
copyRegion.size = vertexBufferSize; copyRegion.size = vertexBufferSize;
@ -588,7 +588,7 @@ public:
1, 1,
&copyRegion); &copyRegion);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
// Free staging resources // Free staging resources
vkDestroyBuffer(device, vertexStaging.buffer, nullptr); vkDestroyBuffer(device, vertexStaging.buffer, nullptr);

View file

@ -504,7 +504,7 @@ public:
&instanceBuffer.memory)); &instanceBuffer.memory));
// Copy to staging buffer // Copy to staging buffer
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = { }; VkBufferCopy copyRegion = { };
copyRegion.size = instanceBuffer.size; copyRegion.size = instanceBuffer.size;
@ -515,7 +515,7 @@ public:
1, 1,
&copyRegion); &copyRegion);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
instanceBuffer.descriptor.range = instanceBuffer.size; instanceBuffer.descriptor.range = instanceBuffer.size;
instanceBuffer.descriptor.buffer = instanceBuffer.buffer; instanceBuffer.descriptor.buffer = instanceBuffer.buffer;

View file

@ -778,14 +778,14 @@ public:
fbufCreateInfo.layers = 1; fbufCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer)); VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer));
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
vks::tools::setImageLayout( vks::tools::setImageLayout(
layoutCmd, layoutCmd,
offscreen.image, offscreen.image,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
} }
// Descriptors // Descriptors
@ -1173,14 +1173,14 @@ public:
fbufCreateInfo.layers = 1; fbufCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer)); VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer));
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
vks::tools::setImageLayout( vks::tools::setImageLayout(
layoutCmd, layoutCmd,
offscreen.image, offscreen.image,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
} }
// Descriptors // Descriptors

View file

@ -719,14 +719,14 @@ public:
fbufCreateInfo.layers = 1; fbufCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer)); VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer));
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
vks::tools::setImageLayout( vks::tools::setImageLayout(
layoutCmd, layoutCmd,
offscreen.image, offscreen.image,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
} }
// Descriptors // Descriptors
@ -1114,14 +1114,14 @@ public:
fbufCreateInfo.layers = 1; fbufCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer)); VK_CHECK_RESULT(vkCreateFramebuffer(device, &fbufCreateInfo, nullptr, &offscreen.framebuffer));
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
vks::tools::setImageLayout( vks::tools::setImageLayout(
layoutCmd, layoutCmd,
offscreen.image, offscreen.image,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
} }
// Descriptors // Descriptors

View file

@ -822,7 +822,7 @@ public:
void loadScene() void loadScene()
{ {
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
scene = new Scene(vulkanDevice, queue); scene = new Scene(vulkanDevice, queue);
#if defined(__ANDROID__) #if defined(__ANDROID__)

View file

@ -195,7 +195,7 @@ public:
VkMemoryAllocateInfo memAllocInfo = vks::initializers::memoryAllocateInfo(); VkMemoryAllocateInfo memAllocInfo = vks::initializers::memoryAllocateInfo();
VkMemoryRequirements memReqs; VkMemoryRequirements memReqs;
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// Create cube map image // Create cube map image
VK_CHECK_RESULT(vkCreateImage(device, &imageCreateInfo, nullptr, &shadowCubeMap.image)); VK_CHECK_RESULT(vkCreateImage(device, &imageCreateInfo, nullptr, &shadowCubeMap.image));
@ -220,7 +220,7 @@ public:
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
subresourceRange); subresourceRange);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
// Create sampler // Create sampler
VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo();
@ -298,7 +298,7 @@ public:
VK_CHECK_RESULT(vkAllocateMemory(device, &memAlloc, nullptr, &offscreenPass.color.mem)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAlloc, nullptr, &offscreenPass.color.mem));
VK_CHECK_RESULT(vkBindImageMemory(device, offscreenPass.color.image, offscreenPass.color.mem, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, offscreenPass.color.image, offscreenPass.color.mem, 0));
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
vks::tools::setImageLayout( vks::tools::setImageLayout(
layoutCmd, layoutCmd,
@ -339,7 +339,7 @@ public:
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); vulkanDevice->flushCommandBuffer(layoutCmd, queue, true);
depthStencilView.image = offscreenPass.depth.image; depthStencilView.image = offscreenPass.depth.image;
VK_CHECK_RESULT(vkCreateImageView(device, &depthStencilView, nullptr, &offscreenPass.depth.view)); VK_CHECK_RESULT(vkCreateImageView(device, &depthStencilView, nullptr, &offscreenPass.depth.view));

View file

@ -636,7 +636,7 @@ public:
indexBufferSize)); indexBufferSize));
// Copy from staging buffers // Copy from staging buffers
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = {}; VkBufferCopy copyRegion = {};
@ -656,7 +656,7 @@ public:
1, 1,
&copyRegion); &copyRegion);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
vkDestroyBuffer(device, vertexStaging.buffer, nullptr); vkDestroyBuffer(device, vertexStaging.buffer, nullptr);
vkFreeMemory(device, vertexStaging.memory, nullptr); vkFreeMemory(device, vertexStaging.memory, nullptr);

View file

@ -552,7 +552,7 @@ public:
&models.terrain.indices.memory)); &models.terrain.indices.memory));
// Copy from staging buffers // Copy from staging buffers
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkBufferCopy copyRegion = {}; VkBufferCopy copyRegion = {};
@ -572,7 +572,7 @@ public:
1, 1,
&copyRegion); &copyRegion);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
models.terrain.device = device; models.terrain.device = device;

View file

@ -255,7 +255,7 @@ public:
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &texture.deviceMemory)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &texture.deviceMemory));
VK_CHECK_RESULT(vkBindImageMemory(device, texture.image, texture.deviceMemory, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, texture.image, texture.deviceMemory, 0));
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// Image memory barriers for the texture image // Image memory barriers for the texture image
@ -321,7 +321,7 @@ public:
// Store current layout for later reuse // Store current layout for later reuse
texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
// Clean up staging resources // Clean up staging resources
vkFreeMemory(device, stagingMemory, nullptr); vkFreeMemory(device, stagingMemory, nullptr);
@ -368,7 +368,7 @@ public:
texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
// Setup image memory barrier transfer image to shader read layout // Setup image memory barrier transfer image to shader read layout
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// The sub resource range describes the regions of the image we will be transition // The sub resource range describes the regions of the image we will be transition
VkImageSubresourceRange subresourceRange = {}; VkImageSubresourceRange subresourceRange = {};
@ -398,7 +398,7 @@ public:
0, nullptr, 0, nullptr,
1, &imageMemoryBarrier); 1, &imageMemoryBarrier);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
} }
ktxTexture_Destroy(ktxTexture); ktxTexture_Destroy(ktxTexture);

View file

@ -381,7 +381,7 @@ public:
memcpy(mapped, data, texMemSize); memcpy(mapped, data, texMemSize);
vkUnmapMemory(device, stagingMemory); vkUnmapMemory(device, stagingMemory);
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// The sub resource range describes the regions of the image we will be transitioned // The sub resource range describes the regions of the image we will be transitioned
VkImageSubresourceRange subresourceRange = {}; VkImageSubresourceRange subresourceRange = {};
@ -428,7 +428,7 @@ public:
texture.imageLayout, texture.imageLayout,
subresourceRange); subresourceRange);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
// Clean up staging resources // Clean up staging resources
delete[] data; delete[] data;

View file

@ -216,7 +216,7 @@ public:
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &textureArray.deviceMemory)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &textureArray.deviceMemory));
VK_CHECK_RESULT(vkBindImageMemory(device, textureArray.image, textureArray.deviceMemory, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, textureArray.image, textureArray.deviceMemory, 0));
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// Image barrier for optimal image (target) // Image barrier for optimal image (target)
// Set initial layout for all array layers (faces) of the optimal (target) tiled texture // Set initial layout for all array layers (faces) of the optimal (target) tiled texture
@ -252,7 +252,7 @@ public:
textureArray.imageLayout, textureArray.imageLayout,
subresourceRange); subresourceRange);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
// Create sampler // Create sampler
VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo();

View file

@ -215,7 +215,7 @@ public:
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &cubeMap.deviceMemory)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &cubeMap.deviceMemory));
VK_CHECK_RESULT(vkBindImageMemory(device, cubeMap.image, cubeMap.deviceMemory, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, cubeMap.image, cubeMap.deviceMemory, 0));
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// Setup buffer copy regions for each face including all of its miplevels // Setup buffer copy regions for each face including all of its miplevels
std::vector<VkBufferImageCopy> bufferCopyRegions; std::vector<VkBufferImageCopy> bufferCopyRegions;
@ -276,7 +276,7 @@ public:
cubeMap.imageLayout, cubeMap.imageLayout,
subresourceRange); subresourceRange);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
// Create sampler // Create sampler
VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo();

View file

@ -204,7 +204,7 @@ public:
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &texture.deviceMemory)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &texture.deviceMemory));
VK_CHECK_RESULT(vkBindImageMemory(device, texture.image, texture.deviceMemory, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, texture.image, texture.deviceMemory, 0));
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
VkImageSubresourceRange subresourceRange = {}; VkImageSubresourceRange subresourceRange = {};
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
@ -247,7 +247,7 @@ public:
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
subresourceRange); subresourceRange);
VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
// Clean up staging resources // Clean up staging resources
vkFreeMemory(device, stagingMemory, nullptr); vkFreeMemory(device, stagingMemory, nullptr);
@ -258,7 +258,7 @@ public:
// --------------------------------------------------------------- // ---------------------------------------------------------------
// We copy down the whole mip chain doing a blit from mip-1 to mip // We copy down the whole mip chain doing a blit from mip-1 to mip
// An alternative way would be to always blit from the first mip level and sample that one down // An alternative way would be to always blit from the first mip level and sample that one down
VkCommandBuffer blitCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer blitCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// Copy down mips from n-1 to n // Copy down mips from n-1 to n
for (int32_t i = 1; i < texture.mipLevels; i++) for (int32_t i = 1; i < texture.mipLevels; i++)
@ -336,7 +336,7 @@ public:
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
subresourceRange); subresourceRange);
VulkanExampleBase::flushCommandBuffer(blitCmd, queue, true); vulkanDevice->flushCommandBuffer(blitCmd, queue, true);
// --------------------------------------------------------------- // ---------------------------------------------------------------
// Create samplers // Create samplers