sultim-t / RayTracedGL1

MIT License
139 stars 32 forks source link

Linux compile broken on hl1 branch #30

Open Rosentti opened 1 year ago

Rosentti commented 1 year ago

Kind of a shame, wanted to try out some HL1 raytraced. Arch Linux, RTX 2080.

Forced CLANG for the build. (Tried to) build with: cmake -DRG_WITH_NVIDIA_DLSS=OFF -DRG_WITH_SURFACE_WAYLAND=ON -DRG_WITH_SURFACE_XCB=OFF -DRG_WITH_SURFACE_XLIB=OFF -DRG_WITH_SURFACE_WIN32=OFF .. Getting errors like:

[ 36%] Building CXX object CMakeFiles/RayTracedGL1.dir/Source/ASManager.cpp.o
In file included from /home/shared/Downloads/RayTracedGL1/Source/Swapchain.cpp:27:
/home/shared/Downloads/RayTracedGL1/Source/Utils.h:200:22: error: expected unqualified-id
    constexpr double M_PI = 3.1415926535897932384626433;
                     ^
/usr/include/math.h:1151:16: note: expanded from macro 'M_PI'
# define M_PI           3.14159265358979323846  /* pi */

make[2]: *** [CMakeFiles/RayTracedGL1.dir/build.make:146: CMakeFiles/RayTracedGL1.dir/Source/Scene.cpp.o] Error 1
/home/shared/Downloads/RayTracedGL1/Source/VulkanDevice_Init.cpp:99:13: error: incompatible pointer to integer conversion assigning to 'VkResult' from 'VkSurfaceKHR *' (aka 'VkSurfaceKHR_T **')
        r = ( instance, &wlInfo, nullptr, &surface );
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And some files reference , which doesn't actually seem to be a valid header (even on clang 15, where it should apparently exist). Also, is the build 32-bit as that might explain some of these issues.

Mis012 commented 11 months ago

I got it to compile with the following, but it seems 32-bit build is even more fun

diff --git a/Source/GltfExporter.cpp b/Source/GltfExporter.cpp
index 86073c7..4e3f350 100644
--- a/Source/GltfExporter.cpp
+++ b/Source/GltfExporter.cpp
@@ -40,6 +40,10 @@
 #include <span>
 #include <type_traits>

