Skip to content

Migrate Axmol shader workflow to HLSL-first axslcc 3.99#3233

Merged
halx99 merged 51 commits into
devfrom
hlsl51
Jul 18, 2026
Merged

Migrate Axmol shader workflow to HLSL-first axslcc 3.99#3233
halx99 merged 51 commits into
devfrom
hlsl51

Conversation

@halx99

@halx99 halx99 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Describe your changes

WIP migration guide: https://github.com/axmolengine/axmol/wiki/Shaders-in-Axmol3

  • Migrates Axmol's built-in shaders from GLSL to a single HLSL-first source workflow. The new axslcc pipeline compiles the same HLSL sources for D3D11, D3D12, Vulkan, Metal, OpenGL and OpenGL ES, and CMake now selects targets from the enabled RHI backends and supports multi-compile shader variants.
  • Updates the shader package and reflection ABI for axslcc 3.99, including target code metadata, semantic-based vertex input reflection, explicit texture/sampler reflection and backend-independent resource binding metadata.
  • Replaces vertex attribute lookup by GLSL variable name with HLSL semantic name plus index (POSITION, TEXCOORD0, COLOR0, custom semantics, etc.), then updates engine, 3D, extension and test vertex layouts to use the new contract.
  • Introduces SamplerRegistry and a unified sampler model: 22 stable built-in presets plus named custom samplers registered before Program creation. Programs validate unresolved samplers, while every RHI backend maps reflected logical bindings to its native binding model.
  • Updates the D3D11, D3D12, Vulkan, Metal and OpenGL/ES backends for the new shader/reflection model, including separate image/sampler handling, D3D12 descriptor allocation and Vulkan descriptor-set layout/accounting changes.
  • Ports the engine shader library, ImGui, Live2D, Spine, VR, Box2D Testbed and cpp-tests shaders to HLSL, and removes the retired GLSL conversion scripts and generated shader-info path.
  • Adds the Axmol HLSL authoring specification and FAQ covering semantics, uniform/resource binding, built-in and custom samplers, GL/GLES limitations, coordinate conventions and shader variants.

Issue ticket number and link

Checklist before requesting a review

For This PR

  • Publish complete rewrited axslcc 3.99.x
  • Compiler front-end: use dxcompiler by default, glslang only for verification
    CMake Deprecation Warning at 3rdparty/glslang/CMakeLists.txt:111 (message):
      ENABLE_HLSL is deprecated.  The HLSL front-end will be removed in a future
      major release of glslang.  See
      https://github.com/KhronosGroup/glslang/issues/4210 for details.

For each PR

  • Add Copyright if it missed:
    - "Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md)."

  • I have performed a self-review of my code.

    Optional:

    • I have checked readme and add important infos to this PR.
    • I have added/adapted some tests too.

For core/new feature PR

  • I have checked readme and add important infos to this PR.
  • I have added thorough tests.

Axmol 3.x ------------------------------------------------------------

For each 3.x PR

  • Check the '#include "axmol.h"' and replace it with the needed headers.

@halx99 halx99 added this to the 3.0.0 milestone Jul 9, 2026
@halx99 halx99 linked an issue Jul 9, 2026 that may be closed by this pull request
@halx99 halx99 changed the title Migrate Shader front language from GLSL to HLSL-51 Switch Shader front language from GLSL to HLSL-51 Jul 9, 2026
@halx99 halx99 added the enhancement New feature or request label Jul 9, 2026
halx99 added 25 commits July 14, 2026 09:30
…ix semantics, remove Sampler12.h dead code, fix base.hlsli SPOTLIGHT overlap and colorUtils.hlsli type error
PS_IN struct member order (D3D12 varying signature fix):
- Reorder PS_IN members in 9 test PS shaders to match VS_OUT declaration order
- Fix example_HorizontalColor_ps.hlsl: add missing v_color, rename gl_FragCoord→pixelCoord

AXSLC_UV_TOP / AX_Y_UP macros (base.hlsli):
- AXSLC_UV_TOP: built-in per-target define (0=GLSL/ESSL, 1=HLSL/SPIRV/MSL)
- AX_Y_UP(v): convert to bottom-left Y-up coordinate convention
- vr_vs.hlsl: TEXCOORD_Y → AX_Y_UP

Fullscreen PS Y-flip (11 shaders):
- Use #if AXSLC_UV_TOP for conditional gl_FragCoord.y flip
- example_Heart, Julia, Flower, Mandelbrot, Monjori, Twist, Plasma,
  shadertoy_FireBall/Glow/LensFlare, example_LensFlare

Live2D vertex shaders (3 files):
- live2d_blend_vs.hlsl: add AX_Y_UP for v_blendCoord
- live2d_masked_vs.hlsl: conditional v_clipPos Y-flip (#if AXSLC_UV_TOP)
- live2d_masked_blend_vs.hlsl: both fixes above

Documentation:
- docs/hlsl-spec.md: add Section 15 Target Macros, updated pipeline diagram
- Remove tmp/pr3233-migration.md (merged into spec)
…variants

- Rename property AXSLCC_OUTPUT1 → AXSLCC_VARIANT_DEFINES for clarity
- Add axslcc_parse_defines() helper to parse comma-separated defines
- Replace single-variant if/else with N-variant foreach loop (semicolons separate variants)
- Fix variant define placement: base output gets SC_FLAGS only, _1 variant gets extra -D flags
- Cleanup: remove empty #ifdef USE_NORMAL_MAPPING blocks in positionNormalTexture_vs.hlsl
- Fix: reorder PS_IN members in colorNormal_ps.hlsl (D3D12 location matching)
- Add ShaderModule::getCodeSpan()
…-spec.md)

