Windows and Vulkan fixes for AMD GPU

This commit is contained in:
Jack Andersen 2017-11-08 22:10:43 -10:00
parent 1a2fc1d2a3
commit 165314b817
10 changed files with 85 additions and 80 deletions

@ -1 +1 @@
Subproject commit d0e9a99ed20e43e1547473c4fb2f8ce0f665af22 Subproject commit 2edde6665d9a56ead5ea0e55b4e64d9a803e6164

View File

@ -10,25 +10,16 @@ namespace boo
class IObj class IObj
{ {
std::atomic_int m_refCount = {0}; std::atomic_int m_refCount = {0};
protected:
std::recursive_mutex* m_mutex = nullptr;
public: public:
virtual ~IObj() = default; virtual ~IObj() = default;
virtual std::unique_lock<std::recursive_mutex> destructorLock() { return {}; }
void increment() { m_refCount++; } void increment() { m_refCount++; }
void decrement() void decrement()
{ {
if (m_refCount.fetch_sub(1) == 1) if (m_refCount.fetch_sub(1) == 1)
{ {
if (std::recursive_mutex* mutex = m_mutex) auto lk = destructorLock();
{ delete this;
mutex->lock();
delete this;
mutex->unlock();
}
else
{
delete this;
}
} }
} }
}; };

View File

@ -427,10 +427,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
continue; continue;
#ifdef UNICODE #ifdef UNICODE
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, nullptr, 0, nullptr, nullptr); ret.push_back(std::make_pair(std::string(name), WCSTMBS(caps.szPname)));
std::string strTo(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, &strTo[0], sizeNeeded, nullptr, nullptr);
ret.push_back(std::make_pair(std::string(name), std::move(strTo)));
#else #else
ret.push_back(std::make_pair(std::string(name), std::string(caps.szPname))); ret.push_back(std::make_pair(std::string(name), std::string(caps.szPname)));
#endif #endif
@ -446,10 +443,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
continue; continue;
#ifdef UNICODE #ifdef UNICODE
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, nullptr, 0, nullptr, nullptr); ret.push_back(std::make_pair(std::string(name), WCSTMBS(caps.szPname)));
std::string strTo(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, &strTo[0], sizeNeeded, nullptr, nullptr);
ret.push_back(std::make_pair(std::string(name), std::move(strTo)));
#else #else
ret.push_back(std::make_pair(std::string(name), std::string(caps.szPname))); ret.push_back(std::make_pair(std::string(name), std::string(caps.szPname)));
#endif #endif
@ -493,10 +487,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
return {}; return {};
#ifdef UNICODE #ifdef UNICODE
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, nullptr, 0, nullptr, nullptr); return WCSTMBS(caps.szPname);
std::string strTo(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, &strTo[0], sizeNeeded, nullptr, nullptr);
return strTo;
#else #else
return caps.szPname; return caps.szPname;
#endif #endif
@ -540,10 +531,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
return {}; return {};
#ifdef UNICODE #ifdef UNICODE
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, nullptr, 0, nullptr, nullptr); return WCSTMBS(caps.szPname);
std::string strTo(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, &strTo[0], sizeNeeded, nullptr, nullptr);
return strTo;
#else #else
return caps.szPname; return caps.szPname;
#endif #endif
@ -598,10 +586,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
return {}; return {};
#ifdef UNICODE #ifdef UNICODE
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, nullptr, 0, nullptr, nullptr); return WCSTMBS(caps.szPname);
std::string strTo(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, &strTo[0], sizeNeeded, nullptr, nullptr);
return strTo;
#else #else
return caps.szPname; return caps.szPname;
#endif #endif

View File

