Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
skallweitNV committed Aug 30, 2024
0 parents commit 4ab6f46
Show file tree
Hide file tree
Showing 383 changed files with 91,680 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
BasedOnStyle: Microsoft
ColumnLimit: 120
MaxEmptyLinesToKeep: 2
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterTemplateKeyword: false
DerivePointerAlignment: false
PointerAlignment: Left
FixNamespaceComments: true

AllowAllConstructorInitializersOnNextLine: true
BreakConstructorInitializers: BeforeComma
Cpp11BracedListStyle: true
SpaceBeforeCpp11BracedList: false
AlwaysBreakTemplateDeclarations: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortEnumsOnASingleLine: true
AllowAllArgumentsOnNextLine: false
BinPackArguments: false
AllowAllParametersOfDeclarationOnNextLine: false
BinPackParameters: false
ExperimentalAutoDetectBinPacking: false
AlignAfterOpenBracket: BlockIndent
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
SplitEmptyRecord: false

AlignTrailingComments: true
ReflowComments: true
CommentPragmas: '^\\.+'
PenaltyBreakComment: 0

AlwaysBreakAfterDefinitionReturnType: None
# BreakAfterReturnType: Automatic
PenaltyReturnTypeOnItsOwnLine: 1000000000
AlwaysBreakBeforeMultilineStrings: true

IndentAccessModifiers: false
AccessModifierOffset: -4
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{h,cpp}]
indent_style = space
indent_size = 4

[CMakeLists.txt]
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/
build/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "external/vulkan-headers"]
path = external/vulkan-headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
[submodule "external/metal-cpp"]
path = external/metal-cpp
url = https://github.com/bkaradzic/metal-cpp.git
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-symlinks
- id: check-merge-conflict
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8
hooks:
- id: clang-format
exclude: |
(?x)^(
build/.*|
external/.*|
src/prelude/.*|
tools/.*|
)$
170 changes: 170 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
cmake_minimum_required(VERSION 3.20)

project(slang-rhi)

include(CMakeDependentOption)

# Check if this project is the master cmake project (i.e. not included via add_subdirectory).
set(SLANG_RHI_MASTER_PROJECT OFF)
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
set(SLANG_RHI_MASTER_PROJECT ON)
endif()

option(SLANG_RHI_BUILD_SHARED "Build shared library" OFF)
option(SLANG_RHI_BUILD_TESTS "Build tests" ON)

set(SLANG_RHI_HAS_D3D11 ${WIN32})
cmake_dependent_option(SLANG_RHI_ENABLE_D3D11 "Enable D3D11 backend" ON "SLANG_RHI_HAS_D3D11" OFF)
set(SLANG_RHI_HAS_D3D12 ${WIN32})
cmake_dependent_option(SLANG_RHI_ENABLE_D3D12 "Enable D3D12 backend" ON "SLANG_RHI_HAS_D3D12" OFF)
set(SLANG_RHI_HAS_VULKAN ON)
cmake_dependent_option(SLANG_RHI_ENABLE_VULKAN "Enable Vulkan backend" ON "SLANG_RHI_HAS_VULKAN" OFF)
set(SLANG_RHI_HAS_METAL ${APPLE})
cmake_dependent_option(SLANG_RHI_ENABLE_METAL "Enable Metal backend" ON "SLANG_RHI_HAS_METAL" OFF)
set(SLANG_RHI_HAS_CUDA ON)
if(APPLE)
set(SLANG_RHI_HAS_CUDA OFF)
endif()
cmake_dependent_option(SLANG_RHI_ENABLE_CUDA "Enable CUDA backend" ON "SLANG_RHI_HAS_CUDA" OFF)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()

