summaryrefslogtreecommitdiffstats
path: root/examples/gpu-printing
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 /examples/gpu-printing
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
Diffstat (limited to 'examples/gpu-printing')
-rw-r--r--examples/gpu-printing/kernels.slang2
-rw-r--r--examples/gpu-printing/main.cpp12
-rw-r--r--examples/gpu-printing/printing.slang9
3 files changed, 15 insertions, 8 deletions
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;