summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-09-15 20:37:45 -0700
committerGitHub <noreply@github.com>2022-09-15 20:37:45 -0700
commita5d3bec25d70f23da1e79cd7773981ff34593611 (patch)
tree92c8cb983c57bbee141d4e6f3f91f265e04d6a08 /tools
parenta6032446c6bf7f64d1e201bf438a4c7605a3dbb4 (diff)
Run simple compute kernel in gfx-smoke test. (#2400)
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx/gfx.slang40
-rw-r--r--tools/gfx/renderer-shared.cpp31
2 files changed, 44 insertions, 27 deletions
diff --git a/tools/gfx/gfx.slang b/tools/gfx/gfx.slang
index d57b746db..17a38e28d 100644
--- a/tools/gfx/gfx.slang
+++ b/tools/gfx/gfx.slang
@@ -864,9 +864,9 @@ interface IShaderObject
slang::TypeLayoutReflection* getElementTypeLayout();
ShaderObjectContainerType getContainerType();
GfxCount getEntryPointCount();
- Result getEntryPoint(GfxIndex index, out IShaderObject entryPoint);
- Result setData(ShaderOffset* offset, void *data, Size size);
- Result getObject(ShaderOffset* offset, out IShaderObject object);
+ Result getEntryPoint(GfxIndex index, out Optional<IShaderObject> entryPoint);
+ Result setData(ShaderOffset *offset, void *data, Size size);
+ Result getObject(ShaderOffset *offset, out Optional<IShaderObject> object);
Result setObject(ShaderOffset* offset, IShaderObject object);
Result setResource(ShaderOffset* offset, IResourceView resourceView);
Result setSampler(ShaderOffset* offset, ISamplerState sampler);
@@ -1473,7 +1473,7 @@ interface IComputeCommandEncoder : IResourceCommandEncoder
// sub-shader-objects bound to it. The user must be responsible for ensuring that any
// resources or shader objects that is set into `outRooShaderObject` stays alive during
// the execution of the command buffer.
- Result bindPipeline(IPipelineState state, out IShaderObject outRootShaderObject);
+ Result bindPipeline(IPipelineState state, out Optional<IShaderObject> outRootShaderObject);
// Sets the current pipeline state along with a pre-created mutable root shader object.
Result bindPipelineWithRootObject(IPipelineState state, IShaderObject rootObject);
@@ -1542,11 +1542,11 @@ interface ICommandBuffer
IFramebuffer framebuffer,
out IRenderCommandEncoder outEncoder);
- void encodeComputeCommands(out IComputeCommandEncoder encoder);
+ void encodeComputeCommands(out Optional<IComputeCommandEncoder> encoder);
- void encodeResourceCommands(out IResourceCommandEncoder outEncoder);
+ void encodeResourceCommands(out Optional<IResourceCommandEncoder> outEncoder);
- void encodeRayTracingCommands(out IRayTracingCommandEncoder outEncoder);
+ void encodeRayTracingCommands(out Optional<IRayTracingCommandEncoder> outEncoder);
void close();
@@ -1616,7 +1616,7 @@ interface ITransientResourceHeap
// buffers must be closed before submission. The current D3D12 implementation has a limitation
// that only one command buffer maybe recorded at a time. User must finish recording a command
// buffer before creating another command buffer.
- Result createCommandBuffer(out ICommandBuffer outCommandBuffer);
+ Result createCommandBuffer(out Optional<ICommandBuffer> outCommandBuffer);
};
struct SwapchainDesc
@@ -1759,7 +1759,7 @@ interface IDevice
Result createTransientResourceHeap(
TransientResourceHeapDesc *desc,
- out ITransientResourceHeap outHeap);
+ out Optional<ITransientResourceHeap> outHeap);
/// Create a texture resource.
///
@@ -1795,7 +1795,7 @@ interface IDevice
Result createBufferResource(
BufferResourceDesc* desc,
void *initData,
- out IBufferResource outResource);
+ out Optional<IBufferResource> outResource);
Result createBufferFromNativeHandle(
InteropHandle handle,
@@ -1814,9 +1814,9 @@ interface IDevice
Result createBufferView(
IBufferResource buffer,
- IBufferResource counterBuffer,
+ Optional<IBufferResource> counterBuffer,
ResourceViewDesc* desc,
- out IResourceView outView);
+ out Optional<IResourceView> outView);
Result createFramebufferLayout(FramebufferLayoutDesc* desc, out IFramebufferLayout outFrameBuffer);
@@ -1832,7 +1832,7 @@ interface IDevice
Result createInputLayout(
InputLayoutDesc* desc, out IInputLayout outLayout);
- Result createCommandQueue(CommandQueueDesc* desc, out ICommandQueue outQueue);
+ Result createCommandQueue(CommandQueueDesc* desc, out Optional<ICommandQueue> outQueue);
Result createShaderObject(
slang::TypeReflection *type,
@@ -1863,19 +1863,19 @@ interface IDevice
Result createProgram2(
ShaderProgramDesc2 *desc,
- out IShaderProgram outProgram,
- out slang::ISlangBlob outDiagnosticBlob);
+ out Optional<IShaderProgram> outProgram,
+ out Optional<slang::ISlangBlob> outDiagnosticBlob);
Result createGraphicsPipelineState(
- GraphicsPipelineStateDesc* desc,
- out IPipelineState outState);
+ GraphicsPipelineStateDesc *desc,
+ out Optional<IPipelineState> outState);
Result createComputePipelineState(
ComputePipelineStateDesc* desc,
- out IPipelineState outState);
+ out Optional<IPipelineState> outState);
Result createRayTracingPipelineState(
- RayTracingPipelineStateDesc* desc, out IPipelineState outState);
+ RayTracingPipelineStateDesc *desc, out Optional<IPipelineState> outState);
/// Read back texture resource and stores the result in `outBlob`.
Result readTextureResource(
@@ -1889,7 +1889,7 @@ interface IDevice
IBufferResource buffer,
Offset offset,
Size size,
- out slang::ISlangBlob outBlob);
+ out Optional<slang::ISlangBlob> outBlob);
/// Get the type of this renderer
DeviceInfo* getDeviceInfo();
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index 2e5454851..69046d216 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -472,14 +472,31 @@ Result RendererBase::createProgram2(
ISlangBlob** outDiagnostic)
{
auto slangSession = slangContext.session.get();
-
- SLANG_RELEASE_ASSERT(desc.sourceType == ShaderModuleSourceType::SlangSourceFile);
-
- auto fileName = (char*)desc.sourceData;
+ slang::IModule* module = nullptr;
ComPtr<slang::IBlob> diagnosticsBlob;
- slang::IModule* module = slangSession->loadModule(fileName, diagnosticsBlob.writeRef());
- if (!module)
- return SLANG_FAIL;
+ switch (desc.sourceType)
+ {
+ case ShaderModuleSourceType::SlangSourceFile:
+ {
+ auto fileName = (char*)desc.sourceData;
+ module = slangSession->loadModule(fileName, diagnosticsBlob.writeRef());
+ if (!module)
+ return SLANG_FAIL;
+ break;
+ }
+ case ShaderModuleSourceType::SlangSource:
+ {
+ auto hash = getStableHashCode32((char*)desc.sourceData, desc.sourceDataSize);
+ auto hashStr = String(hash);
+ auto srcBlob = UnownedRawBlob::create(desc.sourceData, desc.sourceDataSize);
+ module = slangSession->loadModuleFromSource(hashStr.getBuffer(), hashStr.getBuffer(), srcBlob, diagnosticsBlob.writeRef());
+ if (!module)
+ return SLANG_FAIL;
+ break;
+ }
+ default:
+ SLANG_RELEASE_ASSERT(false);
+ }
Slang::List<ComPtr<slang::IComponentType>> componentTypes;
componentTypes.add(ComPtr<slang::IComponentType>(module));