mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-08 21:17:50 +00:00
Major GraphicsDataFactory lambda-API refactor
This commit is contained in:
@@ -60,6 +60,8 @@ public:
|
||||
{glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buf);}
|
||||
void bindUniform(size_t idx) const
|
||||
{glBindBufferBase(GL_UNIFORM_BUFFER, idx, m_buf);}
|
||||
void bindUniformRange(size_t idx, GLintptr off, GLsizeiptr size) const
|
||||
{glBindBufferRange(GL_UNIFORM_BUFFER, idx, m_buf, off, size);}
|
||||
};
|
||||
|
||||
class GLGraphicsBufferD : public IGraphicsBufferD
|
||||
@@ -92,14 +94,13 @@ public:
|
||||
void bindVertex(int b);
|
||||
void bindIndex(int b);
|
||||
void bindUniform(size_t idx, int b);
|
||||
void bindUniformRange(size_t idx, GLintptr off, GLsizeiptr size, int b);
|
||||
};
|
||||
|
||||
IGraphicsBufferS*
|
||||
GLDataFactory::newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
||||
GLDataFactory::Context::newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
||||
{
|
||||
GLGraphicsBufferS* retval = new GLGraphicsBufferS(use, data, stride * count);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_SBufs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
@@ -295,42 +296,19 @@ public:
|
||||
};
|
||||
|
||||
ITextureS*
|
||||
GLDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
||||
const void* data, size_t sz)
|
||||
GLDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
||||
const void* data, size_t sz)
|
||||
{
|
||||
GLTextureS* retval = new GLTextureS(width, height, mips, fmt, data, sz);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_STexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
GraphicsDataToken
|
||||
GLDataFactory::newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
||||
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;
|
||||
|
||||
std::unique_lock<std::mutex> lk(m_committedMutex);
|
||||
m_committedData.insert(tokData);
|
||||
lk.unlock();
|
||||
/* Let's go ahead and flush to ensure our data gets to the GPU
|
||||
While this isn't strictly required, some drivers might behave
|
||||
differently */
|
||||
glFlush();
|
||||
return GraphicsDataToken(this, tokData);
|
||||
}
|
||||
|
||||
ITextureSA*
|
||||
GLDataFactory::newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
|
||||
const void *data, size_t sz)
|
||||
GLDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
|
||||
const void *data, size_t sz)
|
||||
{
|
||||
GLTextureSA* retval = new GLTextureSA(width, height, layers, fmt, data, sz);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_SATexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
@@ -452,7 +430,7 @@ static const GLenum BLEND_FACTOR_TABLE[] =
|
||||
GL_ONE_MINUS_SRC1_COLOR
|
||||
};
|
||||
|
||||
IShaderPipeline* GLDataFactory::newShaderPipeline
|
||||
IShaderPipeline* GLDataFactory::Context::newShaderPipeline
|
||||
(const char* vertSource, const char* fragSource,
|
||||
size_t texCount, const char* texArrayName,
|
||||
size_t uniformBlockCount, const char** uniformBlockNames,
|
||||
@@ -535,16 +513,14 @@ IShaderPipeline* GLDataFactory::newShaderPipeline
|
||||
Log.report(logvisor::Error, "unable to find sampler variable '%s'", texArrayName);
|
||||
else
|
||||
{
|
||||
if (texCount > m_texUnis.size())
|
||||
for (size_t i=m_texUnis.size() ; i<texCount ; ++i)
|
||||
m_texUnis.push_back(i);
|
||||
glUniform1iv(texLoc, m_texUnis.size(), m_texUnis.data());
|
||||
if (texCount > m_parent.m_texUnis.size())
|
||||
for (size_t i=m_parent.m_texUnis.size() ; i<texCount ; ++i)
|
||||
m_parent.m_texUnis.push_back(i);
|
||||
glUniform1iv(texLoc, m_parent.m_texUnis.size(), m_parent.m_texUnis.data());
|
||||
}
|
||||
}
|
||||
|
||||
GLShaderPipeline* retval = new GLShaderPipeline(std::move(shader));
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_SPs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
@@ -567,17 +543,14 @@ struct GLShaderDataBinding : IShaderDataBinding
|
||||
const GLVertexFormat* m_vtxFormat;
|
||||
size_t m_ubufCount;
|
||||
std::unique_ptr<IGraphicsBuffer*[]> m_ubufs;
|
||||
std::vector<std::pair<size_t,size_t>> m_ubufOffs;
|
||||
size_t m_texCount;
|
||||
std::unique_ptr<ITexture*[]> m_texs;
|
||||
|
||||
#ifndef NDEBUG
|
||||
/* Debugging aids */
|
||||
bool m_committed = false;
|
||||
#endif
|
||||
|
||||
GLShaderDataBinding(IShaderPipeline* pipeline,
|
||||
IVertexFormat* vtxFormat,
|
||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||
const size_t* ubufOffs, const size_t* ubufSizes,
|
||||
size_t texCount, ITexture** texs)
|
||||
: m_pipeline(static_cast<GLShaderPipeline*>(pipeline)),
|
||||
m_vtxFormat(static_cast<GLVertexFormat*>(vtxFormat)),
|
||||
@@ -586,29 +559,57 @@ struct GLShaderDataBinding : IShaderDataBinding
|
||||
m_texCount(texCount),
|
||||
m_texs(new ITexture*[texCount])
|
||||
{
|
||||
if (ubufOffs && ubufSizes)
|
||||
{
|
||||
m_ubufOffs.reserve(ubufCount);
|
||||
for (size_t i=0 ; i<ubufCount ; ++i)
|
||||
m_ubufOffs.emplace_back(ubufOffs[i], ubufSizes[i]);
|
||||
}
|
||||
for (size_t i=0 ; i<ubufCount ; ++i)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (!ubufs[i])
|
||||
Log.report(logvisor::Fatal, "null uniform-buffer %d provided to newShaderDataBinding", int(i));
|
||||
#endif
|
||||
m_ubufs[i] = ubufs[i];
|
||||
}
|
||||
for (size_t i=0 ; i<texCount ; ++i)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (!texs[i])
|
||||
Log.report(logvisor::Fatal, "null texture %d provided to newShaderDataBinding", int(i));
|
||||
#endif
|
||||
m_texs[i] = texs[i];
|
||||
}
|
||||
}
|
||||
void bind(int b) const
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (!m_committed)
|
||||
Log.report(logvisor::Fatal,
|
||||
"attempted to use uncommitted GLShaderDataBinding");
|
||||
#endif
|
||||
|
||||
GLuint prog = m_pipeline->bind();
|
||||
m_vtxFormat->bind(b);
|
||||
for (size_t i=0 ; i<m_ubufCount ; ++i)
|
||||
if (m_ubufOffs.size())
|
||||
{
|
||||
IGraphicsBuffer* ubuf = m_ubufs[i];
|
||||
if (ubuf->dynamic())
|
||||
static_cast<GLGraphicsBufferD*>(ubuf)->bindUniform(i, b);
|
||||
else
|
||||
static_cast<GLGraphicsBufferS*>(ubuf)->bindUniform(i);
|
||||
glUniformBlockBinding(prog, m_pipeline->m_uniLocs.at(i), i);
|
||||
for (size_t i=0 ; i<m_ubufCount ; ++i)
|
||||
{
|
||||
IGraphicsBuffer* ubuf = m_ubufs[i];
|
||||
const std::pair<size_t,size_t>& offset = m_ubufOffs[i];
|
||||
if (ubuf->dynamic())
|
||||
static_cast<GLGraphicsBufferD*>(ubuf)->bindUniformRange(i, offset.first, offset.second, b);
|
||||
else
|
||||
static_cast<GLGraphicsBufferS*>(ubuf)->bindUniformRange(i, offset.first, offset.second);
|
||||
glUniformBlockBinding(prog, m_pipeline->m_uniLocs.at(i), i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i=0 ; i<m_ubufCount ; ++i)
|
||||
{
|
||||
IGraphicsBuffer* ubuf = m_ubufs[i];
|
||||
if (ubuf->dynamic())
|
||||
static_cast<GLGraphicsBufferD*>(ubuf)->bindUniform(i, b);
|
||||
else
|
||||
static_cast<GLGraphicsBufferS*>(ubuf)->bindUniform(i);
|
||||
glUniformBlockBinding(prog, m_pipeline->m_uniLocs.at(i), i);
|
||||
}
|
||||
}
|
||||
for (size_t i=0 ; i<m_texCount ; ++i)
|
||||
{
|
||||
@@ -634,16 +635,15 @@ struct GLShaderDataBinding : IShaderDataBinding
|
||||
};
|
||||
|
||||
IShaderDataBinding*
|
||||
GLDataFactory::newShaderDataBinding(IShaderPipeline* pipeline,
|
||||
IVertexFormat* vtxFormat,
|
||||
IGraphicsBuffer*, IGraphicsBuffer*, IGraphicsBuffer*,
|
||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||
size_t texCount, ITexture** texs)
|
||||
GLDataFactory::Context::newShaderDataBinding(IShaderPipeline* pipeline,
|
||||
IVertexFormat* vtxFormat,
|
||||
IGraphicsBuffer*, IGraphicsBuffer*, IGraphicsBuffer*,
|
||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||
const size_t* ubufOffs, const size_t* ubufSizes,
|
||||
size_t texCount, ITexture** texs)
|
||||
{
|
||||
GLShaderDataBinding* retval =
|
||||
new GLShaderDataBinding(pipeline, vtxFormat, ubufCount, ubufs, texCount, texs);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
new GLShaderDataBinding(pipeline, vtxFormat, ubufCount, ubufs, ubufOffs, ubufSizes, texCount, texs);
|
||||
m_deferredData->m_SBinds.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
@@ -651,22 +651,23 @@ GLDataFactory::newShaderDataBinding(IShaderPipeline* pipeline,
|
||||
GLDataFactory::GLDataFactory(IGraphicsContext* parent, uint32_t drawSamples)
|
||||
: m_parent(parent), m_drawSamples(drawSamples) {}
|
||||
|
||||
void GLDataFactory::reset()
|
||||
{
|
||||
delete m_deferredData.get();
|
||||
m_deferredData.reset();
|
||||
}
|
||||
|
||||
GraphicsDataToken GLDataFactory::commit()
|
||||
GraphicsDataToken GLDataFactory::commitTransaction(const FactoryCommitFunc& trans)
|
||||
{
|
||||
if (!m_deferredData.get())
|
||||
if (m_deferredData.get())
|
||||
Log.report(logvisor::Fatal, "nested commitTransaction usage detected");
|
||||
m_deferredData.reset(new GLData());
|
||||
|
||||
GLDataFactory::Context ctx(*this);
|
||||
if (!trans(ctx))
|
||||
{
|
||||
delete m_deferredData.get();
|
||||
m_deferredData.reset();
|
||||
return GraphicsDataToken(this, nullptr);
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lk(m_committedMutex);
|
||||
GLData* retval = m_deferredData.get();
|
||||
#ifndef NDEBUG
|
||||
for (std::unique_ptr<GLShaderDataBinding>& b : retval->m_SBinds)
|
||||
b->m_committed = true;
|
||||
#endif
|
||||
m_deferredData.reset();
|
||||
m_committedData.insert(retval);
|
||||
lk.unlock();
|
||||
@@ -1057,10 +1058,6 @@ struct GLCommandQueue : IGraphicsCommandQueue
|
||||
|
||||
void setShaderDataBinding(IShaderDataBinding* binding)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (!binding)
|
||||
Log.report(logvisor::Fatal, "binding may not be empty");
|
||||
#endif
|
||||
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];
|
||||
cmds.emplace_back(Command::Op::SetShaderDataBinding);
|
||||
cmds.back().binding = binding;
|
||||
@@ -1281,13 +1278,13 @@ void GLGraphicsBufferD::bindIndex(int b)
|
||||
{glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_bufs[b]);}
|
||||
void GLGraphicsBufferD::bindUniform(size_t idx, int b)
|
||||
{glBindBufferBase(GL_UNIFORM_BUFFER, idx, m_bufs[b]);}
|
||||
void GLGraphicsBufferD::bindUniformRange(size_t idx, GLintptr off, GLsizeiptr size, int b)
|
||||
{glBindBufferRange(GL_UNIFORM_BUFFER, idx, m_bufs[b], off, size);}
|
||||
|
||||
IGraphicsBufferD*
|
||||
GLDataFactory::newDynamicBuffer(BufferUse use, size_t stride, size_t count)
|
||||
GLDataFactory::Context::newDynamicBuffer(BufferUse use, size_t stride, size_t count)
|
||||
{
|
||||
GLGraphicsBufferD* retval = new GLGraphicsBufferD(use, stride * count);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_DBufs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
@@ -1360,11 +1357,9 @@ void GLTextureD::bind(size_t idx, int b)
|
||||
}
|
||||
|
||||
ITextureD*
|
||||
GLDataFactory::newDynamicTexture(size_t width, size_t height, TextureFormat fmt)
|
||||
GLDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt)
|
||||
{
|
||||
GLTextureD* retval = new GLTextureD(width, height, fmt);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_DTexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
@@ -1430,15 +1425,13 @@ GLTextureR::~GLTextureR()
|
||||
}
|
||||
|
||||
ITextureR*
|
||||
GLDataFactory::newRenderTexture(size_t width, size_t height,
|
||||
bool enableShaderColorBinding, bool enableShaderDepthBinding)
|
||||
GLDataFactory::Context::newRenderTexture(size_t width, size_t height,
|
||||
bool enableShaderColorBinding, bool enableShaderDepthBinding)
|
||||
{
|
||||
GLCommandQueue* q = static_cast<GLCommandQueue*>(m_parent->getCommandQueue());
|
||||
GLTextureR* retval = new GLTextureR(q, width, height, m_drawSamples,
|
||||
GLCommandQueue* q = static_cast<GLCommandQueue*>(m_parent.m_parent->getCommandQueue());
|
||||
GLTextureR* retval = new GLTextureR(q, width, height, m_parent.m_drawSamples,
|
||||
enableShaderColorBinding, enableShaderDepthBinding);
|
||||
q->resizeRenderTexture(retval, width, height);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_RTexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
@@ -1455,13 +1448,11 @@ GLVertexFormat::GLVertexFormat(GLCommandQueue* q, size_t elementCount,
|
||||
}
|
||||
GLVertexFormat::~GLVertexFormat() {m_q->delVertexFormat(this);}
|
||||
|
||||
IVertexFormat* GLDataFactory::newVertexFormat
|
||||
IVertexFormat* GLDataFactory::Context::newVertexFormat
|
||||
(size_t elementCount, const VertexElementDescriptor* elements)
|
||||
{
|
||||
GLCommandQueue* q = static_cast<GLCommandQueue*>(m_parent->getCommandQueue());
|
||||
GLCommandQueue* q = static_cast<GLCommandQueue*>(m_parent.m_parent->getCommandQueue());
|
||||
GLVertexFormat* retval = new struct GLVertexFormat(q, elementCount, elements);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct GLData());
|
||||
m_deferredData->m_VFmts.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -773,6 +773,7 @@ class VulkanGraphicsBufferS : public IGraphicsBufferS
|
||||
ThrowIfFailed(vkCreateBuffer(ctx->m_dev, &bufInfo, nullptr, &m_bufferInfo.buffer));
|
||||
}
|
||||
public:
|
||||
size_t size() const {return m_sz;}
|
||||
size_t m_stride;
|
||||
size_t m_count;
|
||||
VkDescriptorBufferInfo m_bufferInfo;
|
||||
@@ -2047,6 +2048,7 @@ struct VulkanShaderDataBinding : IShaderDataBinding
|
||||
IGraphicsBuffer* m_ibuf;
|
||||
size_t m_ubufCount;
|
||||
std::unique_ptr<IGraphicsBuffer*[]> m_ubufs;
|
||||
std::vector<VkDescriptorBufferInfo> m_ubufOffs;
|
||||
size_t m_texCount;
|
||||
std::unique_ptr<ITexture*[]> m_texs;
|
||||
|
||||
@@ -2067,6 +2069,7 @@ struct VulkanShaderDataBinding : IShaderDataBinding
|
||||
IShaderPipeline* pipeline,
|
||||
IGraphicsBuffer* vbuf, IGraphicsBuffer* instVbuf, IGraphicsBuffer* ibuf,
|
||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||
const size_t* ubufOffs, const size_t* ubufSizes,
|
||||
size_t texCount, ITexture** texs)
|
||||
: m_ctx(ctx),
|
||||
m_pipeline(static_cast<VulkanShaderPipeline*>(pipeline)),
|
||||
@@ -2078,10 +2081,28 @@ struct VulkanShaderDataBinding : IShaderDataBinding
|
||||
m_texCount(texCount),
|
||||
m_texs(new ITexture*[texCount])
|
||||
{
|
||||
if (ubufOffs && ubufSizes)
|
||||
{
|
||||
m_ubufOffs.reserve(ubufCount);
|
||||
for (size_t i=0 ; i<ubufCount ; ++i)
|
||||
m_ubufOffs.push_back({VK_NULL_HANDLE, ubufOffs[i], ubufSizes[i]});
|
||||
}
|
||||
for (size_t i=0 ; i<ubufCount ; ++i)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (!ubufs[i])
|
||||
Log.report(logvisor::Fatal, "null uniform-buffer %d provided to newShaderDataBinding", int(i));
|
||||
#endif
|
||||
m_ubufs[i] = ubufs[i];
|
||||
}
|
||||
for (size_t i=0 ; i<texCount ; ++i)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (!texs[i])
|
||||
Log.report(logvisor::Fatal, "null texture %d provided to newShaderDataBinding", int(i));
|
||||
#endif
|
||||
m_texs[i] = texs[i];
|
||||
}
|
||||
|
||||
size_t totalDescs = ubufCount + texCount;
|
||||
if (totalDescs > 0)
|
||||
@@ -2151,22 +2172,49 @@ struct VulkanShaderDataBinding : IShaderDataBinding
|
||||
}
|
||||
|
||||
size_t binding = 0;
|
||||
for (size_t i=0 ; i<BOO_GLSL_MAX_UNIFORM_COUNT ; ++i)
|
||||
if (m_ubufOffs.size())
|
||||
{
|
||||
if (i<m_ubufCount)
|
||||
for (size_t i=0 ; i<BOO_GLSL_MAX_UNIFORM_COUNT ; ++i)
|
||||
{
|
||||
writes[totalWrites].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
writes[totalWrites].pNext = nullptr;
|
||||
writes[totalWrites].dstSet = m_descSets[b];
|
||||
writes[totalWrites].descriptorCount = 1;
|
||||
writes[totalWrites].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
||||
writes[totalWrites].pBufferInfo = GetBufferGPUResource(m_ubufs[i], b);
|
||||
writes[totalWrites].dstArrayElement = 0;
|
||||
writes[totalWrites].dstBinding = binding;
|
||||
++totalWrites;
|
||||
if (i<m_ubufCount)
|
||||
{
|
||||
writes[totalWrites].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
writes[totalWrites].pNext = nullptr;
|
||||
writes[totalWrites].dstSet = m_descSets[b];
|
||||
writes[totalWrites].descriptorCount = 1;
|
||||
writes[totalWrites].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
||||
const VkDescriptorBufferInfo* origInfo = GetBufferGPUResource(m_ubufs[i], b);
|
||||
VkDescriptorBufferInfo& modInfo = m_ubufOffs[i];
|
||||
modInfo.buffer = origInfo->buffer;
|
||||
modInfo.offset += origInfo->offset;
|
||||
writes[totalWrites].pBufferInfo = &modInfo;
|
||||
writes[totalWrites].dstArrayElement = 0;
|
||||
writes[totalWrites].dstBinding = binding;
|
||||
++totalWrites;
|
||||
}
|
||||
++binding;
|
||||
}
|
||||
++binding;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i=0 ; i<BOO_GLSL_MAX_UNIFORM_COUNT ; ++i)
|
||||
{
|
||||
if (i<m_ubufCount)
|
||||
{
|
||||
writes[totalWrites].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
writes[totalWrites].pNext = nullptr;
|
||||
writes[totalWrites].dstSet = m_descSets[b];
|
||||
writes[totalWrites].descriptorCount = 1;
|
||||
writes[totalWrites].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
||||
writes[totalWrites].pBufferInfo = GetBufferGPUResource(m_ubufs[i], b);
|
||||
writes[totalWrites].dstArrayElement = 0;
|
||||
writes[totalWrites].dstBinding = binding;
|
||||
++totalWrites;
|
||||
}
|
||||
++binding;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i=0 ; i<BOO_GLSL_MAX_TEXTURE_COUNT ; ++i)
|
||||
{
|
||||
if (i<m_texCount)
|
||||
@@ -2868,7 +2916,7 @@ VulkanDataFactory::VulkanDataFactory(IGraphicsContext* parent, VulkanContext* ct
|
||||
ThrowIfFailed(vkCreateRenderPass(ctx->m_dev, &renderPass, nullptr, &ctx->m_pass));
|
||||
}
|
||||
|
||||
IShaderPipeline* VulkanDataFactory::newShaderPipeline
|
||||
IShaderPipeline* VulkanDataFactory::Context::newShaderPipeline
|
||||
(const char* vertSource, const char* fragSource,
|
||||
std::vector<unsigned int>& vertBlobOut, std::vector<unsigned int>& fragBlobOut,
|
||||
std::vector<unsigned char>& pipelineBlob, IVertexFormat* vtxFmt,
|
||||
@@ -2918,12 +2966,12 @@ IShaderPipeline* VulkanDataFactory::newShaderPipeline
|
||||
smCreateInfo.codeSize = vertBlobOut.size() * sizeof(unsigned int);
|
||||
smCreateInfo.pCode = vertBlobOut.data();
|
||||
VkShaderModule vertModule;
|
||||
ThrowIfFailed(vkCreateShaderModule(m_ctx->m_dev, &smCreateInfo, nullptr, &vertModule));
|
||||
ThrowIfFailed(vkCreateShaderModule(m_parent.m_ctx->m_dev, &smCreateInfo, nullptr, &vertModule));
|
||||
|
||||
smCreateInfo.codeSize = fragBlobOut.size() * sizeof(unsigned int);
|
||||
smCreateInfo.pCode = fragBlobOut.data();
|
||||
VkShaderModule fragModule;
|
||||
ThrowIfFailed(vkCreateShaderModule(m_ctx->m_dev, &smCreateInfo, nullptr, &fragModule));
|
||||
ThrowIfFailed(vkCreateShaderModule(m_parent.m_ctx->m_dev, &smCreateInfo, nullptr, &fragModule));
|
||||
|
||||
VkPipelineCacheCreateInfo cacheDataInfo = {};
|
||||
cacheDataInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
|
||||
@@ -2933,180 +2981,116 @@ IShaderPipeline* VulkanDataFactory::newShaderPipeline
|
||||
cacheDataInfo.pInitialData = pipelineBlob.data();
|
||||
|
||||
VkPipelineCache pipelineCache;
|
||||
ThrowIfFailed(vkCreatePipelineCache(m_ctx->m_dev, &cacheDataInfo, nullptr, &pipelineCache));
|
||||
ThrowIfFailed(vkCreatePipelineCache(m_parent.m_ctx->m_dev, &cacheDataInfo, nullptr, &pipelineCache));
|
||||
|
||||
VulkanShaderPipeline* retval = new VulkanShaderPipeline(m_ctx, vertModule, fragModule, pipelineCache,
|
||||
VulkanShaderPipeline* retval = new VulkanShaderPipeline(m_parent.m_ctx, vertModule, fragModule, pipelineCache,
|
||||
static_cast<const VulkanVertexFormat*>(vtxFmt),
|
||||
srcFac, dstFac, prim, depthTest, depthWrite, backfaceCulling);
|
||||
|
||||
if (pipelineBlob.empty())
|
||||
{
|
||||
size_t cacheSz = 0;
|
||||
ThrowIfFailed(vkGetPipelineCacheData(m_ctx->m_dev, pipelineCache, &cacheSz, nullptr));
|
||||
ThrowIfFailed(vkGetPipelineCacheData(m_parent.m_ctx->m_dev, pipelineCache, &cacheSz, nullptr));
|
||||
if (cacheSz)
|
||||
{
|
||||
pipelineBlob.resize(cacheSz);
|
||||
ThrowIfFailed(vkGetPipelineCacheData(m_ctx->m_dev, pipelineCache, &cacheSz, pipelineBlob.data()));
|
||||
ThrowIfFailed(vkGetPipelineCacheData(m_parent.m_ctx->m_dev, pipelineCache, &cacheSz, pipelineBlob.data()));
|
||||
pipelineBlob.resize(cacheSz);
|
||||
}
|
||||
}
|
||||
|
||||
vkDestroyPipelineCache(m_ctx->m_dev, pipelineCache, nullptr);
|
||||
vkDestroyShaderModule(m_ctx->m_dev, fragModule, nullptr);
|
||||
vkDestroyShaderModule(m_ctx->m_dev, vertModule, nullptr);
|
||||
vkDestroyPipelineCache(m_parent.m_ctx->m_dev, pipelineCache, nullptr);
|
||||
vkDestroyShaderModule(m_parent.m_ctx->m_dev, fragModule, nullptr);
|
||||
vkDestroyShaderModule(m_parent.m_ctx->m_dev, vertModule, nullptr);
|
||||
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_SPs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
IGraphicsBufferS* VulkanDataFactory::newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
||||
IGraphicsBufferS* VulkanDataFactory::Context::newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
||||
{
|
||||
VulkanGraphicsBufferS* retval = new VulkanGraphicsBufferS(use, m_ctx, data, stride, count);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
VulkanGraphicsBufferS* retval = new VulkanGraphicsBufferS(use, m_parent.m_ctx, data, stride, count);
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_SBufs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
IGraphicsBufferD* VulkanDataFactory::newDynamicBuffer(BufferUse use, size_t stride, size_t count)
|
||||
IGraphicsBufferD* VulkanDataFactory::Context::newDynamicBuffer(BufferUse use, size_t stride, size_t count)
|
||||
{
|
||||
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent->getCommandQueue());
|
||||
VulkanGraphicsBufferD* retval = new VulkanGraphicsBufferD(q, use, m_ctx, stride, count);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent.m_parent->getCommandQueue());
|
||||
VulkanGraphicsBufferD* retval = new VulkanGraphicsBufferD(q, use, m_parent.m_ctx, stride, count);
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_DBufs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
ITextureS* VulkanDataFactory::newStaticTexture(size_t width, size_t height, size_t mips,
|
||||
TextureFormat fmt, const void* data, size_t sz)
|
||||
ITextureS* VulkanDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips,
|
||||
TextureFormat fmt, const void* data, size_t sz)
|
||||
{
|
||||
VulkanTextureS* retval = new VulkanTextureS(m_ctx, width, height, mips, fmt, data, sz);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
VulkanTextureS* retval = new VulkanTextureS(m_parent.m_ctx, width, height, mips, fmt, data, sz);
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_STexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
GraphicsDataToken
|
||||
VulkanDataFactory::newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
||||
const void* data, size_t sz, ITextureS*& texOut)
|
||||
ITextureSA* VulkanDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers,
|
||||
TextureFormat fmt, const void* data, size_t sz)
|
||||
{
|
||||
VulkanTextureS* retval = new VulkanTextureS(m_ctx, width, height, mips, fmt, data, sz);
|
||||
VulkanData* tokData = new struct VulkanData(m_ctx);
|
||||
tokData->m_STexs.emplace_back(retval);
|
||||
texOut = retval;
|
||||
|
||||
uint32_t memTypeBits = ~0;
|
||||
VkDeviceSize memSize = SizeTextureForGPU(retval, m_ctx, memTypeBits, 0);
|
||||
|
||||
/* allocate memory */
|
||||
VkMemoryAllocateInfo memAlloc = {};
|
||||
memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
memAlloc.pNext = nullptr;
|
||||
memAlloc.memoryTypeIndex = 0;
|
||||
memAlloc.allocationSize = memSize;
|
||||
ThrowIfFalse(MemoryTypeFromProperties(m_ctx, memTypeBits, 0, &memAlloc.memoryTypeIndex));
|
||||
ThrowIfFailed(vkAllocateMemory(m_ctx->m_dev, &memAlloc, nullptr, &tokData->m_texMem));
|
||||
|
||||
/* Place texture */
|
||||
PlaceTextureForGPU(retval, m_ctx, tokData->m_texMem);
|
||||
|
||||
/* Execute static uploads */
|
||||
ThrowIfFailed(vkEndCommandBuffer(m_ctx->m_loadCmdBuf));
|
||||
VkSubmitInfo submitInfo = {};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &m_ctx->m_loadCmdBuf;
|
||||
ThrowIfFailed(vkQueueSubmit(m_ctx->m_queue, 1, &submitInfo, m_ctx->m_loadFence));
|
||||
|
||||
/* Block handle return until data is ready on GPU */
|
||||
ThrowIfFailed(vkWaitForFences(m_ctx->m_dev, 1, &m_ctx->m_loadFence, VK_TRUE, -1));
|
||||
|
||||
/* Reset fence and command buffer */
|
||||
ThrowIfFailed(vkResetFences(m_ctx->m_dev, 1, &m_ctx->m_loadFence));
|
||||
ThrowIfFailed(vkResetCommandBuffer(m_ctx->m_loadCmdBuf, 0));
|
||||
VkCommandBufferBeginInfo cmdBufBeginInfo = {};
|
||||
cmdBufBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
cmdBufBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
ThrowIfFailed(vkBeginCommandBuffer(m_ctx->m_loadCmdBuf, &cmdBufBeginInfo));
|
||||
|
||||
/* Delete upload objects */
|
||||
retval->deleteUploadObjects();
|
||||
|
||||
/* All set! */
|
||||
std::unique_lock<std::mutex> lk(m_committedMutex);
|
||||
m_committedData.insert(tokData);
|
||||
return GraphicsDataToken(this, tokData);
|
||||
}
|
||||
|
||||
ITextureSA* VulkanDataFactory::newStaticArrayTexture(size_t width, size_t height, size_t layers,
|
||||
TextureFormat fmt, const void* data, size_t sz)
|
||||
{
|
||||
VulkanTextureSA* retval = new VulkanTextureSA(m_ctx, width, height, layers, fmt, data, sz);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
VulkanTextureSA* retval = new VulkanTextureSA(m_parent.m_ctx, width, height, layers, fmt, data, sz);
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_SATexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
ITextureD* VulkanDataFactory::newDynamicTexture(size_t width, size_t height, TextureFormat fmt)
|
||||
ITextureD* VulkanDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt)
|
||||
{
|
||||
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent->getCommandQueue());
|
||||
VulkanTextureD* retval = new VulkanTextureD(q, m_ctx, width, height, fmt);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent.m_parent->getCommandQueue());
|
||||
VulkanTextureD* retval = new VulkanTextureD(q, m_parent.m_ctx, width, height, fmt);
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_DTexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
ITextureR* VulkanDataFactory::newRenderTexture(size_t width, size_t height,
|
||||
bool enableShaderColorBinding, bool enableShaderDepthBinding)
|
||||
ITextureR* VulkanDataFactory::Context::newRenderTexture(size_t width, size_t height,
|
||||
bool enableShaderColorBinding, bool enableShaderDepthBinding)
|
||||
{
|
||||
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent->getCommandQueue());
|
||||
VulkanTextureR* retval = new VulkanTextureR(m_ctx, q, width, height, m_drawSamples,
|
||||
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent.m_parent->getCommandQueue());
|
||||
VulkanTextureR* retval = new VulkanTextureR(m_parent.m_ctx, q, width, height, m_parent.m_drawSamples,
|
||||
enableShaderColorBinding, enableShaderDepthBinding);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_RTexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
IVertexFormat* VulkanDataFactory::newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements)
|
||||
IVertexFormat* VulkanDataFactory::Context::newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements)
|
||||
{
|
||||
VulkanVertexFormat* retval = new struct VulkanVertexFormat(elementCount, elements);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_VFmts.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
IShaderDataBinding* VulkanDataFactory::newShaderDataBinding(IShaderPipeline* pipeline,
|
||||
IShaderDataBinding* VulkanDataFactory::Context::newShaderDataBinding(IShaderPipeline* pipeline,
|
||||
IVertexFormat* /*vtxFormat*/,
|
||||
IGraphicsBuffer* vbuf, IGraphicsBuffer* instVbuf, IGraphicsBuffer* ibuf,
|
||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||
const size_t* ubufOffs, const size_t* ubufSizes,
|
||||
size_t texCount, ITexture** texs)
|
||||
{
|
||||
VulkanShaderDataBinding* retval =
|
||||
new VulkanShaderDataBinding(m_ctx, pipeline, vbuf, instVbuf, ibuf, ubufCount, ubufs, texCount, texs);
|
||||
if (!m_deferredData.get())
|
||||
m_deferredData.reset(new struct VulkanData(m_ctx));
|
||||
new VulkanShaderDataBinding(m_parent.m_ctx, pipeline, vbuf, instVbuf, ibuf,
|
||||
ubufCount, ubufs, ubufOffs, ubufSizes, texCount, texs);
|
||||
static_cast<VulkanData*>(m_deferredData.get())->m_SBinds.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void VulkanDataFactory::reset()
|
||||
GraphicsDataToken VulkanDataFactory::commitTransaction
|
||||
(const std::function<bool(IGraphicsDataFactory::Context&)>& trans)
|
||||
{
|
||||
delete static_cast<VulkanData*>(m_deferredData.get());
|
||||
m_deferredData.reset();
|
||||
}
|
||||
if (m_deferredData.get())
|
||||
Log.report(logvisor::Fatal, "nested commitTransaction usage detected");
|
||||
m_deferredData.reset(new VulkanData(m_ctx));
|
||||
|
||||
GraphicsDataToken VulkanDataFactory::commit()
|
||||
{
|
||||
if (!m_deferredData.get())
|
||||
Context ctx(*this);
|
||||
if (!trans(ctx))
|
||||
{
|
||||
delete m_deferredData.get();
|
||||
m_deferredData.reset();
|
||||
return GraphicsDataToken(this, nullptr);
|
||||
}
|
||||
|
||||
VulkanData* retval = static_cast<VulkanData*>(m_deferredData.get());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user