summaryrefslogtreecommitdiffstats
path: root/examples
Commit message (Collapse)AuthorAge
* Configure the surface with right format (#7710)Gangzheng Tong2025-07-11
|
* Convert gfx unit tests and examples to use slang-rhi (#7577)Gangzheng Tong2025-07-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Port first gfx unit test to slang-rhi * port triangle example to use slang-rhi * port platform-test to slang-rhi * Update platform-test to throttle mouse move events * port gpu-printing example to use slang-rhi * port model-viewer example to use slang-rhi * port ray-tracing example to use slang-rhi * port ray-tracing pipeline example to use slang-rhi * port reflection parameter blocks example to use slang-rhi * port shader-object example to use slang-rhi * port shader-toy example to use slang-rhi * Port most of tests to slang-rhi * port link-time-constant-array-size to use slang-rhi * Fix tests and find matching tests in slang-rhi * port autodiff-texture * remove gfx target; port nv-aftermath-example * update include path for shader-cursor.h * Disabled 2 more ported tests * fix build error * remove gfx test * put slang-rhi (static-lib) before slang (shared) * format code (#7621) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * add debug callback * format code (#7649) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Address review comments; revert back to use SLANG_CHECK_MSG --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Fix a bug in examples/reflection-api (#7652)Theresa Foley2025-07-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug here is subtle enough that it was missed during development of the example, and it it unlikely to be hit by typical applications. All that said, it is good to ensure that this example does things correctly, since we are pointing developers to it as an example of how to correctly extract information using the reflection API. In order to get the bug to surface, one can target Vulkan/SPIR-V using input code like: ``` struct Small { float4 v; Texture2D t; } struct Big { float4 u; ConstantBuffer<Small> smallCB; ParameterBlock<Small> smallPB; } ConstantBuffer<Big> bigCB; ``` Without this change, the example would display an incorrect cumulative offset for `bigCB.smallPB.t`. The incorrectly-computed offset showed that the `binding`s consumed by `bigCB.smallCB` (for both its constant buffer and its `t` field) were being included in the offset computed for the `t` within the parameter block (when the outer parameter block should have caused those offsets to be ignored). The underlying bug in the example is that when recursively printing the cumulative offsets for the "container" and "content" part of a buffer/block, the example was including the buffer/block in the `AccessPath` when printing cumulative offsets for the "content" part, but not for the "container" part. The fix is just to shift the order of things and use the same `AccessPath` when printing both the "container" and "content" parts of a buffer/block. It is difficult to be 100% certain that this change is correct, and that there are no corner cases where the new code gives unexpected/wrong results. I have manually tested the example code by throwing a variety of shader parameter declarations at it, and the new logic seems robust. We are probably at the point where the code of this example probably needs to be turned into a stand-alone tool that we can use as part of our automated testing. That will have to wait for a future change; the goal of this change is to just get the simple bug fixe checked in.
* Add MLP training examples. (#7550)Yong He2025-06-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add MLP training examples. * Formatting fix. * Fix. * Improve documentation on coopvector. * Improve doc. * Update doc. * Fix typo. * Cleanup shader. * Cleanup. * Fix test. * Fix type check recursion. * Fix. * Fix. * Fix override check.
* fix the break to make sure only valid data will be accessed (#7148)Gangzheng Tong2025-05-17
|
* Enable Windows full debug testsuite in CI (#7085)Gangzheng Tong2025-05-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Unify Debug Layer Control Logic and Add Disable Option for Debug Builds This PR refactors and unifies the debug layer control logic in slang-test. A new `-disable-debug-layers` option is introduced, allowing debug builds to skip enabling the validation (debug) layer. This is currently needed to ensure stability in the debug test suite. Previously, different toggles such as ENABLE_VALIDATION_LAYER, ENABLE_DEBUG_LAYER, and debugLayerEnabled were used inconsistently across different components of slang-test. This PR standardizes the logic by using a single variable, debugLayerEnabled, to control the enabling/disabling of the debug layer internally. Notes: By default, the debug/validation layer is enabled in debug builds and is not supported in release builds of slang-test. Fixes: #7132 * Disable spirv-opt for the DebugFunctionDefinition issue * Run debug build only in GCP machines * Fix VUID-vkCmdPipelineBarrier-pBufferMemoryBarriers-02818 dstAcessMask can't include VK_ACCESS_TRANSFER_READ_BIT when stage mask has VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR * Set failed retry limit to 32 --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Remove compiler option no longer needed from the example (#7084)Jay Kwak2025-05-15
|
* Add Payload Access Qualifiers to the raytracing examples (#7092)Gangzheng Tong2025-05-13
|
* Cleanups related to RIFF support (#7041)Theresa Foley2025-05-12
|
* Fix intermittent failure of slang-unit-test-tool/ReplayRecord (#6981)Jay Kwak2025-05-02
| | | | | | | | | | | * Fix intermittent failure of slang-unit-test-tool/ReplayRecord Three problems are addressed: 1. the graphics driver sometimes returns nullptr from GetShaderIdentifier 2. `findRecordFileName()` may not find any records at all. 3. the return value from cleanupRecordFiles() overwrote the error value in `res` and it returned SLANG_OK even when there were errors. * Fix compiler warnings on Windows
* Fix comment typos in the triangle's main.cpp example (#6976)FeuFeve2025-05-01
| | | | | * Fix comment typos in the triangle's main.cpp example * 2nd fix
* expose value of constant integers in module reflection (#6367)Alexandre Bléron2025-02-26
| | | | | | | | | | | | | | | | | | * Expose value of constant integers in module reflection This commit adds `VariableReflection::getDefaultValueInt` to get the value of a variable if it is a compile-time constant integer. TODO: currently it works only if the initializer expression is an integer literal, references to other constant values are not handled. * Update VarDecl folded constant value during DeclBodyVisitor Constant folding for integer values is already done internally by _validateCircularVarDefinition, this just reuses the result. * Address review comments & formatting * Formatting --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Fix native Windows ARM64 build. (#6244)Yong He2025-02-03
| | | | | | | | | * Fix native Windows ARM64 build. * Fix --------- Co-authored-by: Yong He <yongh@outlook.com>
* Add an example for reflection of parameter blocks (#6161)Theresa Foley2025-01-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add an example for reflection of parameter blocks The example loads a shader program, compiles it for Vulkan, and then uses reflection information to set up descriptor set layouts and a pipeline layout. It then validates that the pipeline layout that is created is compatible with the compiled code, by using them together to make a pipeline state object with the validation layer enabled. The basic flow of the application follows the presentation in the companion article, and references its sections. This is example could be expanded in a few ways: * A D3D12 path could be added, to show the comparable operations for creating a root signature from reflection data * The existing shader could be modified to touch/use more of its parameter data, to help ensure that any errors would be caught by the validation layer * The set of shader files/modules that get loaded automatically could be expanded, to test more cases * The code could be expanded to handle more than just compute shaders, by allowing for multiple-entry-point files to be loaded for rasterization or ray-tracing pipelines * format code * fixup: build errors * format code * fixups for build * fixup * fixup --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
* Add backtraces to examples (#5973)Anders Leino2025-01-07
| | | | | | | | | | | | | | | * examples: Log stack trace on exceptions For now, this is only implemented on Windows. This helps to address #5520. * examples: Print log file if there is any * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
* Add example showing how to use Slang/WASM (#5996)Anders Leino2025-01-07
| | | This closes #5656.
* Fix some robustness issues in the examples (#5984)Anders Leino2025-01-07
| | | | | | | | | | | | | | | * examples: Make hello-world example exit gracefully if VK cannot be initialized - Check if VK API function pointers are valid before using them - Return 0 and exit if VK initialization fails - Enable hello-world example * examples: Fixes for ray-tracing examples - Assert that accelleration structure buffer is not nullptr - Check if buffer creation succeeded before proceeding - This makes initialization not hang, but it still fails. Therefore, the test expectations are just updated to point to another issue. - Enable ray-tracing tests on Windows
* Add a basic WebGPU example (#5923)Anders Leino2024-12-30
| | | | | | | * Add a basic WebGPU example This helps to address #5656. * Use serial await rather than Promise.all
* Fix metadata of register space and varying params. (#5906)Yong He2024-12-18
|
* Add slang example tests to CI (#5879)Anders Leino2024-12-18
| | | | | | | | | | | | * Examples: Don't proceed if 'initializeBase' fails * Examples: Only access gWindow if it's been initialized * Examples: Free memory from CommandLineToArgvW * Add example run step to CI Lots of examples are still unexpectedly failing, but is one small step towards addressing issue #5520.
* Add an example for using the reflection API (#5839)Theresa Foley2024-12-12
| | | | | | | | | | | | | | | | | | * Add an example for using the reflection API The example program is meant to accompany a document that goes into more detail about the mental model behind the reflection API and the way this program drives it. Ideally this program can land before the document goes live, and then the document can be published with a link to the example. After that, the example could be updated to include links into the live document. Along with adding the example program, this change also adds some convenience functions to the reflection API to avoid cases where the program would otherwise need to cast between `slang::ParameterCategory` and `SlangParameterCategory`. * format code * fixup: error noticed by clang --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Use perfect forwardnig to preserve the parameters for log (#5841)Jay Kwak2024-12-11
| | | Avoid mixing the variadic template argument and pass-through it with std::forward
* Fix unused struct in sample shader (#5650)Yuki Nishidate2024-11-23
|
* Correct include dir for libslang (#5539)Ellie Hermaszewska2024-11-13
| | | | | | | | This stops adding the repo root to the include path for anything linking with slang. This enabled a bunch of convenient includes, but might lead to confusing behavior for anyone including slang. Not to mention differences including it from an install vs source. Co-authored-by: Yong He <yonghe@outlook.com>
* Move switch statement bodies to their own lines (#5493)Ellie Hermaszewska2024-11-05
| | | | | | | | | * Move switch statement bodies to their own lines * format --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Improve on spirv generation compile option (#5479)kaizhangNV2024-11-01
| | | | | | | | | | | | | | | | | | | CompilerOptionName::EmitSpirvViaGLSL and CompilerOptionName::EmitSpirvDirectly options are not mutually exclusive, but due to compatible reason, we cannot delete those options. Instead, this change makes the effort to create a new option name EmitSpirvMethod, and we will turn those two options into the new one internally. Also, we put a priority implicitly on those two options, where EmitSpirvDirectly always win if it's set. We have another location that can setup the same option, where is through SlangTargetFlags::SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY. We should definitely deprecate this flag to avoid more confusing. But for the same compatible reason, we cannot do that in this PR. Again, we will encourage people to not use this flag, but using the CompilerOptionName instead. In this PR, we will also implicitly give CompilerOptionName higher priority, it means that as long as user setup the CompilerOptionName for emit spirv method, it always take higher priority for the final decision.
* formatEllie Hermaszewska2024-10-29
| | | | | | | * format * Minor test fixes * enable checking cpp format in ci
* preparation for clang format (#5422)Ellie Hermaszewska2024-10-29
| | | | | | | | | | | | | | | | | | | | | | | * Clang-format excludes * Add .clang-format * Don't clang-format in external * Missing includes and forward declarations * Replace wonky include-once macro name * neaten include naming * Add clang-format to formatting script * Add xargs and diff to required binaries * add clang-format to ci formatting check * Add max version check to formatting script * temporarily disable checking formatting for cpp files
* declutter top level CMakeLists.txt (#5391)Ellie Hermaszewska2024-10-24
| | | | | | | | | | | | | | | | | | | | | * Split examples cmake desc * declutter top level CMakeLists.txt * fail if building tests without gfx * Move llvm fetching to another cmake file * Further split CMakeLists.txt * Neaten llvm fetching * Remove last premake remnant * correct cross builds * Neaten * Neaten project organization in vs
* Move C interface from slang.h to slang-deprecated.h (#5301)Ellie Hermaszewska2024-10-15
| | | | | | | | | | | | | | | | | | | | | | | | | * Squash redundant move warnings * Move C interface from slang.h to slang-deprecated.h spGetBuildTagString remains, because it's useful to have before the global session exists. This C API is used quite pervasively in the C++ helpers (for example slang::UserAttribute. It's not trivial to move these to slang-deprecated.h as they're entangled with some enums which are themselves used elsewhere in the compiler. The fact that these helpers use the C API can be viewed as an implementation detail for now, and this usage moved to slang-deprecated in due course. Closes https://github.com/shader-slang/slang/issues/4758 * Squash warnings for our usage of our deprecated API --------- Co-authored-by: Yong He <yonghe@outlook.com>
* capture component type (#4967)kaizhangNV2024-08-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* Migrate 3 more examples to slang-unit-test (#4927)kaizhangNV2024-08-28
| | | | | | | | | * Convert 'ray-tracing-pipeline' example into slang-test * Convert model-view and 'autodiff-texture' examples to slang-test * Add more error message in RecordReplay test * Fix a shader issue in autodiff-texture
* Migrate examples (#4920)kaizhangNV2024-08-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * Migrate cpu-hello-world to new slang API Migrate cpu-hello-world to new slang API, and also convert this example as one of the unit test. * Add 'shader-object' to slang-unit-test * Convert ray-tracing example into unit-test Convert ray-tracing example into unit-test * Fix some replay bugs: - Wrong decode type in 'getEntryPointHostCallable'. - Mistakes in computing the output buffer size. - Wrong decode type in array size in specialize() call. - When capture entrypoint, we should increase the reference count for the allocated entrypoint recorder object, because that is allocated by record layer, it should be owned by the layer, user should not be able to free it. - Improve json consumer on the prelude text. * Test verify change: In our test, we add a "callIdx" string at beginning of the hash-code string, as there could be more than one modules in the example, so they could call 'getEntryPointHash' multiple times, in order for the test can identify them, add "callIdx: <number>" as the key word.
* Feature/record unit test (#4910)kaizhangNV2024-08-26
| | | | | | | | | | | | | | | | | | | | | | | | * Fix the slang-test bug Since we reorganize the build directory, now the libraries are located at different directory with executables in non-Windows platform, we have to change the code on how to find the dll directory. * Integrate the record/replay test into slang-unit-test We create a unit-test-record-replay.cpp to run the converted slang examples in child process as our tests for the record-replay layer. * Disable the test on Apple Due to the limitation of current examples, we temporarily disable them on apples. Change the ci to make this test only be run on the gpu-equipped runners, for other runners we add a white-list file "expected-failure-record-replay-tests.txt". * Remove 'hello-world' example from unit test "hello-world" doesn't use gfx abstract library, instead it uses vk directly, it's not a preferable way. So we will drop this test, instead, we will use cpu-hello-world example.
* Feature/capture unit test (#4898)kaizhangNV2024-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * record/replay: Add tests Modify the hello-world example to generate the hash code for the entry point spirv code, so that we can compare it with replaying the example. Add the test script to run the example and compare the hash code with replaying it. * Check nullptr for out Diagnostics We need to check whether the output Diagnostics is a nullptr, because it's allowed. * Fix the double free pointers * Add triangle example as the new test for record-replay Change the example base to add the offline rendering path because we don't want to display anything when we're in the test mode. This change involves introducing a TestBase that will parse the command line option. It will decide whether we are in the test mode. Disable all the swapchain and windows related creation, instead we will only create one single framebuffer for the render target. * Address comments TODO: In the follow up patches, I will add more tests and integrate the test flow into slang-unit-test.
* Move the file public header files to `include` dir (#4636)kaizhangNV2024-07-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Move the file public header files to `include` dir Close the issue (#4635). Move the following headers files to a `include` dir located at root dir of slang repo: slang-com-helper.h -> include/slang-com-helper.h slang-com-ptr.h -> include/slang-com-ptr.h slang-gfx.h -> include/slang-gfx.h slang.h -> include/slang.h Change cmake/SlangTarget.cmake to add include path to every target, and change the source file to use "#include <slang.h>" to include the public headers. The source code update is by the script like follow: ``` fileNames_slang=$(grep -r "\".*slang\.h\"" source/ -l) for fileName in "${fileNames_slang[@]}" do echo "$fileName" sed -i "s/\".*slang\.h\"/\"slang\.h\"/" $fileName done ``` * Fix the test issues * Fix cpu test issues by adding include seach path * Update cmake to not add include path for every target Also change "#include <slang.h>" to "include "slang.h" " to make the coding style consistent with other slang code. * Change public include to private include for unit-test and slang-glslang
* Resource searching for examples (#4518)venkataram-nv2024-07-01
|
* Improve documentation and example formatting consistency (#4299)Matthew Moulton2024-06-07
| | | | | | * Improve doc and example consistency Improve consistency of formatting in example shaders and remove trailing spaces in documentation files. Fix minor typos.
* Fixed profile string per request in pr#4268 (#4297)Hai Nguyen2024-06-06
| | | | Changed profile string from glsl_440 to spirv_1_5 per request in pr#4268.
* Fixes incorrect profile string (#4268)Hai Nguyen2024-06-04
| | | | | | | This CL fixes a typo in the profile string for the hello-world example. Currently "glsl440" is passed into findProfile() resulting in a return value of SLANG_UNKNOWN_PROFILE since format of the profile name is incorrect. The correct profile name is glsl_440, therefore the string passed into findProfile() should be "glsl_440".
* [gfx] specify resource view buffer range in bytes (#4149)skallweitNV2024-05-13
| | | | | | | | | | | | | * refactor gfx buffer range to use byte range * create buffer view with zero struct stride for ClearUnorderedAccessViewUint/Float * create buffer descriptors on demand * avoid copying gfx.dll --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Add slangc interface to compile and use ir modules. (#3615)Yong He2024-02-23
| | | | | | | | | * Add slangc interface to compile and use ir modules. * Fix glsl scalar layout settings not copied to target. * Fix. * Cleanups.
* macos/vulkan support (#3418)skallweitNV2023-12-18
|
* Support visibility control and default to `internal`. (#3380)Yong He2023-12-06
| | | | | | | | | | | | | | | | | | | * Support visibility control and default to `internal`. * Fix wip. * Fixes. * Fix. * Fix test. * Add legacy language detection and compatibility for existing code. * Add doc. --------- Co-authored-by: Yong He <yhe@nvidia.com>
* Update autodiff-texture example with one that auto-diffs a reference impl. ↵Sai Praveen Bangaru2023-10-25
| | | | (#3288)
* Use direct spirv in hello-world example. (#3207)Yong He2023-09-18
| | | | | | | | | | | | | | | * Use direct spirv in hello-world example. * Use vulkan 1.1 * Use vulkan 1.2. * fix. * Fix test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
* nsight Aftermath crash example (#2984)jsmall-nvidia2023-07-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Small fixes and improvements around reflection tool. * Make PrettyWriter printing a class. * Aftermath crash demo WIP. * Enable aftermath in test project. * Setting failCount. * Dumping out of source maps. * Improve comments. Simplify handling of compile products. * Other small fixes to aftermath example. * Added Emit SourceLocType. Track sourcemap association meaning. Improved documentation. * Small improvements. * Capture debug information for D3D11/D3D12/Vulkan. * Enable debug info. * Small improvements. * Improve aftermath example README.md.
* Some small fixes with Windows/DX usage (#2797)Ellie Hermaszewska2023-04-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Correct case of windows.h includes * Use Slang::SharedLibrary to load directx dlls * s/max/std::max/ * Factor common OS code in calcHasApi * Add DXIL test for compute/simple * s/false/FALSE for calls to WinAPI functions * Factor common OS code in gfxGetAdapters * 2 missing headers d3d12sdklayers for ID3DDebug climits for UINT_MAX * Define out unused function on Linux * Only try to load Vulkan and CUDA on Windows or Linux * simplify D3DUtil::getDxgiModule * Remove WIN32_LEAN_AND_MEAN &co from source files Add a global define * Set WIN32_LEAN_AND_MEAN &friends in headers Restore previous state also * regenerate vs projects
* Add texture tri-linear autodiff example. (#2715)Yong He2023-03-21
| | | | | | | | | | | | | | | | | | | | | * Add quad texture example. * delete output image * remove irrelavent files * update project files * fix * Update example. * Fix. * remove out-texture --------- Co-authored-by: Yong He <yhe@nvidia.com>
* Add ASAN support + fixes (#2614)skallweitNV2023-01-27
| | | | | | | | | | | | | | | | | * Add ASAN support to premake * Fix StringRepresentation when ASAN is enabled * Fix deep recursion in slang-generate * Fix hello-world example * Fix gpu-printing example * Linux fix * Try fixing linux * Add missing include