Skip to content

Commit

Permalink
V1.5.0 (#57)
Browse files Browse the repository at this point in the history
* Adding compression support for serialized data
* Adding option to change the default special index of degenerate triangles (default is fully unknown opaque)
* Adding validation logic to warn about degenerate triangles
* Renaming bake flags to something more generic (EnableWorkloadValidation => EnableValidation)
  • Loading branch information
nv-jdeligiannis authored Oct 14, 2024
1 parent 2f42f5a commit baf2bc9
Show file tree
Hide file tree
Showing 14 changed files with 819 additions and 197 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "thirdparty/ShaderMake"]
path = thirdparty/ShaderMake
url = https://github.com/NVIDIAGameWorks/ShaderMake.git
[submodule "thirdparty/lz4"]
path = thirdparty/lz4
url = https://github.com/lz4/lz4.git
2 changes: 1 addition & 1 deletion omm-sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if(OMM_ENABLE_OPENMP AND OpenMP_CXX_FOUND)
endif()
endif()

target_link_libraries(${TARGET_NAME} omm-shared glm stb_lib xxHash::xxhash)
target_link_libraries(${TARGET_NAME} omm-shared glm stb_lib xxHash::xxhash lz4_static)

set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
target_include_directories(${TARGET_NAME} PUBLIC "include")
Expand Down
12 changes: 9 additions & 3 deletions omm-sdk/include/omm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include <stddef.h>

#define OMM_VERSION_MAJOR 1
#define OMM_VERSION_MINOR 4
#define OMM_VERSION_MINOR 5
#define OMM_VERSION_BUILD 0

#define OMM_MAX_TRANSIENT_POOL_BUFFERS 8
Expand Down Expand Up @@ -321,8 +321,11 @@ typedef enum ommCpuBakeFlags
ommCpuBakeFlags_EnableNearDuplicateDetection = 1u << 4,

// Enable additional validation, when enabled additional processing is performed to validate quality and sanity of input data
// which may help diagnose longer than expected bake time.
ommCpuBakeFlags_EnableWorkloadValidation = 1u << 5,
// which may help diagnose omm bake result or longer than expected bake times.
// *** NOTE messageInterface must be set when using this flag ***
ommCpuBakeFlags_EnableValidation = 1u << 5,

ommCpuBakeFlags_EnableWorkloadValidation OMM_DEPRECATED_MSG("EnableWorkloadValidation is deprecated, use EnableValidation instead") = 1u << 5,

} ommCpuBakeFlags;
OMM_DEFINE_ENUM_FLAG_OPERATORS(ommCpuBakeFlags);
Expand Down Expand Up @@ -417,6 +420,8 @@ typedef struct ommCpuBakeInputDesc
const ommFormat* formats;
// Determines how to promote mixed states
ommUnknownStatePromotion unknownStatePromotion;
// Determines the state of unresolvable/degenerate triangles (nan/inf or zeroa area UV-triangles)
ommSpecialIndex degenTriState;
// Micro triangle count is 4^N, where N is the subdivision level.
// maxSubdivisionLevel level must be in range [0, 12].
// When dynamicSubdivisionScale is enabled maxSubdivisionLevel is the max subdivision level allowed.
Expand Down Expand Up @@ -461,6 +466,7 @@ inline ommCpuBakeInputDesc ommCpuBakeInputDescDefault()
v.format = ommFormat_OC1_4_State;
v.formats = NULL;
v.unknownStatePromotion = ommUnknownStatePromotion_ForceOpaque;
v.degenTriState = ommSpecialIndex_FullyUnknownOpaque;
v.maxSubdivisionLevel = 8;
v.subdivisionLevels = NULL;
v.maxWorkloadSize = 0;
Expand Down
9 changes: 7 additions & 2 deletions omm-sdk/include/omm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ namespace omm
EnableNearDuplicateDetection = 1u << 4,

// Enable additional validation, when enabled additional processing is performed to validate quality and sanity of input data
// which may help diagnose longer than expected bake time.
EnableWorkloadValidation = 1u << 5,
// which may help diagnose omm bake result or longer than expected bake times.
// *** NOTE messageInterface must be set when using this flag ***
EnableValidation = 1u << 5,

EnableWorkloadValidation OMM_DEPRECATED_MSG("EnableWorkloadValidation is deprecated, use EnableValidation instead") = 1u << 5,
};
OMM_DEFINE_ENUM_FLAG_OPERATORS(BakeFlags);

