Skip to content

Commit 97443e5

Browse files
authored
Merge branch 'master' into sparse-textures-spirv-sample
2 parents 791b647 + 86669cb commit 97443e5

File tree

97 files changed

+2790
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2790
-576
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
- uses: actions/checkout@v4
8686
with:
8787
submodules: "recursive"
88-
fetch-depth: "0"
88+
fetch-depth: "2"
8989
- id: filter
9090
run: |
9191
# This step prevents subsequent steps from running if only documentation was 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

docs/design/stdlib-intrinsics.md

-6
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ Sections of the `expansion` string that are to be replaced are prefixed by the `
114114
* $XH - Ray tracing hit object attribute
115115
* $P - Type-based prefix as used for CUDA and C++ targets (I8 for int8_t, F32 - float etc)
116116

117-
## __specialized_for_target(target)
118-
119-
Specialized for target allows defining an implementation *body* for a particular target. The target is the same as is used for [__target_intrinsic](#target-intrinsic).
120-
121-
A declaration can consist of multiple definitions with bodies (for each target) using, `specialized_for_target`, as well as having `target_intrinsic` if that is applicable for a target.
122-
123117
## __attributeTarget(astClassName)
124118

125119
For an attribute, specifies the AST class (and derived class) the attribute can be applied to.

examples/reflection-api/compute-simple.slang

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// compute-simple.slang
22

3+
static const uint THREADGROUP_SIZE_X = 8;
4+
static const uint THREADGROUP_SIZE_Y = THREADGROUP_SIZE_X;
5+
36
struct ImageProcessingOptions
47
{
58
float3 tintColor;
@@ -10,7 +13,7 @@ struct ImageProcessingOptions
1013
}
1114

1215
[shader("compute")]
13-
[numthreads(8, 8)]
16+
[numthreads(THREADGROUP_SIZE_X, THREADGROUP_SIZE_Y)]
1417
void processImage(
1518
uint3 threadID : SV_DispatchThreadID,
1619
uniform Texture2D inputImage,

examples/reflection-api/main.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ struct ReflectingPrinting
114114

115115
List<ComPtr<slang::IComponentType>> componentsToLink;
116116

117+
// ### Variable decls
118+
//
119+
key("global constants");
120+
WITH_ARRAY()
121+
for (auto decl : module->getModuleReflection()->getChildren())
122+
{
123+
if (auto varDecl = decl->asVariable(); varDecl &&
124+
varDecl->findModifier(slang::Modifier::Const) &&
125+
varDecl->findModifier(slang::Modifier::Static))
126+
{
127+
element();
128+
printVariable(varDecl);
129+
}
130+
}
131+
117132
// ### Finding Entry Points
118133
//
119134

@@ -213,6 +228,13 @@ struct ReflectingPrinting
213228
printQuotedString(name);
214229
key("type");
215230
printType(type);
231+
232+
int64_t value;
233+
if (SLANG_SUCCEEDED(variable->getDefaultValueInt(&value)))
234+
{
235+
key("value");
236+
printf("%" PRId64, value);
237+
}
216238
}
217239

218240
// ### Types

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)

include/slang-deprecated.h

+2
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ extern "C"
659659
SlangSession* globalSession,
660660
char const* name);
661661
SLANG_API bool spReflectionVariable_HasDefaultValue(SlangReflectionVariable* inVar);
662+
SLANG_API SlangResult
663+
spReflectionVariable_GetDefaultValueInt(SlangReflectionVariable* inVar, int64_t* rs);
662664
SLANG_API SlangReflectionGeneric* spReflectionVariable_GetGenericContainer(
663665
SlangReflectionVariable* var);
664666
SLANG_API SlangReflectionVariable* spReflectionVariable_applySpecializations(

include/slang.h

+5
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,11 @@ struct VariableReflection
28322832
return spReflectionVariable_HasDefaultValue((SlangReflectionVariable*)this);
28332833
}
28342834

2835+
SlangResult getDefaultValueInt(int64_t* value)
2836+
{
2837+
return spReflectionVariable_GetDefaultValueInt((SlangReflectionVariable*)this, value);
2838+
}
2839+
28352840
GenericReflection* getGenericContainer()
28362841
{
28372842
return (GenericReflection*)spReflectionVariable_GetGenericContainer(

source/core/slang-string.h

+51
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,57 @@ class SLANG_RT_API String
790790
UnownedStringSlice getUnownedSlice() const { return StringRepresentation::asSlice(m_buffer); }
791791
};
792792

793+
class ImmutableHashedString
794+
{
795+
public:
796+
String slice;
797+
HashCode64 hashCode;
798+
ImmutableHashedString()
799+
: hashCode(0)
800+
{
801+
}
802+
ImmutableHashedString(const UnownedStringSlice& slice)
803+
: slice(slice), hashCode(slice.getHashCode())
804+
{
805+
}
806+
ImmutableHashedString(const char* begin, const char* end)
807+
: slice(begin, end), hashCode(slice.getHashCode())
808+
{
809+
}
810+
ImmutableHashedString(const char* begin, size_t len)
811+
: slice(UnownedStringSlice(begin, len)), hashCode(slice.getHashCode())
812+
{
813+
}
814+
ImmutableHashedString(const char* begin)
815+
: slice(begin), hashCode(slice.getHashCode())
816+
{
817+
}
818+
ImmutableHashedString(const String& str)
819+
: slice(str), hashCode(str.getHashCode())
820+
{
821+
}
822+
ImmutableHashedString(String&& str)
823+
: slice(_Move(str)), hashCode(str.getHashCode())
824+
{
825+
}
826+
ImmutableHashedString(const ImmutableHashedString& other) = default;
827+
ImmutableHashedString& operator=(const ImmutableHashedString& other) = default;
828+
bool operator==(const ImmutableHashedString& other) const
829+
{
830+
return hashCode == other.hashCode && slice == other.slice;
831+
}
832+
bool operator!=(const ImmutableHashedString& other) const
833+
{
834+
return hashCode != other.hashCode || slice != other.slice;
835+
}
836+
bool operator==(const UnownedStringSlice& other) const { return slice == other; }
837+
bool operator!=(const UnownedStringSlice& other) const { return slice != other; }
838+
bool operator==(const String& other) const { return slice == other.getUnownedSlice(); }
839+
bool operator!=(const String& other) const { return slice != other.getUnownedSlice(); }
840+
bool operator==(const char* other) const { return slice == UnownedStringSlice(other); }
841+
HashCode64 getHashCode() const { return hashCode; }
842+
};
843+
793844
class SLANG_RT_API StringBuilder : public String
794845
{
795846
private:

source/slang-glslang/slang-glslang.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ extern "C"
175175

176176
spvtools::ValidatorOptions options;
177177
options.SetScalarBlockLayout(true);
178+
options.SetFriendlyNames(true);
178179

179180
spvtools::SpirvTools tools(target_env);
180181
tools.SetMessageConsumer(validationMessageConsumer);
@@ -197,6 +198,7 @@ extern "C"
197198
options |= SPV_BINARY_TO_TEXT_OPTION_COMMENT;
198199
options |= SPV_BINARY_TO_TEXT_OPTION_PRINT;
199200
options |= SPV_BINARY_TO_TEXT_OPTION_COLOR;
201+
options |= SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
200202

201203
spv_diagnostic diagnostic = nullptr;
202204
spv_context context = spvContextCreate(kDefaultEnvironment);

source/slang/core.meta.slang

+30-73
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//public module core;
1+
public module core;
22

33
// Slang `core` library
44

@@ -603,6 +603,7 @@ void static_assert(constexpr bool condition, NativeString errorMessage);
603603
///
604604
///
605605
__magic_type(DifferentiableType)
606+
[KnownBuiltin("IDifferentiable")]
606607
interface IDifferentiable
607608
{
608609
// Note: the compiler implementation requires the `Differential` associated type to be defined
@@ -645,6 +646,7 @@ interface IDifferentiable
645646
/// @remarks Support for this interface is still experimental and subject to change.
646647
///
647648
__magic_type(DifferentiablePtrType)
649+
[KnownBuiltin("IDifferentiablePtr")]
648650
interface IDifferentiablePtrType
649651
{
650652
__builtin_requirement($( (int)BuiltinRequirementKind::DifferentialPtrType) )
@@ -2367,49 +2369,6 @@ __generic<T> __extension vector<T, 4>
23672369

23682370
${{{{
23692371

2370-
// The above extensions are generic in the *type* of the vector,
2371-
// but explicit in the *size*. We will now declare an extension
2372-
// for each builtin type that is generic in the size.
2373-
//
2374-
for (int tt = 0; tt < kBaseTypeCount; ++tt)
2375-
{
2376-
if(kBaseTypes[tt].tag == BaseType::Void) continue;
2377-
2378-
sb << "__generic<let N : int> __extension vector<"
2379-
<< kBaseTypes[tt].name << ",N>\n{\n";
2380-
2381-
for (int ff = 0; ff < kBaseTypeCount; ++ff)
2382-
{
2383-
if(kBaseTypes[ff].tag == BaseType::Void) continue;
2384-
2385-
2386-
if( tt != ff )
2387-
{
2388-
auto cost = getBaseTypeConversionCost(
2389-
kBaseTypes[tt],
2390-
kBaseTypes[ff]);
2391-
auto op = getBaseTypeConversionOp(
2392-
kBaseTypes[tt],
2393-
kBaseTypes[ff]);
2394-
2395-
// Implicit conversion from a vector of the same
2396-
// size, but different element type.
2397-
sb << " __implicit_conversion(" << cost << ")\n";
2398-
sb << " __intrinsic_op(" << int(op) << ")\n";
2399-
sb << " __init(vector<" << kBaseTypes[ff].name << ",N> value);\n";
2400-
2401-
// Constructor to make a vector from a scalar of another type.
2402-
if (cost != kConversionCost_Impossible)
2403-
{
2404-
cost += kConversionCost_ScalarToVector;
2405-
sb << " __implicit_conversion(" << cost << ")\n";
2406-
sb << " [__unsafeForceInlineEarly]\n";
2407-
sb << " __init(" << kBaseTypes[ff].name << " value) { this = vector<" << kBaseTypes[tt].name << ",N>( " << kBaseTypes[tt].name << "(value)); }\n";
2408-
}
2409-
}
2410-
}
2411-
sb << "}\n";
2412-
}
24132372

24142373
for( int R = 1; R <= 4; ++R )
24152374
for( int C = 1; C <= 4; ++C )
@@ -2464,38 +2423,36 @@ for( int C = 1; C <= 4; ++C )
24642423
sb << "}\n";
24652424
}
24662425

2467-
for (int tt = 0; tt < kBaseTypeCount; ++tt)
2468-
{
2469-
if(kBaseTypes[tt].tag == BaseType::Void) continue;
2470-
auto toType = kBaseTypes[tt].name;
24712426
}}}}
24722427

2473-
__generic<let R : int, let C : int, let L : int> extension matrix<$(toType),R,C,L>
2428+
//@hidden:
2429+
__intrinsic_op($(kIROp_BuiltinCast))
2430+
internal T __builtin_cast<T, U>(U u);
2431+
2432+
// If T is implicitly convertible to U, then vector<T,N> is implicitly convertible to vector<U,N>.
2433+
__generic<ToType, let N : int> extension vector<ToType,N>
24742434
{
2475-
${{{{
2476-
for (int ff = 0; ff < kBaseTypeCount; ++ff)
2477-
{
2478-
if(kBaseTypes[ff].tag == BaseType::Void) continue;
2479-
if( tt == ff ) continue;
2435+
__implicit_conversion(constraint)
2436+
__intrinsic_op(BuiltinCast)
2437+
__init<FromType>(vector<FromType,N> value) where ToType(FromType) implicit;
24802438

2481-
auto cost = getBaseTypeConversionCost(
2482-
kBaseTypes[tt],
2483-
kBaseTypes[ff]);
2484-
auto fromType = kBaseTypes[ff].name;
2485-
auto op = getBaseTypeConversionOp(
2486-
kBaseTypes[tt],
2487-
kBaseTypes[ff]);
2488-
}}}}
2489-
__implicit_conversion($(cost))
2490-
__intrinsic_op($(op))
2491-
__init(matrix<$(fromType),R,C,L> value);
2492-
${{{{
2439+
__implicit_conversion(constraint+)
2440+
[__unsafeForceInlineEarly]
2441+
[__readNone]
2442+
[TreatAsDifferentiable]
2443+
__init<FromType>(FromType value) where ToType(FromType) implicit
2444+
{
2445+
this = __builtin_cast<vector<ToType,N>>(vector<FromType,N>(value));
24932446
}
2494-
}}}}
24952447
}
2496-
${{{{
2448+
2449+
// If T is implicitly convertible to U, then matrix<T,R,C,L> is implicitly convertible to matrix<U,R,C,L>.
2450+
__generic<ToType, let R : int, let C : int, let L : int> extension matrix<ToType,R,C,L>
2451+
{
2452+
__implicit_conversion(constraint)
2453+
__intrinsic_op(BuiltinCast)
2454+
__init<FromType>(matrix<FromType,R,C,L> value) where ToType(FromType) implicit;
24972455
}
2498-
}}}}
24992456

25002457
//@ hidden:
25012458
__generic<T, U>
@@ -2643,20 +2600,20 @@ for(auto fixity : kIncDecFixities)
26432600
$(fixity.qual)
26442601
__generic<T : __BuiltinArithmeticType>
26452602
[__unsafeForceInlineEarly]
2646-
T operator$(op.name)(in out T value)
2647-
{$(fixity.bodyPrefix) value = value $(op.binOp) T(1); return $(fixity.returnVal); }
2603+
T operator$(op.name)( in out T value)
2604+
{ $(fixity.bodyPrefix) value = value $(op.binOp) __builtin_cast<T>(1); return $(fixity.returnVal); }
26482605

26492606
$(fixity.qual)
26502607
__generic<T : __BuiltinArithmeticType, let N : int>
26512608
[__unsafeForceInlineEarly]
26522609
vector<T,N> operator$(op.name)(in out vector<T,N> value)
2653-
{$(fixity.bodyPrefix) value = value $(op.binOp) T(1); return $(fixity.returnVal); }
2610+
{$(fixity.bodyPrefix) value = value $(op.binOp) __builtin_cast<T>(1); return $(fixity.returnVal); }
26542611

26552612
$(fixity.qual)
26562613
__generic<T : __BuiltinArithmeticType, let R : int, let C : int, let L : int>
26572614
[__unsafeForceInlineEarly]
26582615
matrix<T,R,C> operator$(op.name)(in out matrix<T,R,C,L> value)
2659-
{$(fixity.bodyPrefix) value = value $(op.binOp) T(1); return $(fixity.returnVal); }
2616+
{$(fixity.bodyPrefix) value = value $(op.binOp) __builtin_cast<T>(1); return $(fixity.returnVal); }
26602617

26612618
$(fixity.qual)
26622619
__generic<T, let addrSpace : uint64_t>

0 commit comments

Comments
 (0)