Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ FetchContent_Declare(metal-cpp
EXCLUDE_FROM_ALL)
FetchContent_Declare(SPIRV-Cross
GIT_REPOSITORY https://github.com/BabylonJS/SPIRV-Cross.git
GIT_TAG 866e5edcc3407997a3ed62f3edf492f91bcb2629
GIT_TAG a512817ddbcd879a3929aef7d1d762871bdf8635
EXCLUDE_FROM_ALL)

# --------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Plugins/ShaderCompiler/Source/ShaderCompilerDXBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace Babylon::Plugins
std::map<std::string, std::string> vertexAttributeRenaming = {};
ShaderCompilerTraversers::AssignLocationsAndNamesToVertexVaryingsD3D(program, ids, vertexAttributeRenaming);
ShaderCompilerTraversers::SplitSamplersIntoSamplersAndTextures(program, ids);
ShaderCompilerTraversers::SplitSamplerFunctionParameters(program, ids);
ShaderCompilerTraversers::InvertYDerivativeOperands(program);

// clang-format off
Expand Down
1 change: 1 addition & 0 deletions Plugins/ShaderCompiler/Source/ShaderCompilerDXIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ namespace Babylon::Plugins
std::map<std::string, std::string> vertexAttributeRenaming = {};
ShaderCompilerTraversers::AssignLocationsAndNamesToVertexVaryingsD3D(program, ids, vertexAttributeRenaming);
ShaderCompilerTraversers::SplitSamplersIntoSamplersAndTextures(program, ids);
ShaderCompilerTraversers::SplitSamplerFunctionParameters(program, ids);
ShaderCompilerTraversers::InvertYDerivativeOperands(program);

// clang-format off
Expand Down
1 change: 1 addition & 0 deletions Plugins/ShaderCompiler/Source/ShaderCompilerMetal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace Babylon::Plugins
std::map<std::string, std::string> vertexAttributeRenaming = {};
ShaderCompilerTraversers::AssignLocationsAndNamesToVertexVaryingsMetal(program, ids, vertexAttributeRenaming);
ShaderCompilerTraversers::SplitSamplersIntoSamplersAndTextures(program, ids);
ShaderCompilerTraversers::SplitSamplerFunctionParameters(program, ids);
ShaderCompilerTraversers::InvertYDerivativeOperands(program);

std::string vertexMSL(vertexSource.data(), vertexSource.size());
Expand Down
402 changes: 402 additions & 0 deletions Plugins/ShaderCompiler/Source/ShaderCompilerTraversers.cpp

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions Plugins/ShaderCompiler/Source/ShaderCompilerTraversers.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ namespace Babylon::ShaderCompilerTraversers
/// the expectations of native platforms.
void SplitSamplersIntoSamplersAndTextures(glslang::TProgram& program, IdGenerator& ids);

/// Split combined `sampler2D`/`samplerCube`/etc. function parameters of user-defined
/// functions into separate texture and sampler parameters. Must be called AFTER
/// SplitSamplersIntoSamplersAndTextures.
///
/// The GLSL emitted by Babylon.js contains user functions that take combined
/// samplers as parameters and pass uniform samplers to them at the call site, e.g.
///
/// vec3 fetch(sampler2D s, vec2 uv) { return texture(s, uv).rgb; }
/// void main() { ... fetch(myUniformSampler, uv); }
///
/// glslang's SPIR-V emitter requires opaque (sampler) function arguments to be
/// l-values (it calls `accessChainGetLValue()` on them). After
/// SplitSamplersIntoSamplersAndTextures has rewritten the call-site sampler argument
/// into an `EOpConstructTextureSampler(t, s)` aggregate (an r-value), glslang
/// asserts at `SpvBuilder.cpp:accessChainGetLValue()`. See TPC #1584 for details.
///
/// This pass fixes the assert by:
/// 1. Rewriting each user function with sampler parameters: each `sampler2D s`
/// parameter becomes two parameters `texture2D sTexture, sampler s`, and every
/// reference to the original `s` in the body becomes an
/// `EOpConstructTextureSampler(sTexture, s)` aggregate.
/// 2. Rewriting every call site to such functions: the single
/// `EOpConstructTextureSampler(t, s)` argument is replaced with two separate
/// arguments (t and s).
void SplitSamplerFunctionParameters(glslang::TProgram& program, IdGenerator& ids);

/// Invert dFdy operands similar to bgfx_shader.sh
/// https://github.com/bkaradzic/bgfx/blob/7be225bf490bb1cd231cfb4abf7e617bf35b59cb/src/bgfx_shader.sh#L44-L45
/// https://github.com/bkaradzic/bgfx/blob/7be225bf490bb1cd231cfb4abf7e617bf35b59cb/src/bgfx_shader.sh#L62-L65
Expand Down
1 change: 1 addition & 0 deletions Plugins/ShaderCompiler/Source/ShaderCompilerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace Babylon::Plugins
std::map<std::string, std::string> vertexAttributeRenaming = {};
ShaderCompilerTraversers::AssignLocationsAndNamesToVertexVaryingsD3D(program, ids, vertexAttributeRenaming);
ShaderCompilerTraversers::SplitSamplersIntoSamplersAndTextures(program, ids);
ShaderCompilerTraversers::SplitSamplerFunctionParameters(program, ids);
ShaderCompilerTraversers::InvertYDerivativeOperands(program);

std::vector<uint32_t> spirvVS;
Expand Down
Loading