From 2cd7de7a284b2bdc6bc61843d4e16940fde35f62 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 6 Nov 2017 22:04:44 -1000 Subject: [PATCH 1/2] Clear Vulkan resources if command buffer abandoned --- lib/graphicsdev/Vulkan.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/graphicsdev/Vulkan.cpp b/lib/graphicsdev/Vulkan.cpp index 66a725c..90a6b25 100644 --- a/lib/graphicsdev/Vulkan.cpp +++ b/lib/graphicsdev/Vulkan.cpp @@ -2349,7 +2349,8 @@ struct VulkanShaderDataBinding : GraphicsDataNode writes[totalWrites].dstSet = m_descSets[b]; writes[totalWrites].descriptorCount = 1; writes[totalWrites].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - writes[totalWrites].pImageInfo = GetTextureGPUResource(m_texs[i].tex.get(), b, m_texs[i].idx, m_texs[i].depth); + writes[totalWrites].pImageInfo = GetTextureGPUResource(m_texs[i].tex.get(), b, + m_texs[i].idx, m_texs[i].depth); writes[totalWrites].dstArrayElement = 0; writes[totalWrites].dstBinding = binding; m_knownViewHandles[b][i] = writes[totalWrites].pImageInfo->imageView; @@ -2382,7 +2383,8 @@ struct VulkanShaderDataBinding : GraphicsDataNode { if (iimageView != m_knownViewHandles[b][i]) { writes[totalWrites].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; @@ -2983,7 +2985,8 @@ void VulkanTextureD::update(int b) /* map memory and copy staging data */ uint8_t* mappedData; - ThrowIfFailed(vk::MapMemory(m_q->m_ctx->m_dev, m_cpuMem, m_cpuOffsets[b], m_cpuSz, 0, reinterpret_cast(&mappedData))); + ThrowIfFailed(vk::MapMemory(m_q->m_ctx->m_dev, m_cpuMem, m_cpuOffsets[b], m_cpuSz, 0, + reinterpret_cast(&mappedData))); memmove(mappedData, m_stagingBuf.get(), m_cpuSz); vk::UnmapMemory(m_q->m_ctx->m_dev, m_cpuMem); @@ -3293,8 +3296,9 @@ boo::ObjToken VulkanDataFactory::Context::newShaderPipeline ThrowIfFailed(vk::CreatePipelineCache(factory.m_ctx->m_dev, &cacheDataInfo, nullptr, &pipelineCache)); } - VulkanShaderPipeline* retval = new VulkanShaderPipeline(m_data, factory.m_ctx, std::move(vertShader), std::move(fragShader), - pipelineCache, vtxFmt, srcFac, dstFac, prim, depthTest, depthWrite, colorWrite, + VulkanShaderPipeline* retval = new VulkanShaderPipeline(m_data, factory.m_ctx, std::move(vertShader), + std::move(fragShader), pipelineCache, vtxFmt, srcFac, + dstFac, prim, depthTest, depthWrite, colorWrite, alphaWrite, culling); if (pipelineBlob && pipelineBlob->empty()) @@ -3304,7 +3308,8 @@ boo::ObjToken VulkanDataFactory::Context::newShaderPipeline if (cacheSz) { pipelineBlob->resize(cacheSz); - ThrowIfFailed(vk::GetPipelineCacheData(factory.m_ctx->m_dev, pipelineCache, &cacheSz, pipelineBlob->data())); + ThrowIfFailed(vk::GetPipelineCacheData(factory.m_ctx->m_dev, pipelineCache, + &cacheSz, pipelineBlob->data())); pipelineBlob->resize(cacheSz); } } @@ -3416,7 +3421,8 @@ void VulkanDataFactoryImpl::commitTransaction if (data->m_DBufs) for (IGraphicsBufferD& buf : *data->m_DBufs) - bufMemSize = static_cast&>(buf).sizeForGPU(m_ctx, bufMemTypeBits, bufMemSize); + bufMemSize = static_cast&>(buf). + sizeForGPU(m_ctx, bufMemTypeBits, bufMemSize); if (data->m_STexs) for (ITextureS& tex : *data->m_STexs) @@ -3611,6 +3617,9 @@ void VulkanCommandQueue::execute() resetCommandBuffer(); m_dynamicNeedsReset = true; m_resolveDispSource = nullptr; + + /* Clear dead data */ + m_drawResTokens[m_fillBuf].clear(); return; } m_submitted = false; From 3cd375e67bc2ba4f6ddad90bf5381e76252cc237 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 7 Nov 2017 16:24:07 -1000 Subject: [PATCH 2/2] Restore VkShaderModule caching --- CMakeLists.txt | 2 +- lib/graphicsdev/GL.cpp | 4 +++- lib/graphicsdev/Vulkan.cpp | 44 +++++++++++++++++-------------------- lib/x11/ApplicationUnix.cpp | 3 ++- lib/x11/ApplicationXlib.hpp | 3 ++- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd9548a..e6c6bbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ add_subdirectory(xxhash) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}") find_package(IPP) if (IPP_FOUND) - add_definitions(-DINTEL_IPP=1) + list(APPEND _BOO_SYS_DEFINES -DINTEL_IPP=1) include_directories(${IPP_INCLUDE_DIRS}) list(APPEND _BOO_SYS_LIBS ${IPP_LIBRARIES}) endif () diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 82c09de..00f3f42 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -1,5 +1,6 @@ #include "boo/graphicsdev/GL.hpp" #include "boo/graphicsdev/glew.h" +#include "boo/IApplication.hpp" #include "Common.hpp" #include #include @@ -1123,7 +1124,8 @@ struct GLCommandQueue : IGraphicsCommandQueue static void RenderingWorker(GLCommandQueue* self) { - logvisor::RegisterThreadName("Boo GL Rendering Thread"); + std::string thrName = APP->getFriendlyName() + " GL Rendering Thread"; + logvisor::RegisterThreadName(thrName.c_str()); { std::unique_lock lk(self->m_initmt); self->m_parent->makeCurrent(); diff --git a/lib/graphicsdev/Vulkan.cpp b/lib/graphicsdev/Vulkan.cpp index 90a6b25..2d7fd8a 100644 --- a/lib/graphicsdev/Vulkan.cpp +++ b/lib/graphicsdev/Vulkan.cpp @@ -26,10 +26,11 @@ class VulkanDataFactoryImpl; struct VulkanShareableShader : IShareableShader { VkDevice m_dev; - std::vector m_shader; + VkShaderModule m_shader; VulkanShareableShader(VulkanDataFactoryImpl& fac, uint64_t srcKey, uint64_t binKey, - VkDevice dev, const std::vector& s) + VkDevice dev, VkShaderModule s) : IShareableShader(fac, srcKey, binKey), m_dev(dev), m_shader(s) {} + ~VulkanShareableShader() { vk::DestroyShaderModule(m_dev, m_shader, nullptr); } }; class VulkanDataFactoryImpl : public VulkanDataFactory, public GraphicsDataFactoryHead @@ -328,9 +329,9 @@ void VulkanContext::initVulkan(const char* appName) #ifndef NDEBUG m_layerNames.push_back("VK_LAYER_LUNARG_core_validation"); - m_layerNames.push_back("VK_LAYER_LUNARG_object_tracker"); - //m_layerNames.push_back("VK_LAYER_LUNARG_parameter_validation"); - //m_layerNames.push_back("VK_LAYER_GOOGLE_threading"); + //m_layerNames.push_back("VK_LAYER_LUNARG_object_tracker"); + m_layerNames.push_back("VK_LAYER_LUNARG_parameter_validation"); + m_layerNames.push_back("VK_LAYER_GOOGLE_threading"); #endif demo_check_layers(m_instanceLayerProperties, m_layerNames); @@ -1910,23 +1911,11 @@ public: VkPipelineShaderStageCreateInfo stages[2] = {}; - VkShaderModuleCreateInfo smCreateInfo = {}; - smCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - VkShaderModule vertModule, fragModule; - const auto& vertShader = m_vert.get().m_shader; - smCreateInfo.codeSize = vertShader.size() * sizeof(unsigned int); - smCreateInfo.pCode = vertShader.data(); - ThrowIfFailed(vk::CreateShaderModule(m_ctx->m_dev, &smCreateInfo, nullptr, &vertModule)); - const auto& fragShader = m_frag.get().m_shader; - smCreateInfo.codeSize = fragShader.size() * sizeof(unsigned int); - smCreateInfo.pCode = fragShader.data(); - ThrowIfFailed(vk::CreateShaderModule(m_ctx->m_dev, &smCreateInfo, nullptr, &fragModule)); - stages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; stages[0].pNext = nullptr; stages[0].flags = 0; stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; - stages[0].module = vertModule; + stages[0].module = m_vert.get().m_shader; stages[0].pName = "main"; stages[0].pSpecializationInfo = nullptr; @@ -1934,7 +1923,7 @@ public: stages[1].pNext = nullptr; stages[1].flags = 0; stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; - stages[1].module = fragModule; + stages[1].module = m_frag.get().m_shader; stages[1].pName = "main"; stages[1].pSpecializationInfo = nullptr; @@ -2051,9 +2040,6 @@ public: ThrowIfFailed(vk::CreateGraphicsPipelines(m_ctx->m_dev, m_pipelineCache, 1, &pipelineCreateInfo, nullptr, &m_pipeline)); - vk::DestroyShaderModule(m_ctx->m_dev, vertModule, nullptr); - vk::DestroyShaderModule(m_ctx->m_dev, fragModule, nullptr); - m_vert.reset(); m_frag.reset(); } @@ -3249,10 +3235,15 @@ boo::ObjToken VulkanDataFactory::Context::newShaderPipeline binHashes[0] = CompileVert(vertBlob, vertSource, srcHashes[0], factory); } + VkShaderModule vertModule; + smCreateInfo.codeSize = useVertBlob->size() * sizeof(unsigned int); + smCreateInfo.pCode = useVertBlob->data(); + ThrowIfFailed(vk::CreateShaderModule(factory.m_ctx->m_dev, &smCreateInfo, nullptr, &vertModule)); + auto it = factory.m_sharedShaders.emplace(std::make_pair(binHashes[0], std::make_unique(factory, srcHashes[0], binHashes[0], - factory.m_ctx->m_dev, *useVertBlob))).first; + factory.m_ctx->m_dev, vertModule))).first; vertShader = it->second->lock(); } auto fragFind = binHashes[1] ? factory.m_sharedShaders.find(binHashes[1]) : @@ -3275,10 +3266,15 @@ boo::ObjToken VulkanDataFactory::Context::newShaderPipeline binHashes[1] = CompileFrag(fragBlob, fragSource, srcHashes[1], factory); } + VkShaderModule fragModule; + smCreateInfo.codeSize = useFragBlob->size() * sizeof(unsigned int); + smCreateInfo.pCode = useFragBlob->data(); + ThrowIfFailed(vk::CreateShaderModule(factory.m_ctx->m_dev, &smCreateInfo, nullptr, &fragModule)); + auto it = factory.m_sharedShaders.emplace(std::make_pair(binHashes[1], std::make_unique(factory, srcHashes[1], binHashes[1], - factory.m_ctx->m_dev, *useFragBlob))).first; + factory.m_ctx->m_dev, fragModule))).first; fragShader = it->second->lock(); } diff --git a/lib/x11/ApplicationUnix.cpp b/lib/x11/ApplicationUnix.cpp index c701197..9871dae 100644 --- a/lib/x11/ApplicationUnix.cpp +++ b/lib/x11/ApplicationUnix.cpp @@ -56,7 +56,8 @@ int ApplicationRun(IApplication::EPlatformType platform, const std::vector& args, bool singleInstance) { - logvisor::RegisterThreadName("Boo Main Thread"); + std::string thrName = friendlyName + " Main Thread"; + logvisor::RegisterThreadName(thrName.c_str()); if (APP) return 1; if (platform == IApplication::EPlatformType::Wayland) diff --git a/lib/x11/ApplicationXlib.hpp b/lib/x11/ApplicationXlib.hpp index 59037e1..128f394 100644 --- a/lib/x11/ApplicationXlib.hpp +++ b/lib/x11/ApplicationXlib.hpp @@ -433,7 +433,8 @@ public: std::unique_lock innerLk(initmt); innerLk.unlock(); initcv.notify_one(); - logvisor::RegisterThreadName("Boo Client Thread"); + std::string thrName = getFriendlyName() + " Client Thread"; + logvisor::RegisterThreadName(thrName.c_str()); clientReturn = m_callback.appMain(this); pthread_kill(mainThread, SIGUSR2); });