Major Vulkan commit

This commit is contained in:
Jack Andersen 2016-02-20 20:27:54 -10:00
parent 8bfb883d59
commit 1037b37f9a
13 changed files with 2581 additions and 98 deletions

View File

@ -16,7 +16,6 @@ include_directories(include ${LOG_VISOR_INCLUDE_DIR})
if(NOT GEKKO AND NOT CAFE)
list(APPEND PLAT_SRCS
lib/graphicsdev/GL.cpp
lib/graphicsdev/Vulkan.cpp
lib/graphicsdev/glew.c)
list(APPEND PLAT_HDRS
@ -81,7 +80,6 @@ else(NOT GEKKO)
lib/graphicsdev/GLX.cpp
lib/graphicsdev/glew.c
lib/audiodev/ALSA.cpp)
# list(APPEND PLAT_HDRS )
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
@ -127,6 +125,14 @@ else(NOT GEKKO)
include_directories(${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR})
list(APPEND _BOO_SYS_LIBS X11 Xi GL ${DBUS_LIBRARY} pthread)
find_library(VULKAN_LIBRARY vulkan)
if(NOT VULKAN_LIBRARY-NOTFOUND)
message(STATUS "Vulkan loader found; enabling Vulkan support")
list(APPEND _BOO_SYS_LIBS ${VULKAN_LIBRARY})
list(APPEND PLAT_SRCS
lib/graphicsdev/Vulkan.cpp)
endif()
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
list(APPEND PLAT_SRCS
lib/inputdev/HIDListenerUdev.cpp

View File

@ -29,14 +29,13 @@ public:
const SystemChar* platformName() const {return _S("OGL");}
IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count);
IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count);
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz);
GraphicsDataToken
newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz, ITextureS** texOut);
const void* data, size_t sz, ITextureS*& texOut);
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void* data, size_t sz);
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);

View File

@ -7,11 +7,6 @@
namespace boo
{
enum class Primitive
{
Triangles,
TriStrips
};
struct IGraphicsCommandQueue
{
@ -32,7 +27,6 @@ struct IGraphicsCommandQueue
virtual void setClearColor(const float rgba[4])=0;
virtual void clearTarget(bool render=true, bool depth=true)=0;
virtual void setDrawPrimitive(Primitive prim)=0;
virtual void draw(size_t start, size_t count)=0;
virtual void drawIndexed(size_t start, size_t count)=0;
virtual void drawInstances(size_t start, size_t count, size_t instCount)=0;

View File

@ -193,8 +193,6 @@ struct IGraphicsDataFactory
virtual IGraphicsBufferS*
newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)=0;
virtual IGraphicsBufferS*
newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count)=0;
virtual IGraphicsBufferD*
newDynamicBuffer(BufferUse use, size_t stride, size_t count)=0;
@ -203,7 +201,7 @@ struct IGraphicsDataFactory
const void* data, size_t sz)=0;
virtual GraphicsDataToken
newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz, ITextureS** texOut)=0;
const void* data, size_t sz, ITextureS*& texOut)=0;
virtual ITextureSA*
newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void* data, size_t sz)=0;
@ -263,6 +261,7 @@ class GraphicsDataToken
friend class D3D12DataFactory;
friend class D3D11DataFactory;
friend class MetalDataFactory;
friend class VulkanDataFactory;
IGraphicsDataFactory* m_factory = nullptr;
IGraphicsData* m_data = nullptr;
GraphicsDataToken(IGraphicsDataFactory* factory, IGraphicsData* data)

View File

@ -38,7 +38,6 @@ public:
const char* platformName() const {return "Metal";}
IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count);
IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count);
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,

View File