+#ifndef M_PI
+#define M_PI RTGL1::Utils::M_PI
+#endif
+
 namespace
 {
 template< class T >
@@ -901,7 +905,7 @@ private:
     static float LuminousFluxToCandela( float lumens )
     {
         // to lumens per steradian
-        return lumens / ( 4 * float( RTGL1::Utils::M_PI ) );
+        return lumens / ( 4 * (float)( M_PI ) );
     }

     static cgltf_light MakeLight( const RgDirectionalLightUploadInfo& sun )
diff --git a/Source/GltfImporter.cpp b/Source/GltfImporter.cpp
index b3658f4..59438c7 100644
--- a/Source/GltfImporter.cpp
+++ b/Source/GltfImporter.cpp
@@ -32,6 +32,10 @@

 #include <format>

+#ifndef M_PI
+#define M_PI Utils::M_PI
+#endif
+
 namespace RTGL1
 {
 namespace
@@ -910,7 +914,7 @@ void RTGL1::GltfImporter::UploadToScene( VkCommandBuffer           cmd,

         constexpr auto candelaToLuminousFlux = []( float lumensPerSteradian ) {
             // to lumens
-            return lumensPerSteradian * ( 4 * float( Utils::M_PI ) );
+            return lumensPerSteradian * ( 4 * (float)( M_PI ) );
         };

         auto makeExtras = []( const char* extradata ) {
diff --git a/Source/VulkanDevice_Init.cpp b/Source/VulkanDevice_Init.cpp
index d01a449..ce4cba4 100644
--- a/Source/VulkanDevice_Init.cpp
+++ b/Source/VulkanDevice_Init.cpp
@@ -96,7 +96,7 @@ VkSurfaceKHR GetSurfaceFromUser( VkInstance instance, const RgInstanceCreateInfo
         wlInfo.display                       = info.pWaylandSurfaceCreateInfo->display;
         wlInfo.surface                       = info.pWaylandSurfaceCreateInfo->surface;

-        r = ( instance, &wlInfo, nullptr, &surface );
+        r = vkCreateWaylandSurfaceKHR( instance, &wlInfo, nullptr, &surface );
         VK_CHECKERROR( r );

         return surface;
Mis012 commented 11 months ago

ok, the following was needed for 32bit build, but who knows if it will work

diff --git a/Source/DebugWindows.cpp b/Source/DebugWindows.cpp
index 68a3360..bcee72a 100644
--- a/Source/DebugWindows.cpp
+++ b/Source/DebugWindows.cpp
@@ -254,7 +254,7 @@ RTGL1::DebugWindows::DebugWindows( VkInstance                               _ins
         .Device          = _device,
         .QueueFamily     = _queueFamiy,
         .Queue           = _queue,
-        .PipelineCache   = nullptr,
+        .PipelineCache   = (VkPipelineCache)nullptr,
         .DescriptorPool  = descPool,
         .Subpass         = 0,
         .MinImageCount   = swapchainImageCount,
diff --git a/Source/DepthCopying.cpp b/Source/DepthCopying.cpp
index 5ff0731..9df03fd 100644
--- a/Source/DepthCopying.cpp
+++ b/Source/DepthCopying.cpp
@@ -359,7 +359,7 @@ void RTGL1::DepthCopying::CreatePipeline( const ShaderManager* shaderManager )
         .basePipelineHandle  = VK_NULL_HANDLE,
     };

-    VkResult r = vkCreateGraphicsPipelines( device, nullptr, 1, &plInfo, nullptr, &pipeline );
+    VkResult r = vkCreateGraphicsPipelines( device, (VkPipelineCache)nullptr, 1, &plInfo, nullptr, &pipeline );

     VK_CHECKERROR( r );
     SET_DEBUG_NAME( device, pipeline, VK_OBJECT_TYPE_PIPELINE, "Rasterizer raster draw pipeline" );
diff --git a/Source/DrawFrameInfo.h b/Source/DrawFrameInfo.h
index 6a92784..33017b4 100644
--- a/Source/DrawFrameInfo.h
+++ b/Source/DrawFrameInfo.h
@@ -248,7 +248,7 @@ namespace detail

     inline void* ReadPNext( void* params )
     {
-        constexpr size_t pNextOffset = 8;
+        constexpr size_t pNextOffset = sizeof(void *);

         // clang-format off
         static_assert( offsetof( RgDrawFrameRenderResolutionParams, pNext ) == pNextOffset );
diff --git a/Source/LensFlares.cpp b/Source/LensFlares.cpp
index 932c96d..8b8ac66 100644
--- a/Source/LensFlares.cpp
+++ b/Source/LensFlares.cpp
@@ -554,13 +554,13 @@ void RTGL1::LensFlares::CreatePipelines( const ShaderManager* shaderManager )
     };
     info.stage.pSpecializationInfo = &spec;

-    VkResult r = vkCreateComputePipelines( device, nullptr, 1, &info, nullptr, &cullPipeline );
+    VkResult r = vkCreateComputePipelines( device, (VkPipelineCache)nullptr, 1, &info, nullptr, &cullPipeline );
     VK_CHECKERROR( r );
 }

 void RTGL1::LensFlares::DestroyPipelines()
 {
-    if( cullPipeline != nullptr )
+    if( cullPipeline != (VkPipeline)nullptr )
     {
         vkDestroyPipeline( device, cullPipeline, nullptr );
     }
diff --git a/Source/RTGL1.cpp b/Source/RTGL1.cpp
index bd6629e..6b570e7 100644
--- a/Source/RTGL1.cpp
+++ b/Source/RTGL1.cpp
@@ -25,10 +25,10 @@

 namespace
 {
-#define INITIALIZED_RGINSTANCE ( reinterpret_cast< RgInstance >( 1024 ) )
+#define INITIALIZED_RGINSTANCE ( reinterpret_cast< RgInstance >( (RgInstance)1024 ) )

-RgInstance                             g_deviceRgInstance{ nullptr };
+RgInstance                             g_deviceRgInstance{ (RgInstance)nullptr };
 std::unique_ptr< RTGL1::VulkanDevice > g_device{};

 RTGL1::VulkanDevice* TryGetDevice( RgInstance rgInstance )
@@ -63,7 +63,7 @@ RgMessageSeverityFlags g_printSeverity{ 0 };

 RgResult rgCreateInstance( const RgInstanceCreateInfo* pInfo, RgInstance* pResult )
 {
-    *pResult = nullptr;
+    *pResult = (RgInstance)nullptr;

     if( TryGetDevice( g_deviceRgInstance ) )
     {
@@ -130,7 +130,7 @@ RgResult rgDestroyInstance( RgInstance rgInstance )
     try
     {
         g_device.reset();
-        g_deviceRgInstance = nullptr;
+        g_deviceRgInstance = (RgInstance)nullptr;
     }
     catch( RTGL1::RgException& e )
     {
sultim-t commented 11 months ago

Oof, sorry, but ray tracing doesn't work in 32-bit :(

Mis012 commented 11 months ago

are you sure? it didn't even compile in 32bit without the patch... I get the menu to display now, but when I try to launch New Game, the whole system locks up... is there some way to load a specific (ideally small) map directly from cmdline?

sultim-t commented 11 months ago

There's no support for 32-bit applications on the driver side for technical reasons, I assume. That is why applications need to be translated to 64-bit :(

Mis012 commented 11 months ago

sounds like a windows-only problem, and this issue is specifically about Linux

Mis012 commented 11 months ago

well, maybe for Nvidia proprietary drivers it would be an issue on Linux as well, but not for Mesa