Skip to content

Commit

Permalink
capture component type (shader-slang#4967)
Browse files Browse the repository at this point in the history
* Refactor the IComponentType recording

Refactor the `IComponentType` recording by creating a abstract class
`IComponentTypeRecorder` to record all the methods of `IComponentType`,
so that `ICompositeComponentType`, `IModule`, 'IEntryPoint',
'ITypeConformance' can share the same recording implementation.

Capture the out IComponentType from
linkWithOptions()
link()
specialize()
renameEntryPoint()

* fix bugs

* Finish the unimeplemented functions in json consumer

Fix the address print to use 64 bit hex.
Fix the reference count issue when allocating new recorder object.

* Disable few examples using reflection APIs

* Add gpu-printing example into slang-test

* Replace of using std::unique_ptr with RefPtr
  • Loading branch information
kaizhangNV authored Aug 30, 2024
1 parent de83628 commit 3cf5935
Show file tree
Hide file tree
Showing 27 changed files with 1,141 additions and 1,488 deletions.
38 changes: 15 additions & 23 deletions examples/gpu-printing/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,16 @@ ComPtr<slang::ISession> createSlangSession(gfx::IDevice* device)

ComPtr<slang::IModule> compileShaderModuleFromFile(slang::ISession* slangSession, char const* filePath)
{
SlangCompileRequest* slangRequest = nullptr;
slangSession->createCompileRequest(&slangRequest);

int translationUnitIndex = spAddTranslationUnit(slangRequest, SLANG_SOURCE_LANGUAGE_SLANG, filePath);
spAddTranslationUnitSourceFile(slangRequest, translationUnitIndex, filePath);

const SlangResult compileRes = spCompile(slangRequest);
if(auto diagnostics = spGetDiagnosticOutput(slangRequest))
{
printf("%s", diagnostics);
}

if(SLANG_FAILED(compileRes))
{
spDestroyCompileRequest(slangRequest);
return ComPtr<slang::IModule>();
}

ComPtr<slang::IModule> slangModule;
spCompileRequest_getModule(slangRequest, translationUnitIndex, slangModule.writeRef());
ComPtr<slang::IBlob> diagnosticBlob;
Slang::String path = resourceBase.resolveResource(filePath);
slangModule = slangSession->loadModule(path.getBuffer(), diagnosticBlob.writeRef());
diagnoseIfNeeded(diagnosticBlob);

return slangModule;
}

struct ExampleProgram
struct ExampleProgram: public TestBase
{
int gWindowWidth = 640;
int gWindowHeight = 480;
Expand All @@ -73,6 +59,11 @@ ComPtr<gfx::IShaderProgram> loadComputeProgram(slang::IModule* slangModule, char
ComPtr<slang::IComponentType> linkedProgram;
entryPoint->link(linkedProgram.writeRef());

if (isTestMode())
{
printEntrypointHashes(1, 1, linkedProgram);
}

gGPUPrinting.loadStrings(linkedProgram->getLayout());

gfx::IShaderProgram::Desc programDesc = {};
Expand All @@ -83,8 +74,9 @@ ComPtr<gfx::IShaderProgram> loadComputeProgram(slang::IModule* slangModule, char
return shaderProgram;
}

Result execute()
Result execute(int argc, char* argv[])
{
parseOption(argc, argv);
IDevice::Desc deviceDesc;
Result res = gfxCreateDevice(&deviceDesc, gDevice.writeRef());
if(SLANG_FAILED(res)) return res;
Expand Down Expand Up @@ -151,10 +143,10 @@ Result execute()

};

int main()
int main(int argc, char* argv[])
{
ExampleProgram app;
if (SLANG_FAILED(app.execute()))
if (SLANG_FAILED(app.execute(argc, argv)))
{
return -1;
}
Expand Down
10 changes: 0 additions & 10 deletions examples/hello-world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct HelloWorldExample : public TestBase

int main(int argc, char* argv[])
{
fprintf(stdout, "Hello, world! Entry Point\n");
initDebugCallback();
HelloWorldExample example;
example.parseOption(argc, argv);
Expand All @@ -84,19 +83,10 @@ int main(int argc, char* argv[])
int HelloWorldExample::run()
{
RETURN_ON_FAIL(initVulkanInstanceAndDevice());
fprintf(stdout, "initVulkanInstanceAndDevice done\n");

RETURN_ON_FAIL(createComputePipelineFromShader());
fprintf(stdout, "createComputePipelineFromShader done\n");

RETURN_ON_FAIL(createInOutBuffers());
fprintf(stdout, "createInOutBuffers done\n");

RETURN_ON_FAIL(dispatchCompute());
fprintf(stdout, "dispatchCompute done\n");

RETURN_ON_FAIL(printComputeResults());
fprintf(stdout, "printComputeResults done\n");
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion source/slang-record-replay/record/output-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace SlangRecord
{
class OutputStream
class OutputStream: public Slang::RefObject
{
public:
virtual ~OutputStream() {}
Expand Down
2 changes: 1 addition & 1 deletion source/slang-record-replay/record/record-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace SlangRecord
}

Slang::String recordFilePath = Slang::Path::combine(m_recordFileDirectory, Slang::String(ss.str().c_str()));
m_fileStream = std::make_unique<FileOutputStream>(recordFilePath);
m_fileStream = new FileOutputStream(recordFilePath);
}

void RecordManager::clearWithHeader(const ApiCallId& callId, uint64_t handleId)
Expand Down
4 changes: 2 additions & 2 deletions source/slang-record-replay/record/record-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace SlangRecord
{
class RecordManager
class RecordManager: public Slang::RefObject
{
public:
RecordManager(uint64_t globalSessionHandle);
Expand All @@ -29,7 +29,7 @@ namespace SlangRecord
void clearWithTailer();

MemoryStream m_memoryStream;
std::unique_ptr<FileOutputStream> m_fileStream;
Slang::RefPtr<FileOutputStream> m_fileStream;
Slang::String m_recordFileDirectory = Slang::Path::getCurrentPath();
ParameterRecorder m_recorder;
};
Expand Down
Loading

0 comments on commit 3cf5935

Please sign in to comment.