@ -6,36 +6,68 @@
#include "boo/IGraphicsContext.hpp"
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <mutex>
#include <vulkan/vulkan.h>
namespace boo
{
struct VulkanContext
{
VkInstance m_instance;
VkPhysicalDevice m_adapter;
VkPhysicalDeviceProperties m_devProps;
VkPhysicalDeviceMemoryProperties m_memoryProperties;
VkDevice m_dev;
VkQueue m_queue;
VkDescriptorSetLayout m_descSetLayout;
VkPipelineLayout m_layout;
VkRenderPass m_pass;
VkCommandPool m_loadPool;
VkCommandBuffer m_loadCmdBuf;
VkFence m_loadFence;
VkSampler m_linearSampler;
struct Window
{
VkSwapchainKHR m_swapChain;
struct Buffer
{
VkImage m_image;
VkImageView m_view;
};
std::vector<Buffer> m_bufs;
uint32_t m_backBuf = 0;
size_t width, height;
};
std::unordered_map<const boo::IWindow*, Window> m_windows;
};
class VulkanDataFactory : public IGraphicsDataFactory
{
friend struct VulkanCommandQueue;
IGraphicsContext* m_parent;
static ThreadLocalPtr<struct GLData> m_deferredData;
std::unordered_set<struct GLData*> m_committedData;
VulkanContext* m_ctx;
static ThreadLocalPtr<struct VulkanData> m_deferredData;
std::unordered_set<struct VulkanData*> m_committedData;
std::mutex m_committedMutex;
std::vector<int> m_texUnis;
void destroyData(IGraphicsData*);
void destroyAllData();
public:
VulkanDataFactory(IGraphicsContext* parent);
VulkanDataFactory(IGraphicsContext* parent, VulkanContext* ctx);
~VulkanDataFactory() {destroyAllData();}
Platform platform() const {return Platform::Vulkan;}
const SystemChar* platformName() const {return _S("Vulkan");}
IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count);
IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count);
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
std::unique_ptr<uint8_t[]>&& data, size_t sz);
GraphicsDataToken newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void *data, size_t sz, ITextureS*& texOut);
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void* data, size_t sz);
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);
@ -46,24 +78,19 @@ public:
IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource,
std::vector<unsigned int>& vertBlobOut, std::vector<unsigned int>& fragBlobOut,
std::vector<unsigned int>& pipelineBlob,
size_t texCount, const char* texArrayName,
size_t uniformBlockCount, const char** uniformBlockNames,
std::vector<unsigned char>& pipelineBlob, IVertexFormat* vtxFmt,
BlendFactor srcFac, BlendFactor dstFac,
bool depthTest, bool depthWrite, bool backfaceCulling);
IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource,
size_t texCount, const char* texArrayName,
size_t uniformBlockCount, const char** uniformBlockNames,
IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource, IVertexFormat* vtxFmt,
BlendFactor srcFac, BlendFactor dstFac,
bool depthTest, bool depthWrite, bool backfaceCulling)
{
std::vector<unsigned int> vertBlob;
std::vector<unsigned int> fragBlob;
std::vector<unsigned int> pipelineBlob;
std::vector<unsigned char> pipelineBlob;
return newShaderPipeline(vertSource, fragSource, vertBlob, fragBlob, pipelineBlob,
texCount, texArrayName, uniformBlockCount, uniformBlockNames,
srcFac, dstFac, depthTest, depthWrite, backfaceCulling);
vtxFmt, srcFac, dstFac, depthTest, depthWrite, backfaceCulling);
}
IShaderDataBinding*

View File