Add section 14.1 'Shader Compile Variants' with variant naming and delimiter rules.
- axslc-spec.h: sync SC_PROFILE_BINARY flag from axslcc
- GraphicsCore: add currentShaderILProfile to State (set by Driver init)
  - D3D12: set 60 (DXIL) if DXC available, else 51 (DXBC)
  - D3D11/Vulkan/Metal: set to currentShaderProfile as default
- ShaderModule: add _precompiled + isPrecompiled()
- ShaderModule::parseShaderCode: binary-aware sc_target_entry matching
  - Reads SC_PROFILE_BINARY from profile_ver
  - Prefers bytecode entry matching currentShaderILProfile
- D3D11 Driver: skip D3DCompile for precompiled DXBC, create shader directly
- D3D12 Driver: skip DXC/FXC compilation for precompiled bytecode
- AXSLCC.cmake: hlsl-50/51 -> d3d11/d3d12, --dxc -> conditional --dxbc
  - --dxbc enabled for Release/MinSizeRel/RelWithDebInfo only
…precompiled

- ShaderModule base: add _blob span + _nativeBlob ComPtr + getBytecode()
- D3D11/D3D12 ShaderModule: remove backend-specific blob storage
- Precompiled: _blob = _codeSpan (zero-copy), _nativeBlob = nullptr
- Source: _blob = compiled blob view, _nativeBlob owns COM blob
- createShaderFromBytecode extracted from D3D11 compileShader
- compileShader: remove isPrecompiled param (handled by caller)
- Program API: getVSBlob/getPSBlob return std::span<uint8_t> universally
- VertexLayout11/RenderPipeline12: use span .data()/.size()
- D3D12BlobHandle retained for Driver internal use only
…2 subclasses

Non-D3D backends (Vulkan/Metal/GL) use _codeSpan directly and don't need
a separate compiled bytecode blob.
AXSLCC_FLAGS is a free-form flags string (like CMAKE_CXX_FLAGS).
Default is '-S' to keep source (safe cross-platform default).
Users can set e.g.:
  -DAXSLCC_FLAGS='-O2'        for optimized bytecode
  -DAXSLCC_FLAGS='-O0 -S'     for debug source
  -DAXSLCC_FLAGS='-O3'        for max optimization
halx99 added 4 commits July 14, 2026 23:39
- Add Program::isValid() to check shader compilation status
- Replace assert(false) with graceful error handling across all backends
- Add dedicated vertex shader layer_radialGradient_vs
- Fix HLSL semantics: float3->float4 a_position, SV_Position->POSITION, NORMAL->POSITION
- Fix example_Noisy_fs.hlsl pixel coordinate and noise color channels
- Add missing a_color/v_color to example_Simple_vs.hlsl
- Add Y-flip conditional for GLSL target in live2d_test_vs.hlsl
- Bump axslcc to 3.99.1
- Add setSamplers() method to resolve sampler presets via SamplerCache
- Call setSamplers() alongside setUniformBuffer() and setTextures()
- Samplers with no preset fall back to texture-owned samplers from setTextures()
- Split sampler binding into two phases: TextureOwned (per-texture)
  and ShaderPreset (built-in sampler presets from base.hlsli)
- Rename SamplerIndex to SamplerPreset and update all backends
  (D3D11, Metal, Vulkan)
- Document sampler model in hlsl-faq.md and update hlsl-spec.md
- Sync lua shader bindings with Shaders.h: fix _vert/_frag to _vs/_fs
  and add all missing shader variables
@halx99

halx99 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

/clang-format

@halx99
halx99 marked this pull request as ready for review July 15, 2026 13:35
@halx99
halx99 marked this pull request as draft July 17, 2026 05:55
@halx99 halx99 changed the title Switch Shader front language from GLSL to HLSL-51 Switch Shader front language from GLSL to HLSL Jul 17, 2026
halx99 added 2 commits July 17, 2026 23:42
- Rename SamplerBindingInfo fields: descriptorSet->space, comparison->flags
- Add SCSamplerFlags enum, kCustomSamplerDescriptorSet, sampler helpers
- Generalize SamplerRegistry: getDesc->getSamplerDesc, use string_map
- D3D11: compact sequential sampler slot binding
- D3D12: add allocateBatch/deallocateBatch, custom sampler root descriptor table
- Vulkan: separate descriptor set (set 2) for custom samplers
- OpenGL: bind custom sampler objects per program
- Update docs/hlsl-faq.md and docs/hlsl-spec.md for custom samplers
- Add ShaderCustomSampler test with custom HLSL shader
@halx99

halx99 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

/clang-format

@halx99
halx99 marked this pull request as ready for review July 18, 2026 09:20
@halx99 halx99 changed the title Switch Shader front language from GLSL to HLSL Migrate Axmol shader workflow to HLSL-first axslcc 3.99 Jul 18, 2026
halx99 added 3 commits July 18, 2026 20:44
- Program: add _textureSamplerIds map and getTextureSampler() for per-binding sampler lookup
- axslc-spec: add sampler_ref field for combined texture uniforms
- Vulkan: rename SET_INDEX_RESERVED to SET_INDEX_CUSTOM_SAMPLER
- D3D11: fix sampler slot overflow check
- OpenGL: simplify bindSampler, use getTextureSampler() per binding
- Test: add ShaderMultiCustomSampler with two custom samplers
@halx99

halx99 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator Author

/clang-format

@halx99
halx99 merged commit 4071f6a into dev Jul 18, 2026
21 of 40 checks passed
@halx99
halx99 deleted the hlsl51 branch July 18, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests\cpp-tests\Source\shaders\example_HorizontalColor.fsh not working with D3D12 Switch front-end shader lang GLSL --> HLSL

2 participants