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)
continue;
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) {
CBooModel* model = *it;
if (model->TryLockTextures()) {
if (activateLights)
ActivateLightsForModel(&item, *model);
model->UpdateUniformData(flags, nullptr, nullptr, bufIdx);
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::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 DrawNormalSurfaces(const CModelFlags& flags) const;
void DrawSurfaces(const CModelFlags& flags) const;
@ -217,7 +217,8 @@ public:
void Touch(int shaderIdx);
void VerifyCurrentShader(int shaderIdx);
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 DrawNormal(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) {
return nullptr;
}
@ -254,7 +254,7 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
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 */
boo::ObjToken<boo::IGraphicsBufferD> geomUniformBuf;
if (sharedLayoutBuf >= 0) {
@ -401,8 +401,13 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
}
}
return true;
} BooTrace);
};
if (ctx) {
withContext(*ctx);
} else {
CGraphics::CommitResources(withContext BooTrace);
}
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,
const CPoseAsTransforms* pose, int sharedLayoutBuf) {
const CPoseAsTransforms* pose, int sharedLayoutBuf,
boo::IGraphicsDataFactory::Context* ctx) {
if (!g_DummyTextures && !TryLockTextures())
return {};
@ -1004,7 +1010,7 @@ boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFl
if (sharedLayoutBuf >= 0) {
if (m_instances.size() <= sharedLayoutBuf) {
do {
inst = PushNewModelInstance(m_instances.size());
inst = PushNewModelInstance(m_instances.size(), ctx);
if (!inst) {
return {};
}
@ -1015,7 +1021,7 @@ boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFl
m_uniUpdateCount = sharedLayoutBuf + 1;
} else {
if (m_instances.size() <= m_uniUpdateCount) {
inst = PushNewModelInstance(sharedLayoutBuf);
inst = PushNewModelInstance(sharedLayoutBuf, ctx);
if (!inst) {
return {};
}