diff --git a/Source/Falcor/Scene/GVDB/gvdbNodes.slang b/Source/Falcor/Scene/GVDB/gvdbNodes.slang index 17ee6d5..010869a 100644 --- a/Source/Falcor/Scene/GVDB/gvdbNodes.slang +++ b/Source/Falcor/Scene/GVDB/gvdbNodes.slang @@ -183,7 +183,7 @@ VDBNode getNodeUnrolledThreeLevel(VDBInfo gvdb, int mipId, int lev, int start_id { vmax = vmin + 4096.f; - if (any((pos < vmin) || (pos >= vmax))) + if (any(pos < vmin) || any(pos >= vmax)) { node_id = ID_UNDEFL; return {}; @@ -202,7 +202,7 @@ VDBNode getNodeUnrolledThreeLevel(VDBInfo gvdb, int mipId, int lev, int start_id { vmax = vmin + 128.f; - if (any((pos < vmin) || (pos >= vmax))) + if (any(pos < vmin) || any(pos >= vmax)) { node_id = ID_UNDEFL; return {}; @@ -234,7 +234,7 @@ VDBNode getNodeUnrolledTwoLevel(VDBInfo gvdb, int mipId, int lev, int start_id, { vmax = vmin + 128.f; - if (any((pos < vmin) || (pos >= vmax))) + if (any(pos < vmin) || any(pos >= vmax)) { node_id = ID_UNDEFL; return {}; diff --git a/Source/Falcor/Utils/Algorithm/ComputeParallelReduction.cpp b/Source/Falcor/Utils/Algorithm/ComputeParallelReduction.cpp index 6c8dc7f..068682f 100644 --- a/Source/Falcor/Utils/Algorithm/ComputeParallelReduction.cpp +++ b/Source/Falcor/Utils/Algorithm/ComputeParallelReduction.cpp @@ -104,9 +104,9 @@ namespace Falcor // Check that reduction type T is compatible with the resource format. if (sizeof(typename T::value_type) != 4 || // The shader is written for 32-bit types - (formatType == FORMAT_TYPE_FLOAT && !std::is_floating_point::value) || - (formatType == FORMAT_TYPE_SINT && (!std::is_integral::value || !std::is_signed::value)) || - (formatType == FORMAT_TYPE_UINT && (!std::is_integral::value || !std::is_unsigned::value))) + (formatType == FORMAT_TYPE_FLOAT && !std::is_floating_point::value) || + (formatType == FORMAT_TYPE_SINT && (!std::is_integral::value || !std::is_signed::value)) || + (formatType == FORMAT_TYPE_UINT && (!std::is_integral::value || !std::is_unsigned::value))) { logError("ComputeParallelReduction::execute() - Template type T is not compatible with resource format. Aborting."); return false; diff --git a/Source/Falcor/Utils/Helpers.slang b/Source/Falcor/Utils/Helpers.slang index 9aae328..0e506e0 100644 --- a/Source/Falcor/Utils/Helpers.slang +++ b/Source/Falcor/Utils/Helpers.slang @@ -97,11 +97,16 @@ float3 computeRayOrigin(float3 pos, float3 normal) // Per-component integer offset to bit representation of fp32 position. int3 iOff = int3(normal * iScale); - float3 iPos = asfloat(asint(pos) + (pos < 0.f ? -iOff : iOff)); + float3 iPos = asfloat(asint(pos) + int3(pos.x < 0.f ? -iOff.x : iOff.x, + pos.y < 0.f ? -iOff.y : iOff.y, + pos.z < 0.f ? -iOff.z : iOff.z)); // Select per-component between small fixed offset or above variable offset depending on distance to origin. float3 fOff = normal * fScale; - return abs(pos) < origin ? pos + fOff : iPos; + bool3 s = abs(pos) < origin; + return float3(s.x ? pos.x + fOff.x : iPos.x, + s.y ? pos.y + fOff.y : iPos.y, + s.z ? pos.z + fOff.z : iPos.z); } /** Ray-sphere intersection. diff --git a/Source/Falcor/Utils/Math/MathHelpers.slang b/Source/Falcor/Utils/Math/MathHelpers.slang index 35be10c..bd2316a 100644 --- a/Source/Falcor/Utils/Math/MathHelpers.slang +++ b/Source/Falcor/Utils/Math/MathHelpers.slang @@ -127,7 +127,7 @@ float3 latlong_map_to_world(float2 uv) */ float2 oct_wrap(float2 v) { - return (1.f - abs(v.yx)) * (v.xy >= 0.f ? 1.f : -1.f); + return (1.f - abs(v.yx)) * float2(v.x >= 0.f ? 1.f : -1.f, v.y >= 0.f ? 1.f : -1.f); } /** Converts normalized direction to the octahedral map (non-equal area, signed normalized). diff --git a/Source/Falcor/Utils/UI/Gui.cpp b/Source/Falcor/Utils/UI/Gui.cpp index bb919c7..732eb2b 100644 --- a/Source/Falcor/Utils/UI/Gui.cpp +++ b/Source/Falcor/Utils/UI/Gui.cpp @@ -753,19 +753,19 @@ namespace Falcor template bool GuiImpl::addVecVar(const char label[], T& var, typename T::value_type minVal, typename T::value_type maxVal, float step, bool sameLine, const char* displayFormat) { - if (std::is_same::value) + if (std::is_same::value) { return addVecVarHelper(label, var, ImGuiDataType_S32, minVal, maxVal, step, sameLine, displayFormat); } - else if (std::is_same::value) + else if (std::is_same::value) { return addVecVarHelper(label, var, ImGuiDataType_U32, minVal, maxVal, step, sameLine, displayFormat); } - else if (std::is_same::value) + else if (std::is_same::value) { return addVecVarHelper(label, var, ImGuiDataType_Float, minVal, maxVal, step, sameLine, displayFormat); } - else if (std::is_same::value) + else if (std::is_same::value) { return addVecVarHelper(label, var, ImGuiDataType_U64, minVal, maxVal, step, sameLine, displayFormat); } @@ -789,15 +789,15 @@ namespace Falcor template bool GuiImpl::addVecSlider(const char label[], T& var, typename T::value_type minVal, typename T::value_type maxVal, bool sameLine, const char* displayFormat) { - if (std::is_same::value) + if (std::is_same::value) { return addVecSliderHelper(label, var, ImGuiDataType_S32, minVal, maxVal, sameLine, displayFormat); } - else if (std::is_same::value) + else if (std::is_same::value) { return addVecSliderHelper(label, var, ImGuiDataType_U32, minVal, maxVal, sameLine, displayFormat); } - else if (std::is_same::value) + else if (std::is_same::value) { return addVecSliderHelper(label, var, ImGuiDataType_Float, minVal, maxVal, sameLine, displayFormat); } diff --git a/Source/RenderPasses/VolumetricReSTIR/FinalShading.cs.slang b/Source/RenderPasses/VolumetricReSTIR/FinalShading.cs.slang index 823f405..3004d75 100644 --- a/Source/RenderPasses/VolumetricReSTIR/FinalShading.cs.slang +++ b/Source/RenderPasses/VolumetricReSTIR/FinalShading.cs.slang @@ -135,7 +135,7 @@ void main(uint3 DTid : SV_DispatchThreadID) pixelPos = DTid.xy; - if (any(isnan(curColor) || isinf(curColor))) curColor = 0.f; + if (any(isnan(curColor)) || any(isinf(curColor))) curColor = 0.f; gOutputFrame[pixelPos] = curColor; } diff --git a/Source/RenderPasses/VolumetricReSTIR/VolumeTrackingAdapterGVDB.slang b/Source/RenderPasses/VolumetricReSTIR/VolumeTrackingAdapterGVDB.slang index 7d59713..dacf9d6 100644 --- a/Source/RenderPasses/VolumetricReSTIR/VolumeTrackingAdapterGVDB.slang +++ b/Source/RenderPasses/VolumetricReSTIR/VolumeTrackingAdapterGVDB.slang @@ -54,7 +54,7 @@ struct MediumTrAnalyticAdapterGVDB : IVolumeTrackingAdapterGVDB dda_leaf.PrepareLeaf(vmin_leaf); - for (int iter = 0; iter < MAX_BRICK_STEPS && all(dda_leaf.p >= 0 && dda_leaf.p < gvdb.res[mipLevel * 3]); iter++) + for (int iter = 0; iter < MAX_BRICK_STEPS && all(dda_leaf.p >= 0) && all(dda_leaf.p < gvdb.res[mipLevel * 3]); iter++) { // compute the next step location, but don't step yet dda_leaf.Next(); @@ -181,7 +181,7 @@ struct MediumTrRayMarchingAdapterGVDB : IVolumeTrackingAdapterGVDB float3 p = wp - vmin_leaf; // Sample point in sub-volume (in units of voxels) const float3 wpt = tStepMultipler * tStep * ray.dir; - for (int iter = 0; iter < MAX_BRICK_STEPS && all(p >= 0 && p < gvdb.res[mipLevel * 3]); iter++) + for (int iter = 0; iter < MAX_BRICK_STEPS && all(p >= 0) && all(p < gvdb.res[mipLevel * 3]); iter++) { if (t >= tFar) { @@ -271,7 +271,7 @@ struct SampleMediumAnalyticAdapterGVDB : IVolumeTrackingAdapterGVDB HDDAState dda_leaf = dda; dda_leaf.PrepareLeaf(vmin_leaf); - for (int iter = 0; iter < MAX_BRICK_STEPS && all(dda_leaf.p >= 0 && dda_leaf.p < gvdb.res[mipLevel * 3]); iter++) + for (int iter = 0; iter < MAX_BRICK_STEPS && all(dda_leaf.p >= 0) && all(dda_leaf.p < gvdb.res[mipLevel * 3]); iter++) { // compute the next step location, but don't step yet dda_leaf.Next(); @@ -472,7 +472,7 @@ struct SampleVolumeCellByDensityAdapterGVDB : IVolumeTrackingAdapterGVDB HDDAState dda_leaf = dda; dda_leaf.PrepareLeaf(vmin_leaf); - for (int iter = 0; iter < MAX_BRICK_STEPS && all(dda_leaf.p >= 0 && dda_leaf.p < gvdb.res[mipLevel * 3]); iter++) + for (int iter = 0; iter < MAX_BRICK_STEPS && all(dda_leaf.p >= 0) && all(dda_leaf.p < gvdb.res[mipLevel * 3]); iter++) { // find density float density = DensityInAtlas(dda_leaf.p + o + 0.5f, mipLevel, false); @@ -561,7 +561,7 @@ struct ReservoirFeatureRayMarchingAdapterGVDB : IVolumeTrackingAdapterGVDB float3 p = wp - vmin_leaf; // Sample point in sub-volume (in units of voxels) const float3 wpt = tStep * ray.dir; - for (int iter = 0; iter < MAX_BRICK_STEPS && all(p >= 0 && p < gvdb.res[mipLevel * 3]); iter++) + for (int iter = 0; iter < MAX_BRICK_STEPS && all(p >= 0) && all(p < gvdb.res[mipLevel * 3]); iter++) { float curTransmittance = exp(Tr); if (curTransmittance < 0.01f) diff --git a/Source/RenderPasses/VolumetricReSTIR/VolumeUtils.slang b/Source/RenderPasses/VolumetricReSTIR/VolumeUtils.slang index e862fc0..84e5742 100644 --- a/Source/RenderPasses/VolumetricReSTIR/VolumeUtils.slang +++ b/Source/RenderPasses/VolumetricReSTIR/VolumeUtils.slang @@ -216,7 +216,7 @@ void VolumeTrackingGVDB(Ra if (vertexCenter) { int iter = 0; - while (iter++<3 && (any(dda.p < 0 || dda.p > gvdb.res[lev + mipLevel * 3]))) // guarantee that the point "enters" + while (iter++<3 && any(dda.p < 0) || any(dda.p > gvdb.res[lev + mipLevel * 3])) // guarantee that the point "enters" { dda.Next(); dda.Step(); @@ -228,7 +228,7 @@ void VolumeTrackingGVDB(Ra float Tr = 0.f; - for (; iter < 4096 && lev > 0 && lev <= topLev && all(dda.p >= 0 && dda.p <= gvdb.res[lev + mipLevel * 3]); iter++) { + for (; iter < 4096 && lev > 0 && lev <= topLev && all(dda.p >= 0) && all(dda.p <= gvdb.res[lev + mipLevel * 3]); iter++) { dda.Next(); diff --git a/Source/Tools/FalcorTest/Tests/Core/BufferTests.cpp b/Source/Tools/FalcorTest/Tests/Core/BufferTests.cpp index bf3b9de..1cd245b 100644 --- a/Source/Tools/FalcorTest/Tests/Core/BufferTests.cpp +++ b/Source/Tools/FalcorTest/Tests/Core/BufferTests.cpp @@ -40,6 +40,9 @@ namespace Falcor StructuredBuffer = 2, }; + // static_assert must depend on template parameter, otherwise it will be evaluated before template instantiation (and always evaluate false) + template inline constexpr bool alwaysFalse = false; + template void testBuffer(GPUUnitTestContext& ctx, uint32_t numElems, uint32_t index = 0, uint32_t count = 0) { @@ -63,7 +66,7 @@ namespace Falcor if constexpr (type == Type::ByteAddressBuffer) pBuffer = Buffer::create(numElems * sizeof(uint32_t), ResourceBindFlags::UnorderedAccess, Buffer::CpuAccess::None); else if constexpr (type == Type::TypedBuffer) pBuffer = Buffer::createTyped(numElems, ResourceBindFlags::UnorderedAccess); else if constexpr (type == Type::StructuredBuffer) pBuffer = Buffer::createStructured(ctx.getProgram(), "buffer", numElems, ResourceBindFlags::UnorderedAccess); - else static_assert(false); + else static_assert(alwaysFalse); ctx["buffer"] = pBuffer; diff --git a/Source/slangdconfig.json b/Source/slangdconfig.json new file mode 100644 index 0000000..9be9314 --- /dev/null +++ b/Source/slangdconfig.json @@ -0,0 +1,17 @@ +{ + "slang.predefinedMacros": [ + "SAMPLE_GENERATOR_TYPE=SAMPLE_GENERATOR_UNIFORM", + + "MAX_BOUNCES=2", + "SURFACE_SCENE", + "VBUFFERDECLARE=VBufferItem vItem,", + "VBUFFERITEM=vItem,", + "VERTEX_REUSE", + "REUSETYPE=inout" + + ], + "slang.additionalSearchPaths": [ + "./", + "./Falcor" + ] +} \ No newline at end of file