mirror of https://github.com/AxioDL/boo.git
Initial vulkan rendering within URDE
This commit is contained in:
parent
6504bfc8c8
commit
295d100ca3
|
@ -45,7 +45,7 @@ public:
|
||||||
virtual EGraphicsAPI getAPI() const=0;
|
virtual EGraphicsAPI getAPI() const=0;
|
||||||
virtual EPixelFormat getPixelFormat() const=0;
|
virtual EPixelFormat getPixelFormat() const=0;
|
||||||
virtual void setPixelFormat(EPixelFormat pf)=0;
|
virtual void setPixelFormat(EPixelFormat pf)=0;
|
||||||
virtual void initializeContext()=0;
|
virtual void initializeContext(void* handle)=0;
|
||||||
virtual void makeCurrent()=0;
|
virtual void makeCurrent()=0;
|
||||||
virtual void postInit()=0;
|
virtual void postInit()=0;
|
||||||
virtual void present()=0;
|
virtual void present()=0;
|
||||||
|
|
|
@ -654,12 +654,15 @@ class VulkanGraphicsBufferS : public IGraphicsBufferS
|
||||||
bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
bufInfo.flags = 0;
|
bufInfo.flags = 0;
|
||||||
ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufInfo, nullptr, &m_bufferInfo.buffer));
|
ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufInfo, nullptr, &m_bufferInfo.buffer));
|
||||||
|
m_bufferInfo.offset = 0;
|
||||||
|
m_bufferInfo.range = m_sz;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
size_t size() const {return m_sz;}
|
size_t size() const {return m_sz;}
|
||||||
size_t m_stride;
|
size_t m_stride;
|
||||||
size_t m_count;
|
size_t m_count;
|
||||||
VkDescriptorBufferInfo m_bufferInfo;
|
VkDescriptorBufferInfo m_bufferInfo;
|
||||||
|
VkDeviceSize m_memOffset;
|
||||||
bool m_uniform = false;
|
bool m_uniform = false;
|
||||||
~VulkanGraphicsBufferS()
|
~VulkanGraphicsBufferS()
|
||||||
{
|
{
|
||||||
|
@ -668,30 +671,29 @@ public:
|
||||||
|
|
||||||
VkDeviceSize sizeForGPU(VulkanContext* ctx, uint32_t& memTypeBits, VkDeviceSize offset)
|
VkDeviceSize sizeForGPU(VulkanContext* ctx, uint32_t& memTypeBits, VkDeviceSize offset)
|
||||||
{
|
{
|
||||||
if (m_uniform && ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment)
|
if (m_uniform)
|
||||||
{
|
{
|
||||||
offset = (offset +
|
size_t minOffset = std::max(VkDeviceSize(256),
|
||||||
ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment - 1) &
|
ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment);
|
||||||
~(ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment - 1);
|
offset = (offset + minOffset - 1) & ~(minOffset - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_bufferInfo.offset = offset;
|
m_memOffset = offset;
|
||||||
|
|
||||||
offset += m_sz;
|
offset += m_sz;
|
||||||
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
|
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
|
||||||
m_bufferInfo.range = offset - m_bufferInfo.offset;
|
|
||||||
|
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void placeForGPU(VulkanContext* ctx, VkDeviceMemory mem, uint8_t* buf)
|
void placeForGPU(VulkanContext* ctx, VkDeviceMemory mem, uint8_t* buf)
|
||||||
{
|
{
|
||||||
memmove(buf + m_bufferInfo.offset, m_stagingBuf.get(), m_sz);
|
memmove(buf + m_memOffset, m_stagingBuf.get(), m_sz);
|
||||||
m_stagingBuf.reset();
|
m_stagingBuf.reset();
|
||||||
ThrowIfFailed(vk::BindBufferMemory(ctx->m_dev, m_bufferInfo.buffer, mem, m_bufferInfo.offset));
|
ThrowIfFailed(vk::BindBufferMemory(ctx->m_dev, m_bufferInfo.buffer, mem, m_memOffset));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -718,6 +720,10 @@ class VulkanGraphicsBufferD : public IGraphicsBufferD
|
||||||
bufInfo.flags = 0;
|
bufInfo.flags = 0;
|
||||||
ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufInfo, nullptr, &m_bufferInfo[0].buffer));
|
ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufInfo, nullptr, &m_bufferInfo[0].buffer));
|
||||||
ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufInfo, nullptr, &m_bufferInfo[1].buffer));
|
ThrowIfFailed(vk::CreateBuffer(ctx->m_dev, &bufInfo, nullptr, &m_bufferInfo[1].buffer));
|
||||||
|
m_bufferInfo[0].offset = 0;
|
||||||
|
m_bufferInfo[0].range = m_cpuSz;
|
||||||
|
m_bufferInfo[1].offset = 0;
|
||||||
|
m_bufferInfo[1].range = m_cpuSz;
|
||||||
}
|
}
|
||||||
void update(int b);
|
void update(int b);
|
||||||
|
|
||||||
|
@ -725,6 +731,7 @@ public:
|
||||||
size_t m_stride;
|
size_t m_stride;
|
||||||
size_t m_count;
|
size_t m_count;
|
||||||
VkDeviceMemory m_mem;
|
VkDeviceMemory m_mem;
|
||||||
|
VkDeviceSize m_memOffset[2];
|
||||||
VkDescriptorBufferInfo m_bufferInfo[2];
|
VkDescriptorBufferInfo m_bufferInfo[2];
|
||||||
bool m_uniform = false;
|
bool m_uniform = false;
|
||||||
~VulkanGraphicsBufferD();
|
~VulkanGraphicsBufferD();
|
||||||
|
@ -736,21 +743,20 @@ public:
|
||||||
{
|
{
|
||||||
for (int i=0 ; i<2 ; ++i)
|
for (int i=0 ; i<2 ; ++i)
|
||||||
{
|
{
|
||||||
if (m_uniform && ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment)
|
if (m_uniform)
|
||||||
{
|
{
|
||||||
offset = (offset +
|
size_t minOffset = std::max(VkDeviceSize(256),
|
||||||
ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment - 1) &
|
ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment);
|
||||||
~(ctx->m_gpuProps.limits.minUniformBufferOffsetAlignment - 1);
|
offset = (offset + minOffset - 1) & ~(minOffset - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_bufferInfo[i].offset = offset;
|
m_memOffset[i] = offset;
|
||||||
|
|
||||||
offset += memReqs.size;
|
offset += memReqs.size;
|
||||||
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
|
offset = (offset + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
|
||||||
m_bufferInfo[i].range = offset - m_bufferInfo[i].offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return offset;
|
return offset;
|
||||||
|
@ -759,8 +765,8 @@ public:
|
||||||
void placeForGPU(VulkanContext* ctx, VkDeviceMemory mem)
|
void placeForGPU(VulkanContext* ctx, VkDeviceMemory mem)
|
||||||
{
|
{
|
||||||
m_mem = mem;
|
m_mem = mem;
|
||||||
ThrowIfFailed(vk::BindBufferMemory(ctx->m_dev, m_bufferInfo[0].buffer, mem, m_bufferInfo[0].offset));
|
ThrowIfFailed(vk::BindBufferMemory(ctx->m_dev, m_bufferInfo[0].buffer, mem, m_memOffset[0]));
|
||||||
ThrowIfFailed(vk::BindBufferMemory(ctx->m_dev, m_bufferInfo[1].buffer, mem, m_bufferInfo[1].offset));
|
ThrowIfFailed(vk::BindBufferMemory(ctx->m_dev, m_bufferInfo[1].buffer, mem, m_memOffset[1]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1647,6 +1653,7 @@ class VulkanShaderPipeline : public IShaderPipeline
|
||||||
{
|
{
|
||||||
friend class VulkanDataFactory;
|
friend class VulkanDataFactory;
|
||||||
VulkanContext* m_ctx;
|
VulkanContext* m_ctx;
|
||||||
|
VkPipelineCache m_pipelineCache;
|
||||||
VulkanShaderPipeline(VulkanContext* ctx,
|
VulkanShaderPipeline(VulkanContext* ctx,
|
||||||
VkShaderModule vert,
|
VkShaderModule vert,
|
||||||
VkShaderModule frag,
|
VkShaderModule frag,
|
||||||
|
@ -1654,7 +1661,7 @@ class VulkanShaderPipeline : public IShaderPipeline
|
||||||
const VulkanVertexFormat* vtxFmt,
|
const VulkanVertexFormat* vtxFmt,
|
||||||
BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
|
BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
|
||||||
bool depthTest, bool depthWrite, bool backfaceCulling)
|
bool depthTest, bool depthWrite, bool backfaceCulling)
|
||||||
: m_ctx(ctx)
|
: m_ctx(ctx), m_pipelineCache(pipelineCache)
|
||||||
{
|
{
|
||||||
VkDynamicState dynamicStateEnables[VK_DYNAMIC_STATE_RANGE_SIZE] = {};
|
VkDynamicState dynamicStateEnables[VK_DYNAMIC_STATE_RANGE_SIZE] = {};
|
||||||
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
||||||
|
@ -1770,6 +1777,7 @@ public:
|
||||||
~VulkanShaderPipeline()
|
~VulkanShaderPipeline()
|
||||||
{
|
{
|
||||||
vk::DestroyPipeline(m_ctx->m_dev, m_pipeline, nullptr);
|
vk::DestroyPipeline(m_ctx->m_dev, m_pipeline, nullptr);
|
||||||
|
vk::DestroyPipelineCache(m_ctx->m_dev, m_pipelineCache, nullptr);
|
||||||
}
|
}
|
||||||
VulkanShaderPipeline& operator=(const VulkanShaderPipeline&) = delete;
|
VulkanShaderPipeline& operator=(const VulkanShaderPipeline&) = delete;
|
||||||
VulkanShaderPipeline(const VulkanShaderPipeline&) = delete;
|
VulkanShaderPipeline(const VulkanShaderPipeline&) = delete;
|
||||||
|
@ -1869,7 +1877,7 @@ struct VulkanShaderDataBinding : IShaderDataBinding
|
||||||
IGraphicsBuffer* m_ibuf;
|
IGraphicsBuffer* m_ibuf;
|
||||||
size_t m_ubufCount;
|
size_t m_ubufCount;
|
||||||
std::unique_ptr<IGraphicsBuffer*[]> m_ubufs;
|
std::unique_ptr<IGraphicsBuffer*[]> m_ubufs;
|
||||||
std::vector<VkDescriptorBufferInfo> m_ubufOffs;
|
std::vector<std::array<VkDescriptorBufferInfo, 2>> m_ubufOffs;
|
||||||
size_t m_texCount;
|
size_t m_texCount;
|
||||||
std::unique_ptr<ITexture*[]> m_texs;
|
std::unique_ptr<ITexture*[]> m_texs;
|
||||||
|
|
||||||
|
@ -1911,7 +1919,9 @@ struct VulkanShaderDataBinding : IShaderDataBinding
|
||||||
if (ubufOffs[i] % 256)
|
if (ubufOffs[i] % 256)
|
||||||
Log.report(logvisor::Fatal, "non-256-byte-aligned uniform-offset %d provided to newShaderDataBinding", int(i));
|
Log.report(logvisor::Fatal, "non-256-byte-aligned uniform-offset %d provided to newShaderDataBinding", int(i));
|
||||||
#endif
|
#endif
|
||||||
m_ubufOffs.push_back({VK_NULL_HANDLE, ubufOffs[i], (ubufSizes[i] + 255) & ~255});
|
std::array<VkDescriptorBufferInfo, 2> fillArr;
|
||||||
|
fillArr.fill({VK_NULL_HANDLE, ubufOffs[i], (ubufSizes[i] + 255) & ~255});
|
||||||
|
m_ubufOffs.push_back(fillArr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (size_t i=0 ; i<ubufCount ; ++i)
|
for (size_t i=0 ; i<ubufCount ; ++i)
|
||||||
|
@ -2004,7 +2014,7 @@ struct VulkanShaderDataBinding : IShaderDataBinding
|
||||||
writes[totalWrites].descriptorCount = 1;
|
writes[totalWrites].descriptorCount = 1;
|
||||||
writes[totalWrites].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
writes[totalWrites].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
const VkDescriptorBufferInfo* origInfo = GetBufferGPUResource(m_ubufs[i], b);
|
const VkDescriptorBufferInfo* origInfo = GetBufferGPUResource(m_ubufs[i], b);
|
||||||
VkDescriptorBufferInfo& modInfo = m_ubufOffs[i];
|
VkDescriptorBufferInfo& modInfo = m_ubufOffs[i][b];
|
||||||
modInfo.buffer = origInfo->buffer;
|
modInfo.buffer = origInfo->buffer;
|
||||||
modInfo.offset += origInfo->offset;
|
modInfo.offset += origInfo->offset;
|
||||||
writes[totalWrites].pBufferInfo = &modInfo;
|
writes[totalWrites].pBufferInfo = &modInfo;
|
||||||
|
@ -2614,7 +2624,7 @@ void VulkanGraphicsBufferD::update(int b)
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
ThrowIfFailed(vk::MapMemory(m_q->m_ctx->m_dev, m_mem,
|
ThrowIfFailed(vk::MapMemory(m_q->m_ctx->m_dev, m_mem,
|
||||||
m_bufferInfo[b].offset, m_bufferInfo[b].range, 0, &ptr));
|
m_memOffset[b], m_cpuSz, 0, &ptr));
|
||||||
memmove(ptr, m_cpuBuf.get(), m_cpuSz);
|
memmove(ptr, m_cpuBuf.get(), m_cpuSz);
|
||||||
vk::UnmapMemory(m_q->m_ctx->m_dev, m_mem);
|
vk::UnmapMemory(m_q->m_ctx->m_dev, m_mem);
|
||||||
m_validSlots |= slot;
|
m_validSlots |= slot;
|
||||||
|
@ -2886,8 +2896,6 @@ IShaderPipeline* VulkanDataFactory::Context::newShaderPipeline
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::DestroyPipelineCache(m_parent.m_ctx->m_dev, pipelineCache, nullptr);
|
|
||||||
|
|
||||||
vk::DestroyShaderModule(m_parent.m_ctx->m_dev, fragModule, nullptr);
|
vk::DestroyShaderModule(m_parent.m_ctx->m_dev, fragModule, nullptr);
|
||||||
vk::DestroyShaderModule(m_parent.m_ctx->m_dev, vertModule, nullptr);
|
vk::DestroyShaderModule(m_parent.m_ctx->m_dev, vertModule, nullptr);
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ public:
|
||||||
m_pf = pf;
|
m_pf = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeContext()
|
void initializeContext(void*)
|
||||||
{
|
{
|
||||||
m_nsContext = [[GraphicsContextCocoaGLInternal alloc] initWithBooContext:this];
|
m_nsContext = [[GraphicsContextCocoaGLInternal alloc] initWithBooContext:this];
|
||||||
if (!m_nsContext)
|
if (!m_nsContext)
|
||||||
|
@ -375,7 +375,7 @@ public:
|
||||||
m_pf = pf;
|
m_pf = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeContext()
|
void initializeContext(void*)
|
||||||
{
|
{
|
||||||
MetalContext::Window& w = m_metalCtx->m_windows[m_parentWindow];
|
MetalContext::Window& w = m_metalCtx->m_windows[m_parentWindow];
|
||||||
m_nsContext = [[GraphicsContextCocoaMetalInternal alloc] initWithBooContext:this];
|
m_nsContext = [[GraphicsContextCocoaMetalInternal alloc] initWithBooContext:this];
|
||||||
|
@ -1246,7 +1246,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
m_gfxCtx = static_cast<GraphicsContextCocoa*>(_GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI::OpenGL3_3,
|
m_gfxCtx = static_cast<GraphicsContextCocoa*>(_GraphicsContextCocoaGLNew(IGraphicsContext::EGraphicsAPI::OpenGL3_3,
|
||||||
this, lastGLCtx, sampleCount));
|
this, lastGLCtx, sampleCount));
|
||||||
m_gfxCtx->initializeContext();
|
m_gfxCtx->initializeContext(nullptr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ public:
|
||||||
m_pf = pf;
|
m_pf = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeContext() {}
|
void initializeContext(void*) {}
|
||||||
|
|
||||||
void makeCurrent() {}
|
void makeCurrent() {}
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ public:
|
||||||
m_pf = pf;
|
m_pf = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeContext() {}
|
void initializeContext(void*) {}
|
||||||
|
|
||||||
void makeCurrent()
|
void makeCurrent()
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,8 @@ DBusConnection* RegisterDBus(const char* appName, bool& isFirst);
|
||||||
|
|
||||||
#if BOO_HAS_VULKAN
|
#if BOO_HAS_VULKAN
|
||||||
#include <X11/Xlib-xcb.h>
|
#include <X11/Xlib-xcb.h>
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace boo
|
namespace boo
|
||||||
|
@ -115,7 +117,7 @@ static Window GetWindowOfEvent(XEvent* event, bool& windowEvent)
|
||||||
IWindow* _WindowXlibNew(const std::string& title,
|
IWindow* _WindowXlibNew(const std::string& title,
|
||||||
Display* display, void* xcbConn,
|
Display* display, void* xcbConn,
|
||||||
int defaultScreen, XIM xIM, XIMStyle bestInputStyle, XFontSet fontset,
|
int defaultScreen, XIM xIM, XIMStyle bestInputStyle, XFontSet fontset,
|
||||||
GLXContext lastCtx, bool useVulkan, uint32_t drawSamples);
|
GLXContext lastCtx, void* vulkanHandle, uint32_t drawSamples);
|
||||||
|
|
||||||
static XIMStyle ChooseBetterStyle(XIMStyle style1, XIMStyle style2)
|
static XIMStyle ChooseBetterStyle(XIMStyle style1, XIMStyle style2)
|
||||||
{
|
{
|
||||||
|
@ -177,8 +179,37 @@ class ApplicationXlib final : public IApplication
|
||||||
|
|
||||||
#if BOO_HAS_VULKAN
|
#if BOO_HAS_VULKAN
|
||||||
/* Vulkan enable */
|
/* Vulkan enable */
|
||||||
bool m_useVulkan = true;
|
|
||||||
xcb_connection_t* m_xcbConn;
|
xcb_connection_t* m_xcbConn;
|
||||||
|
|
||||||
|
void* m_vkHandle = nullptr;
|
||||||
|
PFN_vkGetInstanceProcAddr m_getVkProc = 0;
|
||||||
|
bool loadVk()
|
||||||
|
{
|
||||||
|
const char filename[] = "libvulkan.so";
|
||||||
|
void *handle, *symbol;
|
||||||
|
|
||||||
|
#ifdef UNINSTALLED_LOADER
|
||||||
|
handle = dlopen(UNINSTALLED_LOADER, RTLD_LAZY);
|
||||||
|
if (!handle)
|
||||||
|
handle = dlopen(filename, RTLD_LAZY);
|
||||||
|
#else
|
||||||
|
handle = dlopen(filename, RTLD_LAZY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (handle)
|
||||||
|
symbol = dlsym(handle, "vkGetInstanceProcAddr");
|
||||||
|
|
||||||
|
if (!handle || !symbol) {
|
||||||
|
|
||||||
|
if (handle)
|
||||||
|
dlclose(handle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_vkHandle = handle;
|
||||||
|
m_getVkProc = reinterpret_cast<PFN_vkGetInstanceProcAddr>(symbol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void _deletedWindow(IWindow* window)
|
void _deletedWindow(IWindow* window)
|
||||||
|
@ -200,6 +231,29 @@ public:
|
||||||
m_args(args),
|
m_args(args),
|
||||||
m_singleInstance(singleInstance)
|
m_singleInstance(singleInstance)
|
||||||
{
|
{
|
||||||
|
#if BOO_HAS_VULKAN
|
||||||
|
/* Check for Vulkan presence and preference */
|
||||||
|
bool hasVk = loadVk();
|
||||||
|
if (hasVk)
|
||||||
|
{
|
||||||
|
for (const std::string& arg : args)
|
||||||
|
{
|
||||||
|
if (!arg.compare("--gl"))
|
||||||
|
{
|
||||||
|
dlclose(m_vkHandle);
|
||||||
|
m_vkHandle = nullptr;
|
||||||
|
m_getVkProc = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_getVkProc)
|
||||||
|
Log.report(logvisor::Info, "using Vulkan renderer");
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
Log.report(logvisor::Info, "using OpenGL renderer");
|
||||||
|
|
||||||
/* DBus single instance registration */
|
/* DBus single instance registration */
|
||||||
bool isFirst;
|
bool isFirst;
|
||||||
m_dbus = RegisterDBus(uniqueName.c_str(), isFirst);
|
m_dbus = RegisterDBus(uniqueName.c_str(), isFirst);
|
||||||
|
@ -477,10 +531,10 @@ public:
|
||||||
{
|
{
|
||||||
#if BOO_HAS_VULKAN
|
#if BOO_HAS_VULKAN
|
||||||
IWindow* newWindow = _WindowXlibNew(title, m_xDisp, m_xcbConn, m_xDefaultScreen, m_xIM,
|
IWindow* newWindow = _WindowXlibNew(title, m_xDisp, m_xcbConn, m_xDefaultScreen, m_xIM,
|
||||||
m_bestStyle, m_fontset, m_lastGlxCtx, m_useVulkan, drawSamples);
|
m_bestStyle, m_fontset, m_lastGlxCtx, (void*)m_getVkProc, drawSamples);
|
||||||
#else
|
#else
|
||||||
IWindow* newWindow = _WindowXlibNew(title, m_xDisp, nullptr, m_xDefaultScreen, m_xIM,
|
IWindow* newWindow = _WindowXlibNew(title, m_xDisp, nullptr, m_xDefaultScreen, m_xIM,
|
||||||
m_bestStyle, m_fontset, m_lastGlxCtx, false, drawSamples);
|
m_bestStyle, m_fontset, m_lastGlxCtx, nullptr, drawSamples);
|
||||||
#endif
|
#endif
|
||||||
m_windows[(Window)newWindow->getPlatformHandle()] = newWindow;
|
m_windows[(Window)newWindow->getPlatformHandle()] = newWindow;
|
||||||
return newWindow;
|
return newWindow;
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
m_pf = pf;
|
m_pf = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeContext()
|
void initializeContext(void*)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -440,7 +439,7 @@ public:
|
||||||
m_pf = pf;
|
m_pf = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeContext()
|
void initializeContext(void*)
|
||||||
{
|
{
|
||||||
if (!glXCreateContextAttribsARB)
|
if (!glXCreateContextAttribsARB)
|
||||||
{
|
{
|
||||||
|
@ -729,36 +728,7 @@ public:
|
||||||
m_pf = pf;
|
m_pf = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* m_vkHandle;
|
void initializeContext(void* getVkProc)
|
||||||
static PFN_vkGetInstanceProcAddr loadVk()
|
|
||||||
{
|
|
||||||
const char filename[] = "libvulkan.so";
|
|
||||||
void *handle, *symbol;
|
|
||||||
|
|
||||||
#ifdef UNINSTALLED_LOADER
|
|
||||||
handle = dlopen(UNINSTALLED_LOADER, RTLD_LAZY);
|
|
||||||
if (!handle)
|
|
||||||
handle = dlopen(filename, RTLD_LAZY);
|
|
||||||
#else
|
|
||||||
handle = dlopen(filename, RTLD_LAZY);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (handle)
|
|
||||||
symbol = dlsym(handle, "vkGetInstanceProcAddr");
|
|
||||||
|
|
||||||
if (!handle || !symbol) {
|
|
||||||
Log.report(logvisor::Fatal, "unable to load vulkan: %s", dlerror());
|
|
||||||
|
|
||||||
if (handle)
|
|
||||||
dlclose(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_vkHandle = handle;
|
|
||||||
|
|
||||||
return reinterpret_cast<PFN_vkGetInstanceProcAddr>(symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeContext()
|
|
||||||
{
|
{
|
||||||
if (!glXWaitVideoSyncSGI)
|
if (!glXWaitVideoSyncSGI)
|
||||||
{
|
{
|
||||||
|
@ -768,7 +738,7 @@ public:
|
||||||
Log.report(logvisor::Fatal, "unable to resolve glXWaitVideoSyncSGI");
|
Log.report(logvisor::Fatal, "unable to resolve glXWaitVideoSyncSGI");
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::init_dispatch_table_top(loadVk());
|
vk::init_dispatch_table_top(PFN_vkGetInstanceProcAddr(getVkProc));
|
||||||
if (m_ctx->m_instance == VK_NULL_HANDLE)
|
if (m_ctx->m_instance == VK_NULL_HANDLE)
|
||||||
m_ctx->initVulkan(APP->getUniqueName().c_str());
|
m_ctx->initVulkan(APP->getUniqueName().c_str());
|
||||||
|
|
||||||
|
@ -928,7 +898,6 @@ public:
|
||||||
void present() {}
|
void present() {}
|
||||||
|
|
||||||
};
|
};
|
||||||
void* GraphicsContextXlibVulkan::m_vkHandle = nullptr;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class WindowXlib : public IWindow
|
class WindowXlib : public IWindow
|
||||||
|
@ -992,7 +961,7 @@ public:
|
||||||
WindowXlib(const std::string& title,
|
WindowXlib(const std::string& title,
|
||||||
Display* display, void* xcbConn,
|
Display* display, void* xcbConn,
|
||||||
int defaultScreen, XIM xIM, XIMStyle bestInputStyle, XFontSet fontset,
|
int defaultScreen, XIM xIM, XIMStyle bestInputStyle, XFontSet fontset,
|
||||||
GLXContext lastCtx, bool useVulkan, uint32_t drawSamples)
|
GLXContext lastCtx, void* vulkanHandle, uint32_t drawSamples)
|
||||||
: m_xDisp(display), m_callback(nullptr),
|
: m_xDisp(display), m_callback(nullptr),
|
||||||
m_bestStyle(bestInputStyle)
|
m_bestStyle(bestInputStyle)
|
||||||
{
|
{
|
||||||
|
@ -1000,7 +969,7 @@ public:
|
||||||
S_ATOMS = new XlibAtoms(display);
|
S_ATOMS = new XlibAtoms(display);
|
||||||
|
|
||||||
#if BOO_HAS_VULKAN
|
#if BOO_HAS_VULKAN
|
||||||
if (useVulkan)
|
if (vulkanHandle)
|
||||||
m_gfxCtx.reset(new GraphicsContextXlibVulkan(this, display, (xcb_connection_t*)xcbConn, defaultScreen,
|
m_gfxCtx.reset(new GraphicsContextXlibVulkan(this, display, (xcb_connection_t*)xcbConn, defaultScreen,
|
||||||
&g_VulkanContext, m_visualId, drawSamples));
|
&g_VulkanContext, m_visualId, drawSamples));
|
||||||
else
|
else
|
||||||
|
@ -1100,7 +1069,7 @@ public:
|
||||||
setCursor(EMouseCursor::Pointer);
|
setCursor(EMouseCursor::Pointer);
|
||||||
XFlush(m_xDisp);
|
XFlush(m_xDisp);
|
||||||
|
|
||||||
m_gfxCtx->initializeContext();
|
m_gfxCtx->initializeContext(vulkanHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
~WindowXlib()
|
~WindowXlib()
|
||||||
|
@ -2029,11 +1998,11 @@ public:
|
||||||
IWindow* _WindowXlibNew(const std::string& title,
|
IWindow* _WindowXlibNew(const std::string& title,
|
||||||
Display* display, void* xcbConn,
|
Display* display, void* xcbConn,
|
||||||
int defaultScreen, XIM xIM, XIMStyle bestInputStyle, XFontSet fontset,
|
int defaultScreen, XIM xIM, XIMStyle bestInputStyle, XFontSet fontset,
|
||||||
GLXContext lastCtx, bool useVulkan, uint32_t drawSamples)
|
GLXContext lastCtx, void* vulkanHandle, uint32_t drawSamples)
|
||||||
{
|
{
|
||||||
XLockDisplay(display);
|
XLockDisplay(display);
|
||||||
IWindow* ret = new WindowXlib(title, display, xcbConn, defaultScreen, xIM,
|
IWindow* ret = new WindowXlib(title, display, xcbConn, defaultScreen, xIM,
|
||||||
bestInputStyle, fontset, lastCtx, useVulkan, drawSamples);
|
bestInputStyle, fontset, lastCtx, vulkanHandle, drawSamples);
|
||||||
XUnlockDisplay(display);
|
XUnlockDisplay(display);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue