Skip to content

Commit

Permalink
Replace the word stdlib or standard-library with core-module for sour…
Browse files Browse the repository at this point in the history
…ce code (shader-slang#5415)

This commit changes the word "stdlib" or "standard library" to "core module" in the source code.
  • Loading branch information
jkwak-work authored Oct 28, 2024
1 parent 8047160 commit b7a619b
Show file tree
Hide file tree
Showing 44 changed files with 221 additions and 221 deletions.
2 changes: 1 addition & 1 deletion prelude/slang-cpp-scalar-intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ SLANG_FORCE_INLINE uint64_t U64_abs(uint64_t f) { return f; }
SLANG_FORCE_INLINE uint64_t U64_min(uint64_t a, uint64_t b) { return a < b ? a : b; }
SLANG_FORCE_INLINE uint64_t U64_max(uint64_t a, uint64_t b) { return a > b ? a : b; }

// TODO(JS): We don't define countbits for 64bit in stdlib currently.
// TODO(JS): We don't define countbits for 64bit in the core module currently.
// It's not clear from documentation if it should return 32 or 64 bits, if it exists.
// 32 bits can always hold the result, and will be implicitly promoted.
SLANG_FORCE_INLINE uint32_t U64_countbits(uint64_t v)
Expand Down
2 changes: 1 addition & 1 deletion prelude/slang-cuda-prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ struct RWByteAddressBuffer
memcpy((char*)data + index, &value, sizeof(T));
}

/// Can be used in stdlib to gain access
/// Can be used in the core module to gain access
template <typename T>
SLANG_CUDA_CALL T* _getPtrAt(size_t index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace Slang
if (!coreLibraryCode)
{
StringBuilder sb;
const String path = getStdlibPath();
const String path = getCoreModulePath();
#include "core.meta.slang.h"
coreLibraryCode = StringBlob::moveCreate(sb);
}
Expand All @@ -301,7 +301,7 @@ namespace Slang
#if SLANG_EMBED_CORE_MODULE_SOURCE
if (!hlslLibraryCode)
{
const String path = getStdlibPath();
const String path = getCoreModulePath();
StringBuilder sb;
#include "hlsl.meta.slang.h"
hlslLibraryCode = StringBlob::moveCreate(sb);
Expand All @@ -315,7 +315,7 @@ namespace Slang
#if SLANG_EMBED_CORE_MODULE_SOURCE
if (!autodiffLibraryCode)
{
const String path = getStdlibPath();
const String path = getCoreModulePath();
StringBuilder sb;
#include "diff.meta.slang.h"
autodiffLibraryCode = StringBlob::moveCreate(sb);
Expand All @@ -328,7 +328,7 @@ namespace Slang
{
if (!glslLibraryCode)
{
const String path = getStdlibPath();
const String path = getCoreModulePath();
StringBuilder sb;
#include "glsl.meta.slang.h"
glslLibraryCode = StringBlob::moveCreate(sb);
Expand Down
44 changes: 22 additions & 22 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -2405,12 +2405,12 @@ for (int isArray = 0; isArray <= 1; isArray++)
for (int isMS = 0; isMS <= 1; isMS++) {
if (isMS)
{
if (shapeIndex != kStdlibShapeIndex2D)
if (shapeIndex != kCoreModule_ShapeIndex2D)
continue;
}
if (isArray)
{
if (shapeIndex == kStdlibShapeIndex3D)
if (shapeIndex == kCoreModule_ShapeIndex3D)
continue;
}
auto shapeTypeName = kTextureShapeTypeNames[shapeIndex];
Expand Down Expand Up @@ -3025,7 +3025,7 @@ extension _Texture<T,Shape,isArray,0,sampleCount,0,isShadow,isCombined,format>
{
//@hidden:
static const int isMS = 0;
static const int access = $(kStdlibResourceAccessReadOnly);
static const int access = $(kCoreModule_ResourceAccessReadOnly);
//@public:
__glsl_extension(GL_EXT_samplerless_texture_functions)
[__readNone]
Expand Down Expand Up @@ -3258,7 +3258,7 @@ __generic<T, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let i
extension _Texture<T,Shape,isArray,1,sampleCount,0,isShadow,isCombined,format>
{
//@hidden:
static const int access = $(kStdlibResourceAccessReadOnly);
static const int access = $(kCoreModule_ResourceAccessReadOnly);
static const int isMS = 1;
//@public:
__glsl_extension(GL_EXT_samplerless_texture_functions)
Expand Down Expand Up @@ -3432,7 +3432,7 @@ extension _Texture<T,Shape,isArray,1,sampleCount,0,isShadow,isCombined,format>

// Load/Subscript for readwrite textures
${{{{
for (int access = kStdlibResourceAccessReadWrite; access<=kStdlibResourceAccessRasterizerOrdered; access++) {
for (int access = kCoreModule_ResourceAccessReadWrite; access <= kCoreModule_ResourceAccessRasterizerOrdered; access++) {
const char* glslIntrinsic = "$cimageLoad($0, $1)$z";
const char* glslIntrinsicOffset = "$cimageLoad($0, ($1)+($2))$z";
const char* glslIntrinsicMS = "$cimageLoad($0, $1, $2)$z";
Expand Down Expand Up @@ -3748,7 +3748,7 @@ extension _Texture<T,Shape,isArray,0,sampleCount,$(access),isShadow, 0,format>
}

${{{{
if (access == kStdlibResourceAccessReadWrite) {
if (access == kCoreModule_ResourceAccessReadWrite) {
}}}}

// RW MS textures.
Expand Down Expand Up @@ -3901,7 +3901,7 @@ extension _Texture<T,Shape,isArray,1,sampleCount,$(access),isShadow, 0,format>
}

${{{{
} // if (access == kStdlibResourceAccessReadWrite) // for RW MS textures.
} // if (access == kCoreModule_ResourceAccessReadWrite) // for RW MS textures.
} // for (access).
}}}}

Expand Down Expand Up @@ -3983,13 +3983,13 @@ ${{{{
for (int isArray = 0; isArray<=1; isArray++)
for (int isMS = 0; isMS<=1; isMS++)
for (int isCombined = 0; isCombined<=1; isCombined++)
for (int access = kStdlibResourceAccessReadOnly; access<=kStdlibResourceAccessFeedback; access++) {
if (access != kStdlibResourceAccessReadOnly)
for (int access = kCoreModule_ResourceAccessReadOnly; access <= kCoreModule_ResourceAccessFeedback; access++) {
if (access != kCoreModule_ResourceAccessReadOnly)
{
// No RW Cube.
if (shape == kStdlibShapeIndexCube) continue;
if (shape == kCoreModule_ShapeIndexCube) continue;
}
if (access == kStdlibResourceAccessFeedback)
if (access == kCoreModule_ResourceAccessFeedback)
{
// Feedback only defined for Texture2D and Texture2DArray.
if (shape != 1) continue;
Expand All @@ -3999,14 +3999,14 @@ ${{{{
if (isMS)
{
// Only Texture2DMS.
if (shape != kStdlibShapeIndex2D)
if (shape != kCoreModule_ShapeIndex2D)
continue;
// Only Texture2DMS or RWTexture2DMS.
if (access >= kStdlibShapeIndex3D)
if (access >= kCoreModule_ShapeIndex3D)
continue;
}
// No 3D Array.
if (shape == kStdlibShapeIndex3D && isArray == 1)
if (shape == kCoreModule_ShapeIndex3D && isArray == 1)
continue;
const char* textureTypeName = isCombined ? "Sampler" : "Texture";
}}}}
Expand Down Expand Up @@ -9924,7 +9924,7 @@ __generic<T : __BuiltinIntegerType>
[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]
T max(T x, T y)
{
// Note: a stdlib implementation of `max` (or `min`) will require splitting
// Note: a core module implementation of `max` (or `min`) will require splitting
// floating-point and integer cases apart, because the floating-point
// version needs to correctly handle the case where one of the inputs
// is not-a-number.
Expand Down Expand Up @@ -15159,7 +15159,7 @@ struct BuiltInTriangleIntersectionAttributes
// 10.2 Shaders

// Right now new shader stages need to be added directly to the compiler
// implementation, rather than being something that can be declared in the stdlib.
// implementation, rather than being something that can be declared in the core module.

// 10.3 - Intrinsics

Expand Down Expand Up @@ -16058,7 +16058,7 @@ struct SAMPLER_FEEDBACK_MIP_REGION_USED : __BuiltinSamplerFeedbackType {};
// All of these objects are write-only resources that point to a special kind of unordered access view meant for sampler feedback.

__generic<T:__BuiltinSamplerFeedbackType>
extension _Texture<T,__Shape2D, 0, 0, 0, $(kStdlibResourceAccessFeedback), 0, 0, 0>
extension _Texture<T,__Shape2D, 0, 0, 0, $(kCoreModule_ResourceAccessFeedback), 0, 0, 0>
{
// With Clamp

Expand Down Expand Up @@ -16138,7 +16138,7 @@ extension _Texture<T,__Shape2D, 0, 0, 0, $(kStdlibResourceAccessFeedback), 0, 0,
};

__generic<T:__BuiltinSamplerFeedbackType>
extension _Texture<T,__Shape2D, 1, 0, 0, $(kStdlibResourceAccessFeedback), 0, 0, 0>
extension _Texture<T,__Shape2D, 1, 0, 0, $(kCoreModule_ResourceAccessFeedback), 0, 0, 0>
{
// With Clamp

Expand Down Expand Up @@ -19254,7 +19254,7 @@ ${
// We introduce a few convenience type aliases here,
// which both keep our declarations simpler and easier
// to understand, but which might *also* be useful to
// users of the stdlib, so that they can write things
// users of the standard module, so that they can write things
// like `Texture2D.Footprint`, and also have auto-complete
// help them find such members.
//
Expand All @@ -19273,7 +19273,7 @@ ${
// parameter to the query operation(s). We define
// the GLSL functions here as intrinsics, so that
// we can refer to them later in the definitions
// of our stdlib operaitons.
// of our standard module operaitons; not just in glsl module.
//
// Note: despite the GLSL extension defining the `granularity`
// member of the query result as having type `uint`, the
Expand Down Expand Up @@ -19606,7 +19606,7 @@ for(auto levelChoice : kLevelChoices)

${
// We now define the portable operations that will be officially
// supported by the standard library. For each operation, we
// supported by the standard module. For each operation, we
// need to provide both a version that maps to the GLSL extension,
// and a version that uses the NVAPI functions.
//
Expand Down Expand Up @@ -19850,7 +19850,7 @@ ${{{{

//<T, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>
__generic<Shape:__ITextureShape1D2D3D, let format : int>
extension _Texture<float, Shape, 0, 0, 0, $(kStdlibResourceAccessReadWrite), 0, 0, format>
extension _Texture<float, Shape, 0, 0, 0, $(kCoreModule_ResourceAccessReadWrite), 0, 0, format>
{
[__requiresNVAPI]
[ForceInline]
Expand Down
42 changes: 21 additions & 21 deletions source/slang/slang-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ SLANG_API SlangSession* spCreateSession(const char*)
return globalSession.detach();
}

// Attempt to load a previously compiled stdlib from the same file system location as the slang dll.
// Attempt to load a previously compiled core module from the same file system location as the slang dll.
// Returns SLANG_OK when the cache is sucessfully loaded.
// Also returns the filename to the stdlib cache and the timestamp of current slang dll.
SlangResult tryLoadStdLibFromCache(
// Also returns the filename to the core module cache and the timestamp of current slang dll.
SlangResult tryLoadCoreModuleFromCache(
slang::IGlobalSession* globalSession,
Slang::String& outCachePath,
uint64_t& outTimestamp)
Expand All @@ -35,7 +35,7 @@ SlangResult tryLoadStdLibFromCache(
uint64_t currentLibTimestamp =
Slang::SharedLibraryUtils::getSharedLibraryTimestamp((void*)slang_createGlobalSession);
auto dirName = Slang::Path::getParentDirectory(fileName);
auto cacheFileName = Slang::Path::combine(dirName, "slang-stdlib.bin");
auto cacheFileName = Slang::Path::combine(dirName, "slang-core-module.bin");
outTimestamp = currentLibTimestamp;
outCachePath = cacheFileName;
if (currentLibTimestamp == 0)
Expand All @@ -45,7 +45,7 @@ SlangResult tryLoadStdLibFromCache(
Slang::ScopedAllocation cacheData;
SLANG_RETURN_ON_FAIL(Slang::File::readAllBytes(cacheFileName, cacheData));

// The first 8 bytes stores the timestamp of the slang dll that created this stdlib cache.
// The first 8 bytes stores the timestamp of the slang dll that created this core module cache.
if (cacheData.getSizeInBytes() < sizeof(uint64_t))
return SLANG_FAIL;
auto cacheTimestamp = *(uint64_t*)(cacheData.getData());
Expand All @@ -57,22 +57,22 @@ SlangResult tryLoadStdLibFromCache(
return SLANG_OK;
}

SlangResult trySaveStdLibToCache(
SlangResult trySaveCoreModuleToCache(
slang::IGlobalSession* globalSession,
const Slang::String& cacheFilename,
uint64_t dllTimestamp)
{
if (dllTimestamp != 0 && cacheFilename.getLength() != 0)
{
Slang::ComPtr<ISlangBlob> stdLibBlobPtr;
Slang::ComPtr<ISlangBlob> coreModuleBlobPtr;
SLANG_RETURN_ON_FAIL(
globalSession->saveCoreModule(SLANG_ARCHIVE_TYPE_RIFF_LZ4, stdLibBlobPtr.writeRef()));
globalSession->saveCoreModule(SLANG_ARCHIVE_TYPE_RIFF_LZ4, coreModuleBlobPtr.writeRef()));

Slang::FileStream fileStream;
SLANG_RETURN_ON_FAIL(fileStream.init(cacheFilename, Slang::FileMode::Create));

SLANG_RETURN_ON_FAIL(fileStream.write(&dllTimestamp, sizeof(dllTimestamp)));
SLANG_RETURN_ON_FAIL(fileStream.write(stdLibBlobPtr->getBufferPointer(), stdLibBlobPtr->getBufferSize()))
SLANG_RETURN_ON_FAIL(fileStream.write(coreModuleBlobPtr->getBufferPointer(), coreModuleBlobPtr->getBufferSize()))
}

return SLANG_OK;
Expand All @@ -85,37 +85,37 @@ SLANG_API SlangResult slang_createGlobalSession(
Slang::ComPtr<slang::IGlobalSession> globalSession;

#ifdef SLANG_ENABLE_IR_BREAK_ALLOC
// Set inst debug alloc counter to 0 so IRInsts for stdlib always starts from a large value.
// Set inst debug alloc counter to 0 so IRInsts for core module always starts from a large value.
Slang::_debugGetIRAllocCounter() = 0x80000000;
#endif

SLANG_RETURN_ON_FAIL(slang_createGlobalSessionWithoutCoreModule(apiVersion, globalSession.writeRef()));

// If we have the embedded stdlib, load from that, else compile it
ISlangBlob* stdLibBlob = slang_getEmbeddedCoreModule();
if (stdLibBlob)
// If we have the embedded core module, load from that, else compile it
ISlangBlob* coreModuleBlob = slang_getEmbeddedCoreModule();
if (coreModuleBlob)
{
SLANG_RETURN_ON_FAIL(globalSession->loadCoreModule(stdLibBlob->getBufferPointer(), stdLibBlob->getBufferSize()));
SLANG_RETURN_ON_FAIL(globalSession->loadCoreModule(coreModuleBlob->getBufferPointer(), coreModuleBlob->getBufferSize()));
}
else
{
Slang::String cacheFilename;
uint64_t dllTimestamp = 0;
#define SLANG_PROFILE_STDLIB_COMPILE 0
#if SLANG_PROFILE_STDLIB_COMPILE
#define SLANG_PROFILE_CORE_MODULE_COMPILE 0
#if SLANG_PROFILE_CORE_MODULE_COMPILE
auto startTime = std::chrono::high_resolution_clock::now();
#else
if (tryLoadStdLibFromCache(globalSession, cacheFilename, dllTimestamp) != SLANG_OK)
if (tryLoadCoreModuleFromCache(globalSession, cacheFilename, dllTimestamp) != SLANG_OK)
#endif
{
// Compile std lib from embeded source.
SLANG_RETURN_ON_FAIL(globalSession->compileCoreModule(0));
#if SLANG_PROFILE_STDLIB_COMPILE
#if SLANG_PROFILE_CORE_MODULE_COMPILE
auto timeElapsed = std::chrono::high_resolution_clock::now() - startTime;
printf("stdlib compilation time: %.1fms\n", timeElapsed.count() / 1000000.0);
printf("core module compilation time: %.1fms\n", timeElapsed.count() / 1000000.0);
#endif
// Store the compiled stdlib to cache file.
trySaveStdLibToCache(globalSession, cacheFilename, dllTimestamp);
// Store the compiled core module to cache file.
trySaveCoreModuleToCache(globalSession, cacheFilename, dllTimestamp);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class Val : public NodeBase
}
List<ValNodeOperand> m_operands;

// Private use by stdlib deserialization only. Since we know the Vals serialized into stdlib is already
// Private use by the core module deserialization only. Since we know the Vals serialized into the core module is already
// unique, we can just use `this` pointer as the `m_resolvedVal` so we don't need to resolve them again.
void _setUnique();
protected:
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ ASTBuilder::ASTBuilder(SharedASTBuilder* sharedASTBuilder, const String& name):
{
SLANG_ASSERT(sharedASTBuilder);
// Copy Val deduplication map over so we don't create duplicate Vals that are already
// existent in the stdlib.
// existent in the core module.
m_cachedNodes = sharedASTBuilder->getInnerASTBuilder()->m_cachedNodes;
}

Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SharedASTBuilder : public RefObject
Type* m_overloadedType = nullptr;

// The following types are created lazily, such that part of their definition
// can be in the standard library
// can be in the core module.
//
// Note(tfoley): These logically belong to `Type`,
// but order-of-declaration stuff makes that tricky
Expand Down
Loading

0 comments on commit b7a619b

Please sign in to comment.