@ -64,11 +64,12 @@ struct BaseGraphicsData : IObj
template<class T> GraphicsDataNode<T, BaseGraphicsData>*& getHead(); template<class T> GraphicsDataNode<T, BaseGraphicsData>*& getHead();
template<class T> size_t countForward() template<class T> size_t countForward()
{ auto* head = getHead<T>(); return head ? head->countForward() : 0; } { auto* head = getHead<T>(); return head ? head->countForward() : 0; }
std::unique_lock<std::recursive_mutex> destructorLock() override
{ return std::unique_lock<std::recursive_mutex>{m_head.m_dataMutex}; }
explicit BaseGraphicsData(GraphicsDataFactoryHead& head) explicit BaseGraphicsData(GraphicsDataFactoryHead& head)
: m_head(head) : m_head(head)
{ {
IObj::m_mutex = &m_head.m_dataMutex;
std::lock_guard<std::recursive_mutex> lk(m_head.m_dataMutex); std::lock_guard<std::recursive_mutex> lk(m_head.m_dataMutex);
m_next = head.m_dataHead; m_next = head.m_dataHead;
if (m_next) if (m_next)
@ -127,11 +128,12 @@ struct BaseGraphicsPool : IObj
template<class T> GraphicsDataNode<T, BaseGraphicsPool>*& getHead(); template<class T> GraphicsDataNode<T, BaseGraphicsPool>*& getHead();
template<class T> size_t countForward() template<class T> size_t countForward()
{ auto* head = getHead<T>(); return head ? head->countForward() : 0; } { auto* head = getHead<T>(); return head ? head->countForward() : 0; }
std::unique_lock<std::recursive_mutex> destructorLock() override
{ return std::unique_lock<std::recursive_mutex>{m_head.m_dataMutex}; }
explicit BaseGraphicsPool(GraphicsDataFactoryHead& head) explicit BaseGraphicsPool(GraphicsDataFactoryHead& head)
: m_head(head) : m_head(head)
{ {
IObj::m_mutex = &m_head.m_dataMutex;
std::lock_guard<std::recursive_mutex> lk(m_head.m_dataMutex); std::lock_guard<std::recursive_mutex> lk(m_head.m_dataMutex);
m_next = head.m_poolHead; m_next = head.m_poolHead;
if (m_next) if (m_next)
@ -172,11 +174,12 @@ struct GraphicsDataNode : NodeCls
ObjToken<DataCls> m_data; ObjToken<DataCls> m_data;
GraphicsDataNode<NodeCls, DataCls>* m_next; GraphicsDataNode<NodeCls, DataCls>* m_next;
GraphicsDataNode<NodeCls, DataCls>* m_prev = nullptr; GraphicsDataNode<NodeCls, DataCls>* m_prev = nullptr;
std::unique_lock<std::recursive_mutex> destructorLock() override
{ return std::unique_lock<std::recursive_mutex>{m_data->m_head.m_dataMutex}; }
explicit GraphicsDataNode(const ObjToken<DataCls>& data) explicit GraphicsDataNode(const ObjToken<DataCls>& data)
: m_data(data) : m_data(data)
{ {
IObj::m_mutex = &m_data->m_head.m_dataMutex;
std::lock_guard<std::recursive_mutex> lk(m_data->m_head.m_dataMutex); std::lock_guard<std::recursive_mutex> lk(m_data->m_head.m_dataMutex);
m_next = data->template getHead<NodeCls>(); m_next = data->template getHead<NodeCls>();
if (m_next) if (m_next)

View File

@ -9,6 +9,10 @@
#include <unordered_set> #include <unordered_set>
#include "xxhash.h" #include "xxhash.h"
#if _WIN32
#include "../win/WinCommon.hpp"
#endif
#include "logvisor/logvisor.hpp" #include "logvisor/logvisor.hpp"
#undef min #undef min
@ -1124,7 +1128,11 @@ struct GLCommandQueue : IGraphicsCommandQueue
static void RenderingWorker(GLCommandQueue* self) static void RenderingWorker(GLCommandQueue* self)
{ {
#if _WIN32
std::string thrName = WCSTMBS(APP->getFriendlyName().c_str()) + " GL Rendering Thread";
#else
std::string thrName = APP->getFriendlyName() + " GL Rendering Thread"; std::string thrName = APP->getFriendlyName() + " GL Rendering Thread";
#endif
logvisor::RegisterThreadName(thrName.c_str()); logvisor::RegisterThreadName(thrName.c_str());
{ {
std::unique_lock<std::mutex> lk(self->m_initmt); std::unique_lock<std::mutex> lk(self->m_initmt);

View File

@ -328,10 +328,11 @@ void VulkanContext::initVulkan(const char* appName)
m_deviceExtensionNames.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); m_deviceExtensionNames.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
#ifndef NDEBUG #ifndef NDEBUG
m_layerNames.push_back("VK_LAYER_LUNARG_core_validation"); m_layerNames.push_back("VK_LAYER_LUNARG_standard_validation");
//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_object_tracker");
m_layerNames.push_back("VK_LAYER_LUNARG_parameter_validation"); //m_layerNames.push_back("VK_LAYER_LUNARG_parameter_validation");
m_layerNames.push_back("VK_LAYER_GOOGLE_threading"); //m_layerNames.push_back("VK_LAYER_GOOGLE_threading");
#endif #endif
demo_check_layers(m_instanceLayerProperties, m_layerNames); demo_check_layers(m_instanceLayerProperties, m_layerNames);
@ -453,6 +454,17 @@ void VulkanContext::initDevice()
deviceInfo.pEnabledFeatures = nullptr; deviceInfo.pEnabledFeatures = nullptr;
ThrowIfFailed(vk::CreateDevice(m_gpus[0], &deviceInfo, nullptr, &m_dev)); ThrowIfFailed(vk::CreateDevice(m_gpus[0], &deviceInfo, nullptr, &m_dev));
std::string gpuName = m_gpuProps.deviceName;
Log.report(logvisor::Info, "Initialized %s", gpuName.c_str());
Log.report(logvisor::Info, "Vulkan version %d.%d.%d",
m_gpuProps.apiVersion >> 22,
(m_gpuProps.apiVersion >> 12) & 0b1111111111,
m_gpuProps.apiVersion & 0b111111111111);
Log.report(logvisor::Info, "Driver version %d.%d.%d",
m_gpuProps.driverVersion >> 22,
(m_gpuProps.driverVersion >> 12) & 0b1111111111,
m_gpuProps.driverVersion & 0b111111111111);
} }
void VulkanContext::initSwapChain(VulkanContext::Window& windowCtx, VkSurfaceKHR surface, VkFormat format, VkColorSpaceKHR colorspace) void VulkanContext::initSwapChain(VulkanContext::Window& windowCtx, VkSurfaceKHR surface, VkFormat format, VkColorSpaceKHR colorspace)
@ -821,10 +833,10 @@ public:
VkMemoryRequirements memReqs; VkMemoryRequirements memReqs;
vk::GetBufferMemoryRequirements(ctx->m_dev, m_bufferInfo.buffer, &memReqs); vk::GetBufferMemoryRequirements(ctx->m_dev, m_bufferInfo.buffer, &memReqs);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
m_memOffset = offset;
offset += m_sz;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1); offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
m_memOffset = offset;
offset += memReqs.size;
return offset; return offset;
} }
@ -898,10 +910,10 @@ public:
VkMemoryRequirements memReqs; VkMemoryRequirements memReqs;
vk::GetBufferMemoryRequirements(ctx->m_dev, m_bufferInfo[i].buffer, &memReqs); vk::GetBufferMemoryRequirements(ctx->m_dev, m_bufferInfo[i].buffer, &memReqs);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
m_memOffset[i] = offset;
offset += memReqs.size;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1); offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
m_memOffset[i] = offset;
offset += memReqs.size;
} }
return offset; return offset;
@ -1035,9 +1047,9 @@ public:
vk::GetImageMemoryRequirements(ctx->m_dev, m_gpuTex, &memReqs); vk::GetImageMemoryRequirements(ctx->m_dev, m_gpuTex, &memReqs);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
m_gpuOffset = offset; m_gpuOffset = offset;
offset += memReqs.size; offset += memReqs.size;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
return offset; return offset;
} }
@ -1232,9 +1244,9 @@ public:
vk::GetImageMemoryRequirements(ctx->m_dev, m_gpuTex, &memReqs); vk::GetImageMemoryRequirements(ctx->m_dev, m_gpuTex, &memReqs);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
m_gpuOffset = offset; m_gpuOffset = offset;
offset += memReqs.size; offset += memReqs.size;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
return offset; return offset;
} }
@ -1367,15 +1379,14 @@ class VulkanTextureD : public GraphicsDataNode<ITextureD>
uint32_t memTypeBits = ~0; uint32_t memTypeBits = ~0;
for (int i=0 ; i<2 ; ++i) for (int i=0 ; i<2 ; ++i)
{ {
m_cpuOffsets[i] = memAlloc.allocationSize;
/* create cpu buffer */ /* create cpu buffer */
ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufCreateInfo, nullptr, &m_cpuBuf[i])); ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufCreateInfo, nullptr, &m_cpuBuf[i]));
VkMemoryRequirements memReqs; VkMemoryRequirements memReqs;
vk::GetBufferMemoryRequirements(ctx->m_dev, m_cpuBuf[i], &memReqs); vk::GetBufferMemoryRequirements(ctx->m_dev, m_cpuBuf[i], &memReqs);
memAlloc.allocationSize += memReqs.size;
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1); memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
m_cpuOffsets[i] = memAlloc.allocationSize;
memAlloc.allocationSize += memReqs.size;
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
} }
@ -1439,9 +1450,9 @@ public:
vk::GetImageMemoryRequirements(ctx->m_dev, m_gpuTex[i], &memReqs); vk::GetImageMemoryRequirements(ctx->m_dev, m_gpuTex[i], &memReqs);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
m_gpuOffset[i] = offset; m_gpuOffset[i] = offset;
offset += memReqs.size; offset += memReqs.size;
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
} }
return offset; return offset;
@ -1523,7 +1534,7 @@ class VulkanTextureR : public GraphicsDataNode<ITextureR>
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_colorTex)); ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_colorTex));
/* depth target */ /* depth target */
texCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; texCreateInfo.format = VK_FORMAT_D32_SFLOAT;
texCreateInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; texCreateInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_depthTex)); ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_depthTex));
@ -1543,13 +1554,12 @@ class VulkanTextureR : public GraphicsDataNode<ITextureR>
vk::GetImageMemoryRequirements(ctx->m_dev, m_colorTex, &memReqs); vk::GetImageMemoryRequirements(ctx->m_dev, m_colorTex, &memReqs);
gpuOffsets[0] = memAlloc.allocationSize; gpuOffsets[0] = memAlloc.allocationSize;
memAlloc.allocationSize += memReqs.size; memAlloc.allocationSize += memReqs.size;
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
vk::GetImageMemoryRequirements(ctx->m_dev, m_depthTex, &memReqs); vk::GetImageMemoryRequirements(ctx->m_dev, m_depthTex, &memReqs);
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
gpuOffsets[1] = memAlloc.allocationSize; gpuOffsets[1] = memAlloc.allocationSize;
memAlloc.allocationSize += memReqs.size; memAlloc.allocationSize += memReqs.size;
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
texCreateInfo.samples = VkSampleCountFlagBits(1); texCreateInfo.samples = VkSampleCountFlagBits(1);
@ -1562,9 +1572,9 @@ class VulkanTextureR : public GraphicsDataNode<ITextureR>
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_colorBindTex[i])); ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_colorBindTex[i]));
vk::GetImageMemoryRequirements(ctx->m_dev, m_colorBindTex[i], &memReqs); vk::GetImageMemoryRequirements(ctx->m_dev, m_colorBindTex[i], &memReqs);
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
colorOffsets[i] = memAlloc.allocationSize; colorOffsets[i] = memAlloc.allocationSize;
memAlloc.allocationSize += memReqs.size; memAlloc.allocationSize += memReqs.size;
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
m_colorBindDescInfo[i].sampler = ctx->m_linearSamplers[int(m_clampMode)]; m_colorBindDescInfo[i].sampler = ctx->m_linearSamplers[int(m_clampMode)];
@ -1574,14 +1584,14 @@ class VulkanTextureR : public GraphicsDataNode<ITextureR>
for (size_t i=0 ; i<m_depthBindCount ; ++i) for (size_t i=0 ; i<m_depthBindCount ; ++i)
{ {
m_depthBindLayout[i] = VK_IMAGE_LAYOUT_UNDEFINED; m_depthBindLayout[i] = VK_IMAGE_LAYOUT_UNDEFINED;
texCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; texCreateInfo.format = VK_FORMAT_D32_SFLOAT;
texCreateInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; texCreateInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_depthBindTex[i])); ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_depthBindTex[i]));
vk::GetImageMemoryRequirements(ctx->m_dev, m_depthBindTex[i], &memReqs); vk::GetImageMemoryRequirements(ctx->m_dev, m_depthBindTex[i], &memReqs);
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
depthOffsets[i] = memAlloc.allocationSize; depthOffsets[i] = memAlloc.allocationSize;
memAlloc.allocationSize += memReqs.size; memAlloc.allocationSize += memReqs.size;
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
m_depthBindDescInfo[i].sampler = ctx->m_linearSamplers[int(m_clampMode)]; m_depthBindDescInfo[i].sampler = ctx->m_linearSamplers[int(m_clampMode)];
@ -1593,10 +1603,10 @@ class VulkanTextureR : public GraphicsDataNode<ITextureR>
/* allocate memory */ /* allocate memory */
ThrowIfFailed(vk::AllocateMemory(ctx->m_dev, &memAlloc, nullptr, &m_gpuMem)); ThrowIfFailed(vk::AllocateMemory(ctx->m_dev, &memAlloc, nullptr, &m_gpuMem));
uint8_t* mappedData; //uint8_t* mappedData;
ThrowIfFailed(vk::MapMemory(ctx->m_dev, m_gpuMem, 0, memAlloc.allocationSize, 0, reinterpret_cast<void**>(&mappedData))); //ThrowIfFailed(vk::MapMemory(ctx->m_dev, m_gpuMem, 0, memAlloc.allocationSize, 0, reinterpret_cast<void**>(&mappedData)));
memset(mappedData, 0, memAlloc.allocationSize); //memset(mappedData, 0, memAlloc.allocationSize);
vk::UnmapMemory(ctx->m_dev, m_gpuMem); //vk::UnmapMemory(ctx->m_dev, m_gpuMem);
/* bind memory */ /* bind memory */
ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_colorTex, m_gpuMem, gpuOffsets[0])); ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_colorTex, m_gpuMem, gpuOffsets[0]));
@ -1621,8 +1631,8 @@ class VulkanTextureR : public GraphicsDataNode<ITextureR>
ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_colorView)); ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_colorView));
viewCreateInfo.image = m_depthTex; viewCreateInfo.image = m_depthTex;
viewCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; viewCreateInfo.format = VK_FORMAT_D32_SFLOAT;
viewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; viewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_depthView)); ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_depthView));
for (size_t i=0 ; i<m_colorBindCount ; ++i) for (size_t i=0 ; i<m_colorBindCount ; ++i)
@ -1639,7 +1649,7 @@ class VulkanTextureR : public GraphicsDataNode<ITextureR>
{ {
ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_depthBindTex[i], m_gpuMem, depthOffsets[i])); ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_depthBindTex[i], m_gpuMem, depthOffsets[i]));
viewCreateInfo.image = m_depthBindTex[i]; viewCreateInfo.image = m_depthBindTex[i];
viewCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; viewCreateInfo.format = VK_FORMAT_D32_SFLOAT;
viewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; viewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_depthBindView[i])); ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_depthBindView[i]));
m_depthBindDescInfo[i].imageView = m_depthBindView[i]; m_depthBindDescInfo[i].imageView = m_depthBindView[i];
@ -2540,13 +2550,13 @@ struct VulkanCommandQueue : IGraphicsCommandQueue
VulkanTextureR* btarget = m_boundTarget.cast<VulkanTextureR>(); VulkanTextureR* btarget = m_boundTarget.cast<VulkanTextureR>();
SetImageLayout(cmdBuf, btarget->m_colorTex, VK_IMAGE_ASPECT_COLOR_BIT, SetImageLayout(cmdBuf, btarget->m_colorTex, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1, 1); VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1, 1);
SetImageLayout(cmdBuf, btarget->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, SetImageLayout(cmdBuf, btarget->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1, 1); VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1, 1);
} }
SetImageLayout(cmdBuf, ctarget->m_colorTex, VK_IMAGE_ASPECT_COLOR_BIT, SetImageLayout(cmdBuf, ctarget->m_colorTex, VK_IMAGE_ASPECT_COLOR_BIT,
ctarget->m_layout, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, 1); ctarget->m_layout, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, 1);
SetImageLayout(cmdBuf, ctarget->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, SetImageLayout(cmdBuf, ctarget->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT,
ctarget->m_layout, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1, 1); ctarget->m_layout, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1, 1);
ctarget->m_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; ctarget->m_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
@ -2624,7 +2634,7 @@ struct VulkanCommandQueue : IGraphicsCommandQueue
clr[0].clearValue.color.float32[2] = m_clearColor[2]; clr[0].clearValue.color.float32[2] = m_clearColor[2];
clr[0].clearValue.color.float32[3] = m_clearColor[3]; clr[0].clearValue.color.float32[3] = m_clearColor[3];
clr[0].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; clr[0].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
clr[1].aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; clr[1].aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clr[1].clearValue.depthStencil.depth = 1.f; clr[1].clearValue.depthStencil.depth = 1.f;
vk::CmdClearAttachments(m_cmdBufs[m_fillBuf], 2, clr, 1, &rect); vk::CmdClearAttachments(m_cmdBufs[m_fillBuf], 2, clr, 1, &rect);
} }
@ -2639,7 +2649,7 @@ struct VulkanCommandQueue : IGraphicsCommandQueue
} }
else if (depth) else if (depth)
{ {
clr[0].aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; clr[0].aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clr[0].clearValue.depthStencil.depth = 1.f; clr[0].clearValue.depthStencil.depth = 1.f;
vk::CmdClearAttachments(m_cmdBufs[m_fillBuf], 1, clr, 1, &rect); vk::CmdClearAttachments(m_cmdBufs[m_fillBuf], 1, clr, 1, &rect);
} }
@ -2797,14 +2807,14 @@ struct VulkanCommandQueue : IGraphicsCommandQueue
if (depth && ctexture->m_depthBindCount) if (depth && ctexture->m_depthBindCount)
{ {
if (ctexture == m_boundTarget.get()) if (ctexture == m_boundTarget.get())
SetImageLayout(cmdBuf, ctexture->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, SetImageLayout(cmdBuf, ctexture->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1, 1); VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1, 1);
SetImageLayout(cmdBuf, ctexture->m_depthBindTex[bindIdx], VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, SetImageLayout(cmdBuf, ctexture->m_depthBindTex[bindIdx], VK_IMAGE_ASPECT_DEPTH_BIT,
ctexture->m_depthBindLayout[bindIdx], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, 1); ctexture->m_depthBindLayout[bindIdx], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, 1);
copyInfo.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; copyInfo.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
copyInfo.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; copyInfo.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
vk::CmdCopyImage(cmdBuf, vk::CmdCopyImage(cmdBuf,
ctexture->m_depthTex, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, ctexture->m_depthTex, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
@ -2812,10 +2822,10 @@ struct VulkanCommandQueue : IGraphicsCommandQueue
1, &copyInfo); 1, &copyInfo);
if (ctexture == m_boundTarget.get()) if (ctexture == m_boundTarget.get())
SetImageLayout(cmdBuf, ctexture->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, SetImageLayout(cmdBuf, ctexture->m_depthTex, VK_IMAGE_ASPECT_DEPTH_BIT,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1, 1); VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1, 1);
SetImageLayout(cmdBuf, ctexture->m_depthBindTex[bindIdx], VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, SetImageLayout(cmdBuf, ctexture->m_depthBindTex[bindIdx], VK_IMAGE_ASPECT_DEPTH_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1, 1); VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1, 1);
ctexture->m_depthBindLayout[bindIdx] = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; ctexture->m_depthBindLayout[bindIdx] = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
@ -3075,7 +3085,7 @@ VulkanDataFactoryImpl::VulkanDataFactoryImpl(IGraphicsContext* parent,
VkAttachmentReference colorAttachmentRef = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}; VkAttachmentReference colorAttachmentRef = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
/* depth attachment */ /* depth attachment */
attachments[1].format = VK_FORMAT_D24_UNORM_S8_UINT; attachments[1].format = VK_FORMAT_D32_SFLOAT;
attachments[1].samples = VkSampleCountFlagBits(drawSamples); attachments[1].samples = VkSampleCountFlagBits(drawSamples);
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;

View File

@ -256,7 +256,8 @@ public:
int clientReturn = 0; int clientReturn = 0;
std::thread clientThread([&]() std::thread clientThread([&]()
{ {
logvisor::RegisterThreadName("Boo Client Thread"); std::string thrName = WCSTMBS(getFriendlyName().c_str()) + " Client Thread";
logvisor::RegisterThreadName(thrName.c_str());
clientReturn = m_callback.appMain(this); clientReturn = m_callback.appMain(this);
}); });

View File

@ -375,7 +375,8 @@ public:
int clientReturn = 0; int clientReturn = 0;
std::thread clientThread([&]() std::thread clientThread([&]()
{ {
logvisor::RegisterThreadName("Boo Client Thread"); std::string thrName = WCSTMBS(getFriendlyName().c_str()) + " Client Thread";
logvisor::RegisterThreadName(thrName.c_str());
CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE); CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
clientReturn = m_callback.appMain(this); clientReturn = m_callback.appMain(this);
PostThreadMessage(g_mainThreadId, WM_USER+1, 0, 0); PostThreadMessage(g_mainThreadId, WM_USER+1, 0, 0);
@ -485,7 +486,8 @@ int ApplicationRun(IApplication::EPlatformType platform,
const std::vector<SystemString>& args, const std::vector<SystemString>& args,
bool singleInstance) bool singleInstance)
{ {
logvisor::RegisterThreadName("Boo Main Thread"); std::string thrName = WCSTMBS(friendlyName.c_str()) + " Main Thread";
logvisor::RegisterThreadName(thrName.c_str());
if (APP) if (APP)
return 1; return 1;
if (platform != IApplication::EPlatformType::Win32 && if (platform != IApplication::EPlatformType::Win32 &&

View File

@ -93,4 +93,12 @@ struct Boo3DAppContext
} }
}; };
static inline std::string WCSTMBS(const wchar_t* wstr)
{
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr) - 1;
std::string strTo(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &strTo[0], sizeNeeded, nullptr, nullptr);
return strTo;
}
#endif // BOO_WINCOMMON_HPP #endif // BOO_WINCOMMON_HPP

View File

@ -503,10 +503,7 @@ public:
if (m_ctx->m_instance == VK_NULL_HANDLE) if (m_ctx->m_instance == VK_NULL_HANDLE)
{ {
const SystemString& appName = APP->getUniqueName(); const SystemString& appName = APP->getUniqueName();
int len = WideCharToMultiByte(CP_UTF8, 0, appName.c_str(), appName.size(), nullptr, 0, nullptr, nullptr); m_ctx->initVulkan(WCSTMBS(appName.c_str()).c_str());
std::string utf8(len, '\0');
WideCharToMultiByte(CP_UTF8, 0, appName.c_str(), appName.size(), &utf8[0], len, nullptr, nullptr);
m_ctx->initVulkan(utf8.c_str());
} }
vk::init_dispatch_table_middle(m_ctx->m_instance, false); vk::init_dispatch_table_middle(m_ctx->m_instance, false);