Skip to content

Commit

Permalink
Merge branch 'pkristof/unlimited_budget_support' into 'main'
Browse files Browse the repository at this point in the history
[REMIX-2619] Support unlimited OMM budgets

See merge request lightspeedrtx/dxvk-remix-nv!680
  • Loading branch information
pkristof committed Jan 22, 2024
2 parents f6a8c8a + fe955e9 commit d1ba9c9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
51 changes: 45 additions & 6 deletions src/dxvk/rtx_render/rtx_opacity_micromap_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,10 +1340,26 @@ namespace dxvk {
desc.resolveTransparencyThreshold = std::max(desc.resolveTransparencyThreshold, OpacityMicromapOptions::Building::decalsMinResolveTransparencyThreshold());

const auto& samplers = ctx->getCommonObjects()->getSceneManager().getSamplerTable();
ctx->getCommonObjects()->metaGeometryUtils().dispatchBakeOpacityMicromap(
ctx, blasEntry.modifiedGeometryData,
textures, samplers, instance.getAlbedoOpacityTextureIndex(), instance.getSamplerIndex(), instance.getSecondaryOpacityTextureIndex(), instance.getSecondarySamplerIndex(),
desc, ommCacheItem.bakingState, ommCacheItem.ommArrayBuffer);

// Bake micro triangles
do {
ctx->getCommonObjects()->metaGeometryUtils().dispatchBakeOpacityMicromap(
ctx, blasEntry.modifiedGeometryData,
textures, samplers, instance.getAlbedoOpacityTextureIndex(), instance.getSamplerIndex(), instance.getSecondaryOpacityTextureIndex(), instance.getSecondarySamplerIndex(),
desc, ommCacheItem.bakingState, ommCacheItem.ommArrayBuffer);

if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
desc.maxNumMicroTrianglesToBake = UINT32_MAX;

// There are more micro triangles to bake
if (ommCacheItem.bakingState.numMicroTrianglesBaked < ommCacheItem.bakingState.numMicroTrianglesToBake) {
continue;
}
}

// Exit the loop
break;
} while (true);

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

Expand Down Expand Up @@ -1534,6 +1550,10 @@ namespace dxvk {

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

if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
maxMicroTrianglesToBake = UINT32_MAX;
}

for (auto ommSrcHashIter = m_unprocessedList.begin(); ommSrcHashIter != m_unprocessedList.end() && maxMicroTrianglesToBake > 0; ) {
XXH64_hash_t ommSrcHash = *ommSrcHashIter;

Expand Down Expand Up @@ -1575,8 +1595,11 @@ namespace dxvk {
ommCacheItem.isUnprocessedCacheStateListIterValid = false;
}
else {
// Do nothing, else path means all the budget has been used up and thus the loop will exit due to maxMicroTrianglesToBake == 0
// so don't need to increment the iterator
// Do nothing, else path means all the budget has been used up and thus the loop will exit due to maxMicroTrianglesToBake == 0
// so don't need to increment the iterator
if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
ONCE(Logger::err("[RTX Opacity Micromap] Failed to fully bake an Opacity Micromap due to budget limits even with unlimited budgetting enabled."));
}
}
} else if (result == OmmResult::OutOfMemory) {
// Do nothing, try the next one
Expand All @@ -1603,6 +1626,10 @@ namespace dxvk {
Logger::warn(str::format("[RTX Opacity Micromap] ~Baking ", ommSrcHash, " on thread_id ", std::this_thread::get_id()));
#endif
}

if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
maxMicroTrianglesToBake = UINT32_MAX;
}
}

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

if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
maxMicroTrianglesToBuild = UINT32_MAX;
}

// Force at least one build since a build can't be split across frames even if doesn't fit within the budget
// They're cheap regardless, so it should be fine.
bool forceOmmBuild = maxMicroTrianglesToBuild > 0;
Expand Down Expand Up @@ -1673,6 +1704,10 @@ namespace dxvk {
} else if (result == OmmResult::OutOfBudget) {
// Do nothing, continue onto the next
ommSrcHashIter++;

if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
ONCE(Logger::err("[RTX Opacity Micromap] Failed to fully build an Opacity Micromap due to budget limits even with unlimited budgetting enabled."));
}
} else if (result == OmmResult::OutOfMemory) {
// Do nothing, try the next one
ommSrcHashIter++;
Expand All @@ -1684,6 +1719,10 @@ namespace dxvk {
#ifdef VALIDATION_MODE
Logger::warn(str::format("[RTX Opacity Micromap] ~Building ", ommSrcHash, " on thread_id ", std::this_thread::get_id()));
#endif

if (OpacityMicromapOptions::Building::enableUnlimitedBakingAndBuildingBudgets()) {
maxMicroTrianglesToBuild = UINT32_MAX;
}
}

if (buildItemCount > 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/dxvk/rtx_render/rtx_opacity_micromap_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ namespace dxvk {
"Max Micro Triangles to bake [Million/Second].\n"
"The actual number of issued micro triangles also depends on \"costPerTexelTapPerMicroTriangleBudget\" option.");
RTX_OPTION("rtx.opacityMicromap.building", int, maxMicroTrianglesToBuildMillionPerSecond, 60 * 5, "Max Micro Triangles to build [Million/Second].");
RTX_OPTION_ENV("rtx.opacityMicromap.building", bool, enableUnlimitedBakingAndBuildingBudgets, false,
"RTX_OPACITY_MICROMAP_BUILDING_UNLIMITED_BAKING_AND_BUILDING_BUDGETS",
"Enables unlimited baking and building budgets so that all available Opacity Micromaps are generated in a frame.");

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

0 comments on commit d1ba9c9

Please sign in to comment.