summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2023-01-27 20:53:57 +0100
committerGitHub <noreply@github.com>2023-01-27 11:53:57 -0800
commit93a6b6119b6b65c4f6b00ca12d745e21b679c82f (patch)
tree53bc1a3360d34ae6d15318eebf07245367387b9d
parent9f6b6fb9f1bdde8ef01640257544f0e3c9db9076 (diff)
Add ASAN support + fixes (#2614)
* Add ASAN support to premake * Fix StringRepresentation when ASAN is enabled * Fix deep recursion in slang-generate * Fix hello-world example * Fix gpu-printing example * Linux fix * Try fixing linux * Add missing include
-rw-r--r--build/visual-studio/gfx/gfx.vcxproj12
-rw-r--r--examples/gpu-printing/kernels.slang2
-rw-r--r--examples/gpu-printing/main.cpp12
-rw-r--r--examples/gpu-printing/printing.slang9
-rw-r--r--examples/hello-world/vulkan-api.cpp23
-rw-r--r--premake5.lua28
-rw-r--r--source/core/slang-string.h9
-rw-r--r--tools/slang-generate/main.cpp10
8 files changed, 76 insertions, 29 deletions
diff --git a/build/visual-studio/gfx/gfx.vcxproj b/build/visual-studio/gfx/gfx.vcxproj
index 476f6a808..53067b297 100644
--- a/build/visual-studio/gfx/gfx.vcxproj
+++ b/build/visual-studio/gfx/gfx.vcxproj
@@ -164,7 +164,6 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
- <TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>_DEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -177,7 +176,6 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ImportLibrary>..\..\..\bin\windows-x86\debug\gfx.lib</ImportLibrary>
- <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
<PostBuildEvent>
<Command>IF EXIST "$(SolutionDir)tools\gfx\gfx.slang"\ (xcopy /Q /E /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x86\debug" &gt; nul) ELSE (xcopy /Q /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x86\debug" &gt; nul)
@@ -189,7 +187,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
- <TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>_DEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -202,7 +199,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ImportLibrary>..\..\..\bin\windows-x64\debug\gfx.lib</ImportLibrary>
- <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
<PostBuildEvent>
<Command>IF EXIST "$(SolutionDir)tools\gfx\gfx.slang"\ (xcopy /Q /E /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x64\debug" &gt; nul) ELSE (xcopy /Q /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x64\debug" &gt; nul)
@@ -214,7 +210,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
- <TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>_DEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -227,7 +222,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ImportLibrary>..\..\..\bin\windows-aarch64\debug\gfx.lib</ImportLibrary>
- <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
<PostBuildEvent>
<Command>IF EXIST "$(SolutionDir)tools\gfx\gfx.slang"\ (xcopy /Q /E /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-aarch64\debug" &gt; nul) ELSE (xcopy /Q /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-aarch64\debug" &gt; nul)
@@ -239,7 +233,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
- <TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>NDEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
@@ -255,7 +248,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ImportLibrary>..\..\..\bin\windows-x86\release\gfx.lib</ImportLibrary>
- <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
<PostBuildEvent>
<Command>IF EXIST "$(SolutionDir)tools\gfx\gfx.slang"\ (xcopy /Q /E /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x86\release" &gt; nul) ELSE (xcopy /Q /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x86\release" &gt; nul)
@@ -267,7 +259,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
- <TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>NDEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
@@ -283,7 +274,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ImportLibrary>..\..\..\bin\windows-x64\release\gfx.lib</ImportLibrary>
- <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
<PostBuildEvent>
<Command>IF EXIST "$(SolutionDir)tools\gfx\gfx.slang"\ (xcopy /Q /E /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x64\release" &gt; nul) ELSE (xcopy /Q /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-x64\release" &gt; nul)
@@ -295,7 +285,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
- <TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>NDEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
@@ -311,7 +300,6 @@ IF EXIST "$(SolutionDir)tools\gfx\slang.slang"\ (xcopy /Q /E /Y /I "$(SolutionDi
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ImportLibrary>..\..\..\bin\windows-aarch64\release\gfx.lib</ImportLibrary>
- <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
<PostBuildEvent>
<Command>IF EXIST "$(SolutionDir)tools\gfx\gfx.slang"\ (xcopy /Q /E /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-aarch64\release" &gt; nul) ELSE (xcopy /Q /Y /I "$(SolutionDir)tools\gfx\gfx.slang" "..\..\..\bin\windows-aarch64\release" &gt; nul)
diff --git a/examples/gpu-printing/kernels.slang b/examples/gpu-printing/kernels.slang
index 8693bfed1..d276510da 100644
--- a/examples/gpu-printing/kernels.slang
+++ b/examples/gpu-printing/kernels.slang
@@ -34,5 +34,5 @@ void computeMain(uint3 tid : SV_DispatchThreadID)
// The second facility supported by `printing.slang` is a C-style
// `printf()` function.
//
- printf("printf from thread 0x%x\n", tid.x);
+ printf_("printf from thread 0x%x\n", tid.x);
}
diff --git a/examples/gpu-printing/main.cpp b/examples/gpu-printing/main.cpp
index d8f680376..984534a7b 100644
--- a/examples/gpu-printing/main.cpp
+++ b/examples/gpu-printing/main.cpp
@@ -6,6 +6,7 @@
using Slang::ComPtr;
#include "slang-gfx.h"
+#include "gfx-util/shader-cursor.h"
#include "tools/platform/window.h"
#include "source/core/slang-basic.h"
using namespace gfx;
@@ -101,18 +102,19 @@ Result execute()
size_t printBufferSize = 4 * 1024; // use a small-ish (4KB) buffer for print output
- IBufferResource::Desc printBufferDesc;
+ IBufferResource::Desc printBufferDesc = {};
printBufferDesc.type = IResource::Type::Buffer;
printBufferDesc.sizeInBytes = printBufferSize;
printBufferDesc.elementSize = sizeof(uint32_t);
printBufferDesc.defaultState = ResourceState::UnorderedAccess;
printBufferDesc.allowedStates = ResourceStateSet(
ResourceState::CopySource, ResourceState::CopyDestination, ResourceState::UnorderedAccess);
- printBufferDesc.memoryType = MemoryType::ReadBack;
+ printBufferDesc.memoryType = MemoryType::DeviceLocal;
auto printBuffer = gDevice->createBufferResource(printBufferDesc);
- IResourceView::Desc printBufferViewDesc;
+ IResourceView::Desc printBufferViewDesc = {};
printBufferViewDesc.type = IResourceView::Type::UnorderedAccess;
+ printBufferViewDesc.format = Format::Unknown;
auto printBufferView = gDevice->createBufferView(printBuffer, nullptr, printBufferViewDesc);
ITransientResourceHeap::Desc transientResourceHeapDesc = {};
@@ -124,11 +126,13 @@ Result execute()
auto commandBuffer = transientHeap->createCommandBuffer();
auto encoder = commandBuffer->encodeComputeCommands();
auto rootShaderObject = encoder->bindPipeline(gPipelineState);
+ auto cursor = ShaderCursor(rootShaderObject);
+ cursor["gPrintBuffer"].setResource(printBufferView);
encoder->dispatchCompute(1, 1, 1);
+ encoder->bufferBarrier(printBuffer, ResourceState::UnorderedAccess, ResourceState::CopySource);
encoder->endEncoding();
commandBuffer->close();
queue->executeCommandBuffer(commandBuffer);
- // TODO: need to copy from the print buffer to a staging buffer...
ComPtr<ISlangBlob> blob;
gDevice->readBufferResource(printBuffer, 0, printBufferSize, blob.writeRef());
diff --git a/examples/gpu-printing/printing.slang b/examples/gpu-printing/printing.slang
index 941a1518b..0abf57e34 100644
--- a/examples/gpu-printing/printing.slang
+++ b/examples/gpu-printing/printing.slang
@@ -284,6 +284,9 @@ void println<A : IPrintable, B : IPrintable, C : IPrintable>(
// starts with an allocation function that does the behind-the-scenes
// work.
//
+// Note: We use the name `printf_` here because `printf` clashes with
+// HLSL's printf.
+//
uint _beginPrintf(String format, uint wordCount)
{
@@ -340,14 +343,14 @@ extension String : IPrintf
// A `printf()` with no format arguments can just call back to `_beginPrintf()`
-void printf(String format)
+void printf_(String format)
{
_beginPrintf(format, 0);
}
// The `printf()` cases with one or more format arguments are all quite similar.
-void printf<A : IPrintf>(String format, A a)
+void printf_<A : IPrintf>(String format, A a)
{
// We need to compute the words required by each format argument
// and sum them up.
@@ -366,7 +369,7 @@ void printf<A : IPrintf>(String format, A a)
a.writePrintfWords(gPrintBuffer, wordOffset); wordOffset += aCount;
}
-void printf<A : IPrintf, B : IPrintf>(String format, A a, B b)
+void printf_<A : IPrintf, B : IPrintf>(String format, A a, B b)
{
uint wordCount = 0;
uint aCount = a.getPrintfWordCount(); wordCount += aCount;
diff --git a/examples/hello-world/vulkan-api.cpp b/examples/hello-world/vulkan-api.cpp
index 529ca7196..d2d8aefa6 100644
--- a/examples/hello-world/vulkan-api.cpp
+++ b/examples/hello-world/vulkan-api.cpp
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
+#include <string.h>
#include <vector>
#if SLANG_WINDOWS_FAMILY
@@ -51,6 +52,24 @@ int initializeVulkanDevice(VulkanAPI& api)
if (!api.vkCreateInstance)
return -1;
+ // Enable validation layer if available.
+ std::vector<const char*> layers;
+#ifdef ENABLE_VALIDATION_LAYER
+ uint32_t propertyCount;
+ if (api.vkEnumerateInstanceLayerProperties(&propertyCount, nullptr) != 0)
+ return -1;
+ std::vector< VkLayerProperties> properties(propertyCount);
+ if (api.vkEnumerateInstanceLayerProperties(&propertyCount, properties.data()) != 0)
+ return -1;
+ for (const auto& p : properties)
+ {
+ if (strcmp(p.layerName, "VK_LAYER_KHRONOS_validation") == 0)
+ {
+ layers.push_back("VK_LAYER_KHRONOS_validation");
+ }
+ }
+#endif
+
// Create Vulkan Instance.
VkApplicationInfo applicationInfo = {VK_STRUCTURE_TYPE_APPLICATION_INFO};
applicationInfo.pApplicationName = "slang-hello-world";
@@ -66,10 +85,6 @@ int initializeVulkanDevice(VulkanAPI& api)
instanceCreateInfo.pApplicationInfo = &applicationInfo;
instanceCreateInfo.enabledExtensionCount = SLANG_COUNT_OF(instanceExtensions);
instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0];
- std::vector<const char*> layers;
-#ifdef ENABLE_VALIDATION_LAYER
- layers.push_back("VK_LAYER_KHRONOS_validation");
-#endif
if (layers.size())
{
instanceCreateInfo.ppEnabledLayerNames = &layers[0];
diff --git a/premake5.lua b/premake5.lua
index f3d48f07f..5dd724130 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -192,10 +192,18 @@ newoption {
}
newoption {
- trigger = "full-debug-validation",
+ trigger = "full-debug-validation",
description = "(Optional) If true will enable full IR validation in debug build. (SLOW!)",
- value = "bool",
- default = "false",
+ value = "bool",
+ default = "false",
+ allowed = { { "true", "True"}, { "false", "False" } }
+}
+
+newoption {
+ trigger = "enable-asan",
+ description = "(Optional) If true will enable ASAN (address santizier).",
+ value = "bool",
+ default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
@@ -213,6 +221,7 @@ skipSourceGeneration = (_OPTIONS["skip-source-generation"] == "true")
deployLLVM = (_OPTIONS["deploy-slang-llvm"] == "true")
deployGLSLang = (_OPTIONS["deploy-slang-glslang"] == "true")
fullDebugValidation = (_OPTIONS["full-debug-validation"] == "true")
+enableAsan = (_OPTIONS["enable-asan"] == "true")
-- If stdlib embedding is enabled, disable stdlib source embedding by default
disableStdlibSource = enableEmbedStdLib
@@ -571,6 +580,18 @@ function baseSlangProject(name, sourceDir)
if not not sourceDir then
addSourceDir(sourceDir)
end
+
+ --
+ -- Enable ASAN (address sanitizer) if requested.
+ --
+
+ if enableAsan then
+ if (targetInfo.isWindows) then
+ buildoptions { "/fsanitize=address" }
+ flags { "NoIncrementalLink" }
+ end
+ end
+
end
@@ -992,7 +1013,6 @@ tool "gfx"
addSourceDir "tools/gfx/d3d"
addSourceDir "tools/gfx/d3d11"
addSourceDir "tools/gfx/d3d12"
- flags { "FatalWarnings" }
elseif targetInfo.os == "mingw" or targetInfo.os == "cygwin" then
-- Don't support any render techs...
elseif os.target() == "macosx" then
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 028eec3e4..ecdba46be 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -315,6 +315,15 @@ namespace Slang
return cloneWithCapacity(newCapacity);
}
+
+ /// Overload delete to silence ASAN new-delete-type-mismatch errors.
+ /// These occur because the allocation size of StringRepresentation
+ /// does not match deallocation size (due variable sized string payload).
+ void operator delete(void* p)
+ {
+ StringRepresentation* str = (StringRepresentation*) p;
+ ::operator delete(str);
+ }
};
class String;
diff --git a/tools/slang-generate/main.cpp b/tools/slang-generate/main.cpp
index 8e4824065..7d07cd613 100644
--- a/tools/slang-generate/main.cpp
+++ b/tools/slang-generate/main.cpp
@@ -56,8 +56,16 @@ struct SourceFile : public RefObject
{
if (text.begin())
free((void*)text.begin());
- if (node)
+
+ // To avoid deep recursion in the Node destructor,
+ // we delete the first level of the node tree iteratively.
+ while (node)
+ {
+ Node* next = node->next;
+ node->next = nullptr;
delete node;
+ node = next;
+ }
}
};