Merge remote-tracking branch 'darkszero/feature/support-lazy-commit-resources'

# Conflicts:
#	lib/graphicsdev/Vulkan.cpp
This commit is contained in:
Luke Street 2021-10-25 23:07:39 -04:00
commit 49cfab476f
3 changed files with 45 additions and 13 deletions

View File

@ -277,6 +277,10 @@ struct IGraphicsDataFactory {
};
virtual void commitTransaction(const std::function<bool(Context& ctx)>& __BooTraceArgs) = 0;
virtual void lazyCommitTransaction(const std::function<bool(Context& ctx)>& f __BooTraceArgs) {
commitTransaction(f __BooTraceArgsUse);
}
virtual void commitPendingTransaction() {}
virtual ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs) = 0;
virtual void setDisplayGamma(float gamma) = 0;
virtual bool isTessellationSupported(uint32_t& maxPatchSizeOut) = 0;

View File

@ -130,10 +130,10 @@ public:
friend class VulkanDataFactoryImpl;
VulkanDataFactory& m_parent;
boo::ObjToken<BaseGraphicsData> m_data;
Context(VulkanDataFactory& parent __BooTraceArgs);
~Context();
public:
Context(VulkanDataFactory& parent __BooTraceArgs);
~Context();
Platform platform() const { return Platform::Vulkan; }
const char* platformName() const { return "Vulkan"; }

View File

@ -3,6 +3,7 @@
#include <array>
#include <cmath>
#include <vector>
#include <optional>
#include <glslang/Public/ShaderLang.h>
#include <StandAlone/ResourceLimits.h>
@ -82,6 +83,8 @@ class VulkanDataFactoryImpl final : public VulkanDataFactory, public GraphicsDat
VulkanDescriptorPool* m_descPoolHead = nullptr;
PipelineCompileQueue<class VulkanShaderPipeline> m_pipelineQueue;
std::optional<Context> m_lazyContext;
void flushContext(Context&);
float m_gamma = 1.f;
ObjToken<IShaderPipeline> m_gammaShader;
@ -126,21 +129,23 @@ public:
VulkanDataFactoryImpl(IGraphicsContext* parent, VulkanContext* ctx);
~VulkanDataFactoryImpl() { assert(m_descPoolHead == nullptr && "Dangling descriptor pools detected"); }
Platform platform() const { return Platform::Vulkan; }
const char* platformName() const { return "Vulkan"; }
Platform platform() const override { return Platform::Vulkan; }
const char* platformName() const override { return "Vulkan"; }
boo::ObjToken<VulkanDescriptorPool> allocateDescriptorSets(VkDescriptorSet* out);
void commitTransaction(const FactoryCommitFunc& __BooTraceArgs);
void commitTransaction(const FactoryCommitFunc& __BooTraceArgs) override;
void lazyCommitTransaction(const FactoryCommitFunc& __BooTraceArgs) override;
void commitPendingTransaction() override;
boo::ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs);
boo::ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs) override;
void setDisplayGamma(float gamma) {
void setDisplayGamma(float gamma) override {
m_gamma = gamma;
UpdateGammaLUT(m_gammaLUT.get(), gamma);
}
bool isTessellationSupported(uint32_t& maxPatchSizeOut) {
bool isTessellationSupported(uint32_t& maxPatchSizeOut) override {
maxPatchSizeOut = 0;
if (!m_ctx->m_features.tessellationShader)
return false;
@ -148,11 +153,11 @@ public:
return true;
}
void waitUntilShadersReady() {
void waitUntilShadersReady() override {
m_pipelineQueue.waitUntilReady();
}
bool areShadersReady() {
bool areShadersReady() override {
return m_pipelineQueue.isReady();
}
};
@ -3791,10 +3796,33 @@ boo::ObjToken<IShaderDataBinding> VulkanDataFactory::Context::newShaderDataBindi
void VulkanDataFactoryImpl::commitTransaction(
const std::function<bool(IGraphicsDataFactory::Context&)>& trans __BooTraceArgs) {
Context ctx(*this __BooTraceArgsUse);
if (!trans(ctx))
return;
Context ctx(*this __BooTraceArgsUse);
if (!trans(ctx)) {
return;
}
commitPendingTransaction();
flushContext(ctx);
}
void VulkanDataFactoryImpl::lazyCommitTransaction(
const std::function<bool(IGraphicsDataFactory::Context&)>& trans __BooTraceArgs) {
if (!m_lazyContext) {
m_lazyContext.emplace(*this __BooTraceArgsUse);
}
trans(*m_lazyContext);
}
void VulkanDataFactoryImpl::commitPendingTransaction() {
if (m_lazyContext) {
flushContext(*m_lazyContext);
m_lazyContext.reset();
}
}
void VulkanDataFactoryImpl::flushContext(Context& ctx) {
OPTICK_EVENT();
VulkanData* data = ctx.m_data.cast<VulkanData>();
/* Start asynchronous shader compiles */