Expand Down Expand Up @@ -313,6 +316,8 @@ namespace omm
const Format* formats = nullptr;
// Determines how to promote mixed states
UnknownStatePromotion unknownStatePromotion = UnknownStatePromotion::ForceOpaque;
// Determines the state of unresolvable/degenerate triangles (nan/inf or zeroa area UV-triangles)
SpecialIndex degenTriState = SpecialIndex::FullyUnknownOpaque;
// Micro triangle count is 4^N, where N is the subdivision level.
// maxSubdivisionLevel level must be in range [0, 12].
// When dynamicSubdivisionScale is enabled maxSubdivisionLevel is the max subdivision level allowed.
Expand Down
28 changes: 19 additions & 9 deletions omm-sdk/src/bake_cpu_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Cpu
Force32BitIndices = 1u << 2,
DisableDuplicateDetection = 1u << 3,
EnableNearDuplicateDetection = 1u << 4,
EnableWorkloadValidation = 1u << 5,
EnableValidation = 1u << 5,

// Internal / not publicly exposed options.
EnableAABBTesting = 1u << 6,
Expand All @@ -55,7 +55,7 @@ namespace Cpu
static_assert((uint32_t)BakeFlagsInternal::DisableSpecialIndices == (uint32_t)ommCpuBakeFlags_DisableSpecialIndices);
static_assert((uint32_t)BakeFlagsInternal::DisableDuplicateDetection == (uint32_t)ommCpuBakeFlags_DisableDuplicateDetection);
static_assert((uint32_t)BakeFlagsInternal::EnableNearDuplicateDetection == (uint32_t)ommCpuBakeFlags_EnableNearDuplicateDetection);
static_assert((uint32_t)BakeFlagsInternal::EnableWorkloadValidation == (uint32_t)ommCpuBakeFlags_EnableWorkloadValidation);
static_assert((uint32_t)BakeFlagsInternal::EnableValidation == (uint32_t)ommCpuBakeFlags_EnableValidation);
}

struct Options
Expand All @@ -66,7 +66,7 @@ namespace Cpu
disableDuplicateDetection(((uint32_t)flags& (uint32_t)BakeFlagsInternal::DisableDuplicateDetection) == (uint32_t)BakeFlagsInternal::DisableDuplicateDetection),
enableNearDuplicateDetection(((uint32_t)flags& (uint32_t)BakeFlagsInternal::EnableNearDuplicateDetection) == (uint32_t)BakeFlagsInternal::EnableNearDuplicateDetection),
enableNearDuplicateDetectionBruteForce(((uint32_t)flags& (uint32_t)BakeFlagsInternal::EnableNearDuplicateDetectionBruteForce) == (uint32_t)BakeFlagsInternal::EnableNearDuplicateDetectionBruteForce),
enableWorkloadValidation(((uint32_t)flags& (uint32_t)BakeFlagsInternal::EnableWorkloadValidation) == (uint32_t)BakeFlagsInternal::EnableWorkloadValidation),
enableValidation(((uint32_t)flags& (uint32_t)BakeFlagsInternal::EnableValidation) == (uint32_t)BakeFlagsInternal::EnableValidation),
enableAABBTesting(((uint32_t)flags& (uint32_t)BakeFlagsInternal::EnableAABBTesting) == (uint32_t)BakeFlagsInternal::EnableAABBTesting),
disableRemovePoorQualityOMM(((uint32_t)flags& (uint32_t)BakeFlagsInternal::DisableRemovePoorQualityOMM) == (uint32_t)BakeFlagsInternal::DisableRemovePoorQualityOMM),
disableLevelLineIntersection(((uint32_t)flags& (uint32_t)BakeFlagsInternal::DisableLevelLineIntersection) == (uint32_t)BakeFlagsInternal::DisableLevelLineIntersection),
Expand All @@ -77,7 +77,7 @@ namespace Cpu
const bool disableDuplicateDetection;
const bool enableNearDuplicateDetection;
const bool enableNearDuplicateDetectionBruteForce;
const bool enableWorkloadValidation;
const bool enableValidation;
const bool enableAABBTesting;
const bool disableRemovePoorQualityOMM;
const bool disableLevelLineIntersection;
Expand Down Expand Up @@ -216,8 +216,8 @@ namespace Cpu
{
return m_log.InvalidArg("[Invalid Argument] - EnableNearDuplicateDetection or EnableNearDuplicateDetectionBruteForce is used together with DisableDuplicateDetection");
}
if (options.enableWorkloadValidation && !m_log.HasLogger())
return m_log.InvalidArg("[Invalid Argument] - EnableWorkloadValidation is set but not message callback was provided"); // this works more as documentation since it won't be logged
if (options.enableValidation && !m_log.HasLogger())
return m_log.InvalidArg("[Invalid Argument] - EnableValidation is set but no message callback was provided"); // this works more as documentation since it won't be logged

