diff options
| author | yum <yum.food.vr@gmail.com> | 2025-10-11 17:47:54 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-10-11 17:47:54 -0700 |
| commit | e11e40dde87bb67f404c3681f6266af32449feca (patch) | |
| tree | 7c13104f0896a3389a61d80fd0beb591b1c34494 | |
| parent | 56bae6342544974194468661e0827f425e2a79bb (diff) | |
more stuff
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | build.ps1 | 2 | ||||
| -rw-r--r-- | example.slang | 70 | ||||
| -rw-r--r-- | main.cc | 2 | ||||
| -rw-r--r-- | slang.patch | 85 |
5 files changed, 165 insertions, 9 deletions
@@ -14,19 +14,20 @@ build instructions ```bash git clone https://github.com/shader-slang/slang +cd slang +git checkout 1a193d6e5cdcdab05aa291d725c3b1c1260b8762 +patch -p1 <../slang.patch git submodule update --init --recursive -j 32 # wait, the previous command takes a while -mkdir slang/build -cd slang/build +mkdir build +cd build # run this part in powershell, from ./slang/build cmake.exe .. -cmake.exe --build . -j +cmake.exe --build . -j 32 --config Release # the previous command will take a long fucking time # switch back to top level of repo cd ../.. -# do this in wsl2 or powershell. Showing wsl2/bash syntax -# you'd do this for each incremental build. -powershell.exe ./build.ps1 && ./build/bin/Release/modular_slange.exe ./test.slang +# do this in wsl2 or powershell. Showing wsl2/bash syntax. +powershell.exe ./build.ps1 && ./dist/modular_slang.exe ./demo.slang ``` - @@ -5,7 +5,7 @@ mkdir ./build cmake -S . -B build -G "Visual Studio 17 2022" -A x64 if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } -cmake --build build --config Release +cmake --build build --config Release -j 32 if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # Package up into ./dist dir diff --git a/example.slang b/example.slang new file mode 100644 index 0000000..b87e1bb --- /dev/null +++ b/example.slang @@ -0,0 +1,70 @@ +#ifndef __EXAMPLE_INC +#define __EXAMPLE_INC + +float3x3 inverse(float3x3 m) { + float det = + m._11 * (m._22 * m._33 - m._23 * m._32) - + m._12 * (m._21 * m._33 - m._23 * m._31) + + m._13 * (m._21 * m._32 - m._22 * m._31); + + if (abs(det) < 1e-6) { + return float3x3( + 1,0,0, + 0,1,0, + 0,0,1); + } + + float invDet = 1.0f / det; + float3x3 inv; + + inv._11 = (m._22 * m._33 - m._23 * m._32) * invDet; + inv._12 = (m._13 * m._32 - m._12 * m._33) * invDet; + inv._13 = (m._12 * m._23 - m._13 * m._22) * invDet; + inv._21 = (m._23 * m._31 - m._21 * m._33) * invDet; + inv._22 = (m._11 * m._33 - m._13 * m._31) * invDet; + inv._23 = (m._13 * m._21 - m._11 * m._23) * invDet; + inv._31 = (m._21 * m._32 - m._22 * m._31) * invDet; + inv._32 = (m._31 * m._12 - m._11 * m._32) * invDet; + inv._33 = (m._11 * m._22 - m._12 * m._21) * invDet; + + return inv; +} + +#define PI 3.14159265f + +[Differentiable] +public float3 ex_deform(float3 xyz, no_diff float A, no_diff float k, no_diff float t) { + float x = xyz.x; + float y = xyz.y; + float z = xyz.z; + return float3( + x + sin(y * k) * 0.1, + y + sin(x * k * 4) * 0.5, + (z + sin(x * y * k * PI + t) * A) * (1.0 + sin(y * k) * sin(x * k)) + ); +} + +// Deform a normal vector using the inverse transpose of the jacobian. +public void ex_deform_normal(float3 xyz, inout float3 normal, inout float3 tangent, float A, float k, float t) { + // Compute jacobian using autodiff applied to basis vectors. + DifferentialPair<float3> dp_x = diffPair(xyz, float3(1, 0, 0)); + DifferentialPair<float3> dp_y = diffPair(xyz, float3(0, 1, 0)); + DifferentialPair<float3> dp_z = diffPair(xyz, float3(0, 0, 1)); + + DifferentialPair<float3> dp_x_out = fwd_diff(ex_deform)(dp_x, A, k, t); + DifferentialPair<float3> dp_y_out = fwd_diff(ex_deform)(dp_y, A, k, t); + DifferentialPair<float3> dp_z_out = fwd_diff(ex_deform)(dp_z, A, k, t); + + // Transform normal and tangent using jacobian + float3x3 jacobian = float3x3( + float3(dp_x_out.d.x, dp_y_out.d.x, dp_z_out.d.x), + float3(dp_x_out.d.y, dp_y_out.d.y, dp_z_out.d.y), + float3(dp_x_out.d.z, dp_y_out.d.z, dp_z_out.d.z) + ); + float3x3 itjac = inverse(transpose(jacobian)); + normal = normalize(mul(itjac, normal)); + tangent = normalize(mul(jacobian, tangent)); +} + +#endif // __EXAMPLE_INC + @@ -317,7 +317,7 @@ std::vector<CompilerOptionEntry> makeCommonOptions() { addCompilerOption(options, CompilerOptionName::NoHLSLBinding); addCompilerOption(options, CompilerOptionName::NoMangle); addCompilerOption(options, CompilerOptionName::NoHLSLPackConstantBufferElements); - addCompilerOption(options, CompilerOptionName::NoEntryPointUniformParamTransform); + addCompilerOption(options, CompilerOptionName::PlainFunctionEntryPoints); return options; } diff --git a/slang.patch b/slang.patch new file mode 100644 index 0000000..db40383 --- /dev/null +++ b/slang.patch @@ -0,0 +1,85 @@ +commit 0f5a49961975089977de7207c063cc58df04028e +Author: yum <yum.food.vr@gmail.com> +Date: Sat Oct 11 13:34:03 2025 -0700 + + Optionally disable entry point param cbuffer transform + +diff --git a/include/slang.h b/include/slang.h +index a3ed2112a..abb1c967e 100644 +--- a/include/slang.h ++++ b/include/slang.h +@@ -1004,6 +1004,7 @@ typedef uint32_t SlangSizeT; + NoMangle, + NoHLSLBinding, + NoHLSLPackConstantBufferElements, ++ PlainFunctionEntryPoints, + ValidateUniformity, + AllowGLSL, + EnableExperimentalPasses, +diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp +index a5d634ebf..bd12335da 100644 +--- a/source/slang/slang-emit-hlsl.cpp ++++ b/source/slang/slang-emit-hlsl.cpp +@@ -442,6 +442,11 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl( + { + if (profile.getVersion() >= ProfileVersion::DX_6_1) + { ++ if (m_codeGenContext->getTargetProgram()->getOptionSet().getBoolOption( ++ CompilerOptionName::PlainFunctionEntryPoints)) ++ { ++ return; ++ } + char const* stageName = getStageName(stage); + if (stageName) + { +diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp +index 1bd1f8b5c..0a64199ed 100644 +--- a/source/slang/slang-emit.cpp ++++ b/source/slang/slang-emit.cpp +@@ -829,6 +829,7 @@ Result linkAndOptimizeIR( + // TODO: We should skip this step for CUDA targets. + // (NM): we actually do need to do this step for OptiX based CUDA targets + // ++ if (!targetProgram->getOptionSet().getBoolOption(CompilerOptionName::PlainFunctionEntryPoints)) + { + CollectEntryPointUniformParamsOptions passOptions; + passOptions.targetReq = targetRequest; +@@ -861,10 +862,13 @@ Result linkAndOptimizeIR( + switch (target) + { + default: +- moveEntryPointUniformParamsToGlobalScope(irModule); ++ if (!targetProgram->getOptionSet().getBoolOption(CompilerOptionName::PlainFunctionEntryPoints)) ++ { ++ moveEntryPointUniformParamsToGlobalScope(irModule); + #if 0 +- dumpIRIfEnabled(codeGenContext, irModule, "ENTRY POINT UNIFORMS MOVED"); ++ dumpIRIfEnabled(codeGenContext, irModule, "ENTRY POINT UNIFORMS MOVED"); + #endif ++ } + validateIRModuleIfEnabled(codeGenContext, irModule); + break; + case CodeGenTarget::HostCPPSource: +diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp +index fa185d54a..8320e4512 100644 +--- a/source/slang/slang-options.cpp ++++ b/source/slang/slang-options.cpp +@@ -934,6 +934,10 @@ void initCommandOptions(CommandOptions& options) + "-embed-downstream-ir", + nullptr, + "Embed downstream IR into emitted slang IR"}, ++ {OptionKind::PlainFunctionEntryPoints, ++ "-plain-function-entry-points", ++ nullptr, ++ "Keep entry points as plain functions without moving uniform parameters into global constant buffers"}, + }; + _addOptions(makeConstArrayView(experimentalOpts), options); + +@@ -2279,6 +2283,7 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv) + case OptionKind::IncompleteLibrary: + case OptionKind::NoHLSLBinding: + case OptionKind::NoHLSLPackConstantBufferElements: ++ case OptionKind::PlainFunctionEntryPoints: + case OptionKind::LoopInversion: + case OptionKind::UnscopedEnum: + case OptionKind::PreserveParameters: |
