Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1d7c025
Remove unused material graph type parameter
nv-rthomson Sep 2, 2026
68481fb
Compose Method on MDL closest-hit shading from named steps
nv-rthomson Sep 2, 2026
522d566
Compose Method on MDL target code compilation from named steps
nv-rthomson Sep 2, 2026
e1260b4
Extract MDL SDK session to eliminate duplication
nv-rthomson Sep 2, 2026
3abbd31
Extract common MDL signature graph traversal
nv-rthomson Sep 2, 2026
830f92e
Extract MDL SDK test fixture
nv-rthomson Sep 2, 2026
a26f303
Extract MDL handle type aliases
nv-rthomson Sep 2, 2026
cfa9eae
Compose Method on MDL bound material parameter generation
nv-rthomson Sep 2, 2026
6cbbada
Extract common MDL compilation utilities
nv-rthomson Sep 2, 2026
c169cdf
Use field initializers for MDL shader state
nv-rthomson Sep 2, 2026
5440a9f
Centralize generated MDL texture policy
nv-rthomson Sep 2, 2026
d057c94
Unify PBRT texture graph traversal
nv-rthomson Sep 2, 2026
295ab08
Shorten named-material texture helper names
nv-rthomson Sep 2, 2026
0379078
Extract repeated mix binding matcher
nv-rthomson Sep 2, 2026
f520f6b
Compose Method on Fourier BSDF table loading
nv-rthomson Sep 2, 2026
b9c7ffc
Extract Fourier BSDF table test writer
nv-rthomson Sep 2, 2026
ded46e8
Compose Method on Fourier BSDF sampling
nv-rthomson Sep 2, 2026
4f108c4
Replace PBRT material type strings with descriptors
nv-rthomson Sep 2, 2026
b0b7133
Decompose MDL shader cache translation unit
nv-rthomson Sep 2, 2026
78ce0b0
Rename MDL material device source
nv-rthomson Sep 3, 2026
5e41488
Clarify PBRT film parameter warning
nv-rthomson Sep 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion examples/DemandLoading/DemandPbrtScene/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,37 @@ if(OTK_USE_MDL)
find_package(mdl CONFIG REQUIRED)
set(DEMAND_PBRT_SCENE_MDL_CUDA_SOURCES
FourierMaterial.cu
MdlSmokeMaterial.cu
MdlMaterial.cu
)
set(DEMAND_PBRT_SCENE_MDL_LIBRARIES mdl::mdl_sdk)
set(DEMAND_PBRT_SCENE_MDL_SOURCES
FourierBsdfTable.cpp
FourierBsdfTableResource.cpp
MdlBsdfCompiler.cpp
MdlKeyBuilder.cpp
MdlMaterialModelBuilder.cpp
MdlParameterBinder.cpp
MdlSdkSession.cpp
MdlShaderCache.cpp
MdlTextureGraphGenerator.cpp
MdlUtils.cpp
PbrtMaterialKind.cpp
include/DemandPbrtScene/FourierBsdfEval.h
include/DemandPbrtScene/FourierBsdfTable.h
include/DemandPbrtScene/FourierBsdfTableResource.h
include/DemandPbrtScene/FourierMdlMeasuredBsdfCapability.h
include/DemandPbrtScene/MdlBumpMap.h
include/DemandPbrtScene/MdlBsdfCompiler.h
include/DemandPbrtScene/MdlHandleTypes.h
include/DemandPbrtScene/MdlKeyBuilder.h
include/DemandPbrtScene/MdlMaterialModelBuilder.h
include/DemandPbrtScene/MdlParameterBinder.h
include/DemandPbrtScene/MdlSdkSession.h
include/DemandPbrtScene/MdlShaderCache.h
include/DemandPbrtScene/MdlShaderCompileCacheStatistics.h
include/DemandPbrtScene/MdlTextureGraphGenerator.h
include/DemandPbrtScene/MdlUtils.h
include/DemandPbrtScene/PbrtMaterialKind.h
)
endif()

Expand Down
110 changes: 94 additions & 16 deletions examples/DemandLoading/DemandPbrtScene/FourierBsdfTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ FourierBsdfTableLoadResult makeFailure( FourierBsdfTableLoadStatus status, const
return result;
}

