mirror of https://github.com/AxioDL/boo.git
Preliminary Vulkan shader pipeline factory
This commit is contained in:
parent
a79f55c5c1
commit
5a2fb0768b
|
@ -16,10 +16,12 @@ 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
|
||||
include/boo/graphicsdev/GL.hpp)
|
||||
include/boo/graphicsdev/GL.hpp
|
||||
include/boo/graphicsdev/Vulkan.hpp)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
|
@ -139,7 +141,7 @@ set(BOO_SYS_LIBS ${_BOO_SYS_LIBS} CACHE PATH "Boo System Libraries" FORCE)
|
|||
set(BOO_SYS_DEFINES ${_BOO_SYS_DEFINES} CACHE PATH "Boo System Defines" FORCE)
|
||||
|
||||
add_definitions(${_BOO_SYS_DEFINES})
|
||||
include_directories(include)
|
||||
include_directories(include glslang)
|
||||
|
||||
add_library(Boo
|
||||
lib/inputdev/CafeProPad.cpp include/boo/inputdev/CafeProPad.hpp
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef GDEV_GLES3_HPP
|
||||
#define GDEV_GLES3_HPP
|
||||
#ifndef GDEV_GL_HPP
|
||||
#define GDEV_GL_HPP
|
||||
|
||||
#include "IGraphicsDataFactory.hpp"
|
||||
#include "IGraphicsCommandQueue.hpp"
|
||||
|
@ -63,4 +63,4 @@ public:
|
|||
|
||||
}
|
||||
|
||||
#endif // GDEV_GLES3_HPP
|
||||
#endif // GDEV_GL_HPP
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
#ifndef GDEV_VULKAN_HPP
|
||||
#define GDEV_VULKAN_HPP
|
||||
|
||||
#include "IGraphicsDataFactory.hpp"
|
||||
#include "IGraphicsCommandQueue.hpp"
|
||||
#include "boo/IGraphicsContext.hpp"
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <mutex>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class VulkanDataFactory : public IGraphicsDataFactory
|
||||
{
|
||||
friend struct VulkanCommandQueue;
|
||||
IGraphicsContext* m_parent;
|
||||
static ThreadLocalPtr<struct GLData> m_deferredData;
|
||||
std::unordered_set<struct GLData*> m_committedData;
|
||||
std::mutex m_committedMutex;
|
||||
std::vector<int> m_texUnis;
|
||||
void destroyData(IGraphicsData*);
|
||||
void destroyAllData();
|
||||
public:
|
||||
VulkanDataFactory(IGraphicsContext* parent);
|
||||
~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);
|
||||
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);
|
||||
ITextureR* newRenderTexture(size_t width, size_t height, size_t samples);
|
||||
|
||||
bool bindingNeedsVertexFormat() const {return true;}
|
||||
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);
|
||||
|
||||
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,
|
||||
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,
|
||||
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;
|
||||
return newShaderPipeline(vertSource, fragSource, vertBlob, fragBlob, pipelineBlob,
|
||||
texCount, texArrayName, uniformBlockCount, uniformBlockNames,
|
||||
srcFac, dstFac, depthTest, depthWrite, backfaceCulling);
|
||||
}
|
||||
|
||||
IShaderDataBinding*
|
||||
newShaderDataBinding(IShaderPipeline* pipeline,
|
||||
IVertexFormat* vtxFormat,
|
||||
IGraphicsBuffer* vbo, IGraphicsBuffer* instVbo, IGraphicsBuffer* ibo,
|
||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||
size_t texCount, ITexture** texs);
|
||||
|
||||
void reset();
|
||||
GraphicsDataToken commit();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GDEV_VULKAN_HPP
|
|
@ -0,0 +1,160 @@
|
|||
#include "boo/graphicsdev/Vulkan.hpp"
|
||||
#include "boo/IGraphicsContext.hpp"
|
||||
#include <vector>
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
#include <SPIRV/GlslangToSpv.h>
|
||||
|
||||
#include <LogVisor/LogVisor.hpp>
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
static const TBuiltInResource DefaultBuiltInResource =
|
||||
{
|
||||
32,
|
||||
6,
|
||||
32,
|
||||
32,
|
||||
64,
|
||||
4096,
|
||||
64,
|
||||
32,
|
||||
80,
|
||||
32,
|
||||
4096,
|
||||
32,
|
||||
128,
|
||||
8,
|
||||
16,
|
||||
16,
|
||||
15,
|
||||
-8,
|
||||
7,
|
||||
8,
|
||||
65535,
|
||||
65535,
|
||||
65535,
|
||||
1024,
|
||||
1024,
|
||||
64,
|
||||
1024,
|
||||
16,
|
||||
8,
|
||||
8,
|
||||
1,
|
||||
60,
|
||||
64,
|
||||
64,
|
||||
128,
|
||||
128,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8,
|
||||
8,
|
||||
16,
|
||||
256,
|
||||
1024,
|
||||
1024,
|
||||
64,
|
||||
128,
|
||||
128,
|
||||
16,
|
||||
1024,
|
||||
4096,
|
||||
128,
|
||||
128,
|
||||
16,
|
||||
1024,
|
||||
120,
|
||||
32,
|
||||
64,
|
||||
16,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8,
|
||||
8,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
16384,
|
||||
4,
|
||||
64,
|
||||
8,
|
||||
8,
|
||||
4,
|
||||
|
||||
{
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
}
|
||||
};
|
||||
|
||||
namespace boo
|
||||
{
|
||||
static LogVisor::LogModule Log("boo::Vulkan");
|
||||
|
||||
IShaderPipeline* VulkanDataFactory::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,
|
||||
BlendFactor srcFac, BlendFactor dstFac,
|
||||
bool depthTest, bool depthWrite, bool backfaceCulling)
|
||||
{
|
||||
if (vertBlobOut.empty() || fragBlobOut.empty())
|
||||
{
|
||||
glslang::TShader vs(EShLangVertex);
|
||||
vs.setStrings(&vertSource, 1);
|
||||
if (!vs.parse(&DefaultBuiltInResource, 110, true, EShMsgDefault))
|
||||
{
|
||||
Log.report(LogVisor::Error, "unable to compile vertex shader\n%s", vs.getInfoLog());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
glslang::TShader fs(EShLangFragment);
|
||||
fs.setStrings(&fragSource, 1);
|
||||
if (!fs.parse(&DefaultBuiltInResource, 110, true, EShMsgDefault))
|
||||
{
|
||||
Log.report(LogVisor::Error, "unable to compile fragment shader\n%s", fs.getInfoLog());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
glslang::TProgram prog;
|
||||
prog.addShader(&vs);
|
||||
prog.addShader(&fs);
|
||||
if (!prog.link(EShMsgDefault))
|
||||
{
|
||||
Log.report(LogVisor::Error, "unable to link shader program\n%s", prog.getInfoLog());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
glslang::GlslangToSpv(*prog.getIntermediate(EShLangVertex), vertBlobOut);
|
||||
glslang::GlslangToSpv(*prog.getIntermediate(EShLangFragment), fragBlobOut);
|
||||
}
|
||||
|
||||
/* TODO: The actual Vulkan API stuff */
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue