Skip to content

Commit 336254b

Browse files
authored
Merge branch 'master' into feature/make-witness-table-hoistable
2 parents 7f0ad0d + 2631811 commit 336254b

20 files changed

+437
-44
lines changed

.github/workflows/dockerfiles/ubuntu-18.04-x64/Dockerfile

-15
This file was deleted.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*.zip
1313
*.ini
1414
*.DS_store
15+
.direnv
16+
.envrc
1517
.gdb_history
1618
.vimspector
1719
.vimspector.json

docs/building.md

+14
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,20 @@ cmake --preset vs2022 --fresh -A arm64 -DSLANG_GENERATORS_PATH=generators/bin
311311
cmake --build --preset release
312312
```
313313

314+
### Nix
315+
316+
This repository contains a [Nix](https://nixos.org/)
317+
[flake](https://wiki.nixos.org/wiki/Flakes) (not officially supported or
318+
tested), which provides the necessary prerequisites for local development. Also,
319+
if you use [direnv](https://direnv.net/), you can run the following commands to
320+
have the Nix environment automatically activate when you enter your clone of
321+
this repository:
322+
323+
```bash
324+
echo 'use flake' >> .envrc
325+
direnv allow
326+
```
327+
314328
## Building with an older CMake
315329

316330
Because older CMake versions don't support all the features we want to use in

flake.lock

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
description = "The Slang Shading Language and Compiler";
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
};
7+
outputs =
8+
{
9+
self,
10+
nixpkgs,
11+
flake-utils,
12+
}:
13+
flake-utils.lib.eachDefaultSystem (
14+
system:
15+
let
16+
pkgs = import nixpkgs { inherit system; };
17+
in
18+
{
19+
devShell =
20+
with pkgs;
21+
mkShell {
22+
buildInputs = [
23+
cmake
24+
llvm
25+
ninja
26+
nixfmt-rfc-style
27+
python3
28+
xorg.libX11
29+
];
30+
};
31+
}
32+
);
33+
}

include/slang-deprecated.h

+2
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ extern "C"
681681
SLANG_API size_t spReflectionVariableLayout_GetSpace(
682682
SlangReflectionVariableLayout* var,
683683
SlangParameterCategory category);
684+
SLANG_API SlangImageFormat
685+
spReflectionVariableLayout_GetImageFormat(SlangReflectionVariableLayout* var);
684686

685687
SLANG_API char const* spReflectionVariableLayout_GetSemanticName(
686688
SlangReflectionVariableLayout* var);

include/slang.h

+11
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ typedef uint32_t SlangSizeT;
10151015
SaveGLSLModuleBinSource,
10161016

10171017
SkipDownstreamLinking, // bool, experimental
1018+
DumpModule,
10181019
CountOf,
10191020
};
10201021

@@ -2921,6 +2922,11 @@ struct VariableLayoutReflection
29212922
(SlangParameterCategory)category);
29222923
}
29232924

2925+
SlangImageFormat getImageFormat()
2926+
{
2927+
return spReflectionVariableLayout_GetImageFormat((SlangReflectionVariableLayout*)this);
2928+
}
2929+
29242930
char const* getSemanticName()
29252931
{
29262932
return spReflectionVariableLayout_GetSemanticName((SlangReflectionVariableLayout*)this);
@@ -4417,6 +4423,11 @@ struct IModule : public IComponentType
44174423
virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath(SlangInt32 index) = 0;
44184424

44194425
virtual SLANG_NO_THROW DeclReflection* SLANG_MCALL getModuleReflection() = 0;
4426+
4427+
/** Disassemble a module.
4428+
*/
4429+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
4430+
disassemble(slang::IBlob** outDisassembledBlob) = 0;
44204431
};
44214432

44224433
#define SLANG_UUID_IModule IModule::getTypeGuid()

source/slang-record-replay/record/slang-module.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,12 @@ IEntryPointRecorder* ModuleRecorder::getEntryPointRecorder(slang::IEntryPoint* e
244244
return result.detach();
245245
}
246246
}
247+
248+
SlangResult ModuleRecorder::disassemble(ISlangBlob** outBlob)
249+
{
250+
// No need to record this call as it is just a query.
251+
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
252+
auto res = m_actualModule->disassemble(outBlob);
253+
return res;
254+
}
247255
} // namespace SlangRecord

source/slang-record-replay/record/slang-module.h

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class ModuleRecorder : public IModuleRecorder, public IComponentTypeRecorder
5656
ISlangBlob** outDiagnostics) override;
5757
virtual SLANG_NO_THROW SlangInt32 SLANG_MCALL getDependencyFileCount() override;
5858
virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath(SlangInt32 index) override;
59+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
60+
disassemble(slang::IBlob** outDisassembly) override;
5961

6062
// Interfaces for `IComponentType`
6163
virtual SLANG_NO_THROW slang::ISession* SLANG_MCALL getSession() override

source/slang/slang-compiler.h

+12
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,18 @@ class Module : public ComponentType, public slang::IModule
18321832

18331833
// Source files that have been pulled into the module with `__include`.
18341834
Dictionary<SourceFile*, FileDecl*> m_mapSourceFileToFileDecl;
1835+
1836+
public:
1837+
SLANG_NO_THROW SlangResult SLANG_MCALL disassemble(slang::IBlob** outDisassembledBlob) override
1838+
{
1839+
if (!outDisassembledBlob)
1840+
return SLANG_E_INVALID_ARG;
1841+
String disassembly;
1842+
this->getIRModule()->getModuleInst()->dump(disassembly);
1843+
auto blob = StringUtil::createStringBlob(disassembly);
1844+
*outDisassembledBlob = blob.detach();
1845+
return SLANG_OK;
1846+
}
18351847
};
18361848
typedef Module LoadedModule;
18371849

source/slang/slang-ir.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -9001,24 +9001,33 @@ void IRInst::addBlock(IRBlock* block)
90019001
block->insertAtEnd(this);
90029002
}
90039003

9004-
void IRInst::dump()
9004+
void IRInst::dump(String& outStr)
90059005
{
9006+
StringBuilder sb;
9007+
90069008
if (auto intLit = as<IRIntLit>(this))
90079009
{
9008-
std::cout << intLit->getValue() << std::endl;
9010+
sb << intLit->getValue();
90099011
}
90109012
else if (auto stringLit = as<IRStringLit>(this))
90119013
{
9012-
std::cout << stringLit->getStringSlice().begin() << std::endl;
9014+
sb << stringLit->getStringSlice();
90139015
}
90149016
else
90159017
{
9016-
StringBuilder sb;
90179018
IRDumpOptions options;
90189019
StringWriter writer(&sb, Slang::WriterFlag::AutoFlush);
90199020
dumpIR(this, options, nullptr, &writer);
9020-
std::cout << sb.toString().begin() << std::endl;
90219021
}
9022+
9023+
outStr = sb.toString();
9024+
}
9025+
9026+
void IRInst::dump()
9027+
{
9028+
String s;
9029+
dump(s);
9030+
std::cout << s.begin() << std::endl;
90229031
}
90239032
} // namespace Slang
90249033

source/slang/slang-ir.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,14 @@ struct IRInst
814814
///
815815
void _insertAt(IRInst* inPrev, IRInst* inNext, IRInst* inParent);
816816

817-
/// Print the IR to stdout for debugging purposes
817+
/// Print the IR to stdout for debugging purposes.
818818
///
819819
void dump();
820820

821+
/// Print the IR to a string for debugging purposes.
822+
///
823+
void dump(String& outStr);
824+
821825
/// Insert a basic block at the end of this func/code containing inst.
822826
void addBlock(IRBlock* block);
823827

source/slang/slang-options.cpp

+84-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ void initCommandOptions(CommandOptions& options)
802802
{OptionKind::VerifyDebugSerialIr,
803803
"-verify-debug-serial-ir",
804804
nullptr,
805-
"Verify IR in the front-end."}};
805+
"Verify IR in the front-end."},
806+
{OptionKind::DumpModule, "-dump-module", nullptr, "Disassemble and print the module IR."}};
806807
_addOptions(makeConstArrayView(debuggingOpts), options);
807808

808809
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Experimental !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
@@ -2947,6 +2948,88 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv)
29472948
Int index = 0;
29482949
SLANG_RETURN_ON_FAIL(_expectInt(arg, index));
29492950
linkage->m_optionSet.add(OptionKind::BindlessSpaceIndex, (int)index);
2951+
break;
2952+
}
2953+
case OptionKind::DumpModule:
2954+
{
2955+
CommandLineArg fileName;
2956+
SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName));
2957+
auto desc = slang::SessionDesc();
2958+
ComPtr<slang::ISession> session;
2959+
m_session->createSession(desc, session.writeRef());
2960+
ComPtr<slang::IBlob> diagnostics;
2961+
2962+
// Coerce Slang to load from the given file, without letting it automatically
2963+
// choose .slang-module files over .slang files.
2964+
// First try to load as source string, and fall back to loading as an IR Blob.
2965+
// Avoid guessing based on filename or inspecting the file contents.
2966+
FileStream file;
2967+
if (SLANG_FAILED(file.init(
2968+
fileName.value,
2969+
FileMode::Open,
2970+
FileAccess::Read,
2971+
FileShare::None)))
2972+
{
2973+
m_sink->diagnose(arg.loc, Diagnostics::cannotOpenFile, fileName.value);
2974+
return SLANG_FAIL;
2975+
}
2976+
2977+
List<uint8_t> buffer;
2978+
file.seek(SeekOrigin::End, 0);
2979+
const Int64 size = file.getPosition();
2980+
buffer.setCount(size + 1);
2981+
file.seek(SeekOrigin::Start, 0);
2982+
SLANG_RETURN_ON_FAIL(file.readExactly(buffer.getBuffer(), (size_t)size));
2983+
buffer[size] = 0;
2984+
file.close();
2985+
2986+
ComPtr<slang::IModule> module;
2987+
module = session->loadModuleFromSourceString(
2988+
"module",
2989+
"path",
2990+
(const char*)buffer.getBuffer(),
2991+
diagnostics.writeRef());
2992+
if (!module)
2993+
{
2994+
// Load buffer as an IR blob
2995+
ComPtr<slang::IBlob> blob;
2996+
blob = RawBlob::create(buffer.getBuffer(), size);
2997+
2998+
module = session->loadModuleFromIRBlob(
2999+
"module",
3000+
"path",
3001+
blob,
3002+
diagnostics.writeRef());
3003+
}
3004+
3005+
if (module)
3006+
{
3007+
ComPtr<slang::IBlob> disassemblyBlob;
3008+
if (SLANG_FAILED(module->disassemble(disassemblyBlob.writeRef())))
3009+
{
3010+
m_sink->diagnose(arg.loc, Diagnostics::cannotDisassemble, fileName.value);
3011+
return SLANG_FAIL;
3012+
}
3013+
else
3014+
{
3015+
// success, print out the disassembly in a way that slang-test can read
3016+
m_sink->diagnoseRaw(
3017+
Severity::Note,
3018+
(const char*)disassemblyBlob->getBufferPointer());
3019+
}
3020+
}
3021+
else
3022+
{
3023+
if (diagnostics)
3024+
{
3025+
m_sink->diagnoseRaw(
3026+
Severity::Error,
3027+
(const char*)diagnostics->getBufferPointer());
3028+
}
3029+
return SLANG_FAIL;
3030+
}
3031+
3032+
29503033
break;
29513034
}
29523035
default:

0 commit comments

Comments
 (0)