patch to compile/run on Linux on 2019.2 MDL SDK binary release
idcrook opened this issue · comments
On master, needed to make some edits to compile and build samples with binary MDL SDK release. Didn't see these covered or mentioned elsewhere.
Have the binary MDL SDK (mdl-sdk-325000.1814.zip
) unzipped locally
Summary for compilation (patch below):
- add a stub for
MDL::Logger
virtual function - add a
Sample4D()
and point to with some Sample3D() call sites - chose
data.evaluate.bsdf_diffuse
for.bsdf
from a templatedmi::neuraylib::Bsdf_evaluate_data<mi::neuraylib::DF_HSM_NONE>
struct. not sure if this is the appropriate struct or evaluate.field mapping.
to build and run on my Ubuntu Linux 19.10 machine.
with MDL SDK, installed CUDA SDK (ubuntu 19.10 system toolkit package) and Optix 6.5 SDK (installer)
cd /home/dpc/projects/learning/rt/github/optix/VisRTX/
mkdir build && cd build
cmake \
-D OptiX_INSTALL_DIR="/usr/local/nvidia/NVIDIA-OptiX-SDK-6.5.0-linux64/" \
-D MDL_INSTALL_DIR=$HOME/projects/learning/rt/github/optix/mdl-sdk-325000.1814 \
-D VISRTX_BUILD_SAMPLE=ON \
-B . ..
make
LD_LIBRARY_PATH=$HOME/projects/learning/rt/github/optix/mdl-sdk-325000.1814/linux-x86-64/lib ./visRtxSampleBasic
here's a diff of edits (my editorconfig setting trims whitespace in some paces)
diff --git a/src/MDL/MDL.cpp b/src/MDL/MDL.cpp
index a2f8021..54e8c43 100644
--- a/src/MDL/MDL.cpp
+++ b/src/MDL/MDL.cpp
@@ -481,6 +481,13 @@ public:
this->logFile << "[" << module_category << "] " << message_severity_to_string(level) << ": " << message << std::endl;
}
+ virtual void message( mi::base::Message_severity level,
+ const char * module_category,
+ const mi::base::Message_details & ,
+ const char * message)
+ {
+ }
+
private:
std::ofstream logFile;
};
@@ -879,7 +886,7 @@ MDL::CompiledMaterial MDL::Compile(const MDL::Material& material, bool classComp
&result.pdfProg,
&result.opacityProg,
&result.thinwalledProg,
- &result.iorProg,
+ &result.iorProg,
&result.absorbProg
};
@@ -1020,7 +1027,7 @@ MDL::CompiledMaterial MDL::Compile(const MDL::Material& material, bool classComp
&result.pdfProg,
&result.opacityProg,
&result.thinwalledProg,
- &result.iorProg,
+ &result.iorProg,
&result.absorbProg
};
diff --git a/src/Pathtracer/Pathtracer.cu b/src/Pathtracer/Pathtracer.cu
index 9970e75..47674d5 100644
--- a/src/Pathtracer/Pathtracer.cu
+++ b/src/Pathtracer/Pathtracer.cu
@@ -654,7 +654,8 @@ RT_FUNCTION bool SampleMaterial(PathtracePRD & prd, optix::Ray & ray, VolumeStac
union // Put the BSDF data structs into a union to reduce number of memory writes
{
mi::neuraylib::Bsdf_sample_data sample;
- mi::neuraylib::Bsdf_evaluate_data evaluate;
+ //mi::neuraylib::Bsdf_evaluate_data evaluate;
+ mi::neuraylib::Bsdf_evaluate_data<mi::neuraylib::DF_HSM_NONE> evaluate;
mi::neuraylib::Bsdf_pdf_data pdf;
} data;
@@ -714,7 +715,7 @@ RT_FUNCTION bool SampleMaterial(PathtracePRD & prd, optix::Ray & ray, VolumeStac
data.evaluate.k2 = L;
parameters.evaluate(&data.evaluate, &state, &res_data, NULL, argBlock);
- if (0.0f < data.evaluate.pdf && isNotNull(data.evaluate.bsdf))
+ if (0.0f < data.evaluate.pdf && isNotNull(data.evaluate.bsdf_diffuse))
{
#ifdef TEST_NEE_ONLY
const float misWeight = 1.0f;
@@ -723,7 +724,7 @@ RT_FUNCTION bool SampleMaterial(PathtracePRD & prd, optix::Ray & ray, VolumeStac
const float misWeight = (lightPdf <= 0.0f) ? 1.0f : powerHeuristic(lightPdf * prd.lastLightPdfFactor, data.evaluate.pdf);
#endif
- const optix::float3 radiance = prd.alpha * data.evaluate.bsdf * lightEdf_over_pdf * lightFactor * misWeight; // data.evaluate.bsdf contains: bsdf * dot(normal, k2)
+ const optix::float3 radiance = prd.alpha * data.evaluate.bsdf_diffuse * lightEdf_over_pdf * lightFactor * misWeight; // data.evaluate.bsdf contains: bsdf * dot(normal, k2)
prd.radiance += clampRadiance(prd.depth, launchParameters[0].fireflyClampingIndirect, radiance);
}
}
@@ -731,7 +732,7 @@ RT_FUNCTION bool SampleMaterial(PathtracePRD & prd, optix::Ray & ray, VolumeStac
#endif
// Sample BSDF
- data.sample.xi = Sample3D(prd.randState);
+ data.sample.xi = Sample4D(prd.randState);
parameters.sample(&data.sample, &state, &res_data, NULL, argBlock);
prd.lastPdf = data.sample.pdf;
@@ -784,7 +785,7 @@ RT_FUNCTION bool SampleMaterial(PathtracePRD & prd, optix::Ray & ray, VolumeStac
RT_FUNCTION void Pathtrace(const float3& rayOrigin, const float3& rayDirection, RandState* randState)
{
#ifdef VISRTX_USE_DEBUG_EXCEPTIONS
-#ifdef PRINT_PIXEL_X
+#ifdef PRINT_PIXEL_X
rtPrintf("\n\n--- New frame ---\n");
@@ -865,7 +866,7 @@ RT_FUNCTION void Pathtrace(const float3& rayOrigin, const float3& rayDirection,
}
break;
- }
+ }
else
{
ray.origin = prd.hitPoint;
@@ -1218,7 +1219,7 @@ RT_PROGRAM void AnyHitOcclusion()
//data.ior2 = make_float3(1.f);
data.k1 = optix::normalize(-ray.direction);
- data.xi = Sample3D(shadowPrd.randState);
+ data.xi = Sample4D(shadowPrd.randState);
parameters.sample(&data, &state, &res_data, NULL, argBlock);
if (data.event_type & mi::neuraylib::BSDF_EVENT_TRANSMISSION)
diff --git a/src/Pathtracer/Random.h b/src/Pathtracer/Random.h
index 32560a9..495e9f0 100644
--- a/src/Pathtracer/Random.h
+++ b/src/Pathtracer/Random.h
@@ -55,10 +55,14 @@ RT_FUNCTION optix::float3 Sample3D(RandState* state)
return optix::make_float3(curand_uniform(state), curand_uniform(state), curand_uniform(state));
}
+RT_FUNCTION optix::float4 Sample4D(RandState* state)
+{
+ return optix::make_float4(curand_uniform(state), curand_uniform(state), curand_uniform(state),
+ curand_uniform(state));
+}
+
#else
typedef int RandState;
#endif
-
-
After looking again, guess these were mentioned in the 2019.2 MDL SDK release notes
excerpts from the release notes
-
The signature of the function mi::base::ILogger::message() has been changed.
... -
For evaluating parts of distribution functions that are named by handles,
Bsdf_evaluate_data and Bsdf_auxiliary_data are adapted to select individual
handles. -
A new backend option df_handle_slot_mode to select how evaluate and auxiliary
data is passed between the generated code and the render has been added. -
The bsdf field of Bsdf_evaluate_data is split into bsdf_diffuse and
bsdf_glossy. -
The Bsdf_sample_data structure now requires a 4th uniform random number and
returns the handle of the sampled distribution part.
And I see that someone else made these similar 2019.2 MDL SDK edits mentioned in
https://devtalk.nvidia.com/default/topic/1069194/mdl-sdk/mdl-in-optix-7/post/5419925/#5419925
with a different expression to consume the .bsdf_diffuse/.bsdf_glossy components
Thanks! The relevant fixes for MDL SDK 2019.2 are now in master.