summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 13:59:28 +0800
committerGitHub <noreply@github.com>2024-10-29 13:59:28 +0800
commita729c15e9dce9f5116a38afc66329ab2ca4cea54 (patch)
tree9580072eb0d796b51c04ad5be95230a747709150
parenta15d770242f88aa4b33cd7d3a97de9c8d86a2315 (diff)
preparation for clang format (#5422)
* Clang-format excludes * Add .clang-format * Don't clang-format in external * Missing includes and forward declarations * Replace wonky include-once macro name * neaten include naming * Add clang-format to formatting script * Add xargs and diff to required binaries * add clang-format to ci formatting check * Add max version check to formatting script * temporarily disable checking formatting for cpp files
-rw-r--r--.clang-format44
-rw-r--r--.github/actions/format-setup/action.yml2
-rw-r--r--.github/workflows/check-formatting.yml4
-rw-r--r--examples/example-base/test-base.cpp7
-rw-r--r--examples/hello-world/vulkan-api.h2
-rw-r--r--external/.clang-format1
-rw-r--r--extras/.clang-format48
-rwxr-xr-xextras/formatting.sh50
-rw-r--r--include/.clang-format2
-rw-r--r--include/slang-gfx.h6
-rw-r--r--source/compiler-core/slang-artifact-desc-util.cpp2
-rw-r--r--source/compiler-core/slang-dxc-compiler.cpp47
-rw-r--r--source/compiler-core/slang-nvrtc-compiler.cpp2
-rw-r--r--source/core/slang-blob.h2
-rw-r--r--source/core/slang-chunked-list.h2
-rw-r--r--source/core/slang-common.h6
-rw-r--r--source/core/slang-crypto.h2
-rw-r--r--source/core/slang-file-system.h2
-rw-r--r--source/core/slang-free-list.h2
-rw-r--r--source/core/slang-hash.h2
-rw-r--r--source/core/slang-hex-dump-util.h2
-rw-r--r--source/core/slang-http.h2
-rw-r--r--source/core/slang-io.cpp9
-rw-r--r--source/core/slang-linked-list.h3
-rw-r--r--source/core/slang-list.h2
-rw-r--r--source/core/slang-math.h1
-rw-r--r--source/core/slang-memory-arena.h2
-rw-r--r--source/core/slang-persistent-cache.h2
-rw-r--r--source/core/slang-platform.h2
-rw-r--r--source/core/slang-random-generator.h2
-rw-r--r--source/core/slang-shared-library.h2
-rw-r--r--source/core/slang-short-list.h2
-rw-r--r--source/core/slang-smart-pointer.h3
-rw-r--r--source/core/slang-type-convert-util.h2
-rw-r--r--source/core/slang-type-text-util.cpp2
-rw-r--r--source/core/slang-type-text-util.h2
-rw-r--r--source/slang-glslang/slang-glslang.h4
-rw-r--r--source/slang-llvm/slang-llvm.cpp3
-rw-r--r--source/slang/slang-ast-iterator.h1
-rw-r--r--source/slang/slang-ast-support-types.h2
-rw-r--r--source/slang/slang-ast-val.h1
-rw-r--r--[-rwxr-xr-x]source/slang/slang-compiler.h0
-rw-r--r--source/slang/slang-emit-precedence.h4
-rw-r--r--source/slang/slang-ir-inst-defs.h2
-rw-r--r--source/slang/slang-ir-variable-scope-correction.h1
-rw-r--r--source/slang/slang-repro.cpp4
-rw-r--r--source/slang/slang-serialize-types.cpp7
-rw-r--r--source/slang/slang-syntax.cpp2
-rw-r--r--source/slang/slang-type-layout.h2
-rw-r--r--tools/gfx/open-gl/render-gl.cpp8
-rw-r--r--tools/gfx/simple-transient-resource-heap.h1
-rw-r--r--tools/gfx/vulkan/vk-api.h3
-rw-r--r--tools/render-test/shader-input-layout.cpp2
53 files changed, 208 insertions, 114 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000..7360b01ea
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,44 @@
+BasedOnStyle: LLVM
+
+# Whitespace
+MaxEmptyLinesToKeep: 2
+IndentWidth: 4
+ColumnLimit: 100
+
+# Preprocessor
+AlignEscapedNewlines: Left
+IncludeBlocks: Regroup
+
+# Functions
+AllowAllArgumentsOnNextLine: false
+BinPackArguments: false
+BinPackParameters: false
+AllowAllParametersOfDeclarationOnNextLine: false
+PenaltyReturnTypeOnItsOwnLine: 9999999
+PenaltyBreakBeforeFirstCallParameter: 6
+AllowShortFunctionsOnASingleLine: Inline
+
+# Brackets and braces
+AlignAfterOpenBracket: AlwaysBreak
+BreakBeforeBraces: Allman
+
+# Pointers
+PointerAlignment: Left
+
+# Classes
+PackConstructorInitializers: NextLineOnly
+BreakConstructorInitializers: BeforeComma
+AccessModifierOffset: -4
+
+# Switch statements
+IndentCaseBlocks: true
+AllowShortCaseLabelsOnASingleLine: true
+AlignConsecutiveShortCaseStatements:
+ Enabled: true
+
+# Templates
+SpaceAfterTemplateKeyword: false
+AlwaysBreakTemplateDeclarations: true
+
+# Misc
+SortUsingDeclarations: false
diff --git a/.github/actions/format-setup/action.yml b/.github/actions/format-setup/action.yml
index 58eddac77..d99be4d3a 100644
--- a/.github/actions/format-setup/action.yml
+++ b/.github/actions/format-setup/action.yml
@@ -16,6 +16,6 @@ runs:
tmpdir=$(mktemp -d)
curl -L -H "Authorization: token ${{github.token}}" \
-o "$tmpdir/clang-format" \
- https://github.com/shader-slang/slang-binaries/raw/4e88845ec51641b4c92e68027e359090bdb219e0/clang-format/x86_64-linux/bin/clang-format
+ https://github.com/shader-slang/slang-binaries/raw/306d22efc0f5f72c7230b0b6b7c99f03c46995bd/clang-format/x86_64-linux/bin/clang-format
chmod +x "$tmpdir/clang-format"
echo "$tmpdir" >> $GITHUB_PATH
diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml
index c923d1855..f4226cd8c 100644
--- a/.github/workflows/check-formatting.yml
+++ b/.github/workflows/check-formatting.yml
@@ -10,7 +10,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- - name: Setup
- uses: ./.github/actions/format-setup
+ - uses: ./.github/actions/format-setup
- run: ./extras/formatting.sh --check-only
-
diff --git a/examples/example-base/test-base.cpp b/examples/example-base/test-base.cpp
index 0e0f8a69c..9d8ec8ce6 100644
--- a/examples/example-base/test-base.cpp
+++ b/examples/example-base/test-base.cpp
@@ -1,8 +1,11 @@
#include "test-base.h"
#ifdef _WIN32
-#include <windows.h>
-#include <shellapi.h>
+// clang-format off
+// include ordering sensitive
+# include <windows.h>
+# include <shellapi.h>
+// clang-format on
#endif
int TestBase::parseOption(int argc, char** argv)
diff --git a/examples/hello-world/vulkan-api.h b/examples/hello-world/vulkan-api.h
index 17d0465a6..89ca9747d 100644
--- a/examples/hello-world/vulkan-api.h
+++ b/examples/hello-world/vulkan-api.h
@@ -7,6 +7,7 @@
// the Vulkan API.
// The Vulkan function pointers we will use in this example.
+// clang-format off
#define VK_API_GLOBAL_PROCS(x) \
x(vkGetInstanceProcAddr) \
x(vkCreateInstance) \
@@ -87,6 +88,7 @@
/* */
#define VK_API_DECLARE_PROC(NAME) PFN_##NAME NAME = nullptr;
+// clang-format on
struct VulkanAPI
{
diff --git a/external/.clang-format b/external/.clang-format
new file mode 100644
index 000000000..e3845288a
--- /dev/null
+++ b/external/.clang-format
@@ -0,0 +1 @@
+DisableFormat: true
diff --git a/extras/.clang-format b/extras/.clang-format
deleted file mode 100644
index 81cacff35..000000000
--- a/extras/.clang-format
+++ /dev/null
@@ -1,48 +0,0 @@
----
-BasedOnStyle: LLVM
-IndentWidth: 4
----
-Language: Cpp
-# Force pointers to the type for C++.
-IndentPPDirectives: AfterHash
-DerivePointerAlignment: false
-PointerAlignment: Left
-BinPackArguments: false
-BinPackParameters: false
-ExperimentalAutoDetectBinPacking: false
-AllowAllParametersOfDeclarationOnNextLine: true
-NamespaceIndentation: None
-FixNamespaceComments: true
-AccessModifierOffset: -4
-AlignTrailingComments: false
-ConstructorInitializerIndentWidth: 4
-AlignEscapedNewlinesLeft: true
-PenaltyReturnTypeOnItsOwnLine: 100
-ColumnLimit: 100
-IncludeBlocks: Preserve
-AlignAfterOpenBracket: AlwaysBreak
-IndentCaseBlocks: true
-SortIncludes: true
-SortUsingDeclarations: true
-UseTab: Never
-BreakConstructorInitializers: BeforeComma
-BreakInheritanceList: BeforeComma
-BreakBeforeBraces: Custom
-BraceWrapping:
- AfterCaseLabel: true
- AfterClass: true
- AfterEnum: true
- AfterStruct: true
- AfterUnion: true
- SplitEmptyFunction: false
- AfterControlStatement: Always
- AfterFunction: true
- AfterNamespace: true
- AfterExternBlock: true
- BeforeCatch: true
- BeforeElse: true
- # BeforeLambdaBody: true
- # BeforeWhile: false
- IndentBraces: false
- SplitEmptyFunction: false
- SplitEmptyRecord: false \ No newline at end of file
diff --git a/extras/formatting.sh b/extras/formatting.sh
index a53930eaf..58d7d3509 100755
--- a/extras/formatting.sh
+++ b/extras/formatting.sh
@@ -40,7 +40,8 @@ cd "$source_dir" || exit 1
require_bin() {
local name="$1"
- local required="$2"
+ local min_version="$2"
+ local max_version="${3:-}"
local version
if ! command -v "$name" &>/dev/null; then
@@ -50,16 +51,29 @@ require_bin() {
fi
if [ "$no_version_check" -eq 0 ]; then
- version=$("$name" --version | grep -oP "$name(?:\s+version)?\s+\K\d+\.\d+\.?\d*")
- if ! printf '%s\n%s\n' "$required" "$version" | sort -V -C; then
- echo "$name version $version is too old. Version $required or newer is required."
+ version=$("$name" --version | grep -oP "\d+\.\d+\.?\d*" | head -n1)
+
+ if ! printf '%s\n%s\n' "$min_version" "$version" | sort -V -C; then
+ echo "$name version $version is too old. Version $min_version or newer is required."
missing_bin=1
+ return
+ fi
+
+ if [ -n "$max_version" ]; then
+ if ! printf '%s\n%s\n' "$version" "$max_version" | sort -V -C; then
+ echo "$name version $version is too new. Version less than $max_version is required."
+ missing_bin=1
+ return
+ fi
fi
fi
}
require_bin "git" "1.8"
require_bin "gersemi" "0.17"
+require_bin "xargs" "3"
+require_bin "diff" "2"
+require_bin "clang-format" "17" "18"
if [ "$missing_bin" ]; then
exit 1
@@ -84,7 +98,33 @@ cmake_formatting() {
fi
}
+cpp_formatting() {
+ readarray -t files < <(git ls-files '*.cpp' '*.hpp' '*.c' '*.h')
+
+ if [ "$check_only" -eq 1 ]; then
+ local tmpdir
+ tmpdir=$(mktemp -d)
+ trap 'rm -rf "$tmpdir"' EXIT
+
+ printf '%s\n' "${files[@]}" | xargs -P "$(nproc)" -I{} bash -c "
+ mkdir -p \"\$(dirname \"$tmpdir/{}\")\"
+ diff -u --color=always --label \"{}\" --label \"{}\" \"{}\" <(clang-format \"{}\") > \"$tmpdir/{}\"
+ :
+ "
+
+ for file in "${files[@]}"; do
+ if [ -s "$tmpdir/$file" ]; then
+ cat "$tmpdir/$file"
+ exit_code=1
+ fi
+ done
+ else
+ printf '%s\n' "${files[@]}" | xargs -n1 -P "$(nproc)" clang-format -i
+ fi
+}
+
cmake_formatting
+# Disable until we've formatted the code
+# cpp_formatting
exit $exit_code
-
diff --git a/include/.clang-format b/include/.clang-format
new file mode 100644
index 000000000..12ac8862d
--- /dev/null
+++ b/include/.clang-format
@@ -0,0 +1,2 @@
+BasedOnStyle: InheritParentConfig
+IndentPPDirectives: BeforeHash
diff --git a/include/slang-gfx.h b/include/slang-gfx.h
index 207b3e136..7756d76da 100644
--- a/include/slang-gfx.h
+++ b/include/slang-gfx.h
@@ -199,6 +199,7 @@ public:
// TODO: Confirm with Yong that we really want this naming convention
// TODO: Rename to what?
// Dont' change without keeping in sync with Format
+// clang-format off
#define GFX_FORMAT(x) \
x( Unknown, 0, 0) \
\
@@ -304,8 +305,9 @@ public:
\
x(R64_UINT, 8, 1) \
\
- x(R64_SINT, 8, 1) \
- \
+ x(R64_SINT, 8, 1)
+// clang-format on
+
// TODO: This should be generated from above
// TODO: enum class should be explicitly uint32_t or whatever's appropriate
/// Different formats of things like pixels or elements of vertices
diff --git a/source/compiler-core/slang-artifact-desc-util.cpp b/source/compiler-core/slang-artifact-desc-util.cpp
index 907a953ce..7c2622f70 100644
--- a/source/compiler-core/slang-artifact-desc-util.cpp
+++ b/source/compiler-core/slang-artifact-desc-util.cpp
@@ -154,6 +154,7 @@ bool isDerivedFrom(ENUM_TYPE kind, ENUM_TYPE base) { return g_table##ENUM_TYPE.i
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! ArtifactKind !!!!!!!!!!!!!!!!!!!!!!! */
+// clang-format off
#define SLANG_ARTIFACT_KIND(x) \
x(Invalid, Invalid) \
x(Base, Invalid) \
@@ -245,6 +246,7 @@ SLANG_HIERARCHICAL_ENUM(ArtifactPayload, SLANG_ARTIFACT_PAYLOAD, SLANG_ARTIFACT_
x(Kernel, CodeLike) \
x(Host, CodeLike) \
x(Obfuscated, Base)
+// clang-format on
#define SLANG_ARTIFACT_STYLE_ENTRY(TYPE, PARENT) { Index(ArtifactStyle::TYPE), Index(ArtifactStyle::PARENT), #TYPE },
diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp
index 3a949b3bd..30bf71968 100644
--- a/source/compiler-core/slang-dxc-compiler.cpp
+++ b/source/compiler-core/slang-dxc-compiler.cpp
@@ -37,26 +37,33 @@
// generate code on Windows.
#if SLANG_ENABLE_DXIL_SUPPORT
-# ifdef _WIN32
-# include <windows.h>
-# include <unknwn.h>
-# include "../../external/dxc/dxcapi.h"
-# else
-# include "../../external/dxc/dxcapi.h"
-
-# ifdef __uuidof
- // DXC's WinAdapter.h defines __uuidof(T) over types, but the existing
- // usage in this file is over values (both are accepted on MSVC.)
- // We also need to decay through Slang::ComPtr, hence the helper struct
- template <typename T>
- struct StripSlangComPtr { using type = T; };
- template <typename T>
- struct StripSlangComPtr<Slang::ComPtr<T>> { using type = T; };
-# undef __uuidof
-# define __uuidof(x) __emulated_uuidof<StripSlangComPtr<std::decay_t<decltype(x)>>::type>()
-# endif
-# endif
-
+# ifdef _WIN32
+# include <unknwn.h>
+# include <windows.h>
+# endif
+
+# include "../../external/dxc/dxcapi.h"
+
+# ifndef _WIN32
+# ifdef __uuidof
+// DXC's WinAdapter.h defines __uuidof(T) over types, but the existing
+// usage in this file is over values (both are accepted on MSVC.)
+// We also need to decay through Slang::ComPtr, hence the helper struct
+template<typename T>
+struct StripSlangComPtr
+{
+ using type = T;
+};
+template<typename T>
+struct StripSlangComPtr<Slang::ComPtr<T>>
+{
+ using type = T;
+};
+# undef __uuidof
+# define __uuidof(x) \
+ __emulated_uuidof<StripSlangComPtr<std::decay_t<decltype(x)>>::type>()
+# endif
+# endif
#endif
namespace Slang
diff --git a/source/compiler-core/slang-nvrtc-compiler.cpp b/source/compiler-core/slang-nvrtc-compiler.cpp
index 80fde277b..8e234e634 100644
--- a/source/compiler-core/slang-nvrtc-compiler.cpp
+++ b/source/compiler-core/slang-nvrtc-compiler.cpp
@@ -41,6 +41,7 @@ typedef enum {
typedef struct _nvrtcProgram *nvrtcProgram;
+// clang-format off
#define SLANG_NVRTC_FUNCS(x) \
x(const char*, nvrtcGetErrorString, (nvrtcResult result)) \
x(nvrtcResult, nvrtcVersion, (int *major, int *minor)) \
@@ -53,6 +54,7 @@ typedef struct _nvrtcProgram *nvrtcProgram;
x(nvrtcResult, nvrtcGetProgramLog, (nvrtcProgram prog, char *log))\
x(nvrtcResult, nvrtcAddNameExpression, (nvrtcProgram prog, const char * const name_expression)) \
x(nvrtcResult, nvrtcGetLoweredName, (nvrtcProgram prog, const char *const name_expression, const char** lowered_name))
+// clang-format on
} // namespace nvrtc
diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h
index 2b752b306..4df8f0db6 100644
--- a/source/core/slang-blob.h
+++ b/source/core/slang-blob.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_BLOB_H
#define SLANG_CORE_BLOB_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-string.h"
#include "slang-list.h"
diff --git a/source/core/slang-chunked-list.h b/source/core/slang-chunked-list.h
index f963ecfab..d414eaefb 100644
--- a/source/core/slang-chunked-list.h
+++ b/source/core/slang-chunked-list.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_CHUNKED_LIST_H
#define SLANG_CORE_CHUNKED_LIST_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-allocator.h"
#include "slang-array-view.h"
diff --git a/source/core/slang-common.h b/source/core/slang-common.h
index 8c84894ca..2952eccd2 100644
--- a/source/core/slang-common.h
+++ b/source/core/slang-common.h
@@ -1,7 +1,6 @@
-#ifndef SLANG_CORE_COMMON_H
-#define SLANG_CORE_COMMON_H
+#pragma once
-#include "../../include/slang.h"
+#include "slang.h"
#include <assert.h>
@@ -237,7 +236,6 @@ template<typename T> void slang_use_obj(T&) {}
#define SLANG_UNREFERENCED_PARAMETER(P) slang_use_obj(P)
#define SLANG_UNREFERENCED_VARIABLE(P) slang_use_obj(P)
-#endif
#if defined(SLANG_RT_DYNAMIC)
#if defined(_MSC_VER)
diff --git a/source/core/slang-crypto.h b/source/core/slang-crypto.h
index c6cd733e7..feab88aa4 100644
--- a/source/core/slang-crypto.h
+++ b/source/core/slang-crypto.h
@@ -1,5 +1,5 @@
#pragma once
-#include "../../include/slang.h"
+#include "slang.h"
#include "../core/slang-string.h"
#include "../core/slang-blob.h"
#include "../core/slang-list.h"
diff --git a/source/core/slang-file-system.h b/source/core/slang-file-system.h
index 7de5b5dbd..dad2731d9 100644
--- a/source/core/slang-file-system.h
+++ b/source/core/slang-file-system.h
@@ -1,7 +1,7 @@
#ifndef SLANG_FILE_SYSTEM_H_INCLUDED
#define SLANG_FILE_SYSTEM_H_INCLUDED
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-com-helper.h"
#include "slang-com-ptr.h"
diff --git a/source/core/slang-free-list.h b/source/core/slang-free-list.h
index 97aee5bc9..5c4e55607 100644
--- a/source/core/slang-free-list.h
+++ b/source/core/slang-free-list.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_FREE_LIST_H
#define SLANG_CORE_FREE_LIST_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-common.h"
diff --git a/source/core/slang-hash.h b/source/core/slang-hash.h
index ff0cdc181..12239221b 100644
--- a/source/core/slang-hash.h
+++ b/source/core/slang-hash.h
@@ -1,8 +1,8 @@
#ifndef SLANG_CORE_HASH_H
#define SLANG_CORE_HASH_H
-#include "../../include/slang.h"
#include "slang-math.h"
+#include "slang.h"
#include "../../external/unordered_dense/include/ankerl/unordered_dense.h"
diff --git a/source/core/slang-hex-dump-util.h b/source/core/slang-hex-dump-util.h
index 6dcabf2ef..037355f2d 100644
--- a/source/core/slang-hex-dump-util.h
+++ b/source/core/slang-hex-dump-util.h
@@ -5,7 +5,7 @@
#include "slang-string.h"
#include "slang-list.h"
-#include "../../include/slang.h"
+#include "slang.h"
namespace Slang
{
diff --git a/source/core/slang-http.h b/source/core/slang-http.h
index 09f2fd91e..11d834bd8 100644
--- a/source/core/slang-http.h
+++ b/source/core/slang-http.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_HTTP_H
#define SLANG_CORE_HTTP_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-string.h"
#include "slang-list.h"
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 928026267..edd21639b 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -15,9 +15,12 @@
#include <sys/stat.h>
#ifdef _WIN32
-# include <direct.h>
-# include <windows.h>
-# include <shellapi.h>
+// clang-format off
+// include ordering sensitive
+# include <windows.h>
+# include <direct.h>
+# include <shellapi.h>
+// clang-format on
#endif
#if defined(__linux__) || defined(__CYGWIN__) || SLANG_APPLE_FAMILY || SLANG_WASM
diff --git a/source/core/slang-linked-list.h b/source/core/slang-linked-list.h
index 496eddb1a..ff8f7ce40 100644
--- a/source/core/slang-linked-list.h
+++ b/source/core/slang-linked-list.h
@@ -1,9 +1,10 @@
#ifndef SLANG_CORE_LINKED_LIST_H
#define SLANG_CORE_LINKED_LIST_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-allocator.h"
+#include "slang-list.h"
#include <type_traits>
namespace Slang
diff --git a/source/core/slang-list.h b/source/core/slang-list.h
index 0b7b803bf..b1c67e438 100644
--- a/source/core/slang-list.h
+++ b/source/core/slang-list.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_LIST_H
#define SLANG_CORE_LIST_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-allocator.h"
#include "slang-math.h"
diff --git a/source/core/slang-math.h b/source/core/slang-math.h
index 231e59007..51ada76a9 100644
--- a/source/core/slang-math.h
+++ b/source/core/slang-math.h
@@ -1,6 +1,7 @@
#ifndef SLANG_CORE_MATH_H
#define SLANG_CORE_MATH_H
+#include "slang.h"
#include <cmath>
namespace Slang
diff --git a/source/core/slang-memory-arena.h b/source/core/slang-memory-arena.h
index 1d899b064..cbd0fdc56 100644
--- a/source/core/slang-memory-arena.h
+++ b/source/core/slang-memory-arena.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_MEMORY_ARENA_H
#define SLANG_CORE_MEMORY_ARENA_H
-#include "../../include/slang.h"
+#include "slang.h"
#include <stdlib.h>
#include <string.h>
diff --git a/source/core/slang-persistent-cache.h b/source/core/slang-persistent-cache.h
index 1411b9094..e7d02b861 100644
--- a/source/core/slang-persistent-cache.h
+++ b/source/core/slang-persistent-cache.h
@@ -1,8 +1,8 @@
#pragma once
-#include "../../include/slang.h"
#include "../core/slang-crypto.h"
#include "../core/slang-io.h"
#include "../core/slang-string.h"
+#include "slang.h"
#include <mutex>
diff --git a/source/core/slang-platform.h b/source/core/slang-platform.h
index 57a624e6d..81bae88d6 100644
--- a/source/core/slang-platform.h
+++ b/source/core/slang-platform.h
@@ -2,8 +2,8 @@
#ifndef SLANG_CORE_PLATFORM_H
#define SLANG_CORE_PLATFORM_H
-#include "../../include/slang.h"
#include "../core/slang-string.h"
+#include "slang.h"
namespace Slang
{
diff --git a/source/core/slang-random-generator.h b/source/core/slang-random-generator.h
index be416c8e2..fa83fec3b 100644
--- a/source/core/slang-random-generator.h
+++ b/source/core/slang-random-generator.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_RANDOM_GENERATOR_H
#define SLANG_CORE_RANDOM_GENERATOR_H
-#include "../../include/slang.h"
+#include "slang.h"
#include <stdlib.h>
#include <string.h>
diff --git a/source/core/slang-shared-library.h b/source/core/slang-shared-library.h
index ede5b1615..d6c1618ec 100644
--- a/source/core/slang-shared-library.h
+++ b/source/core/slang-shared-library.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_SHARED_LIBRARY_H
#define SLANG_CORE_SHARED_LIBRARY_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-com-helper.h"
#include "slang-com-ptr.h"
diff --git a/source/core/slang-short-list.h b/source/core/slang-short-list.h
index f40223a32..66165fc72 100644
--- a/source/core/slang-short-list.h
+++ b/source/core/slang-short-list.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_SHORT_LIST_H
#define SLANG_CORE_SHORT_LIST_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-allocator.h"
#include "slang-math.h"
diff --git a/source/core/slang-smart-pointer.h b/source/core/slang-smart-pointer.h
index 2f1f485dc..a45f7a8ad 100644
--- a/source/core/slang-smart-pointer.h
+++ b/source/core/slang-smart-pointer.h
@@ -4,8 +4,9 @@
#include "slang-common.h"
#include "slang-hash.h"
#include "slang-type-traits.h"
+#include "slang.h"
-#include "../../include/slang.h"
+#include "slang.h"
namespace Slang
{
diff --git a/source/core/slang-type-convert-util.h b/source/core/slang-type-convert-util.h
index 0fd221450..70565b896 100644
--- a/source/core/slang-type-convert-util.h
+++ b/source/core/slang-type-convert-util.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_TYPE_CONVERT_UTIL_H
#define SLANG_CORE_TYPE_CONVERT_UTIL_H
-#include "../../include/slang.h"
+#include "slang.h"
namespace Slang
{
diff --git a/source/core/slang-type-text-util.cpp b/source/core/slang-type-text-util.cpp
index f02325792..51ed2060e 100644
--- a/source/core/slang-type-text-util.cpp
+++ b/source/core/slang-type-text-util.cpp
@@ -9,6 +9,7 @@ namespace Slang
namespace { // anonymous
+// clang-format off
#define SLANG_SCALAR_TYPES(x) \
x(None, none) \
x(Void, void) \
@@ -20,6 +21,7 @@ namespace { // anonymous
x(UInt64, uint64_t) \
x(Float32, float) \
x(Float64, double)
+// clang-format on
struct ScalarTypeInfo
{
diff --git a/source/core/slang-type-text-util.h b/source/core/slang-type-text-util.h
index 1e1c25364..6d07e7d58 100644
--- a/source/core/slang-type-text-util.h
+++ b/source/core/slang-type-text-util.h
@@ -1,7 +1,7 @@
#ifndef SLANG_CORE_TYPE_TEXT_UTIL_H
#define SLANG_CORE_TYPE_TEXT_UTIL_H
-#include "../../include/slang.h"
+#include "slang.h"
#include "slang-string.h"
#include "slang-array-view.h"
diff --git a/source/slang-glslang/slang-glslang.h b/source/slang-glslang/slang-glslang.h
index 00205a114..f3d81fc62 100644
--- a/source/slang-glslang/slang-glslang.h
+++ b/source/slang-glslang/slang-glslang.h
@@ -20,6 +20,8 @@ struct glsl_SPIRVVersion
int major, minor, patch;
};
+// clang-format off
+
#define SLANG_GLSLANG_COMPILE_REQUEST_1_0(x) \
x(sourcePath) \
x(inputBegin) \
@@ -35,6 +37,8 @@ struct glsl_SPIRVVersion
#define SLANG_GLSLANG_FIELD_COPY(name) name = in.name;
+// clang-format on
+
// Pre-declare
struct glslang_CompileRequest_1_1;
diff --git a/source/slang-llvm/slang-llvm.cpp b/source/slang-llvm/slang-llvm.cpp
index b84a79340..811b27123 100644
--- a/source/slang-llvm/slang-llvm.cpp
+++ b/source/slang-llvm/slang-llvm.cpp
@@ -386,10 +386,12 @@ static uint64_t __stdcall _aulldiv(uint64_t a, uint64_t b)
#endif
+
// These are only the functions that cannot be implemented with 'reasonable performance' in the prelude.
// It is assumed that calling from JIT to C function whilst not super expensive, is an issue.
// name, cppName, retType, paramTypes
+// clang-format off
#define SLANG_LLVM_FUNCS(x) \
x(F64_ceil, ceil, double, (double)) \
x(F64_floor, floor, double, (double)) \
@@ -476,6 +478,7 @@ static uint64_t __stdcall _aulldiv(uint64_t a, uint64_t b)
\
x(__bzero, OSXSpecific::bzero, void, (void*, size_t))
#endif
+// clang-format on
#if SLANG_WINDOWS_FAMILY
# if SLANG_PROCESSOR_X86
diff --git a/source/slang/slang-ast-iterator.h b/source/slang/slang-ast-iterator.h
index c6f74fdf8..bbabb8ab5 100644
--- a/source/slang/slang-ast-iterator.h
+++ b/source/slang/slang-ast-iterator.h
@@ -1,5 +1,6 @@
#pragma once
#include "slang-syntax.h"
+#include "slang-visitor.h"
namespace Slang
{
diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h
index e35f970f5..3b10539cf 100644
--- a/source/slang/slang-ast-support-types.h
+++ b/source/slang/slang-ast-support-types.h
@@ -9,7 +9,7 @@
#include "slang-profile.h"
#include "slang-type-system-shared.h"
-#include "../../include/slang.h"
+#include "slang.h"
#include "../core/slang-semantic-version.h"
diff --git a/source/slang/slang-ast-val.h b/source/slang/slang-ast-val.h
index 8752195cb..98161596d 100644
--- a/source/slang/slang-ast-val.h
+++ b/source/slang/slang-ast-val.h
@@ -3,6 +3,7 @@
#pragma once
#include "slang-ast-base.h"
+#include "slang-ast-decl.h"
namespace Slang {
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 67c931ac8..67c931ac8 100755..100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
diff --git a/source/slang/slang-emit-precedence.h b/source/slang/slang-emit-precedence.h
index f23287bcb..75a45c7ce 100644
--- a/source/slang/slang-emit-precedence.h
+++ b/source/slang/slang-emit-precedence.h
@@ -26,6 +26,7 @@ namespace Slang
// x macro of precedence of types in order.
// Used because in header, need to prefix macros to avoid clashes, and this style allows for prefixing without additional clutter
+// clang-format off
#define SLANG_PRECEDENCE(x) \
x(None, NON_ASSOC) \
x(Comma, LEFT) \
@@ -50,6 +51,7 @@ namespace Slang
x(Prefix, RIGHT) \
x(Postfix, LEFT) \
x(Atomic, NON_ASSOC)
+// clang-format on
// Precedence enum produced from the SLANG_PRECEDENCE macro
enum EPrecedence
@@ -59,6 +61,7 @@ enum EPrecedence
// Macro for define OpInfo and an associated enum type. Order or macro parameters is
// Op, OpName, Precedence
+// clang-format off
#define SLANG_OP_INFO(x) \
x(None, "", None) \
\
@@ -111,6 +114,7 @@ enum EPrecedence
x(Not, "!", Prefix) \
x(Neg, "-", Prefix) \
x(BitNot, "~", Prefix)
+// clang-format on
#define SLANG_OP_INFO_ENUM(op, name, precedence) op,
diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h
index f4365cf62..c98fae55e 100644
--- a/source/slang/slang-ir-inst-defs.h
+++ b/source/slang/slang-ir-inst-defs.h
@@ -1,5 +1,7 @@
// slang-ir-inst-defs.h
+// clang-format off
+
#ifndef INST
#error Must #define `INST` before including `ir-inst-defs.h`
#endif
diff --git a/source/slang/slang-ir-variable-scope-correction.h b/source/slang/slang-ir-variable-scope-correction.h
index 5f958f9d0..9694689d9 100644
--- a/source/slang/slang-ir-variable-scope-correction.h
+++ b/source/slang/slang-ir-variable-scope-correction.h
@@ -6,6 +6,7 @@ namespace Slang
{
struct IRModule;
+class TargetRequest;
/// This pass correct the scope of variables in loop regions
///
diff --git a/source/slang/slang-repro.cpp b/source/slang/slang-repro.cpp
index 32f8d3289..4e5a03bc3 100644
--- a/source/slang/slang-repro.cpp
+++ b/source/slang/slang-repro.cpp
@@ -26,6 +26,7 @@ namespace Slang {
// to set up the thing to hash.
//
// Note that bool is in the list because size of bool can change between compilers.
+// clang-format off
#define SLANG_STATE_TYPES(x) \
x(Util::FileState) \
x(Util::PathInfoState) \
@@ -52,7 +53,8 @@ namespace Slang {
x(OptimizationLevel) \
x(ContainerFormat) \
x(PassThroughMode) \
- x(SlangMatrixLayoutMode) \
+ x(SlangMatrixLayoutMode)
+// clang-format on
#define SLANG_STATE_TYPE_SIZE(x) uint32_t(sizeof(x)),
diff --git a/source/slang/slang-serialize-types.cpp b/source/slang/slang-serialize-types.cpp
index a091a2850..cab108b1a 100644
--- a/source/slang/slang-serialize-types.cpp
+++ b/source/slang/slang-serialize-types.cpp
@@ -208,9 +208,11 @@ struct ByteReader
// !!!!!!!!!!!!!!!!!!!!!!!!!!!! SerialParseUtil !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+// clang-format off
#define SLANG_SERIAL_BINARY_COMPRESSION_TYPE(x) \
x(None, none) \
x(VariableByteLite, lite)
+// clang-format on
/* static */SlangResult SerialParseUtil::parseCompressionType(const UnownedStringSlice& text, SerialCompressionType& outType)
{
@@ -220,7 +222,10 @@ struct ByteReader
SerialCompressionType type;
};
-#define SLANG_SERIAL_BINARY_PAIR(type, name) { UnownedStringSlice::fromLiteral(#name), SerialCompressionType::type},
+// clang-format off
+#define SLANG_SERIAL_BINARY_PAIR(type, name) \
+ {UnownedStringSlice::fromLiteral(#name), SerialCompressionType::type},
+// clang-format on
static const Pair s_pairs[] =
{
diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp
index 8422a304b..053064755 100644
--- a/source/slang/slang-syntax.cpp
+++ b/source/slang/slang-syntax.cpp
@@ -912,10 +912,12 @@ bool findImageFormatByName(const UnownedStringSlice& name, ImageFormat* outForma
}
// https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#id71
+// clang-format off
#define SLANG_VK_TO_IMAGE_FORMAT(x) \
x(r11g11b10f, r11f_g11f_b10f) \
x(rgb10a2, rgb10_a2) \
x(rgb10a2ui, rgb10_a2ui)
+// clang-format on
struct VkImageFormatInfo
{
diff --git a/source/slang/slang-type-layout.h b/source/slang/slang-type-layout.h
index 4248df508..d932b4f16 100644
--- a/source/slang/slang-type-layout.h
+++ b/source/slang/slang-type-layout.h
@@ -244,6 +244,7 @@ struct UniformArrayLayoutInfo : UniformLayoutInfo
typedef slang::ParameterCategory LayoutResourceKind;
// Any change to slang::ParameterCategory, requires a change to this macro.
+// clang-format off
#define SLANG_PARAMETER_CATEGORIES(x) \
x(None) \
x(Mixed) \
@@ -277,6 +278,7 @@ typedef slang::ParameterCategory LayoutResourceKind;
x(MetalBuffer) \
x(MetalTexture) \
x(MetalArgumentBufferElement)
+// clang-format on
#define SLANG_PARAMETER_CATEGORY_FLAG(x) x = ParameterCategoryFlags(1) << int(slang::x),
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index abb178375..4b2acd094 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -34,9 +34,11 @@
#pragma comment(lib, "opengl32")
-#include <GL/GL.h>
-#include "external/glext.h"
-#include "external/wglext.h"
+// clang-format off
+# include <GL/GL.h>
+# include "external/glext.h"
+# include "external/wglext.h"
+// clang-format on
// We define an "X-macro" for mapping over loadable OpenGL
// extension entry point that we will use, so that we can
diff --git a/tools/gfx/simple-transient-resource-heap.h b/tools/gfx/simple-transient-resource-heap.h
index c94fe2a7b..4e3a04094 100644
--- a/tools/gfx/simple-transient-resource-heap.h
+++ b/tools/gfx/simple-transient-resource-heap.h
@@ -4,6 +4,7 @@
// Provide a simple no-op implementation for `ITransientResourceHeap` for targets that
// already support version management.
+#include "renderer-shared.h"
#include "slang-gfx.h"
namespace gfx
diff --git a/tools/gfx/vulkan/vk-api.h b/tools/gfx/vulkan/vk-api.h
index 70af62ed1..04744369a 100644
--- a/tools/gfx/vulkan/vk-api.h
+++ b/tools/gfx/vulkan/vk-api.h
@@ -5,6 +5,7 @@
namespace gfx {
+// clang-format off
#define VK_API_GLOBAL_PROCS(x) \
x(vkGetInstanceProcAddr) \
x(vkCreateInstance) \
@@ -235,7 +236,7 @@ namespace gfx {
/* */
#define VK_API_DECLARE_PROC(NAME) PFN_##NAME NAME = nullptr;
-
+// clang-format on
struct VulkanExtendedFeatureProperties
{
diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp
index 07711d712..013e86c37 100644
--- a/tools/render-test/shader-input-layout.cpp
+++ b/tools/render-test/shader-input-layout.cpp
@@ -11,10 +11,12 @@ namespace renderer_test
{
using namespace Slang;
+// clang-format off
#define SLANG_SCALAR_TYPES(x) \
x("int", INT32) \
x("uint", UINT32) \
x("float", FLOAT32)
+// clang-format on
Format _getFormatFromName(const UnownedStringSlice& slice)