Combine CommitResources for CBooRenderer::UpdateAreaUniforms.

This shares the IGraphicsDataFactory::Context over many functions, to avoid
the overhead of calling CGraphics::CommitResources multiple times.
This commit is contained in:
Henrique Gemignani Passos Lima 2021-04-04 01:01:23 +03:00 committed by Luke Street
parent 05d8ab688e
commit e3896bdee9
3 changed files with 26 additions and 16 deletions

View File

@ -796,14 +796,17 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode,
if (shadowMode == EWorldShadowMode::BallOnWorldShadow || shadowMode == EWorldShadowMode::BallOnWorldIds) if (shadowMode == EWorldShadowMode::BallOnWorldShadow || shadowMode == EWorldShadowMode::BallOnWorldIds)
continue; continue;
for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
CBooModel* model = *it; for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) {
if (model->TryLockTextures()) { CBooModel* model = *it;
if (activateLights) if (model->TryLockTextures()) {
ActivateLightsForModel(&item, *model); if (activateLights)
model->UpdateUniformData(flags, nullptr, nullptr, bufIdx); ActivateLightsForModel(&item, *model);
model->UpdateUniformData(flags, nullptr, nullptr, bufIdx, &ctx);
}
} }
} return true;
} BooTrace);
} }
} }

View File

@ -177,7 +177,7 @@ private:
boo::ObjToken<boo::ITexture> m_lastDrawnOneTexture; boo::ObjToken<boo::ITexture> m_lastDrawnOneTexture;
boo::ObjToken<boo::ITextureCubeR> m_lastDrawnReflectionCube; boo::ObjToken<boo::ITextureCubeR> m_lastDrawnReflectionCube;
ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1); ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1, boo::IGraphicsDataFactory::Context* ctx = nullptr);
void DrawAlphaSurfaces(const CModelFlags& flags) const; void DrawAlphaSurfaces(const CModelFlags& flags) const;
void DrawNormalSurfaces(const CModelFlags& flags) const; void DrawNormalSurfaces(const CModelFlags& flags) const;
void DrawSurfaces(const CModelFlags& flags) const; void DrawSurfaces(const CModelFlags& flags) const;
@ -217,7 +217,8 @@ public:
void Touch(int shaderIdx); void Touch(int shaderIdx);
void VerifyCurrentShader(int shaderIdx); void VerifyCurrentShader(int shaderIdx);
boo::ObjToken<boo::IGraphicsBufferD> UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, boo::ObjToken<boo::IGraphicsBufferD> UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr,
const CPoseAsTransforms* pose, int sharedLayoutBuf = -1); const CPoseAsTransforms* pose, int sharedLayoutBuf = -1,
boo::IGraphicsDataFactory::Context* ctx = nullptr);
void DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); void DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose);
void DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); void DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose);
void Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); void Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose);

View File

@ -243,7 +243,7 @@ GeometryUniformLayout::GeometryUniformLayout(const CModel* model, const Material
} }
} }
CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) { CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf, boo::IGraphicsDataFactory::Context* ctx) {
if (!x40_24_texturesLoaded && !g_DummyTextures) { if (!x40_24_texturesLoaded && !g_DummyTextures) {
return nullptr; return nullptr;
} }
@ -254,7 +254,7 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
ModelInstance& newInst = m_instances.emplace_back(); ModelInstance& newInst = m_instances.emplace_back();
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { auto withContext = [&](boo::IGraphicsDataFactory::Context& ctx) {
/* Build geometry uniform buffer if shared not available */ /* Build geometry uniform buffer if shared not available */
boo::ObjToken<boo::IGraphicsBufferD> geomUniformBuf; boo::ObjToken<boo::IGraphicsBufferD> geomUniformBuf;
if (sharedLayoutBuf >= 0) { if (sharedLayoutBuf >= 0) {
@ -401,8 +401,13 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
} }
} }
return true; return true;
} BooTrace); };
if (ctx) {
withContext(*ctx);
} else {
CGraphics::CommitResources(withContext BooTrace);
}
return &newInst; return &newInst;
} }
@ -974,7 +979,8 @@ boo::ObjToken<boo::IGraphicsBufferD> GeometryUniformLayout::GetSharedBuffer(int
} }
boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr,
const CPoseAsTransforms* pose, int sharedLayoutBuf) { const CPoseAsTransforms* pose, int sharedLayoutBuf,
boo::IGraphicsDataFactory::Context* ctx) {
if (!g_DummyTextures && !TryLockTextures()) if (!g_DummyTextures && !TryLockTextures())
return {}; return {};
@ -1004,7 +1010,7 @@ boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFl
if (sharedLayoutBuf >= 0) { if (sharedLayoutBuf >= 0) {
if (m_instances.size() <= sharedLayoutBuf) { if (m_instances.size() <= sharedLayoutBuf) {
do { do {
inst = PushNewModelInstance(m_instances.size()); inst = PushNewModelInstance(m_instances.size(), ctx);
if (!inst) { if (!inst) {
return {}; return {};
} }
@ -1015,7 +1021,7 @@ boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFl
m_uniUpdateCount = sharedLayoutBuf + 1; m_uniUpdateCount = sharedLayoutBuf + 1;
} else { } else {
if (m_instances.size() <= m_uniUpdateCount) { if (m_instances.size() <= m_uniUpdateCount) {
inst = PushNewModelInstance(sharedLayoutBuf); inst = PushNewModelInstance(sharedLayoutBuf, ctx);
if (!inst) { if (!inst) {
return {}; return {};
} }