Skip to content

Commit 1621635

Browse files
authoredFeb 19, 2025
Merge branch 'master' into bugfix/gh-2890_1
2 parents f00de93 + 7315b33 commit 1621635

10 files changed

+91
-83
lines changed
 

‎cmake/CompilerFlags.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function(set_default_compile_options target)
205205
$<$<BOOL:${SLANG_ENABLE_FULL_DEBUG_VALIDATION}>:SLANG_ENABLE_FULL_IR_VALIDATION>
206206
$<$<BOOL:${SLANG_ENABLE_IR_BREAK_ALLOC}>:SLANG_ENABLE_IR_BREAK_ALLOC>
207207
$<$<BOOL:${SLANG_ENABLE_DX_ON_VK}>:SLANG_CONFIG_DX_ON_VK>
208+
$<$<STREQUAL:${SLANG_LIB_TYPE},STATIC>:STB_IMAGE_STATIC>
208209
)
209210

210211
if(SLANG_ENABLE_ASAN)

‎docs/building.md

+15
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,21 @@ cmake -B build -G Ninja
321321
cmake --build build -j
322322
```
323323

324+
## Static linking against libslang
325+
326+
If linking against a static `libslang.a` you will need to link against some
327+
dependencies also if you're not already incorporating them into your project.
328+
329+
You will need to link against:
330+
331+
```
332+
${SLANG_DIR}/build/Release/lib/libslang.a
333+
${SLANG_DIR}/build/Release/lib/libcompiler-core.a
334+
${SLANG_DIR}/build/Release/lib/libcore.a
335+
${SLANG_DIR}/build/external/miniz/libminiz.a
336+
${SLANG_DIR}/build/external/lz4/build/cmake/liblz4.a
337+
```
338+
324339
## Notes
325340

326341
[^1] below 3.25, CMake lacks the ability to mark directories as being

‎external/CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,19 @@ endif()
8989

9090
# imgui
9191
add_library(imgui INTERFACE)
92-
target_include_directories(imgui INTERFACE "${CMAKE_CURRENT_LIST_DIR}/imgui")
92+
target_include_directories(
93+
imgui
94+
${system}
95+
INTERFACE "${CMAKE_CURRENT_LIST_DIR}/imgui"
96+
)
9397

9498
# stb
9599
add_library(stb INTERFACE)
96-
target_include_directories(stb INTERFACE "${CMAKE_CURRENT_LIST_DIR}/stb")
100+
target_include_directories(
101+
stb
102+
${system}
103+
INTERFACE "${CMAKE_CURRENT_LIST_DIR}/stb"
104+
)
97105

98106
# slang-rhi
99107
if(SLANG_ENABLE_SLANG_RHI)

‎source/slang/hlsl.meta.slang

+4
Original file line numberDiff line numberDiff line change
@@ -23667,6 +23667,8 @@ void coopVecOuterProductAccumulate<T : __BuiltinArithmeticType, let M : int, let
2366723667
{
2366823668
__target_switch
2366923669
{
23670+
case hlsl:
23671+
__intrinsic_asm "$0.OuterProductAccumulate($1, $2, $3, $4, $5, $6)";
2367023672
case spirv:
2367123673
let matrixInterpretationSpirv : int = __getSpvCoopVecComponentType(matrixInterpretation);
2367223674
let memoryLayoutSpirv : int = __getSpvCoopVecMatrixLayout(memoryLayout);
@@ -23742,6 +23744,8 @@ void coopVecReduceSumAccumulate<T : __BuiltinArithmeticType, let N : int>(
2374223744
{
2374323745
__target_switch
2374423746
{
23747+
case hlsl:
23748+
__intrinsic_asm "$0.ReduceSumAccumulate($1, $2)";
2374523749
case spirv:
2374623750
let bufferPtr = buffer.GetBufferPointer();
2374723751
spirv_asm

‎source/slang/slang-reflection-json.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection*
328328
writer << "]";
329329
}
330330
}
331+
static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* func)
332+
{
333+
auto attribCount = func->getUserAttributeCount();
334+
if (attribCount)
335+
{
336+
writer << ",\n\"userAttribs\": [";
337+
for (unsigned int i = 0; i < attribCount; i++)
338+
{
339+
if (i > 0)
340+
writer << ",\n";
341+
auto attrib = func->getUserAttributeByIndex(i);
342+
emitUserAttributeJSON(writer, attrib);
343+
}
344+
writer << "]";
345+
}
346+
}
331347

332348
static void emitReflectionVarLayoutJSON(PrettyWriter& writer, slang::VariableLayoutReflection* var)
333349
{
@@ -1091,6 +1107,8 @@ static void emitReflectionEntryPointJSON(
10911107
writer << "\n]";
10921108
}
10931109

1110+
emitUserAttributes(writer, entryPoint->getFunction());
1111+
10941112
writer.dedent();
10951113
writer << "\n}";
10961114
}

‎tests/reflection/attribute.slang

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//TEST:REFLECTION:-stage compute -entry main -target hlsl -no-codegen
66

77
[__AttributeUsage(_AttributeTargets.Struct)]
8+
[__AttributeUsage(_AttributeTargets.Function)]
89
struct MyStructAttribute
910
{
1011
int iParam;
@@ -58,6 +59,7 @@ D param3;
5859
[StructVarParam(1)] int globalInt2;
5960

6061

62+
[MyStruct(2, 3.0)]
6163
[numthreads(1, 1, 1)]
6264
void main(
6365
uint3 dispatchThreadID : SV_DispatchThreadID,

‎tests/reflection/attribute.slang.expected

+9-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,15 @@ standard output = {
310310
}
311311
}
312312
],
313-
"threadGroupSize": [1, 1, 1]
313+
"threadGroupSize": [1, 1, 1],
314+
"userAttribs": [{
315+
"name": "MyStruct",
316+
"arguments": [
317+
2,
318+
3.000000
319+
]
320+
}
321+
]
314322
}
315323
]
316324
}

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

+14-29
Original file line numberDiff line numberDiff line change
@@ -154,28 +154,28 @@ class RenderTestApp
154154
struct AssignValsFromLayoutContext
155155
{
156156
IDevice* device;
157-
slang::ISession* slangSession;
157+
slang::IComponentType* slangComponent;
158158
ShaderOutputPlan& outputPlan;
159159
TestResourceContext& resourceContext;
160-
slang::ProgramLayout* slangReflection;
161160
IAccelerationStructure* accelerationStructure;
162161

163162
AssignValsFromLayoutContext(
164163
IDevice* device,
165-
slang::ISession* slangSession,
164+
slang::IComponentType* slangComponent,
166165
ShaderOutputPlan& outputPlan,
167166
TestResourceContext& resourceContext,
168-
slang::ProgramLayout* slangReflection,
169167
IAccelerationStructure* accelerationStructure)
170168
: device(device)
171-
, slangSession(slangSession)
169+
, slangComponent(slangComponent)
172170
, outputPlan(outputPlan)
173171
, resourceContext(resourceContext)
174-
, slangReflection(slangReflection)
175172
, accelerationStructure(accelerationStructure)
176173
{
177174
}
178175

176+
slang::ProgramLayout* slangReflection() { return slangComponent->getLayout(); }
177+
slang::ISession* slangSession() { return slangComponent->getSession(); }
178+
179179
void maybeAddOutput(
180180
ShaderCursor const& dstCursor,
181181
ShaderInputLayout::Val* srcVal,
@@ -389,7 +389,7 @@ struct AssignValsFromLayoutContext
389389
// If the input line specified the name of the type
390390
// to allocate, then we use it directly.
391391
//
392-
slangType = slangReflection->findTypeByName(typeName.getBuffer());
392+
slangType = slangReflection()->findTypeByName(typeName.getBuffer());
393393
}
394394
else
395395
{
@@ -418,7 +418,7 @@ struct AssignValsFromLayoutContext
418418

419419
ComPtr<IShaderObject> shaderObject;
420420
device->createShaderObject(
421-
slangSession,
421+
slangSession(),
422422
slangType,
423423
ShaderObjectContainerType::None,
424424
shaderObject.writeRef());
@@ -437,7 +437,7 @@ struct AssignValsFromLayoutContext
437437
List<slang::SpecializationArg> args;
438438
for (auto& typeName : srcVal->typeArgs)
439439
{
440-
auto slangType = slangReflection->findTypeByName(typeName.getBuffer());
440+
auto slangType = slangReflection()->findTypeByName(typeName.getBuffer());
441441
if (!slangType)
442442
{
443443
StdWriters::getError().print(
@@ -516,42 +516,30 @@ struct AssignValsFromLayoutContext
516516
}
517517
};
518518

519-
SlangResult _assignVarsFromLayout(
519+
static SlangResult _assignVarsFromLayout(
520520
IDevice* device,
521-
slang::ISession* slangSession,
521+
slang::IComponentType* slangComponent,
522522
IShaderObject* shaderObject,
523523
ShaderInputLayout const& layout,
524524
ShaderOutputPlan& ioOutputPlan,
525525
TestResourceContext& ioResourceContext,
526-
slang::ProgramLayout* slangReflection,
527526
IAccelerationStructure* accelerationStructure)
528527
{
529-
AssignValsFromLayoutContext context(
530-
device,
531-
slangSession,
532-
ioOutputPlan,
533-
ioResourceContext,
534-
slangReflection,
535-
accelerationStructure);
528+
AssignValsFromLayoutContext
529+
context(device, slangComponent, ioOutputPlan, ioResourceContext, accelerationStructure);
536530
ShaderCursor rootCursor = ShaderCursor(shaderObject);
537531
return context.assign(rootCursor, layout.rootVal);
538532
}
539533

540534
Result RenderTestApp::applyBinding(IShaderObject* rootObject)
541535
{
542-
auto slangReflection = (slang::ProgramLayout*)spGetReflection(
543-
m_compilationOutput.output.getRequestForReflection());
544-
ComPtr<slang::ISession> slangSession;
545-
m_compilationOutput.output.m_requestForKernels->getSession(slangSession.writeRef());
546-
547536
return _assignVarsFromLayout(
548537
m_device,
549-
slangSession,
538+
m_compilationOutput.output.slangProgram,
550539
rootObject,
551540
m_compilationOutput.layout,
552541
m_outputPlan,
553542
m_resourceContext,
554-
slangReflection,
555543
m_topLevelAccelerationStructure);
556544
}
557545

@@ -1086,9 +1074,6 @@ Result RenderTestApp::update()
10861074
m_options.shaderType == Options::ShaderProgramType::GraphicsMeshCompute ||
10871075
m_options.shaderType == Options::ShaderProgramType::GraphicsTaskMeshCompute)
10881076
{
1089-
auto request = m_compilationOutput.output.getRequestForReflection();
1090-
auto slangReflection = (slang::ShaderReflection*)spGetReflection(request);
1091-
10921077
SLANG_RETURN_ON_FAIL(writeBindingOutput(m_options.outputPath));
10931078
}
10941079
else

‎tools/render-test/slang-support.cpp

+16-23
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ void ShaderCompilerUtil::Output::reset()
3636
}
3737

3838
session = nullptr;
39-
m_requestForKernels = nullptr;
40-
m_extraRequestForReflection = nullptr;
39+
m_requestDEPRECATED = nullptr;
4140
}
4241

43-
/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(
42+
static SlangResult _compileProgramImpl(
4443
slang::IGlobalSession* globalSession,
4544
const Options& options,
46-
const Input& input,
45+
const ShaderCompilerUtil::Input& input,
4746
const ShaderCompileRequest& request,
48-
Output& out)
47+
ShaderCompilerUtil::Output& out)
4948
{
5049
out.reset();
5150

@@ -58,7 +57,7 @@ void ShaderCompilerUtil::Output::reset()
5857
SLANG_ALLOW_DEPRECATED_BEGIN
5958
globalSession->createCompileRequest(slangRequest.writeRef());
6059
SLANG_ALLOW_DEPRECATED_END
61-
out.m_requestForKernels = slangRequest;
60+
out.m_requestDEPRECATED = slangRequest;
6261
out.session = globalSession;
6362

6463
bool hasRepro = false;
@@ -303,12 +302,12 @@ void ShaderCompilerUtil::Output::reset()
303302
return SLANG_OK;
304303
}
305304

306-
/* static */ SlangResult ShaderCompilerUtil::compileProgram(
305+
static SlangResult compileProgram(
307306
slang::IGlobalSession* globalSession,
308307
const Options& options,
309-
const Input& input,
308+
const ShaderCompilerUtil::Input& input,
310309
const ShaderCompileRequest& request,
311-
Output& out)
310+
ShaderCompilerUtil::Output& out)
312311
{
313312
if (input.passThrough == SLANG_PASS_THROUGH_NONE)
314313
{
@@ -333,7 +332,7 @@ void ShaderCompilerUtil::Output::reset()
333332
// compile in another pass using the desired downstream compiler
334333
// so that we can get the refleciton information we need.
335334
//
336-
Output slangOutput;
335+
ShaderCompilerUtil::Output slangOutput;
337336
if (canUseSlangForPrecompile)
338337
{
339338
ShaderCompilerUtil::Input slangInput = input;
@@ -354,17 +353,16 @@ void ShaderCompilerUtil::Output::reset()
354353
//
355354
SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, input, request, out));
356355

357-
out.m_extraRequestForReflection = slangOutput.getRequestForReflection();
356+
out.m_requestDEPRECATED = slangOutput.m_requestDEPRECATED;
358357
out.desc.slangGlobalScope = slangOutput.desc.slangGlobalScope;
359-
slangOutput.m_requestForKernels = nullptr;
358+
slangOutput.m_requestDEPRECATED = nullptr;
360359

361360
return SLANG_OK;
362361
}
363362
}
364363

365-
/* static */ SlangResult ShaderCompilerUtil::readSource(
366-
const String& inSourcePath,
367-
List<char>& outSourceText)
364+
// Helper for compileWithLayout
365+
/* static */ SlangResult readSource(const String& inSourcePath, List<char>& outSourceText)
368366
{
369367
// Read in the source code
370368
FILE* sourceFile = fopen(inSourcePath.getBuffer(), "rb");
@@ -392,8 +390,8 @@ void ShaderCompilerUtil::Output::reset()
392390
/* static */ SlangResult ShaderCompilerUtil::compileWithLayout(
393391
slang::IGlobalSession* globalSession,
394392
const Options& options,
395-
const ShaderCompilerUtil::Input& input,
396-
OutputAndLayout& output)
393+
const Input& input,
394+
ShaderCompilerUtil::OutputAndLayout& output)
397395
{
398396
String sourcePath = options.sourcePath;
399397
auto shaderType = options.shaderType;
@@ -531,12 +529,7 @@ void ShaderCompilerUtil::Output::reset()
531529
c.idOverride = conformance.idOverride;
532530
compileRequest.typeConformances.add(c);
533531
}
534-
return ShaderCompilerUtil::compileProgram(
535-
globalSession,
536-
options,
537-
input,
538-
compileRequest,
539-
output.output);
532+
return compileProgram(globalSession, options, input, compileRequest, output.output);
540533
}
541534

542535
} // namespace renderer_test

0 commit comments

Comments
 (0)