diff --git a/base/VulkanTools.cpp b/base/VulkanTools.cpp index 29b558ac..5e720fc8 100644 --- a/base/VulkanTools.cpp +++ b/base/VulkanTools.cpp @@ -294,23 +294,6 @@ namespace vks exitFatal(message, (int32_t)resultCode); } - std::string readTextFile(const char *fileName) - { - std::string fileContent; - std::ifstream fileStream(fileName, std::ios::in); - if (!fileStream.is_open()) { - printf("File %s not found\n", fileName); - return ""; - } - std::string line = ""; - while (!fileStream.eof()) { - getline(fileStream, line); - fileContent.append(line + "\n"); - } - fileStream.close(); - return fileContent; - } - #if defined(__ANDROID__) // Android shaders are stored as assets in the apk // So they need to be loaded via the asset manager diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index da4aae53..be758470 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -110,18 +110,6 @@ std::string VulkanExampleBase::getWindowTitle() return windowTitle; } -bool VulkanExampleBase::checkCommandBuffers() -{ - for (auto& cmdBuffer : drawCmdBuffers) - { - if (cmdBuffer == VK_NULL_HANDLE) - { - return false; - } - } - return true; -} - void VulkanExampleBase::createCommandBuffers() { // Create one command buffer for each swap chain image and reuse for rendering @@ -141,51 +129,6 @@ void VulkanExampleBase::destroyCommandBuffers() vkFreeCommandBuffers(device, cmdPool, static_cast(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() { VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {}; diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 8d6ba2b6..e01ce6f3 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -71,6 +71,8 @@ private: void createSynchronizationPrimitives(); void initSwapchain(); void setupSwapChain(); + void createCommandBuffers(); + void destroyCommandBuffers(); protected: // Frame counter to display fps uint32_t frameCounter = 0; @@ -332,18 +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 */ virtual void getEnabledFeatures(); - /** @brief Checks if command buffers are valid (!= VK_NULL_HANDLE) */ - bool checkCommandBuffers(); - /** @brief Creates the per-frame command buffers */ - void createCommandBuffers(); - /** @brief Destroy all command buffers and set their handles to VK_NULL_HANDLE */ - void destroyCommandBuffers(); - - /** @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 */ virtual void prepare(); diff --git a/examples/computecloth/computecloth.cpp b/examples/computecloth/computecloth.cpp index 34ed35f1..c73cf479 100644 --- a/examples/computecloth/computecloth.cpp +++ b/examples/computecloth/computecloth.cpp @@ -231,13 +231,6 @@ public: void buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; @@ -417,7 +410,7 @@ public: storageBufferSize); // 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 = {}; copyRegion.size = storageBufferSize; vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.input.buffer, 1, ©Region); @@ -426,7 +419,7 @@ public: // 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" addGraphicsToComputeBarriers(copyCmd); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); stagingBuffer.destroy(); @@ -457,11 +450,11 @@ public: indexBufferSize); // Copy from staging buffer - copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); + copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); copyRegion = {}; copyRegion.size = indexBufferSize; vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, graphics.indices.buffer, 1, ©Region); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); stagingBuffer.destroy(); } diff --git a/examples/computenbody/computenbody.cpp b/examples/computenbody/computenbody.cpp index 5dd81add..7e184c30 100644 --- a/examples/computenbody/computenbody.cpp +++ b/examples/computenbody/computenbody.cpp @@ -135,13 +135,6 @@ public: void buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; @@ -416,7 +409,7 @@ public: storageBufferSize); // 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 = {}; copyRegion.size = storageBufferSize; vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffer.buffer, 1, ©Region); @@ -445,7 +438,7 @@ public: 1, &buffer_barrier, 0, nullptr); } - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); stagingBuffer.destroy(); diff --git a/examples/computeparticles/computeparticles.cpp b/examples/computeparticles/computeparticles.cpp index a063d77a..c11b4c38 100644 --- a/examples/computeparticles/computeparticles.cpp +++ b/examples/computeparticles/computeparticles.cpp @@ -327,7 +327,7 @@ public: storageBufferSize); // 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 = {}; copyRegion.size = storageBufferSize; vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffer.buffer, 1, ©Region); @@ -356,7 +356,7 @@ public: 1, &buffer_barrier, 0, nullptr); } - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); stagingBuffer.destroy(); diff --git a/examples/computeraytracing/computeraytracing.cpp b/examples/computeraytracing/computeraytracing.cpp index 9a34f737..cceaa587 100644 --- a/examples/computeraytracing/computeraytracing.cpp +++ b/examples/computeraytracing/computeraytracing.cpp @@ -162,7 +162,7 @@ public: VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &tex->deviceMemory)); 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; vks::tools::setImageLayout( @@ -172,7 +172,7 @@ public: VK_IMAGE_LAYOUT_UNDEFINED, tex->imageLayout); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); // Create sampler VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); @@ -208,13 +208,6 @@ public: void buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; @@ -344,11 +337,11 @@ public: storageBufferSize); // 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 = {}; copyRegion.size = storageBufferSize; vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.spheres.buffer, 1, ©Region); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); stagingBuffer.destroy(); @@ -379,10 +372,10 @@ public: storageBufferSize); // 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; vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.storageBuffers.planes.buffer, 1, ©Region); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); stagingBuffer.destroy(); } diff --git a/examples/computeshader/computeshader.cpp b/examples/computeshader/computeshader.cpp index 37d13447..f9cabbe6 100644 --- a/examples/computeshader/computeshader.cpp +++ b/examples/computeshader/computeshader.cpp @@ -152,7 +152,7 @@ public: VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &tex->deviceMemory)); 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; vks::tools::setImageLayout( @@ -161,7 +161,7 @@ public: VK_IMAGE_LAYOUT_UNDEFINED, tex->imageLayout); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); // Create sampler VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); @@ -203,13 +203,6 @@ public: void buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; diff --git a/examples/deferred/deferred.cpp b/examples/deferred/deferred.cpp index 10d407e3..f004067c 100644 --- a/examples/deferred/deferred.cpp +++ b/examples/deferred/deferred.cpp @@ -438,7 +438,7 @@ public: { 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 @@ -529,16 +529,6 @@ public: textures.floor.normalMap.loadFromFile(getAssetPath() + "textures/stonefloor01_normal" + texFormatSuffix + ".ktx", texFormat, vulkanDevice, queue); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); diff --git a/examples/deferredmultisampling/deferredmultisampling.cpp b/examples/deferredmultisampling/deferredmultisampling.cpp index 994a64b3..17efd146 100644 --- a/examples/deferredmultisampling/deferredmultisampling.cpp +++ b/examples/deferredmultisampling/deferredmultisampling.cpp @@ -450,7 +450,7 @@ public: void buildDeferredCommandBuffer() { 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 diff --git a/examples/deferredshadows/deferredshadows.cpp b/examples/deferredshadows/deferredshadows.cpp index 9bc27c25..ca330bac 100644 --- a/examples/deferredshadows/deferredshadows.cpp +++ b/examples/deferredshadows/deferredshadows.cpp @@ -354,7 +354,7 @@ public: { 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 @@ -467,16 +467,6 @@ public: textures.background.normalMap.loadFromFile(getAssetPath() + "textures/stonefloor02_normal" + texFormatSuffix + ".ktx", texFormat, vulkanDevice, queue); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); diff --git a/examples/distancefieldfonts/distancefieldfonts.cpp b/examples/distancefieldfonts/distancefieldfonts.cpp index 9ded1f7c..8269b5ab 100644 --- a/examples/distancefieldfonts/distancefieldfonts.cpp +++ b/examples/distancefieldfonts/distancefieldfonts.cpp @@ -201,16 +201,6 @@ public: textures.fontBitmap.loadFromFile(getAssetPath() + "textures/font_bitmap_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); diff --git a/examples/geometryshader/geometryshader.cpp b/examples/geometryshader/geometryshader.cpp index e19651be..6569f1e0 100644 --- a/examples/geometryshader/geometryshader.cpp +++ b/examples/geometryshader/geometryshader.cpp @@ -107,16 +107,6 @@ public: } } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); diff --git a/examples/gltfscene/gltfscene.cpp b/examples/gltfscene/gltfscene.cpp index eae17dfb..74405946 100644 --- a/examples/gltfscene/gltfscene.cpp +++ b/examples/gltfscene/gltfscene.cpp @@ -520,7 +520,7 @@ public: } } else { - vks::tools::exitFatal("Could not open the glTF file\n\nThe file is part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1); + vks::tools::exitFatal("Could not open the glTF file.\n\nThe file is part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1); return; } @@ -569,7 +569,7 @@ public: &glTFModel.indices.memory)); // 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 = {}; copyRegion.size = vertexBufferSize; @@ -588,7 +588,7 @@ public: 1, ©Region); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); // Free staging resources vkDestroyBuffer(device, vertexStaging.buffer, nullptr); diff --git a/examples/instancing/instancing.cpp b/examples/instancing/instancing.cpp index 4e86d64f..31b24e5a 100644 --- a/examples/instancing/instancing.cpp +++ b/examples/instancing/instancing.cpp @@ -504,7 +504,7 @@ public: &instanceBuffer.memory)); // 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 = { }; copyRegion.size = instanceBuffer.size; @@ -515,7 +515,7 @@ public: 1, ©Region); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); instanceBuffer.descriptor.range = instanceBuffer.size; instanceBuffer.descriptor.buffer = instanceBuffer.buffer; diff --git a/examples/pbribl/pbribl.cpp b/examples/pbribl/pbribl.cpp index cf936adf..ac0cad83 100644 --- a/examples/pbribl/pbribl.cpp +++ b/examples/pbribl/pbribl.cpp @@ -778,14 +778,14 @@ public: fbufCreateInfo.layers = 1; 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( layoutCmd, offscreen.image, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); } // Descriptors @@ -1173,14 +1173,14 @@ public: fbufCreateInfo.layers = 1; 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( layoutCmd, offscreen.image, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); } // Descriptors diff --git a/examples/pbrtexture/main.cpp b/examples/pbrtexture/main.cpp index d9f60b06..bb6b238c 100644 --- a/examples/pbrtexture/main.cpp +++ b/examples/pbrtexture/main.cpp @@ -719,14 +719,14 @@ public: fbufCreateInfo.layers = 1; 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( layoutCmd, offscreen.image, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); } // Descriptors @@ -1114,14 +1114,14 @@ public: fbufCreateInfo.layers = 1; 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( layoutCmd, offscreen.image, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); } // Descriptors diff --git a/examples/pushconstants/pushconstants.cpp b/examples/pushconstants/pushconstants.cpp index d2330230..c56e371a 100644 --- a/examples/pushconstants/pushconstants.cpp +++ b/examples/pushconstants/pushconstants.cpp @@ -91,16 +91,6 @@ public: uniformBuffer.destroy(); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -457,7 +447,7 @@ public: draw(); if (!paused) { - reBuildCommandBuffers(); + buildCommandBuffers(); } } diff --git a/examples/scenerendering/scenerendering.cpp b/examples/scenerendering/scenerendering.cpp index b3a46e1f..4902f9df 100644 --- a/examples/scenerendering/scenerendering.cpp +++ b/examples/scenerendering/scenerendering.cpp @@ -822,7 +822,7 @@ public: 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); #if defined(__ANDROID__) diff --git a/examples/shadowmappingomni/shadowmappingomni.cpp b/examples/shadowmappingomni/shadowmappingomni.cpp index 5418f67a..fc694de3 100644 --- a/examples/shadowmappingomni/shadowmappingomni.cpp +++ b/examples/shadowmappingomni/shadowmappingomni.cpp @@ -195,7 +195,7 @@ public: VkMemoryAllocateInfo memAllocInfo = vks::initializers::memoryAllocateInfo(); 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 VK_CHECK_RESULT(vkCreateImage(device, &imageCreateInfo, nullptr, &shadowCubeMap.image)); @@ -220,7 +220,7 @@ public: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, subresourceRange); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); // Create sampler VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); @@ -298,7 +298,7 @@ public: VK_CHECK_RESULT(vkAllocateMemory(device, &memAlloc, nullptr, &offscreenPass.color.mem)); 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( layoutCmd, @@ -339,7 +339,7 @@ public: VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); - VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true); + vulkanDevice->flushCommandBuffer(layoutCmd, queue, true); depthStencilView.image = offscreenPass.depth.image; VK_CHECK_RESULT(vkCreateImageView(device, &depthStencilView, nullptr, &offscreenPass.depth.view)); diff --git a/examples/skeletalanimation/skeletalanimation.cpp b/examples/skeletalanimation/skeletalanimation.cpp index c49ecb5f..58afe7fb 100644 --- a/examples/skeletalanimation/skeletalanimation.cpp +++ b/examples/skeletalanimation/skeletalanimation.cpp @@ -636,7 +636,7 @@ public: indexBufferSize)); // 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 = {}; @@ -656,7 +656,7 @@ public: 1, ©Region); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); vkDestroyBuffer(device, vertexStaging.buffer, nullptr); vkFreeMemory(device, vertexStaging.memory, nullptr); diff --git a/examples/terraintessellation/terraintessellation.cpp b/examples/terraintessellation/terraintessellation.cpp index 284431d5..cc72b704 100644 --- a/examples/terraintessellation/terraintessellation.cpp +++ b/examples/terraintessellation/terraintessellation.cpp @@ -305,16 +305,6 @@ public: textures.terrainArray.descriptor.sampler = textures.terrainArray.sampler; } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -562,7 +552,7 @@ public: &models.terrain.indices.memory)); // 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 = {}; @@ -582,7 +572,7 @@ public: 1, ©Region); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); models.terrain.device = device; diff --git a/examples/texture/texture.cpp b/examples/texture/texture.cpp index 5cc5b943..3b2aa6df 100644 --- a/examples/texture/texture.cpp +++ b/examples/texture/texture.cpp @@ -255,7 +255,7 @@ public: VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &texture.deviceMemory)); 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 @@ -321,7 +321,7 @@ public: // Store current layout for later reuse texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); // Clean up staging resources vkFreeMemory(device, stagingMemory, nullptr); @@ -368,7 +368,7 @@ public: texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; // 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 VkImageSubresourceRange subresourceRange = {}; @@ -398,7 +398,7 @@ public: 0, nullptr, 1, &imageMemoryBarrier); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); } ktxTexture_Destroy(ktxTexture); diff --git a/examples/texture3d/texture3d.cpp b/examples/texture3d/texture3d.cpp index 63803243..2363f73a 100644 --- a/examples/texture3d/texture3d.cpp +++ b/examples/texture3d/texture3d.cpp @@ -381,7 +381,7 @@ public: memcpy(mapped, data, texMemSize); 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 VkImageSubresourceRange subresourceRange = {}; @@ -428,7 +428,7 @@ public: texture.imageLayout, subresourceRange); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); // Clean up staging resources delete[] data; diff --git a/examples/texturearray/texturearray.cpp b/examples/texturearray/texturearray.cpp index 4ea1cc17..c672d2d8 100644 --- a/examples/texturearray/texturearray.cpp +++ b/examples/texturearray/texturearray.cpp @@ -216,7 +216,7 @@ public: VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &textureArray.deviceMemory)); 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) // Set initial layout for all array layers (faces) of the optimal (target) tiled texture @@ -252,7 +252,7 @@ public: textureArray.imageLayout, subresourceRange); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); // Create sampler VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); diff --git a/examples/texturecubemap/texturecubemap.cpp b/examples/texturecubemap/texturecubemap.cpp index d56857e1..5532b5f1 100644 --- a/examples/texturecubemap/texturecubemap.cpp +++ b/examples/texturecubemap/texturecubemap.cpp @@ -215,7 +215,7 @@ public: VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &cubeMap.deviceMemory)); 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 std::vector bufferCopyRegions; @@ -276,7 +276,7 @@ public: cubeMap.imageLayout, subresourceRange); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); // Create sampler VkSamplerCreateInfo sampler = vks::initializers::samplerCreateInfo(); diff --git a/examples/texturemipmapgen/texturemipmapgen.cpp b/examples/texturemipmapgen/texturemipmapgen.cpp index 04c98e33..e0e12140 100644 --- a/examples/texturemipmapgen/texturemipmapgen.cpp +++ b/examples/texturemipmapgen/texturemipmapgen.cpp @@ -204,7 +204,7 @@ public: VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &texture.deviceMemory)); 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 = {}; subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -247,7 +247,7 @@ public: VK_PIPELINE_STAGE_TRANSFER_BIT, subresourceRange); - VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); // Clean up staging resources vkFreeMemory(device, stagingMemory, nullptr); @@ -258,7 +258,7 @@ public: // --------------------------------------------------------------- // 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 - 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 for (int32_t i = 1; i < texture.mipLevels; i++) @@ -336,7 +336,7 @@ public: VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, subresourceRange); - VulkanExampleBase::flushCommandBuffer(blitCmd, queue, true); + vulkanDevice->flushCommandBuffer(blitCmd, queue, true); // --------------------------------------------------------------- // Create samplers