if (TextureImpl* texture = GetHandleImpl<TextureImpl>(desc.texture))
{
Expand Down Expand Up @@ -506,6 +506,8 @@ namespace Cpu
{
const uint32_t texCoordStrideInBytes = desc.texCoordStrideInBytes == 0 ? GetTexCoordFormatSize(desc.texCoordFormat) : desc.texCoordStrideInBytes;

uint32_t numDegenTri = 0;

for (int32_t i = 0; i < triangleCount; ++i)
{
uint32_t triangleIndices[3];
Expand All @@ -520,6 +522,7 @@ namespace Cpu

if (bIsDisabled || bIsDegenerate)
{
numDegenTri++;
continue; // These indices will be set to special index unknown later.
}

Expand Down Expand Up @@ -552,6 +555,13 @@ namespace Cpu
vmWorkItems[it->second].primitiveIndices.push_back(i);
}
}

if (options.enableValidation && numDegenTri != 0)
{
const char* specialIndex = ToString(desc.degenTriState);
log.Infof("[Info] - The workload consists of %d degenerate triangles, these will be classified as Fully Unknown Opaque (this behaviour can be changed by degenTriState).",
numDegenTri, specialIndex);
}
}
return ommResult_SUCCESS;
}
Expand Down Expand Up @@ -581,7 +591,7 @@ namespace Cpu
{
const bool limitWorkloadSize = desc.maxWorkloadSize != 0xFFFFFFFFFFFFFFFF;

if (!options.enableWorkloadValidation && !limitWorkloadSize)
if (!options.enableValidation && !limitWorkloadSize)
return ommResult_SUCCESS;

uint64_t workloadSize = ComputeWorkloadSize(desc, ommWorkItems);
Expand All @@ -594,7 +604,7 @@ namespace Cpu
}
}

if (options.enableWorkloadValidation)
if (options.enableValidation)
{
const uint64_t warnSize = 1ull << 27ull; // 128 * 1024x1024 texels.
if (workloadSize > warnSize)
Expand Down Expand Up @@ -1503,7 +1513,7 @@ namespace Cpu
// Set special indices...
{
res.ommIndexBuffer.resize(triangleCount);
std::fill(res.ommIndexBuffer.begin(), res.ommIndexBuffer.end(), (int32_t)ommSpecialIndex_FullyUnknownOpaque);
std::fill(res.ommIndexBuffer.begin(), res.ommIndexBuffer.end(), (int32_t)desc.degenTriState);
for (const OmmWorkItem& vm : vmWorkItems)
{
for (uint32_t primitiveIndex : vm.primitiveIndices)
Expand Down
18 changes: 18 additions & 0 deletions omm-sdk/src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

namespace omm
{
static const char* ToString(ommSpecialIndex specialIndex)
{
switch (specialIndex)
{
case ommSpecialIndex_FullyTransparent: return "Fully Transparent";
case ommSpecialIndex_FullyOpaque: return "Fully Opaque";
case ommSpecialIndex_FullyUnknownTransparent: return "Fully Unknown Transparent";
case ommSpecialIndex_FullyUnknownOpaque: return "Fully Unknown Opaque";
default: return "Unknown State";
}
}

class Logger
{
public:
Expand All @@ -36,6 +48,12 @@ namespace omm
_Log(ommMessageSeverity_Info, msg);
}

template<int N = 256, typename... Args>
void Infof(const char* format, Args&&... args) const
{
_Logf<N>(ommMessageSeverity_Info, format, std::forward<Args>(args)...);
}

void PerfWarn(const char* msg) const
{
_Log(ommMessageSeverity_PerfWarning, msg);
Expand Down
Loading

0 comments on commit baf2bc9

Please sign in to comment.