summaryrefslogtreecommitdiffstats
path: root/tests/cpu-program
diff options
context:
space:
mode:
authorGangzheng Tong <tonggangzheng@gmail.com>2025-07-08 23:44:56 -0700
committerGitHub <noreply@github.com>2025-07-09 06:44:56 +0000
commit43d0c2100ef1a5df4b54525e50eb29fe7c39ec16 (patch)
tree25ec4fb9c726115f90bdaa9878f2f4ca372ad0a6 /tests/cpu-program
parent00746bf09047cdf01c19dac513a532bcf3ed3ea3 (diff)
Convert gfx unit tests and examples to use slang-rhi (#7577)
* Port first gfx unit test to slang-rhi * port triangle example to use slang-rhi * port platform-test to slang-rhi * Update platform-test to throttle mouse move events * port gpu-printing example to use slang-rhi * port model-viewer example to use slang-rhi * port ray-tracing example to use slang-rhi * port ray-tracing pipeline example to use slang-rhi * port reflection parameter blocks example to use slang-rhi * port shader-object example to use slang-rhi * port shader-toy example to use slang-rhi * Port most of tests to slang-rhi * port link-time-constant-array-size to use slang-rhi * Fix tests and find matching tests in slang-rhi * port autodiff-texture * remove gfx target; port nv-aftermath-example * update include path for shader-cursor.h * Disabled 2 more ported tests * fix build error * remove gfx test * put slang-rhi (static-lib) before slang (shared) * format code (#7621) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * add debug callback * format code (#7649) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Address review comments; revert back to use SLANG_CHECK_MSG --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests/cpu-program')
-rw-r--r--tests/cpu-program/gfx-smoke.slang101
1 files changed, 0 insertions, 101 deletions
diff --git a/tests/cpu-program/gfx-smoke.slang b/tests/cpu-program/gfx-smoke.slang
deleted file mode 100644
index 3ed04877e..000000000
--- a/tests/cpu-program/gfx-smoke.slang
+++ /dev/null
@@ -1,101 +0,0 @@
-//TEST:EXECUTABLE:
-import gfx;
-import slang;
-
-export __extern_cpp int main()
-{
- gfx.DeviceDesc deviceDesc = {};
- deviceDesc.deviceType = gfx.DeviceType.CPU;
- Optional<gfx.IDevice> device;
- gfx.gfxCreateDevice(&deviceDesc, device);
- if (device == none)
- {
- printf("fail\n");
- return -1;
- }
-
- gfx.CommandQueueDesc queueDesc = {gfx::QueueType::Graphics};
- queueDesc.type = gfx.QueueType.Graphics;
- Optional<gfx.ICommandQueue> queue;
- device.value.createCommandQueue(&queueDesc, queue);
-
- gfx.ShaderProgramDesc2 programDesc = {};
- NativeString s = R"(
- [shader("compute")]
- [numthreads(4, 1, 1)]
- void computeMain(
- uint3 sv_dispatchThreadID: SV_DispatchThreadID,
- uniform RWStructuredBuffer<float> buffer
- )
- {
- var input = buffer[sv_dispatchThreadID.x];
- buffer[sv_dispatchThreadID.x] = sv_dispatchThreadID.x;
- })";
- programDesc.sourceData = s;
- programDesc.sourceType = gfx.ShaderModuleSourceType.SlangSource;
- programDesc.sourceDataSize = s.length;
- programDesc.entryPointCount = 1;
- NativeString entryPointName = "computeMain";
- programDesc.entryPointNames = &entryPointName;
- Optional<gfx.IShaderProgram> program;
- Optional<slang.ISlangBlob> diagBlob;
- device.value.createProgram2(&programDesc, program, diagBlob);
-
- Optional<gfx.IPipelineState> pipeline;
- gfx.ComputePipelineStateDesc pipelineDesc;
- pipelineDesc.program = NativeRef<gfx.IShaderProgram>(program.value);
- device.value.createComputePipelineState(&pipelineDesc, pipeline);
-
- Optional<gfx.ITransientResourceHeap> transientHeap;
- gfx.TransientResourceHeapDesc transientHeapDesc;
- transientHeapDesc.constantBufferDescriptorCount = 64;
- transientHeapDesc.constantBufferSize = 1024;
- transientHeapDesc.srvDescriptorCount = 1024;
- transientHeapDesc.uavDescriptorCount = 1024;
- transientHeapDesc.samplerDescriptorCount = 256;
- transientHeapDesc.accelerationStructureDescriptorCount = 32;
- device.value.createTransientResourceHeap(&transientHeapDesc, transientHeap);
-
- Optional<gfx.IBufferResource> buffer;
- gfx.BufferResourceDesc bufferDesc = {};
- bufferDesc.memoryType = gfx.MemoryType.DeviceLocal;
- bufferDesc.allowedStates.add(gfx.ResourceState.UnorderedAccess);
- bufferDesc.defaultState = gfx.ResourceState.UnorderedAccess;
- bufferDesc.elementSize = 4;
- bufferDesc.sizeInBytes = 256;
- bufferDesc.type = gfx.ResourceType.Buffer;
- device.value.createBufferResource(&bufferDesc, nullptr, buffer);
-
- Optional<gfx.IResourceView> bufferView;
- gfx.ResourceViewDesc viewDesc;
- viewDesc.type = gfx.ResourceViewType.UnorderedAccess;
- device.value.createBufferView(buffer.value, none, &viewDesc, bufferView);
-
- Optional<gfx.ICommandBuffer> commandBuffer;
- transientHeap.value.createCommandBuffer(commandBuffer);
- Optional<gfx.IComputeCommandEncoder> encoder;
- commandBuffer.value.encodeComputeCommands(encoder);
- Optional<gfx.IShaderObject> rootObject;
- encoder.value.bindPipeline(pipeline.value, rootObject);
- Optional<gfx.IShaderObject> entryPointObject;
- rootObject.value.getEntryPoint(0, entryPointObject);
- gfx.ShaderOffset offset = {};
- entryPointObject.value.setResource(&offset, bufferView.value);
- encoder.value.dispatchCompute(1, 1, 1);
- encoder.value.endEncoding();
- commandBuffer.value.close();
-
- NativeRef<gfx.ICommandBuffer> commandBufferRef = NativeRef<gfx.ICommandBuffer>(commandBuffer.value);
- queue.value.executeCommandBuffers(1, &commandBufferRef, none, 0);
- queue.value.waitOnHost();
-
- Optional<slang.ISlangBlob> blob;
- device.value.readBufferResource(buffer.value, 0, 16, blob);
-
- for (int i = 0; i < 4; i++)
- {
- float val = ((float *)blob.value.getBufferPointer())[i];
- printf("%.1f\n", val);
- }
- return 0;
-}