FourierBsdfTableLoadResult makeSuccess()
{
FourierBsdfTableLoadResult result{};
result.status = FourierBsdfTableLoadStatus::SUCCESS;
return result;
}

std::string sectionDiagnostic( const std::string& fileName, const std::string& section )
{
return "Truncated Fourier BSDF table \"" + fileName + "\" while reading " + section;
Expand Down Expand Up @@ -155,18 +162,19 @@ std::string unsupportedDiagnostic( const std::string& fileName, const FourierBsd
return out.str();
}

} // namespace

FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
FourierBsdfTableLoadResult readTableHeader( const std::string& fileName,
std::ifstream& input,
std::streamoff& fileSize,
FourierBsdfTable& table )
{
std::ifstream input{ fileName, std::ios::binary | std::ios::ate };
input.open( fileName, std::ios::binary | std::ios::ate );
if( !input )
{
return makeFailure( FourierBsdfTableLoadStatus::FILE_NOT_FOUND,
"Unable to open Fourier BSDF table file \"" + fileName + "\"" );
}

const std::streamoff fileSize{ input.tellg() };
fileSize = input.tellg();
input.seekg( 0, std::ios::beg );

char header[8]{};
Expand All @@ -180,8 +188,7 @@ FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
"Invalid Fourier BSDF table header in \"" + fileName + "\"" );
}

FourierBsdfTable table{};
int unused{};
int unused{};
if( !readInt32( input, table.flags ) || !readInt32( input, table.nMu ) || !readInt32( input, table.nCoefficients )
|| !readInt32( input, table.maxOrder ) || !readInt32( input, table.nChannels )
|| !readInt32( input, table.nBases ) || !readInt32( input, unused ) || !readInt32( input, unused )
Expand All @@ -190,7 +197,11 @@ FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
{
return makeFailure( FourierBsdfTableLoadStatus::TRUNCATED, sectionDiagnostic( fileName, "metadata" ) );
}
return makeSuccess();
}

FourierBsdfTableLoadResult validateMetadata( const std::string& fileName, const FourierBsdfTable& table )
{
if( table.flags != 1 || ( table.nChannels != 1 && table.nChannels != 3 ) || table.nBases != 1 )
{
return makeFailure( FourierBsdfTableLoadStatus::UNSUPPORTED, unsupportedDiagnostic( fileName, table ) );
Expand All @@ -200,15 +211,29 @@ FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
return makeFailure( FourierBsdfTableLoadStatus::MALFORMED,
"Malformed Fourier BSDF table \"" + fileName + "\": invalid dimensions" );
}
return makeSuccess();
}

FourierBsdfTableLoadResult computeGridSize( const std::string& fileName,
const FourierBsdfTable& table,
std::size_t& gridSize )
{
const std::size_t nMu{ static_cast<std::size_t>( table.nMu ) };
std::size_t gridSize{};
if( !checkedMultiply( nMu, nMu, gridSize ) )
{
return makeFailure( FourierBsdfTableLoadStatus::MALFORMED,
"Malformed Fourier BSDF table \"" + fileName + "\": dimension overflow" );
}
return makeSuccess();
}