if(APPLE)
enable_language(OBJCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-assume -Wno-switch")
endif()

set(SLANG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../slang/include CACHE STRING "Slang include directory")
set(SLANG_BINARY_DIR ${CMAKE_SOURCE_DIR}/../slang/build/Debug CACHE STRING "Slang binary directory")

if(CMAKE_CONFIGURATION_TYPES)
set(SLANG_RHI_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
else()
set(SLANG_RHI_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()

if(SLANG_RHI_BUILD_SHARED)
add_library(slang-rhi SHARED)
else()
add_library(slang-rhi STATIC)
endif()

if(SLANG_RHI_MASTER_PROJECT)
add_library(slang SHARED IMPORTED GLOBAL)
if(WIN32)
set_target_properties(slang PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${SLANG_INCLUDE_DIR}
IMPORTED_IMPLIB ${SLANG_BINARY_DIR}/lib/slang.lib
IMPORTED_LOCATION ${SLANG_BINARY_DIR}/bin/slang.dll
)
elseif(APPLE)
set_target_properties(slang PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${SLANG_INCLUDE_DIR}
IMPORTED_LOCATION ${SLANG_BINARY_DIR}/lib/libslang.dylib
)
endif()

if(WIN32)
add_custom_command(
OUTPUT ${SLANG_RHI_OUTPUT_DIRECTORY}/slang.dll
DEPENDS ${SLANG_BINARY_DIR}/bin/slang.dll
COMMAND ${CMAKE_COMMAND} -E copy ${SLANG_BINARY_DIR}/bin/slang.dll ${SLANG_RHI_OUTPUT_DIRECTORY}/slang.dll
COMMENT "Copying slang.dll"
)
add_custom_target(slang_binary_files ALL DEPENDS ${SLANG_RHI_OUTPUT_DIRECTORY}/slang.dll)
add_dependencies(slang-rhi slang_binary_files)
endif()

target_link_libraries(slang-rhi PRIVATE slang)

# sgl_copy_binary(${SLANG_DIR}/bin/slang.dll .)
# sgl_copy_binary(${SLANG_DIR}/bin/slang-glslang.dll .)
# sgl_copy_binary(${SLANG_DIR}/bin/slang-llvm.dll .)
# sgl_copy_binary(${SLANG_DIR}/bin/slang-rt.dll .)
else()
target_include_directories(slang-rhi PUBLIC ${SLANG_INCLUDE_DIR})
endif()

file(GLOB RHI_SOURCES
src/*.cpp
src/core/*.cpp
src/cpu/*.cpp
src/debug-layer/*.cpp
)
target_sources(slang-rhi PRIVATE ${RHI_SOURCES})

if(APPLE)
file(GLOB OBJC_SOURCES src/*.mm)
target_sources(slang-rhi PRIVATE ${OBJC_SOURCES})
endif()
if(SLANG_RHI_ENABLE_D3D11 OR SLANG_RHI_HAS_D3D12)
file(GLOB D3D_SOURCES src/d3d/*.cpp src/nvapi/*.cpp)
target_sources(slang-rhi PRIVATE ${D3D_SOURCES})
endif()
if(SLANG_RHI_ENABLE_D3D11)
file(GLOB D3D11_SOURCES src/d3d11/*.cpp)
target_sources(slang-rhi PRIVATE ${D3D11_SOURCES})
endif()
if(SLANG_RHI_ENABLE_D3D12)
file(GLOB D3D12_SOURCES src/d3d12/*.cpp)
target_sources(slang-rhi PRIVATE ${D3D12_SOURCES})
endif()
if(SLANG_RHI_ENABLE_VULKAN)
file(GLOB VULKAN_SOURCES src/vulkan/*.cpp)
target_sources(slang-rhi PRIVATE ${VULKAN_SOURCES})

add_library(slang-rhi-vulkan-headers INTERFACE)
target_include_directories(slang-rhi-vulkan-headers INTERFACE external/vulkan-headers/include)
target_link_libraries(slang-rhi PRIVATE slang-rhi-vulkan-headers)
endif()
if(SLANG_RHI_ENABLE_METAL)
file(GLOB METAL_SOURCES src/metal/*.cpp src/metal/*.mm)
target_sources(slang-rhi PRIVATE ${METAL_SOURCES})

add_library(slang-rhi-metal-cpp INTERFACE)
target_include_directories(slang-rhi-metal-cpp INTERFACE external/metal-cpp)
target_link_libraries(slang-rhi-metal-cpp INTERFACE "-framework Foundation" "-framework Metal" "-framework QuartzCore")
target_link_libraries(slang-rhi PRIVATE slang-rhi-metal-cpp)
endif()
if(SLANG_RHI_ENABLE_CUDA)
file(GLOB CUDA_SOURCES src/cuda/*.cpp)
target_sources(slang-rhi PRIVATE ${CUDA_SOURCES})
endif()

target_include_directories(slang-rhi PUBLIC include)
target_include_directories(slang-rhi PRIVATE src)
target_compile_definitions(slang-rhi
PRIVATE
SLANG_RHI_ENABLE_D3D11=$<BOOL:${SLANG_RHI_ENABLE_D3D11}>
SLANG_RHI_ENABLE_D3D12=$<BOOL:${SLANG_RHI_ENABLE_D3D12}>
SLANG_RHI_ENABLE_VULKAN=$<BOOL:${SLANG_RHI_ENABLE_VULKAN}>
SLANG_RHI_ENABLE_METAL=$<BOOL:${SLANG_RHI_ENABLE_METAL}>
SLANG_RHI_ENABLE_CUDA=$<BOOL:${SLANG_RHI_ENABLE_CUDA}>
$<$<PLATFORM_ID:Windows>:NOMINMAX> # do not define min/max macros
$<$<PLATFORM_ID:Windows>:UNICODE> # force character map to unicode
)
target_compile_features(slang-rhi PRIVATE cxx_std_17)

if(SLANG_RHI_BUILD_TESTS)
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE external/doctest)

add_library(stb INTERFACE)
target_include_directories(stb INTERFACE external/stb)

file(GLOB TEST_SOURCES
tests/*.cpp
)
add_executable(slang-rhi-tests)
target_sources(slang-rhi-tests PRIVATE ${TEST_SOURCES})
target_compile_definitions(slang-rhi-tests
PRIVATE
$<$<PLATFORM_ID:Windows>:NOMINMAX> # do not define min/max macros
$<$<PLATFORM_ID:Windows>:UNICODE> # force character map to unicode
)
target_compile_features(slang-rhi-tests PRIVATE cxx_std_17)
target_include_directories(slang-rhi-tests PRIVATE tests)
target_link_libraries(slang-rhi-tests PRIVATE doctest stb slang slang-rhi)
endif()
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016, Carnegie Mellon University and NVIDIA Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# slang-rhi

## Introduction

The `slang-rhi` library provides a render hardware interface for the Slang shading language.
It is based on the "gfx" layer originally developed in the Slang repository.
This library is under active refactoring and development, and is not yet ready for general use.

## License

`slang-rhi` is released under the MIT license. See the file [LICENSE](LICENSE) for more information.

`slang-rhi` depends on the following third-party libraries, which have their own license:

- [doctest](https://github.com/doctest/doctest) (MIT)
- [metal-cpp](https://developer.apple.com/metal/cpp) (Apache 2.0)
- [RenderDoc API](https://github.com/baldurk/renderdoc) (MIT)
- [stb](https://github.com/nothings/stb) (Public Domain)
- [Vulkan-Headers](https://github.com/KhronosGroup/Vulkan-Headers) (MIT)
Loading

0 comments on commit 4ab6f46

Please sign in to comment.