Skip to content

Commit

Permalink
Automatic update (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
skallweitNV authored Dec 11, 2023
1 parent 921b3f6 commit 036a44b
Show file tree
Hide file tree
Showing 93 changed files with 2,758 additions and 891 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ For more information on how to use Falcor as a Python module see [Falcor In Pyth
## Microsoft DirectX 12 Agility SDK
Falcor uses the [Microsoft DirectX 12 Agility SDK](https://devblogs.microsoft.com/directx/directx12agility/) to get access to the latest DirectX 12 features. Applications can enable the Agility SDK by putting `FALCOR_EXPORT_D3D12_AGILITY_SDK` in the main `.cpp` file. `Mogwai`, `FalcorTest` and `RenderGraphEditor` have the Agility SDK enabled by default.

## NVAPI
To enable NVAPI support, head over to https://developer.nvidia.com/nvapi and download the latest version of NVAPI (this build is tested against version R535).
Extract the content of the zip file into `external/packman/` and rename `R535-developer` to `nvapi`.

## NSight Aftermath
To enable NSight Aftermath support, head over to https://developer.nvidia.com/nsight-aftermath and download the latest version of Aftermath (this build is tested against version 2023.1).
Extract the content of the zip file into `external/packman/aftermath`.
Expand Down
18 changes: 14 additions & 4 deletions Source/Falcor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ target_sources(Falcor PRIVATE
Core/State/StateGraph.h

DiffRendering/AggregateGradients.cs.slang
DiffRendering/DiffDebug.slang
DiffRendering/DiffDebugParams.slang
DiffRendering/DiffMaterialData.slang
DiffRendering/DiffSceneIO.slang
DiffRendering/DiffSceneQuery.slang
DiffRendering/GradientIOWrapper.slang
DiffRendering/InverseOptimizationParams.slang
DiffRendering/SceneGradientInfo.slang
DiffRendering/SceneGradients.cpp
DiffRendering/SceneGradients.h
Expand Down Expand Up @@ -543,6 +544,7 @@ target_sources(Falcor PRIVATE
Utils/Dictionary.h
Utils/fast_vector.h
Utils/HostDeviceShared.slangh
Utils/IndexedVector.h
Utils/Logger.cpp
Utils/Logger.h
Utils/NumericRange.h
Expand All @@ -554,13 +556,13 @@ target_sources(Falcor PRIVATE
Utils/PathResolving.h
Utils/Properties.cpp
Utils/Properties.h
Utils/Settings.cpp
Utils/Settings.h
Utils/SharedCache.h
Utils/SlangUtils.slang
Utils/StringFormatters.h
Utils/StringUtils.cpp
Utils/StringUtils.h
Utils/TaskManager.cpp
Utils/TaskManager.h
Utils/TermColor.cpp
Utils/TermColor.h
Utils/Threading.cpp
Expand Down Expand Up @@ -700,6 +702,13 @@ target_sources(Falcor PRIVATE
Utils/SDF/SDFOperations.slang
Utils/SDF/SDFOperationType.slang

Utils/Settings/AttributeFilters.cpp
Utils/Settings/AttributeFilters.h
Utils/Settings/Attributes.h
Utils/Settings/Settings.cpp
Utils/Settings/Settings.h
Utils/Settings/SettingsUtils.h

Utils/Timing/Clock.cpp
Utils/Timing/Clock.h
Utils/Timing/CpuTimer.h
Expand Down Expand Up @@ -923,6 +932,7 @@ target_compile_definitions(Falcor
$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
$<$<CXX_COMPILER_ID:MSVC>:_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING>
$<$<CXX_COMPILER_ID:MSVC>:_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS>
# Clang.
$<$<CXX_COMPILER_ID:Clang>:_MSC_EXTENSIONS> # enable MS extensions
# Falcor feature flags.
Expand Down Expand Up @@ -963,7 +973,7 @@ target_link_libraries(Falcor
$<$<BOOL:${FALCOR_HAS_CUDA}>:CUDA::cudart_static>
PRIVATE
git_version
FreeImage assimp OpenEXR OpenVDB lz4 zlib pugixml
FreeImage assimp OpenEXR OpenVDB lz4 zlib pugixml opensubdiv
glfw mikktspace nvtt
$<$<BOOL:${FALCOR_HAS_D3D12}>:d3d12>
$<$<BOOL:${FALCOR_HAS_D3D12_AGILITY_SDK}>:agility-sdk>
Expand Down
14 changes: 9 additions & 5 deletions Source/Falcor/Core/API/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ ref<Texture> Texture::createMippedFromFiles(
ref<Device> pDevice,
fstd::span<const std::filesystem::path> paths,
bool loadAsSrgb,
ResourceBindFlags bindFlags
ResourceBindFlags bindFlags,
Bitmap::ImportFlags importFlags
)
{
std::vector<Bitmap::UniqueConstPtr> mips;
Expand All @@ -281,7 +282,7 @@ ref<Texture> Texture::createMippedFromFiles(
}
else
{
pBitmap = Bitmap::createFromFile(path, kTopDown);
pBitmap = Bitmap::createFromFile(path, kTopDown, importFlags);
}
if (!pBitmap)
{
Expand Down Expand Up @@ -335,14 +336,15 @@ ref<Texture> Texture::createMippedFromFiles(
if (loadAsSrgb)
texFormat = linearToSrgbFormat(texFormat);

// Create mip mapped latent texture
// Create mip mapped texture.
pTex =
pDevice->createTexture2D(mips[0]->getWidth(), mips[0]->getHeight(), texFormat, 1, mips.size(), combinedData.get(), bindFlags);
}

if (pTex != nullptr)
{
pTex->setSourcePath(fullPathMip0);
pTex->mImportFlags = importFlags;

// Log debug info.
std::string str = fmt::format(
Expand All @@ -364,7 +366,8 @@ ref<Texture> Texture::createFromFile(
const std::filesystem::path& path,
bool generateMipLevels,
bool loadAsSrgb,
ResourceBindFlags bindFlags
ResourceBindFlags bindFlags,
Bitmap::ImportFlags importFlags
)
{
if (!std::filesystem::exists(path))
Expand All @@ -387,7 +390,7 @@ ref<Texture> Texture::createFromFile(
}
else
{
Bitmap::UniqueConstPtr pBitmap = Bitmap::createFromFile(path, kTopDown);
Bitmap::UniqueConstPtr pBitmap = Bitmap::createFromFile(path, kTopDown, importFlags);
if (pBitmap)
{
ResourceFormat texFormat = pBitmap->getFormat();
Expand All @@ -411,6 +414,7 @@ ref<Texture> Texture::createFromFile(
if (pTex != nullptr)
{
pTex->setSourcePath(path);
pTex->mImportFlags = importFlags;

// Log debug info.
std::string str = fmt::format(
Expand Down
14 changes: 12 additions & 2 deletions Source/Falcor/Core/API/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ class FALCOR_API Texture : public Resource
* @param[in] paths List of full paths of all mips, starting from mip0.
* @param[in] loadAsSrgb Load the texture using sRGB format. Only valid for 3 or 4 component textures.
* @param[in] bindFlags The bind flags to create the texture with.
* @param[in] importFlags Optional flags for the file import.
* @return A new texture, or nullptr if the texture failed to load.
*/
static ref<Texture> createMippedFromFiles(
ref<Device> pDevice,
fstd::span<const std::filesystem::path> paths,
bool loadAsSrgb,
ResourceBindFlags bindFlags = ResourceBindFlags::ShaderResource
ResourceBindFlags bindFlags = ResourceBindFlags::ShaderResource,
Bitmap::ImportFlags importFlags = Bitmap::ImportFlags::None
);

/**
Expand All @@ -181,14 +183,16 @@ class FALCOR_API Texture : public Resource
* @param[in] generateMipLevels Whether the mip-chain should be generated.
* @param[in] loadAsSrgb Load the texture using sRGB format. Only valid for 3 or 4 component textures.
* @param[in] bindFlags The bind flags to create the texture with.
* @param[in] importFlags Optional flags for the file import.
* @return A new texture, or nullptr if the texture failed to load.
*/
static ref<Texture> createFromFile(
ref<Device> pDevice,
const std::filesystem::path& path,
bool generateMipLevels,
bool loadAsSrgb,
ResourceBindFlags bindFlags = ResourceBindFlags::ShaderResource
ResourceBindFlags bindFlags = ResourceBindFlags::ShaderResource,
Bitmap::ImportFlags importFlags = Bitmap::ImportFlags::None
);

gfx::ITextureResource* getGfxTextureResource() const { return mGfxTextureResource; }
Expand Down Expand Up @@ -306,6 +310,11 @@ class FALCOR_API Texture : public Resource
*/
const std::filesystem::path& getSourcePath() const { return mSourcePath; }

/**
* In case the texture was loaded from a file, get the import flags used.
*/
Bitmap::ImportFlags getImportFlags() const { return mImportFlags; }

/**
* Returns the total number of texels across all mip levels and array slices.
*/
Expand All @@ -329,6 +338,7 @@ class FALCOR_API Texture : public Resource

bool mReleaseRtvsAfterGenMips = true;
std::filesystem::path mSourcePath;
Bitmap::ImportFlags mImportFlags = Bitmap::ImportFlags::None; ///< Flags used for import if loaded from file.

ResourceFormat mFormat = ResourceFormat::Unknown;
uint32_t mWidth = 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/Falcor/Core/SampleApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "Utils/Scripting/Scripting.h"
#include "Utils/Scripting/ScriptBindings.h"
#include "Utils/UI/TextRenderer.h"
#include "Utils/Settings.h"
#include "Utils/Settings/Settings.h"
#include "Utils/StringUtils.h"

#include <imgui.h>
Expand Down
File renamed without changes.
145 changes: 140 additions & 5 deletions Source/Falcor/DiffRendering/DiffSceneIO.slang
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import Scene.Scene;
import Scene.SceneTypes;

__exported import DiffRendering.SceneGradientInfo;
import DiffRendering.DiffDebug;
import DiffRendering.DiffDebugParams;
import DiffRendering.InverseOptimizationParams;
import DiffRendering.SceneGradients;
import DiffRendering.GradientIOWrapper;

RWTexture2D<float4> gOutputDColor;

Expand All @@ -44,6 +47,15 @@ RWTexture2D<float4> gOutputDColor;
// Scene IO wrapper for propagating gradients.
struct DiffSceneIO
{
// Returns the local vertex indices for a given triangle.
uint3 getVtxIndices(const GeometryInstanceID instanceID, const uint triangleID)
{
const GeometryInstanceData instance = gScene.getGeometryInstance(instanceID);
uint3 vtxIndices =
gScene.getLocalIndices(instance.ibOffset, triangleID, instance.flags & uint(GeometryInstanceFlags::Use16BitIndices));
return vtxIndices;
}

// Vertex position
[ForwardDerivative(fwd_loadVertexPositionsW)]
[BackwardDerivative(bwd_loadVertexPositionsW)]
Expand Down Expand Up @@ -93,7 +105,21 @@ struct DiffSceneIO
in float3.Differential dPos[3]
)
{
#if DIFF_MODE == 3 // BackwardDiffDebug
#if DIFF_MODE == 1 // BackwardDiff
if (dpGradInfo.d.flag.gradMode == GradientMode.Scene && gInvOpt.meshID == instanceID.index) // Indicate which mesh to compute
// gradients for.
{
uint3 vtxIndices = getVtxIndices(instanceID, triangleID);
uint hashIndex = hashFunction(dpGradInfo.p.pixelID, gSceneGradients.getHashSize(GradientType::MeshPosition));
[ForceUnroll]
for (uint i = 0; i < 3; i++)
{
[ForceUnroll]
for (uint j = 0; j < 3; j++)
gSceneGradients.atomicAddGrad(GradientType::MeshPosition, vtxIndices[i] * 3 + j, hashIndex, dPos[i][j]);
}
}
#elif DIFF_MODE == 3 // BackwardDiffDebug
// For visualizing a gradient image.
if (dpGradInfo.d.flag.gradMode == GradientMode.Scene && gDiffDebug.varType == DiffVariableType::GeometryTranslation &&
gDiffDebug.id.x == instanceID.index)
Expand All @@ -105,10 +131,10 @@ struct DiffSceneIO
#endif
}

// TODO: Add custom derivatives for the following functions.

// Vertex normal
[Differentiable]
[ForwardDerivative(fwd_loadVertexNormalsW)]
[BackwardDerivative(bwd_loadVertexNormalsW)]
[PreferRecompute]
void loadVertexNormalsW(SceneGradientInfo gradInfo, GeometryInstanceID instanceID, uint triangleID, out float3 n[3])
{
uint3 indices = gScene.getIndices(instanceID, triangleID);
Expand All @@ -122,6 +148,115 @@ struct DiffSceneIO
}
}

[Differentiable]
[PreferRecompute]
void fwd_loadVertexNormalsW(
DifferentialPair<SceneGradientInfo> dpGradInfo,
GeometryInstanceID instanceID,
uint triangleID,
out DifferentialPair<float3[3]> dpNorm
)
{
float3 n[3];
loadVertexNormalsW(dpGradInfo.p, instanceID, triangleID, n);

float3.Differential dN[3];
[ForceUnroll]
for (uint i = 0; i < 3; i++)
dN[i] = float3(0.f);

dpNorm = diffPair(n, dN);
}

[Differentiable]
[PreferRecompute]
void bwd_loadVertexNormalsW(
inout DifferentialPair<SceneGradientInfo> dpGradInfo,
GeometryInstanceID instanceID,
uint triangleID,
in float3.Differential dNorm[3]
)
{
#if DIFF_MODE == 1 // BackwardDiff
if (dpGradInfo.d.flag.gradMode == GradientMode.Scene && gInvOpt.meshID == instanceID.index) // Indicate which mesh to compute
// gradients for.
{
uint3 vtxIndices = getVtxIndices(instanceID, triangleID);
uint hashIndex = hashFunction(dpGradInfo.p.pixelID, gSceneGradients.getHashSize(GradientType::MeshNormal));
[ForceUnroll]
for (uint i = 0; i < 3; i++)
{
[ForceUnroll]
for (uint j = 0; j < 3; j++)
gSceneGradients.atomicAddGrad(GradientType::MeshNormal, vtxIndices[i] * 3 + j, hashIndex, dNorm[i][j]);
}
}
#endif
}

// Vertex tangent
[ForwardDerivative(fwd_loadVertexTangentsW)]
[BackwardDerivative(bwd_loadVertexTangentsW)]
[PreferRecompute]
void loadVertexTangentsW(SceneGradientInfo gradInfo, GeometryInstanceID instanceID, uint triangleID, out float3 t[3])
{
uint3 indices = gScene.getIndices(instanceID, triangleID);
float3x3 mat = float3x3(no_diff gScene.getWorldMatrix(instanceID));

[ForceUnroll]
for (int i = 0; i < 3; i++)
{
var v = no_diff gScene.getVertex(indices[i]);
t[i] = normalize(mul(mat, v.tangent.xyz));
}
}

[Differentiable]
[PreferRecompute]
void fwd_loadVertexTangentsW(
DifferentialPair<SceneGradientInfo> dpGradInfo,
GeometryInstanceID instanceID,
uint triangleID,
out DifferentialPair<float3[3]> dpTang
)
{
float3 t[3];
loadVertexTangentsW(dpGradInfo.p, instanceID, triangleID, t);

float3.Differential dT[3];
[ForceUnroll]
for (uint i = 0; i < 3; i++)
dT[i] = float3(0.f);

dpTang = diffPair(t, dT);
}

[Differentiable]
[PreferRecompute]
void bwd_loadVertexTangentsW(
inout DifferentialPair<SceneGradientInfo> dpGradInfo,
GeometryInstanceID instanceID,
uint triangleID,
in float3.Differential dTang[3]
)
{
#if DIFF_MODE == 1 // BackwardDiff
if (dpGradInfo.d.flag.gradMode == GradientMode.Scene && gInvOpt.meshID == instanceID.index) // Indicate which mesh to compute
// gradients for.
{
uint3 vtxIndices = getVtxIndices(instanceID, triangleID);
uint hashIndex = hashFunction(dpGradInfo.p.pixelID, gSceneGradients.getHashSize(GradientType::MeshTangent));
[ForceUnroll]
for (uint i = 0; i < 3; i++)
{
[ForceUnroll]
for (uint j = 0; j < 3; j++)
gSceneGradients.atomicAddGrad(GradientType::MeshTangent, vtxIndices[i] * 3 + j, hashIndex, dTang[i][j]);
}
}
#endif
}

// Camera position
[Differentiable]
float3 loadCameraPositionW(SceneGradientInfo gradInfo) { return no_diff gScene.camera.getPosition(); }
Expand Down
Loading

0 comments on commit 036a44b

Please sign in to comment.