summaryrefslogtreecommitdiffstats
path: root/examples/gpu-printing/main.cpp
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/main.cpp
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/main.cpp')
-rw-r--r--examples/gpu-printing/main.cpp12
1 files changed, 8 insertions, 4 deletions
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());