summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-03-15 12:59:58 -0700
committerGitHub <noreply@github.com>2021-03-15 12:59:58 -0700
commit10b39e0cb545f98f1a417da8e8e52258134a3e87 (patch)
treef57192ca5b79365a40e02d64879591ed70c9975a
parente428f6e6cb868e7ca487dba09f3ca5530fd85ca6 (diff)
Enable `gfx::CUDADevice` on linux. (#1756)
-rw-r--r--.gitignore2
-rw-r--r--premake5.lua90
-rw-r--r--tools/gfx/cuda/render-cuda.cpp41
-rw-r--r--tools/gfx/render.cpp14
-rw-r--r--tools/render-test/bind-location.h8
-rw-r--r--tools/render-test/cuda/cuda-compute-util.cpp8
-rw-r--r--tools/render-test/cuda/cuda-compute-util.h2
-rw-r--r--tools/render-test/shader-input-layout.h6
8 files changed, 97 insertions, 74 deletions
diff --git a/.gitignore b/.gitignore
index fad8a1030..fe322c934 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
*.exe
*.pdb
.vs
+.vscode
*.VC.opendb
*.VC.db
*.vcxproj.user
@@ -15,6 +16,7 @@
bin/
intermediate/
build.*/
+Makefile
# Files generated by test runner.
#
diff --git a/premake5.lua b/premake5.lua
index 13debb57b..7052d1de9 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -351,6 +351,48 @@ function getBuildLocationName()
end
end
+-- Adds CUDA dependency to a project
+function addCUDAIfEnabled()
+ if type(cudaPath) == "string" and isTargetWindows then
+ filter {}
+ includedirs { cudaPath .. "/include" }
+ includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
+ links { "cuda", "cudart" }
+ if optixPath then
+ defines { "RENDER_TEST_OPTIX" }
+ includedirs { optixPath .. "include/" }
+ end
+
+ filter { "platforms:x86" }
+ libdirs { cudaPath .. "/lib/Win32/" }
+
+ filter { "platforms:x64" }
+ libdirs { cudaPath .. "/lib/x64/" }
+ filter {}
+ return true
+ elseif enableCuda then
+ filter {}
+ if type(cudaPath) == "string" then
+ includedirs { cudaPath .. "/include" }
+ includedirs { cudaPath .. "/include" }
+ if optixPath then
+ defines { "GFX_OPTIX" }
+ includedirs { optixPath .. "include/" }
+ end
+ filter { "platforms:x86" }
+ libdirs { cudaPath .. "/lib32/" }
+ filter { "platforms:x64" }
+ libdirs { cudaPath .. "/lib64/" }
+ filter {}
+ links { "cuda", "cudart" }
+ else
+ print "Error: CUDA is enabled but --cuda-sdk-path is not specified."
+ end
+ return true
+ end
+ return false
+end
+
--
-- Next we will define a helper routine that all of our
-- projects will bottleneck through. Here `name` is
@@ -500,7 +542,7 @@ function toolSharedLibrary(name)
-- specifying that the project lives under the `tools/` path.
--
baseSlangProject(name .. "-tool", "tools/" .. name)
-
+
defines { "SLANG_SHARED_LIBRARY_TOOL" }
kind "SharedLib"
@@ -547,6 +589,8 @@ function example(name)
links {"X11"}
end
end
+
+ addCUDAIfEnabled();
end
--
@@ -716,7 +760,6 @@ toolSharedLibrary "render-test"
includedirs { ".", "external", "source", "tools/gfx", "tools/platform" }
links { "core", "slang", "gfx", "gfx-util", "platform" }
-
if isTargetWindows then
addSourceDir "tools/render-test/windows"
@@ -727,27 +770,14 @@ toolSharedLibrary "render-test"
-- directory into the output directory.
-- d3dcompiler_47.dll is copied from the external/slang-binaries submodule.
postbuildcommands { '"$(SolutionDir)tools\\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/%{cfg.platform:lower()}/" "%{cfg.targetdir}/" "windows-%{cfg.platform:lower()}"'}
+ if (type(cudaPath) == "string") then
+ addSourceDir "tools/render-test/cuda"
+ end
end
-
- if type(cudaPath) == "string" and isTargetWindows then
- addSourceDir "tools/render-test/cuda"
+ if addCUDAIfEnabled() then
defines { "RENDER_TEST_CUDA" }
- includedirs { cudaPath .. "/include" }
- includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
- links { "cuda", "cudart" }
- if optixPath then
- defines { "RENDER_TEST_OPTIX" }
- includedirs { optixPath .. "include/" }
- end
-
- filter { "platforms:x86" }
- libdirs { cudaPath .. "/lib/Win32/" }
-
- filter { "platforms:x64" }
- libdirs { cudaPath .. "/lib/x64/" }
-
end
-
+
--
-- `gfx` is a abstraction layer for different GPU platforms.
--
@@ -769,6 +799,7 @@ tool "gfx"
-- Will compile across targets
addSourceDir "tools/gfx/cpu"
addSourceDir "tools/gfx/nvapi"
+ addSourceDir "tools/gfx/cuda"
-- To special case that we may be building using cygwin on windows. If 'true windows' we build for dx12/vk and run the script
-- If not we assume it's a cygwin/mingw type situation and remove files that aren't appropriate
@@ -786,22 +817,6 @@ tool "gfx"
addSourceDir "tools/gfx/d3d"
addSourceDir "tools/gfx/d3d11"
addSourceDir "tools/gfx/d3d12"
- addSourceDir "tools/gfx/cuda"
-
- if type(cudaPath) == "string" then
- defines { "GFX_ENABLE_CUDA" }
- includedirs { cudaPath .. "/include" }
- includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
- if optixPath then
- defines { "GFX_OPTIX" }
- includedirs { optixPath .. "include/" }
- end
- links { "cuda", "cudart" }
- filter { "platforms:x86" }
- libdirs { cudaPath .. "/lib/Win32/" }
- filter { "platforms:x64" }
- libdirs { cudaPath .. "/lib/x64/" }
- end
elseif targetDetail == "mingw" or targetDetail == "cygwin" then
-- Don't support any render techs...
elseif os.target() == "macosx" then
@@ -836,6 +851,9 @@ tool "gfx"
links { "nvapi64" }
end
+ if addCUDAIfEnabled() then
+ defines { "GFX_ENABLE_CUDA" }
+ end
--
-- `gfx-util` is a static library containing utilities and helpers for using
diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp
index 89aaa33aa..3e94f5571 100644
--- a/tools/gfx/cuda/render-cuda.cpp
+++ b/tools/gfx/cuda/render-cuda.cpp
@@ -1,20 +1,19 @@
#include "render-cuda.h"
-#include "slang.h"
-#include "slang-com-ptr.h"
-#include "slang-com-helper.h"
+
+#ifdef GFX_ENABLE_CUDA
+#include <cuda.h>
+#include <cuda_runtime_api.h>
#include "core/slang-basic.h"
#include "core/slang-blob.h"
+#include "core/slang-std-writers.h"
+#include "slang.h"
+#include "slang-com-ptr.h"
+#include "slang-com-helper.h"
#include "../command-writer.h"
#include "../renderer-shared.h"
#include "../render-graphics-common.h"
#include "../slang-context.h"
-
-#ifdef GFX_ENABLE_CUDA
-#include <cuda.h>
-#include <cuda_runtime_api.h>
-#include "core/slang-std-writers.h"
-
#endif
namespace gfx
@@ -466,7 +465,7 @@ public:
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& offset, void const* data, size_t size)
+ setData(ShaderOffset const& offset, void const* data, size_t size) override
{
size = Math::Min(size, bufferResource->getDesc()->sizeInBytes - offset.uniformOffset);
SLANG_CUDA_RETURN_ON_FAIL(cudaMemcpy(
@@ -488,7 +487,7 @@ public:
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- getObject(ShaderOffset const& offset, IShaderObject** object)
+ getObject(ShaderOffset const& offset, IShaderObject** object) override
{
auto subObjectIndex =
getLayout()->m_bindingRanges[offset.bindingRangeIndex].baseIndex + offset.bindingArrayIndex;
@@ -507,7 +506,7 @@ public:
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object)
+ setObject(ShaderOffset const& offset, IShaderObject* object) override
{
auto layout = getLayout();
@@ -625,7 +624,7 @@ public:
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView)
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) override
{
auto layout = getLayout();
@@ -669,14 +668,14 @@ public:
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- setSampler(ShaderOffset const& offset, ISamplerState* sampler)
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override
{
SLANG_UNUSED(sampler);
SLANG_UNUSED(offset);
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler)
+ ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) override
{
SLANG_UNUSED(sampler);
setResource(offset, textureView);
@@ -758,7 +757,7 @@ public:
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- setDeviceData(size_t offset, void* data, size_t size)
+ setDeviceData(size_t offset, void* data, size_t size) override
{
size = Math::Min(size, uniformBufferSize - offset);
SLANG_CUDA_RETURN_ON_FAIL(cudaMemcpy(
@@ -1004,8 +1003,8 @@ public:
*outObject = nullptr;
return SLANG_E_NO_INTERFACE;
}
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() { return 1; }
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
public:
CommandWriter* m_writer;
@@ -1064,8 +1063,8 @@ public:
*outObject = nullptr;
return SLANG_E_NO_INTERFACE;
}
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() { return 1; }
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
public:
CommandWriter* m_writer;
@@ -1087,7 +1086,7 @@ public:
}
virtual SLANG_NO_THROW void SLANG_MCALL
- uploadBufferData(IBufferResource* dst, size_t offset, size_t size, void* data)
+ uploadBufferData(IBufferResource* dst, size_t offset, size_t size, void* data) override
{
m_writer->uploadBufferData(dst, offset, size, data);
}
diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp
index e7d30b728..183afaffd 100644
--- a/tools/gfx/render.cpp
+++ b/tools/gfx/render.cpp
@@ -92,11 +92,15 @@ extern "C"
}
break;
#elif SLANG_LINUX_FAMILY
- case DeviceType::Default:
- case DeviceType::Vulkan:
- {
- return createVKDevice(desc, outDevice);
- }
+ case DeviceType::Default:
+ case DeviceType::Vulkan:
+ {
+ return createVKDevice(desc, outDevice);
+ }
+ case DeviceType::CUDA:
+ {
+ return createCUDADevice(desc, outDevice);
+ }
#endif
case DeviceType::CPU:
{
diff --git a/tools/render-test/bind-location.h b/tools/render-test/bind-location.h
index cfa88cce0..33670bf4b 100644
--- a/tools/render-test/bind-location.h
+++ b/tools/render-test/bind-location.h
@@ -1,10 +1,10 @@
#ifndef BIND_LOCATION_H
#define BIND_LOCATION_H
-#include "core/slang-basic.h"
-#include "core/slang-free-list.h"
-#include "core/slang-memory-arena.h"
-#include "core/slang-writer.h"
+#include "source/core/slang-basic.h"
+#include "source/core/slang-free-list.h"
+#include "source/core/slang-memory-arena.h"
+#include "source/core/slang-writer.h"
#include "slang.h"
diff --git a/tools/render-test/cuda/cuda-compute-util.cpp b/tools/render-test/cuda/cuda-compute-util.cpp
index ea7dab163..bd77919a2 100644
--- a/tools/render-test/cuda/cuda-compute-util.cpp
+++ b/tools/render-test/cuda/cuda-compute-util.cpp
@@ -1,11 +1,11 @@
#include "cuda-compute-util.h"
-#include "../../slang-com-helper.h"
+#include "slang-com-helper.h"
-#include "../../source/core/slang-std-writers.h"
-#include "../../source/core/slang-token-reader.h"
-#include "../../source/core/slang-semantic-version.h"
+#include "source/core/slang-std-writers.h"
+#include "source/core/slang-token-reader.h"
+#include "source/core/slang-semantic-version.h"
#include "../bind-location.h"
diff --git a/tools/render-test/cuda/cuda-compute-util.h b/tools/render-test/cuda/cuda-compute-util.h
index ac0c6bba3..9c6c8b9b4 100644
--- a/tools/render-test/cuda/cuda-compute-util.h
+++ b/tools/render-test/cuda/cuda-compute-util.h
@@ -4,7 +4,7 @@
#include "../slang-support.h"
#include "../options.h"
-#include "../../source/core/slang-smart-pointer.h"
+#include "source/core/slang-smart-pointer.h"
namespace renderer_test {
diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h
index 2c8dbe821..253f065f6 100644
--- a/tools/render-test/shader-input-layout.h
+++ b/tools/render-test/shader-input-layout.h
@@ -1,10 +1,10 @@
#ifndef SLANG_TEST_SHADER_INPUT_LAYOUT_H
#define SLANG_TEST_SHADER_INPUT_LAYOUT_H
-#include "core/slang-basic.h"
-#include "core/slang-random-generator.h"
+#include "source/core/slang-basic.h"
+#include "source/core/slang-random-generator.h"
-#include "core/slang-writer.h"
+#include "source/core/slang-writer.h"
#include "bind-location.h"