FourierBsdfTableLoadResult readArrays( std::istream& input,
const std::string& fileName,
std::size_t gridSize,
FourierBsdfTable& table,
std::vector<int>& offsetsAndLengths )
{
const std::size_t nMu{ static_cast<std::size_t>( table.nMu ) };
if( !readFloatVector( input, table.mu, nMu ) )
{
return makeFailure( FourierBsdfTableLoadStatus::TRUNCATED, sectionDiagnostic( fileName, "mu values" ) );
Expand All @@ -224,8 +249,7 @@ FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
return makeFailure( FourierBsdfTableLoadStatus::MALFORMED,
"Malformed Fourier BSDF table \"" + fileName + "\": offset table overflow" );
}
std::vector<int> offsetAndLength;
if( !readInt32Vector( input, offsetAndLength, offsetPairCount ) )
if( !readInt32Vector( input, offsetsAndLengths, offsetPairCount ) )
{
return makeFailure( FourierBsdfTableLoadStatus::TRUNCATED,
sectionDiagnostic( fileName, "coefficient offsets" ) );
Expand All @@ -234,25 +258,35 @@ FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
{
return makeFailure( FourierBsdfTableLoadStatus::TRUNCATED, sectionDiagnostic( fileName, "coefficients" ) );
}
return makeSuccess();
}

FourierBsdfTableLoadResult validateCoefficientSpans( const std::string& fileName,
const std::vector<int>& offsetsAndLengths,
std::size_t gridSize,
FourierBsdfTable& table )
{
table.coefficientOffsets.resize( gridSize );
table.coefficientCounts.resize( gridSize );
table.zeroOrderCoefficients.resize( gridSize );
for( std::size_t i = 0; i < gridSize; ++i )
{
const int offset{ offsetAndLength[2U * i] };
const int length{ offsetAndLength[2U * i + 1U] };
const int offset{ offsetsAndLengths[2U * i] };
const int length{ offsetsAndLengths[2U * i + 1U] };
if( offset < 0 || length < 0 || length > table.maxOrder )
{
return makeFailure( FourierBsdfTableLoadStatus::MALFORMED,
"Malformed Fourier BSDF table \"" + fileName + "\": invalid coefficient span" );
}

std::size_t channelCoefficientCount{};
if( !checkedMultiply( static_cast<std::size_t>( length ), static_cast<std::size_t>( table.nChannels ), channelCoefficientCount ) )
if( !checkedMultiply( static_cast<std::size_t>( length ), static_cast<std::size_t>( table.nChannels ),
channelCoefficientCount ) )
{
return makeFailure( FourierBsdfTableLoadStatus::MALFORMED,
"Malformed Fourier BSDF table \"" + fileName + "\": coefficient span overflow" );
}

std::size_t spanEnd{};
if( !checkedAdd( static_cast<std::size_t>( offset ), channelCoefficientCount, spanEnd )
|| spanEnd > table.coefficients.size() )
Expand All @@ -266,17 +300,61 @@ FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
table.coefficientCounts[i] = length;
table.zeroOrderCoefficients[i] = length > 0 ? table.coefficients[static_cast<std::size_t>( offset )] : 0.0f;
}
return makeSuccess();
}

void recordTrailingByteCount( std::istream& input, std::streamoff fileSize, FourierBsdfTable& table )
{
const std::streamoff tableEnd{ input.tellg() };
if( tableEnd >= 0 && fileSize >= tableEnd )
{
table.trailingByteCount = static_cast<std::size_t>( fileSize - tableEnd );
}
}

FourierBsdfTableLoadResult result{};
result.status = FourierBsdfTableLoadStatus::SUCCESS;
result.table = std::move( table );
FourierBsdfTableLoadResult makeSuccess( FourierBsdfTable&& table )
{
FourierBsdfTableLoadResult result{ makeSuccess() };
result.table = std::move( table );
return result;
}

} // namespace

FourierBsdfTableLoadResult loadFourierBsdfTable( const std::string& fileName )
{
std::ifstream input;
std::streamoff fileSize{};
FourierBsdfTable table{};
std::size_t gridSize{};
std::vector<int> offsetsAndLengths;

if( const FourierBsdfTableLoadResult result{ readTableHeader( fileName, input, fileSize, table ) }; !result )
{
return result;
}
if( const FourierBsdfTableLoadResult result{ validateMetadata( fileName, table ) }; !result )
{
return result;
}
if( const FourierBsdfTableLoadResult result{ computeGridSize( fileName, table, gridSize ) }; !result )
{
return result;
}
if( const FourierBsdfTableLoadResult result{ readArrays( input, fileName, gridSize, table, offsetsAndLengths ) };
!result )
{
return result;
}
if( const FourierBsdfTableLoadResult result{
validateCoefficientSpans( fileName, offsetsAndLengths, gridSize, table ) };
!result )
{
return result;
}

recordTrailingByteCount( input, fileSize, table );
return makeSuccess( std::move( table ) );
}

} // namespace demandPbrtScene
Loading