diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-08-30 15:57:11 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-30 13:57:11 -0700 |
| commit | 3cf5935b434a8b9a07a6df5a6ab4c4dc373a1ac3 (patch) | |
| tree | 7480a6c583b97b8f90797d73b88731a8854bf3c8 /examples | |
| parent | de83628070614ec37349c9f334ed72a54a6889da (diff) | |
capture component type (#4967)
* 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
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/gpu-printing/main.cpp | 38 | ||||
| -rw-r--r-- | examples/hello-world/main.cpp | 10 |
2 files changed, 15 insertions, 33 deletions
diff --git a/examples/gpu-printing/main.cpp b/examples/gpu-printing/main.cpp index aa5beea95..fd15661dd 100644 --- a/examples/gpu-printing/main.cpp +++ b/examples/gpu-printing/main.cpp @@ -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; @@ -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 = {}; @@ -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; @@ -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; } diff --git a/examples/hello-world/main.cpp b/examples/hello-world/main.cpp index 526ab1a2a..87d440901 100644 --- a/examples/hello-world/main.cpp +++ b/examples/hello-world/main.cpp @@ -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); @@ -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; } |