@ -1013,16 +1013,6 @@ public:
return retval;
}
IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count)
{
std::unique_ptr<uint8_t[]> d = std::move(data);
D3D11GraphicsBufferS* retval = new D3D11GraphicsBufferS(use, m_ctx, d.get(), stride, count);
if (!m_deferredData)
m_deferredData = new struct D3D11Data();
static_cast<D3D11Data*>(m_deferredData)->m_SBufs.emplace_back(retval);
return retval;
}
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count)
{
D3D11CommandQueue* q = static_cast<D3D11CommandQueue*>(m_parent->getCommandQueue());

View File

@ -1369,16 +1369,6 @@ public:
return retval;
}
IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count)
{
std::unique_ptr<uint8_t[]> d = std::move(data);
D3D12GraphicsBufferS* retval = new D3D12GraphicsBufferS(use, m_ctx, d.get(), stride, count);
if (!m_deferredData)
m_deferredData = new struct D3D12Data();
static_cast<D3D12Data*>(m_deferredData)->m_SBufs.emplace_back(retval);
return retval;
}
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count)
{
D3D12CommandQueue* q = static_cast<D3D12CommandQueue*>(m_parent->getCommandQueue());

View File

@ -104,17 +104,6 @@ GLDataFactory::newStaticBuffer(BufferUse use, const void* data, size_t stride, s
return retval;
}
IGraphicsBufferS*
GLDataFactory::newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count)
{
std::unique_ptr<uint8_t[]> d = std::move(data);
GLGraphicsBufferS* retval = new GLGraphicsBufferS(use, d.get(), stride * count);
if (!m_deferredData.get())
m_deferredData.reset(new struct GLData());
m_deferredData->m_SBufs.emplace_back(retval);
return retval;
}
class GLTextureS : public ITextureS
{
friend class GLDataFactory;
@ -294,12 +283,12 @@ GLDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, Textur
GraphicsDataToken
GLDataFactory::newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz, ITextureS** texOut)
const void* data, size_t sz, ITextureS*& texOut)
{
GLTextureS* retval = new GLTextureS(width, height, mips, fmt, data, sz);
GLData* tokData = new struct GLData();
tokData->m_STexs.emplace_back(retval);
*texOut = retval;
texOut = retval;
std::unique_lock<std::mutex> lk(m_committedMutex);
m_committedData.insert(tokData);
@ -728,7 +717,6 @@ struct GLCommandQueue : IGraphicsCommandQueue
SetScissor,
SetClearColor,
ClearTarget,
SetDrawPrimitive,
Draw,
DrawIndexed,
DrawInstances,
@ -743,7 +731,6 @@ struct GLCommandQueue : IGraphicsCommandQueue
SWindowRect rect;
float rgba[4];
GLbitfield flags;
GLenum prim;
struct
{
size_t start;
@ -911,7 +898,6 @@ struct GLCommandQueue : IGraphicsCommandQueue
posts.swap(self->m_pendingPosts2);
}
std::vector<Command>& cmds = self->m_cmdBufs[self->m_drawBuf];
GLenum prim = GL_TRIANGLES;
for (const Command& cmd : cmds)
{
switch (cmd.m_op)
@ -948,20 +934,17 @@ struct GLCommandQueue : IGraphicsCommandQueue
case Command::Op::ClearTarget:
glClear(cmd.flags);
break;
case Command::Op::SetDrawPrimitive:
prim = cmd.prim;
break;
case Command::Op::Draw:
glDrawArrays(prim, cmd.start, cmd.count);
glDrawArrays(GL_TRIANGLE_STRIP, cmd.start, cmd.count);
break;
case Command::Op::DrawIndexed:
glDrawElements(prim, cmd.count, GL_UNSIGNED_INT, (void*)cmd.start);
glDrawElements(GL_TRIANGLE_STRIP, cmd.count, GL_UNSIGNED_INT, (void*)cmd.start);
break;
case Command::Op::DrawInstances:
glDrawArraysInstanced(prim, cmd.start, cmd.count, cmd.instCount);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, cmd.start, cmd.count, cmd.instCount);
break;
case Command::Op::DrawInstancesIndexed:
glDrawElementsInstanced(prim, cmd.count, GL_UNSIGNED_INT, (void*)cmd.start, cmd.instCount);
glDrawElementsInstanced(GL_TRIANGLE_STRIP, cmd.count, GL_UNSIGNED_INT, (void*)cmd.start, cmd.instCount);
break;
case Command::Op::Present:
{
@ -1067,16 +1050,6 @@ struct GLCommandQueue : IGraphicsCommandQueue
cmds.back().flags |= GL_DEPTH_BUFFER_BIT;
}
void setDrawPrimitive(Primitive prim)
{
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];
cmds.emplace_back(Command::Op::SetDrawPrimitive);
if (prim == Primitive::Triangles)
cmds.back().prim = GL_TRIANGLES;
else if (prim == Primitive::TriStrips)
cmds.back().prim = GL_TRIANGLE_STRIP;
}
void draw(size_t start, size_t count)
{
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];

View File

@ -850,15 +850,6 @@ IGraphicsBufferS* MetalDataFactory::newStaticBuffer(BufferUse use, const void* d
m_deferredData->m_SBufs.emplace_back(retval);
return retval;
}
IGraphicsBufferS* MetalDataFactory::newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count)
{
std::unique_ptr<uint8_t[]> d = std::move(data);
MetalGraphicsBufferS* retval = new MetalGraphicsBufferS(use, m_ctx, d.get(), stride, count);
if (!m_deferredData.get())
m_deferredData.reset(new struct MetalData());
m_deferredData->m_SBufs.emplace_back(retval);
return retval;
}
IGraphicsBufferD* MetalDataFactory::newDynamicBuffer(BufferUse use, size_t stride, size_t count)
{
MetalCommandQueue* q = static_cast<MetalCommandQueue*>(m_parent->getCommandQueue());

File diff suppressed because it is too large Load Diff

View File

@ -461,7 +461,7 @@ public:
XLockDisplay(vsyncDisp);
static int attributeList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, 0 };
XVisualInfo *vi = glXChooseVisual(vsyncDisp, DefaultScreen(vsyncDisp),attributeList);
XVisualInfo *vi = glXChooseVisual(vsyncDisp, DefaultScreen(vsyncDisp), attributeList);
vsyncCtx = glXCreateContext(vsyncDisp, vi, nullptr, True);
if (!vsyncCtx)

View File

@ -441,7 +441,6 @@ struct TestApplicationCallback : IApplicationCallback
float rgba[] = {sinf(frameIdx / 60.0), cosf(frameIdx / 60.0), 0.0, 1.0};
gfxQ->setClearColor(rgba);
gfxQ->clearTarget();
gfxQ->setDrawPrimitive(Primitive::TriStrips);
gfxQ->setShaderDataBinding(m_binding);
gfxQ->draw(0, 4);