Skip to content

Commit

Permalink
Merge pull request #36 from pixelcluster/linux-build
Browse files Browse the repository at this point in the history
Linux build fixes and improvements
  • Loading branch information
sultim-t authored Nov 26, 2023
2 parents 4ef5805 + c2ede7a commit 2457acc
Show file tree
Hide file tree
Showing 19 changed files with 16,150 additions and 15,594 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
python GenerateShaders.py
- name: CMake
run: cmake -B ${{github.workspace}}/BuildCMake/${{env.BUILD_FOLDER}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRG_WITH_SURFACE_WIN32=ON -DRG_WITH_NVIDIA_DLSS=${{ matrix.dlss }}
run: cmake -B ${{github.workspace}}/BuildCMake/${{env.BUILD_FOLDER}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRG_WITH_SURFACE_WIN32=ON -DRG_WITH_NVIDIA_DLSS=${{ matrix.dlss }} -DRG_WITH_SHADERS=OFF

- name: Build
run: cmake --build ${{github.workspace}}/BuildCMake/${{env.BUILD_FOLDER}} --config ${{env.BUILD_TYPE}}
Expand Down
34 changes: 25 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ option(RG_WITH_SURFACE_XLIB "Build with Xlib VkSurfaceKHR support" OFF)

option(RG_WITH_NVIDIA_DLSS "Build RTGL1 with Nvidia DLSS" OFF)
option(RG_WITH_IMGUI "Build RTGL1 with ImGui debug windows" ON)
option(RG_WITH_AMD_FSR2 "Build RTGL1 with AMD FSR2" ON)

option(RG_WITH_EXAMPLES "Build with examples executable" ON)
option(RG_WITH_SHADERS "Compile shaders during build" ON)


# for KTX-Software
Expand Down Expand Up @@ -243,17 +245,21 @@ target_link_libraries(RayTracedGL1 PUBLIC Vulkan)
target_include_directories(RayTracedGL1 PUBLIC "Include")

# FSR2
target_include_directories(RayTracedGL1 PRIVATE "Source/FSR2/include" )
if (WIN32)
if (BUILD_TYPE STREQUAL "DEBUG")
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_x64d.lib" )
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_vk_x64d.lib" )
if (RG_WITH_AMD_FSR2)
message(STATUS "RG_WITH_AMD_FSR2 enabled")
add_definitions(-DRG_USE_AMD_FSR2)
target_include_directories(RayTracedGL1 PRIVATE "Source/FSR2/include" )
if (WIN32)
if (BUILD_TYPE STREQUAL "DEBUG")
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_x64d.lib" )
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_vk_x64d.lib" )
else()
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_x64.lib" )
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_vk_x64.lib" )
endif()
else()
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_x64.lib" )
target_link_libraries(RayTracedGL1 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source/FSR2/win32/ffx_fsr2_api_vk_x64.lib" )
message(FATAL_ERROR "On non-WIN32, please, provide static libraries of FSR2 or disable FSR2")
endif()
else()
message(FATAL_ERROR "On non-WIN32, please, provide static libraries of FSR2 or disable FSR2")
endif()

# Debug windows - ImGui
Expand Down Expand Up @@ -287,4 +293,14 @@ if (MSVC AND WIN32 AND NOT MSVC_VERSION VERSION_LESS 142)
target_link_options(RtglExample PRIVATE $<$<CONFIG:Debug>:/INCREMENTAL>)
target_compile_options(RtglExample PRIVATE $<$<CONFIG:Debug>:/ZI>)
endif()
endif()

if (RG_WITH_SHADERS)
message(STATUS "RG_WITH_SHADERS enabled")
# Build shaders as custom target
add_custom_target(Shaders
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/Source/Shaders/GenerateShaders.py -builddir ${CMAKE_CURRENT_BINARY_DIR}/shaders
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Source/Shaders)

add_dependencies(RayTracedGL1 Shaders)
endif()
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ RTGL1 is a library that aims to simplify the process of porting 3D applications
1. Build
* `cmake --build .`

1. Build shaders
* Run `Source/Shaders/GenerateShaders.py` with Python3, it will generate SPIR-V files to `Build` folder

### Notes:
* RTGL1 requires a set of blue noise images on start-up: `RgInstanceCreateInfo::pBlueNoiseFilePath`. A ready-to-use resource can be found here: `Tools/BlueNoise_LDR_RGBA_128.ktx2`

Expand Down
45 changes: 45 additions & 0 deletions Source/FSR2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "FSR2.h"

#ifdef RG_USE_AMD_FSR2

#include <ffx_fsr2.h>
#include <vk/ffx_fsr2_vk.h>

Expand Down Expand Up @@ -232,3 +234,46 @@ RgFloat2D RTGL1::FSR2::GetJitter( const ResolutionState& resolutionState, uint32

return jitter;
}

bool RTGL1::FSR2::IsFsr2Available() {
return true;
}

#else

struct FfxFsr2Context {};

RTGL1::FSR2::FSR2(VkDevice _device, VkPhysicalDevice _physDevice)
: device(_device)
, physDevice(_physDevice) {}

RTGL1::FSR2::~FSR2() {}

void RTGL1::FSR2::OnFramebuffersSizeChange(const ResolutionState &resolutionState) {}

RTGL1::FramebufferImageIndex RTGL1::FSR2::Apply(
VkCommandBuffer cmd,
uint32_t frameIndex,
const std::shared_ptr< Framebuffers >& framebuffers,
const RenderResolutionHelper& renderResolution,
RgFloat2D jitterOffset,
double timeDelta,
float nearPlane,
float farPlane,
float fovVerticalRad,
bool resetAccumulation )
{
return FramebufferImageIndex::FB_IMAGE_INDEX_FINAL;
}

RgFloat2D RTGL1::FSR2::GetJitter(const RTGL1::ResolutionState &resolutionState, uint32_t frameId)
{
return RgFloat2D{0, 0};
}

bool RTGL1::FSR2::IsFsr2Available()
{
return false;
}

#endif
1 change: 1 addition & 0 deletions Source/FSR2.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class FSR2 : public IFramebuffersDependency

static RgFloat2D GetJitter( const ResolutionState& resolutionState, uint32_t frameId );

static bool IsFsr2Available();
private:
VkDevice device;
VkPhysicalDevice physDevice;
Expand Down
2 changes: 1 addition & 1 deletion Source/GltfExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ struct GltfTextures
makeSampler( RG_SAMPLER_ADDRESS_MODE_CLAMP, RG_SAMPLER_ADDRESS_MODE_REPEAT ),
makeSampler( RG_SAMPLER_ADDRESS_MODE_CLAMP, RG_SAMPLER_ADDRESS_MODE_CLAMP ),
};
auto findSampler = [ this ]( const RTGL1::TextureManager::ExportResult& r ) {
auto findSampler = [ this, makeSampler ]( const RTGL1::TextureManager::ExportResult& r ) {
cgltf_sampler target = makeSampler( r.addressModeU, r.addressModeV );
for( cgltf_sampler& found : allocSamplers )
{
Expand Down
1 change: 1 addition & 0 deletions Source/GltfImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Generated/ShaderCommonC.h"

#include "cgltf/cgltf.h"
#include <cfloat>

#include <format>

Expand Down
1 change: 1 addition & 0 deletions Source/ImageComposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "ImageComposition.h"

#include <cmath>
#include "Generated/ShaderCommonC.h"
#include "CmdLabel.h"
#include "Utils.h"
Expand Down
1 change: 1 addition & 0 deletions Source/ImageComposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "GlobalUniform.h"
#include "Tonemapping.h"
#include "Volumetric.h"
#include <cfloat>

namespace RTGL1
{
Expand Down
8 changes: 1 addition & 7 deletions Source/MemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ RTGL1::MemoryAllocator::MemoryAllocator( VkInstance _inst
// dedicated allocation
.physicalDevice = physDevice->Get(),
.device = device,
.frameInUseCount = MAX_FRAMES_IN_FLIGHT,
.instance = _instance,
.vulkanApiVersion = VK_API_VERSION_1_2,
};
Expand Down Expand Up @@ -185,11 +184,9 @@ void RTGL1::MemoryAllocator::CreateTexturesStagingPool()
VK_CHECKERROR( r );

VmaPoolCreateInfo poolInfo = {};
poolInfo.frameInUseCount = MAX_FRAMES_IN_FLIGHT;
poolInfo.memoryTypeIndex = memTypeIndex;
poolInfo.blockSize = ALLOCATOR_BLOCK_SIZE_STAGING_TEXTURES;
// buddy algorithm as textures has commonly a size of power of 2
poolInfo.flags = VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT;


r = vmaCreatePool( allocator, &poolInfo, &texturesStagingPool );
VK_CHECKERROR( r );
Expand Down Expand Up @@ -226,10 +223,7 @@ void RTGL1::MemoryAllocator::CreateTexturesFinalPool()

VmaPoolCreateInfo poolInfo = {
.memoryTypeIndex = memTypeIndex,
// buddy algorithm as textures has commonly a size of power of 2
.flags = VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT,
.blockSize = ALLOCATOR_BLOCK_SIZE_TEXTURES,
.frameInUseCount = MAX_FRAMES_IN_FLIGHT,
};

r = vmaCreatePool( allocator, &poolInfo, &texturesFinalPool );
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ bool RTGL1::Scene::InsertLightInfo( bool isStatic, const GenericLightPtr& light
{
// just check that there's no id collision
auto foundSameId =
std::ranges::find_if( staticLights, [ &light ]( const GenericLight& other ) {
std::ranges::find_if( staticLights, [ &light, getIdFromRef, getId ]( const GenericLight& other ) {
return getIdFromRef( other ) == getId( light );
} );

Expand Down
2 changes: 1 addition & 1 deletion Source/ShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ VkPipelineShaderStageCreateInfo ShaderManager::GetStageInfo( std::string_view na
VkShaderModule ShaderManager::LoadModuleFromFile( const std::filesystem::path& path )
{
std::ifstream shaderFile( path, std::ios::binary );
std::vector< uint8_t > shaderSource( std::istreambuf_iterator( shaderFile ), {} );
std::vector< uint8_t > shaderSource( std::istreambuf_iterator<char>( shaderFile ), {} );

if( shaderSource.empty() )
{
Expand Down
11 changes: 11 additions & 0 deletions Source/Shaders/GenerateShaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ def main():
subprocess.run(["python", "../Generated/GenerateShaderCommon.py", "--path", "../Generated/"])
if "-psout" in sys.argv or "--psout" in sys.argv or "-ps" in sys.argv or "--ps" in sys.argv:
powerShellOutput = True

global TARGET_FOLDER_PATH
try:
buildDirIndex = sys.argv.index("-builddir")
if len(sys.argv) == buildDirIndex:
print("No build directory specified")
return
TARGET_FOLDER_PATH = sys.argv[buildDirIndex + 1] + "/"
except ValueError:
pass

#elif len(sys.argv) > 1:
# print("> Couldn't parse arguments")
# return
Expand Down
7 changes: 2 additions & 5 deletions Source/Shaders/ShaderCommonGLSLFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ layout(
binding = BINDING_TEXTURES)
uniform sampler2D globalTextures[];

sampler2D getTexture(uint textureIndex)
{
return globalTextures[nonuniformEXT(textureIndex)];
}
#define getTexture(textureIndex) globalTextures[nonuniformEXT(textureIndex)]

vec4 getTextureSample(uint textureIndex, const vec2 texCoord)
{
Expand Down Expand Up @@ -496,4 +493,4 @@ bool classicShading( ivec2 regularPix )
{
return regularPix.x < globalUniform.lightmapScreenCoverage * globalUniform.renderWidth;
}
#endif // DESC_SET_GLOBAL_UNIFORM
#endif // DESC_SET_GLOBAL_UNIFORM
5 changes: 4 additions & 1 deletion Source/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <algorithm>
#include <array>
#include <optional>
#include <limits>

#include "Common.h"
#include "RTGL1/RTGL1.h"
Expand Down Expand Up @@ -197,7 +198,9 @@ namespace Utils
RgTransform MakeTransform( const RgFloat3D& up, const RgFloat3D& forward, float scale );
RgTransform MakeTransform( const RgFloat3D& position, const RgFloat3D& forward );

#ifndef M_PI
constexpr double M_PI = 3.1415926535897932384626433;
#endif

constexpr float DegToRad( float degrees )
{
Expand Down Expand Up @@ -384,4 +387,4 @@ uint32_t Utils::GetWorkGroupCountT( T1 size, T2 groupSize )
static_cast< uint32_t >( groupSize ) );
}

}
}
2 changes: 1 addition & 1 deletion Source/Vma/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2017-2022 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 2457acc

Please sign in to comment.