Skip to content

Commit

Permalink
Falcor 8.0
Browse files Browse the repository at this point in the history
Co-authored-by: Tomas Davidovic <tdavidovic@nvidia.com>
  • Loading branch information
tomas-davidovic and Tomas Davidovic committed Aug 19, 2024
1 parent de2d654 commit 9dc819c
Show file tree
Hide file tree
Showing 303 changed files with 10,393 additions and 2,401 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ insert_final_newline = true
# Override trailing whitespace setting for Markdown since there it's actually useful
[*.{md}]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
*.mp4
*.tlog
*.bak
*.swp
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ file(TO_NATIVE_PATH ${output_dir} output_dir)

if(FALCOR_WINDOWS)
add_custom_target(deploy_dependencies ALL
COMMAND ${CMAKE_SOURCE_DIR}/build_scripts/deploycommon.bat ${source_dir} ${output_dir} $<CONFIG> ${FALCOR_SLANG_CONFIG} ${FALCOR_DLSS_DIR}
COMMAND ${CMAKE_SOURCE_DIR}/build_scripts/deploycommon.bat ${source_dir} ${output_dir} $<CONFIG> ${FALCOR_SLANG_DIR} ${FALCOR_DLSS_DIR}
)
elseif(FALCOR_LINUX)
add_custom_target(deploy_dependencies ALL
COMMAND ${CMAKE_SOURCE_DIR}/build_scripts/deploycommon.sh ${source_dir} ${output_dir} $<CONFIG> ${FALCOR_SLANG_CONFIG} ${FALCOR_DLSS_DIR}
COMMAND ${CMAKE_SOURCE_DIR}/build_scripts/deploycommon.sh ${source_dir} ${output_dir} $<CONFIG> ${FALCOR_SLANG_DIR} ${FALCOR_DLSS_DIR}
)
endif()
set_target_properties(deploy_dependencies PROPERTIES FOLDER "Misc")
Expand Down
5 changes: 1 addition & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,12 @@
"hidden": true,
"inherits": "windows-base",
"generator": "Ninja Multi-Config",
"environment": {
"VCToolsVersion": "14.30"
},
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "host=x86,version=14.3",
"value": "host=x86,v143",
"strategy": "external"
},
"cacheVariables": {
Expand Down
13 changes: 11 additions & 2 deletions Source/Falcor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ target_sources(Falcor PRIVATE
Rendering/Materials/IsotropicGGX.slang
Rendering/Materials/LayeredBSDF.slang
Rendering/Materials/LobeType.slang
Rendering/Materials/MaterialInstanceHints.slang
Rendering/Materials/MERLCommon.slang
Rendering/Materials/MERLMaterialInstance.slang
Rendering/Materials/MERLMaterial.slang
Expand Down Expand Up @@ -326,6 +327,8 @@ target_sources(Falcor PRIVATE
Scene/Importer.h
Scene/ImporterError.h
Scene/Intersection.slang
Scene/IScene.cpp
Scene/IScene.h
Scene/MeshIO.cs.slang
Scene/NullTrace.cs.slang
Scene/Raster.slang
Expand All @@ -352,6 +355,7 @@ target_sources(Falcor PRIVATE
Scene/TriangleMesh.cpp
Scene/TriangleMesh.h
Scene/VertexAttrib.slangh
Scene/VertexData.slang

Scene/Animation/Animatable.cpp
Scene/Animation/Animatable.h
Expand Down Expand Up @@ -392,6 +396,7 @@ target_sources(Falcor PRIVATE
Scene/Lights/EnvMap.slang
Scene/Lights/EnvMapData.slang
Scene/Lights/FinalizeIntegration.cs.slang
Scene/Lights/ILightCollection.h
Scene/Lights/Light.cpp
Scene/Lights/Light.h
Scene/Lights/LightCollection.cpp
Expand Down Expand Up @@ -558,6 +563,7 @@ target_sources(Falcor PRIVATE
Utils/Properties.h
Utils/SharedCache.h
Utils/SlangUtils.slang
Utils/SplitBuffer.h
Utils/StringFormatters.h
Utils/StringUtils.cpp
Utils/StringUtils.h
Expand Down Expand Up @@ -639,6 +645,7 @@ target_sources(Falcor PRIVATE
Utils/Math/MathHelpers.h
Utils/Math/MathHelpers.slang
Utils/Math/Matrix.h
Utils/Math/MatrixJson.h
Utils/Math/MatrixMath.h
Utils/Math/MatrixTypes.h
Utils/Math/MatrixUtils.slang
Expand All @@ -652,11 +659,13 @@ target_sources(Falcor PRIVATE
Utils/Math/Ray.slang
Utils/Math/Rectangle.cpp
Utils/Math/Rectangle.h
Utils/Math/ScalarJson.h
Utils/Math/ScalarMath.h
Utils/Math/ScalarTypes.h
Utils/Math/ShadingFrame.slang
Utils/Math/SphericalHarmonics.slang
Utils/Math/Vector.h
Utils/Math/VectorJson.h
Utils/Math/VectorMath.h
Utils/Math/VectorTypes.h

Expand Down Expand Up @@ -820,8 +829,8 @@ target_compile_options(Falcor
# Configure warnings
/WX # warnings as errors
/W4 # increase warning level
/wd4819 # the file contains a character that cannot be represented in the current code page(936)
/wd4251 # 'type' : class 'type1' needs to have dll-interface to be used by clients of class 'type2'
/wd4819 # The file contains a character that cannot be represented in the current code page(936)
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
/wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
/wd4100 # unreferenced formal parameter
Expand Down Expand Up @@ -947,6 +956,7 @@ target_compile_definitions(Falcor
FALCOR_HAS_D3D12_AGILITY_SDK=$<BOOL:${FALCOR_HAS_D3D12_AGILITY_SDK}>
# TODO: RTXDI is always available, we might want to remove the feature flag.
FALCOR_HAS_RTXDI=1
IMGUI_USER_CONFIG="Utils/UI/ImGuiConfig.h"
PRIVATE
#$<$<CONFIG:Debug>:_ITERATOR_DEBUG_LEVEL=0>
FALCOR_PROJECT_DIR="${CMAKE_SOURCE_DIR}/"
Expand Down Expand Up @@ -989,7 +999,6 @@ target_link_libraries(Falcor
$<$<PLATFORM_ID:Linux>:gtk3>
)


target_include_directories(Falcor
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
85 changes: 52 additions & 33 deletions Source/Falcor/Core/API/Buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
# Copyright (c) 2015-23, NVIDIA CORPORATION. All rights reserved.
# Copyright (c) 2015-24, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -28,6 +28,7 @@
#include "Buffer.h"
#include "Device.h"
#include "GFXAPI.h"
#include "GFXHelpers.h"
#include "NativeHandleTraits.h"
#include "PythonHelpers.h"
#include "Core/Error.h"
Expand All @@ -47,9 +48,18 @@ namespace Falcor
// TODO: Replace with include?
void getGFXResourceState(ResourceBindFlags flags, gfx::ResourceState& defaultState, gfx::ResourceStateSet& allowedStates);

static void prepareGFXBufferDesc(gfx::IBufferResource::Desc& bufDesc, size_t size, ResourceBindFlags bindFlags, MemoryType memoryType)
static void prepareGFXBufferDesc(
gfx::IBufferResource::Desc& bufDesc,
size_t size,
size_t elementSize,
ResourceFormat format,
ResourceBindFlags bindFlags,
MemoryType memoryType
)
{
bufDesc.sizeInBytes = size;
bufDesc.elementSize = elementSize;
bufDesc.format = getGFXFormat(format);
switch (memoryType)
{
case MemoryType::DeviceLocal:
Expand All @@ -74,6 +84,8 @@ Slang::ComPtr<gfx::IBufferResource> createBufferResource(
ref<Device> pDevice,
Buffer::State initState,
size_t size,
size_t elementSize,
ResourceFormat format,
ResourceBindFlags bindFlags,
MemoryType memoryType
)
Expand All @@ -82,7 +94,7 @@ Slang::ComPtr<gfx::IBufferResource> createBufferResource(

// Create the buffer
gfx::IBufferResource::Desc bufDesc = {};
prepareGFXBufferDesc(bufDesc, size, bindFlags, memoryType);
prepareGFXBufferDesc(bufDesc, size, elementSize, format, bindFlags, memoryType);

Slang::ComPtr<gfx::IBufferResource> pApiHandle;
FALCOR_GFX_CALL(pDevice->getGfxDevice()->createBufferResource(bufDesc, nullptr, pApiHandle.writeRef()));
Expand All @@ -91,24 +103,31 @@ Slang::ComPtr<gfx::IBufferResource> createBufferResource(
return pApiHandle;
}

Buffer::Buffer(ref<Device> pDevice, size_t size, ResourceBindFlags bindFlags, MemoryType memoryType, const void* pInitData)
Buffer::Buffer(
ref<Device> pDevice,
size_t size,
size_t structSize,
ResourceFormat format,
ResourceBindFlags bindFlags,
MemoryType memoryType,
const void* pInitData
)
: Resource(pDevice, Type::Buffer, bindFlags, size), mMemoryType(memoryType)
{
FALCOR_CHECK(size > 0, "Can't create GPU buffer of size zero");

// Check that buffer size is within 4GB limit. Larger buffers are currently not well supported in D3D12.
// TODO: Revisit this check in the future.
if (size > (1ull << 32))
{
logWarning("Creating GPU buffer of size {} bytes. Buffers above 4GB are not currently well supported.", size);
}
FALCOR_CHECK(size <= (1ull << 32), "Creating GPU buffer of size {} bytes. Buffers above 4GB are not currently well supported.", size);

if (mMemoryType != MemoryType::DeviceLocal && is_set(mBindFlags, ResourceBindFlags::Shared))
{
FALCOR_THROW("Can't create shared resource with CPU access other than 'None'.");
}

mSize = align_to(mpDevice->getBufferDataAlignment(bindFlags), mSize);
mStructSize = structSize;
mFormat = format;

if (mMemoryType == MemoryType::DeviceLocal)
{
Expand All @@ -125,14 +144,18 @@ Buffer::Buffer(ref<Device> pDevice, size_t size, ResourceBindFlags bindFlags, Me
mState.global = Resource::State::CopyDest;
}

mGfxBufferResource = createBufferResource(mpDevice, mState.global, mSize, mBindFlags, mMemoryType);
mGfxBufferResource = createBufferResource(mpDevice, mState.global, mSize, mStructSize, mFormat, mBindFlags, mMemoryType);

if (pInitData)
setBlob(pInitData, 0, size);

mElementCount = uint32_t(size);
}

Buffer::Buffer(ref<Device> pDevice, size_t size, ResourceBindFlags bindFlags, MemoryType memoryType, const void* pInitData)
: Buffer(pDevice, size, 0, ResourceFormat::Unknown, bindFlags, memoryType, pInitData)
{}

Buffer::Buffer(
ref<Device> pDevice,
ResourceFormat format,
Expand All @@ -141,9 +164,8 @@ Buffer::Buffer(
MemoryType memoryType,
const void* pInitData
)
: Buffer(pDevice, (size_t)getFormatBytesPerBlock(format) * elementCount, bindFlags, memoryType, pInitData)
: Buffer(pDevice, (size_t)getFormatBytesPerBlock(format) * elementCount, 0, format, bindFlags, memoryType, pInitData)
{
mFormat = format;
mElementCount = elementCount;
}

Expand All @@ -156,20 +178,28 @@ Buffer::Buffer(
const void* pInitData,
bool createCounter
)
: Buffer(pDevice, (size_t)structSize * elementCount, bindFlags, memoryType, pInitData)
: Buffer(pDevice, (size_t)structSize * elementCount, structSize, ResourceFormat::Unknown, bindFlags, memoryType, pInitData)
{
mElementCount = elementCount;
mStructSize = structSize;
static const uint32_t zero = 0;
if (createCounter)
{
mpUAVCounter = make_ref<Buffer>(mpDevice, sizeof(uint32_t), ResourceBindFlags::UnorderedAccess, MemoryType::DeviceLocal, &zero);
FALCOR_CHECK(mStructSize > 0, "Can't create a counter buffer with struct size of 0.");
mpUAVCounter = make_ref<Buffer>(
mpDevice,
sizeof(uint32_t),
sizeof(uint32_t),
ResourceFormat::Unknown,
ResourceBindFlags::UnorderedAccess,
MemoryType::DeviceLocal,
&zero
);
}
}

// TODO: Its wasteful to create a buffer just to replace it afterwards with the supplied one!
Buffer::Buffer(ref<Device> pDevice, gfx::IBufferResource* pResource, size_t size, ResourceBindFlags bindFlags, MemoryType memoryType)
: Buffer(pDevice, size, bindFlags, memoryType, nullptr)
: Buffer(pDevice, size, 0, ResourceFormat::Unknown, bindFlags, memoryType, nullptr)
{
FALCOR_ASSERT(pResource);
mGfxBufferResource = pResource;
Expand All @@ -184,7 +214,7 @@ inline Slang::ComPtr<gfx::IBufferResource> gfxResourceFromNativeHandle(
)
{
gfx::IBufferResource::Desc bufDesc = {};
prepareGFXBufferDesc(bufDesc, size, bindFlags, memoryType);
prepareGFXBufferDesc(bufDesc, size, 0, ResourceFormat::Unknown, bindFlags, memoryType);

gfx::InteropHandle gfxNativeHandle = {};
#if FALCOR_HAS_D3D12
Expand Down Expand Up @@ -225,12 +255,12 @@ gfx::IResource* Buffer::getGfxResource() const
return mGfxBufferResource;
}

ref<ShaderResourceView> Buffer::getSRV(uint32_t firstElement, uint32_t elementCount)
ref<ShaderResourceView> Buffer::getSRV(uint64_t offset, uint64_t size)
{
ResourceViewInfo view = ResourceViewInfo(firstElement, elementCount);
ResourceViewInfo view = ResourceViewInfo(offset, size);

if (mSrvs.find(view) == mSrvs.end())
mSrvs[view] = ShaderResourceView::create(getDevice().get(), this, firstElement, elementCount);
mSrvs[view] = ShaderResourceView::create(getDevice().get(), this, offset, size);

return mSrvs[view];
}
Expand All @@ -240,12 +270,12 @@ ref<ShaderResourceView> Buffer::getSRV()
return getSRV(0);
}

ref<UnorderedAccessView> Buffer::getUAV(uint32_t firstElement, uint32_t elementCount)
ref<UnorderedAccessView> Buffer::getUAV(uint64_t offset, uint64_t size)
{
ResourceViewInfo view = ResourceViewInfo(firstElement, elementCount);
ResourceViewInfo view = ResourceViewInfo(offset, size);

if (mUavs.find(view) == mUavs.end())
mUavs[view] = UnorderedAccessView::create(getDevice().get(), this, firstElement, elementCount);
mUavs[view] = UnorderedAccessView::create(getDevice().get(), this, offset, size);

return mUavs[view];
}
Expand Down Expand Up @@ -323,16 +353,6 @@ void Buffer::unmap() const
}
}

uint32_t Buffer::getElementSize() const
{
if (mStructSize != 0)
return mStructSize;
if (mFormat == ResourceFormat::Unknown)
return 1;

FALCOR_THROW("Inferring element size from resource format is not implemented");
}

bool Buffer::adjustSizeOffsetParams(size_t& size, size_t& offset) const
{
if (offset >= mSize)
Expand Down Expand Up @@ -455,7 +475,6 @@ FALCOR_SCRIPT_BINDING(Buffer)
buffer.def_property_readonly("is_typed", &Buffer::isTyped);
buffer.def_property_readonly("is_structured", &Buffer::isStructured);
buffer.def_property_readonly("format", &Buffer::getFormat);
buffer.def_property_readonly("element_size", &Buffer::getElementSize);
buffer.def_property_readonly("element_count", &Buffer::getElementCount);
buffer.def_property_readonly("struct_size", &Buffer::getStructSize);

Expand Down
Loading

0 comments on commit 9dc819c

Please sign in to comment.