Skip to content

Commit d1ba9c9

Browse files
committed
Merge branch 'pkristof/unlimited_budget_support' into 'main'
[REMIX-2619] Support unlimited OMM budgets See merge request lightspeedrtx/dxvk-remix-nv!680
2 parents f6a8c8a + fe955e9 commit d1ba9c9

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

src/dxvk/rtx_render/rtx_opacity_micromap_manager.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,10 +1340,26 @@ namespace dxvk {
13401340
desc.resolveTransparencyThreshold = std::max(desc.resolveTransparencyThreshold, OpacityMicromapOptions::Building::decalsMinResolveTransparencyThreshold());
13411341

13421342
const auto& samplers = ctx->getCommonObjects()->getSceneManager().getSamplerTable();
1343-
ctx->getCommonObjects()->metaGeometryUtils().dispatchBakeOpacityMicromap(
1344-
ctx, blasEntry.modifiedGeometryData,
1345-
textures, samplers, instance.getAlbedoOpacityTextureIndex(), instance.getSamplerIndex(), instance.getSecondaryOpacityTextureIndex(), instance.getSecondarySamplerIndex(),
1346-
desc, ommCacheItem.bakingState, ommCacheItem.ommArrayBuffer);
1343+
1344+
// Bake micro triangles
1345+
do {
1346+
ctx->getCommonObjects()->metaGeometryUtils().dispatchBakeOpacityMicromap(
1347+
ctx, blasEntry.modifiedGeometryData,
1348+
textures, samplers, instance.getAlbedoOpacityTextureIndex(), instance.getSamplerIndex(), instance.getSecondaryOpacityTextureIndex(), instance.getSecondarySamplerIndex(),
1349+
desc, ommCacheItem.bakingState, ommCacheItem.ommArrayBuffer);
1350+
1351+
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
1352+
desc.maxNumMicroTrianglesToBake = UINT32_MAX;
1353+
1354+
// There are more micro triangles to bake
1355+
if (ommCacheItem.bakingState.numMicroTrianglesBaked < ommCacheItem.bakingState.numMicroTrianglesToBake) {
1356+
continue;
1357+
}
1358+
}
1359+
1360+
// Exit the loop
1361+
break;
1362+
} while (true);
13471363

13481364
ctx->getCommandList()->trackResource<DxvkAccess::Write>(ommCacheItem.ommArrayBuffer);
13491365

@@ -1534,6 +1550,10 @@ namespace dxvk {
15341550

15351551
ScopedGpuProfileZone(ctx, "Bake Opacity Micromap Arrays");
15361552

1553+
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
1554+
maxMicroTrianglesToBake = UINT32_MAX;
1555+
}
1556+
15371557
for (auto ommSrcHashIter = m_unprocessedList.begin(); ommSrcHashIter != m_unprocessedList.end() && maxMicroTrianglesToBake > 0; ) {
15381558
XXH64_hash_t ommSrcHash = *ommSrcHashIter;
15391559

@@ -1575,8 +1595,11 @@ namespace dxvk {
15751595
ommCacheItem.isUnprocessedCacheStateListIterValid = false;
15761596
}
15771597
else {
1578-
// Do nothing, else path means all the budget has been used up and thus the loop will exit due to maxMicroTrianglesToBake == 0
1579-
// so don't need to increment the iterator
1598+
// Do nothing, else path means all the budget has been used up and thus the loop will exit due to maxMicroTrianglesToBake == 0
1599+
// so don't need to increment the iterator
1600+
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
1601+
ONCE(Logger::err("[RTX Opacity Micromap] Failed to fully bake an Opacity Micromap due to budget limits even with unlimited budgetting enabled."));
1602+
}
15801603
}
15811604
} else if (result == OmmResult::OutOfMemory) {
15821605
// Do nothing, try the next one
@@ -1603,6 +1626,10 @@ namespace dxvk {
16031626
Logger::warn(str::format("[RTX Opacity Micromap] ~Baking ", ommSrcHash, " on thread_id ", std::this_thread::get_id()));
16041627
#endif
16051628
}
1629+
1630+
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
1631+
maxMicroTrianglesToBake = UINT32_MAX;
1632+
}
16061633
}
16071634

16081635
void OpacityMicromapManager::buildOpacityMicromapsInternal(Rc<DxvkContext> ctx,
@@ -1637,6 +1664,10 @@ namespace dxvk {
16371664
std::vector<VkMicromapBuildInfoEXT> micromapBuildInfos(maxBuildItems);
16381665
uint32_t buildItemCount = 0;
16391666

1667+
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
1668+
maxMicroTrianglesToBuild = UINT32_MAX;
1669+
}
1670+
16401671
// Force at least one build since a build can't be split across frames even if doesn't fit within the budget
16411672
// They're cheap regardless, so it should be fine.
16421673
bool forceOmmBuild = maxMicroTrianglesToBuild > 0;
@@ -1673,6 +1704,10 @@ namespace dxvk {
16731704
} else if (result == OmmResult::OutOfBudget) {
16741705
// Do nothing, continue onto the next
16751706
ommSrcHashIter++;
1707+
1708+
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
1709+
ONCE(Logger::err("[RTX Opacity Micromap] Failed to fully build an Opacity Micromap due to budget limits even with unlimited budgetting enabled."));
1710+
}
16761711
} else if (result == OmmResult::OutOfMemory) {
16771712
// Do nothing, try the next one
16781713
ommSrcHashIter++;
@@ -1684,6 +1719,10 @@ namespace dxvk {
16841719
#ifdef VALIDATION_MODE
16851720
Logger::warn(str::format("[RTX Opacity Micromap] ~Building ", ommSrcHash, " on thread_id ", std::this_thread::get_id()));
16861721
#endif
1722+
1723+
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
1724+
maxMicroTrianglesToBuild = UINT32_MAX;
1725+
}
16871726
}
16881727

16891728
if (buildItemCount > 0) {

src/dxvk/rtx_render/rtx_opacity_micromap_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ namespace dxvk {
111111
"Max Micro Triangles to bake [Million/Second].\n"
112112
"The actual number of issued micro triangles also depends on \"costPerTexelTapPerMicroTriangleBudget\" option.");
113113
RTX_OPTION("rtx.opacityMicromap.building", int, maxMicroTrianglesToBuildMillionPerSecond, 60 * 5, "Max Micro Triangles to build [Million/Second].");
114+
RTX_OPTION_ENV("rtx.opacityMicromap.building", bool, enableUnlimitedBakingAndBuildingBudgets, false,
115+
"RTX_OPACITY_MICROMAP_BUILDING_UNLIMITED_BAKING_AND_BUILDING_BUDGETS",
116+
"Enables unlimited baking and building budgets so that all available Opacity Micromaps are generated in a frame.");
114117

115118
// Disabled for now as camera cuts occur even on non-camera movements, i.e. when
116119
// a plasma ball hits a sink, to avoid increased workload during those moments/gameplay

0 commit comments

Comments
 (0)