Skip to content

Commit 38734ec

Browse files
update slang-rhi (shader object refactor) (#6251)
* remove unused resource * define buffer data * add vs2022 build presets * update slang-rhi API usage * update slang-rhi --------- Co-authored-by: Yong He <yonghe@outlook.com>
1 parent cd20e94 commit 38734ec

9 files changed

+42
-40
lines changed

CMakePresets.json

+15
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
"configurePreset": "default",
105105
"configuration": "RelWithDebInfo"
106106
},
107+
{
108+
"name": "vs2022-debug",
109+
"configurePreset": "vs2022",
110+
"configuration": "Debug"
111+
},
112+
{
113+
"name": "vs2022-release",
114+
"configurePreset": "vs2022",
115+
"configuration": "Release"
116+
},
117+
{
118+
"name": "vs2022-releaseWithDebugInfo",
119+
"configurePreset": "vs2022",
120+
"configuration": "RelWithDebInfo"
121+
},
107122
{
108123
"name": "emscripten",
109124
"configurePreset": "emscripten",

external/slang-rhi

Submodule slang-rhi updated 273 files

tests/bugs/ray-query-in-generic.slang

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ struct Ray
3636
float3 eval(float t) { return origin + t * dir; }
3737
};
3838

39-
RaytracingAccelerationStructure sceneBVH;
40-
4139
uint getCommittedStatus<let Flags : int>(RayQuery<Flags> q)
4240
{
4341
return q.CommittedStatus();

tests/compute/byte-address-buffer-aligned.slang

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// Confirm compilation of `(RW)ByteAddressBuffer` with aligned load / stores to wider data types.
1111

12+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=buffer0
1213
[vk::binding(2, 3)] RWByteAddressBuffer buffer0;
1314

1415
[shader("compute")]

tests/compute/byte-address-buffer-array.slang

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// Confirm compilation of `(RW)ByteAddressBuffer` with aligned load / stores to wider data types.
1111

12+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=buffer
1213
[vk::binding(2, 3)] RWByteAddressBuffer buffer;
1314
struct Block {
1415
float4 val[2];

tools/render-test/options.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ static rhi::DeviceType _toRenderType(Slang::RenderApiType apiType)
249249
{
250250
SLANG_RETURN_ON_FAIL(reader.expectArg(outOptions.entryPointName));
251251
}
252-
else if (argValue == "-enable-backend-validation")
252+
else if (argValue == "-enable-debug-layers")
253253
{
254-
outOptions.enableBackendValidation = true;
254+
outOptions.enableDebugLayers = true;
255255
}
256256
else if (argValue == "-dx12-experimental")
257257
{

tools/render-test/options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct Options
8787

8888
bool generateSPIRVDirectly = true;
8989

90-
bool enableBackendValidation = false;
90+
bool enableDebugLayers = false;
9191

9292
bool dx12Experimental = false;
9393

tools/render-test/render-test-main.cpp

+20-33
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ struct AssignValsFromLayoutContext
355355
if (field.name.getLength() == 0)
356356
{
357357
// If no name was given, assume by-indexing matching is requested
358-
auto fieldCursor = dstCursor.getElement((GfxIndex)fieldIndex);
358+
auto fieldCursor = dstCursor.getElement((uint32_t)fieldIndex);
359359
if (!fieldCursor.isValid())
360360
{
361361
StdWriters::getError().print(
@@ -638,7 +638,7 @@ SlangResult RenderTestApp::initialize(
638638
SLANG_RETURN_ON_FAIL(
639639
device->createBuffer(vertexBufferDesc, kVertexData, m_vertexBuffer.writeRef()));
640640

641-
ColorTargetState colorTarget;
641+
ColorTargetDesc colorTarget;
642642
colorTarget.format = Format::R8G8B8A8_UNORM;
643643
RenderPipelineDesc desc;
644644
desc.program = m_shaderProgram;
@@ -653,7 +653,7 @@ SlangResult RenderTestApp::initialize(
653653
case Options::ShaderProgramType::GraphicsMeshCompute:
654654
case Options::ShaderProgramType::GraphicsTaskMeshCompute:
655655
{
656-
ColorTargetState colorTarget;
656+
ColorTargetDesc colorTarget;
657657
colorTarget.format = Format::R8G8B8A8_UNORM;
658658
RenderPipelineDesc desc;
659659
desc.program = m_shaderProgram;
@@ -986,15 +986,10 @@ Result RenderTestApp::update()
986986
auto encoder = m_queue->createCommandEncoder();
987987
if (m_options.shaderType == Options::ShaderProgramType::Compute)
988988
{
989-
auto rootObject = m_device->createRootShaderObject(m_pipeline);
990-
applyBinding(rootObject);
991-
rootObject->finalize();
992-
993989
auto passEncoder = encoder->beginComputePass();
994-
ComputeState state;
995-
state.pipeline = static_cast<IComputePipeline*>(m_pipeline.get());
996-
state.rootObject = rootObject;
997-
passEncoder->setComputeState(state);
990+
auto rootObject =
991+
passEncoder->bindPipeline(static_cast<IComputePipeline*>(m_pipeline.get()));
992+
applyBinding(rootObject);
998993
passEncoder->dispatchCompute(
999994
m_options.computeDispatchSize[0],
1000995
m_options.computeDispatchSize[1],
@@ -1003,16 +998,11 @@ Result RenderTestApp::update()
1003998
}
1004999
else if (m_options.shaderType == Options::ShaderProgramType::RayTracing)
10051000
{
1006-
auto rootObject = m_device->createRootShaderObject(m_pipeline);
1007-
applyBinding(rootObject);
1008-
rootObject->finalize();
1009-
10101001
auto passEncoder = encoder->beginRayTracingPass();
1011-
RayTracingState state;
1012-
state.pipeline = static_cast<IRayTracingPipeline*>(m_pipeline.get());
1013-
state.rootObject = rootObject;
1014-
state.shaderTable = m_shaderTable;
1015-
passEncoder->setRayTracingState(state);
1002+
auto rootObject = passEncoder->bindPipeline(
1003+
static_cast<IRayTracingPipeline*>(m_pipeline.get()),
1004+
m_shaderTable);
1005+
applyBinding(rootObject);
10161006
passEncoder->dispatchRays(
10171007
0,
10181008
m_options.computeDispatchSize[0],
@@ -1022,11 +1012,6 @@ Result RenderTestApp::update()
10221012
}
10231013
else
10241014
{
1025-
auto rootObject = m_device->createRootShaderObject(m_pipeline);
1026-
applyBinding(rootObject);
1027-
setProjectionMatrix(rootObject);
1028-
rootObject->finalize();
1029-
10301015
RenderPassColorAttachment colorAttachment = {};
10311016
colorAttachment.view = m_colorBufferView;
10321017
colorAttachment.loadOp = LoadOp::Clear;
@@ -1041,13 +1026,15 @@ Result RenderTestApp::update()
10411026
renderPass.depthStencilAttachment = &depthStencilAttachment;
10421027

10431028
auto passEncoder = encoder->beginRenderPass(renderPass);
1029+
auto rootObject =
1030+
passEncoder->bindPipeline(static_cast<IRenderPipeline*>(m_pipeline.get()));
1031+
applyBinding(rootObject);
1032+
setProjectionMatrix(rootObject);
10441033

10451034
RenderState state;
1046-
state.pipeline = static_cast<IRenderPipeline*>(m_pipeline.get());
1047-
state.rootObject = rootObject;
1048-
state.viewports[0] = Viewport((float)gWindowWidth, (float)gWindowHeight);
1035+
state.viewports[0] = Viewport::fromSize(gWindowWidth, gWindowHeight);
10491036
state.viewportCount = 1;
1050-
state.scissorRects[0] = ScissorRect(gWindowWidth, gWindowHeight);
1037+
state.scissorRects[0] = ScissorRect::fromSize(gWindowWidth, gWindowHeight);
10511038
state.scissorRectCount = 1;
10521039

10531040
if (m_options.shaderType == Options::ShaderProgramType::GraphicsMeshCompute ||
@@ -1413,9 +1400,6 @@ static SlangResult _innerMain(
14131400
desc.debugCallback = &debugCallback;
14141401
#endif
14151402

1416-
if (options.enableBackendValidation)
1417-
desc.enableBackendValidation = true;
1418-
14191403
desc.slang.lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_NONE;
14201404
if (options.generateSPIRVDirectly)
14211405
desc.slang.targetFlags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY;
@@ -1460,7 +1444,10 @@ static SlangResult _innerMain(
14601444
desc.slang.slangGlobalSession = session;
14611445
desc.slang.targetProfile = options.profileName.getBuffer();
14621446
{
1463-
getRHI()->enableDebugLayers();
1447+
if (options.enableDebugLayers)
1448+
{
1449+
getRHI()->enableDebugLayers();
1450+
}
14641451
SlangResult res = getRHI()->createDevice(desc, device.writeRef());
14651452
if (SLANG_FAILED(res))
14661453
{

tools/slang-test/slang-test-main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3528,7 +3528,7 @@ TestResult runComputeComparisonImpl(
35283528
// This is due to the limitation that Slang RPC implementation expects only
35293529
// one time communication.
35303530
if (input.spawnType != SpawnType::UseTestServer)
3531-
cmdLine.addArg("-enable-backend-validation");
3531+
cmdLine.addArg("-enable-debug-layers");
35323532
#endif
35333533

35343534
if (context->isExecuting())

0 commit comments

Comments
 (0)