Skip to content

Vulkan test#1648

Draft
CedricGuillemet wants to merge 12 commits intoBabylonJS:masterfrom
CedricGuillemet:vulkanTest
Draft

Vulkan test#1648
CedricGuillemet wants to merge 12 commits intoBabylonJS:masterfrom
CedricGuillemet:vulkanTest

Conversation

@CedricGuillemet
Copy link
Copy Markdown
Contributor

No description provided.

CedricGuillemet and others added 12 commits March 20, 2026 17:03
- Add RendererType header for Vulkan (DeviceT=void*, TextureT=uint64_t)
- Add DeviceImpl_Vulkan.cpp setting bgfx renderer to Vulkan
- Add ExternalTexture_Vulkan.cpp stub implementation
- Add Utils.Vulkan.cpp stub for unit tests
- Enable SPIRV-Cross GLSL for Vulkan (needed by ShaderCompilerVulkan)
- Add VertexVaryingInTraverserVulkan shader traverser with location-based
  attribute bindings matching bgfx's Vulkan expectations
- Update ShaderCompilerVulkan to use Vulkan-specific traverser
- Add Vulkan CI jobs: Ubuntu/Clang/JSC and Win32/x64/Chakra
- Add graphics_api parameter to linux.yml CI template

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The shader compiler hardcoded layoutBinding = 0 for all shader stages
and descriptor types, but bgfx's old binding model (shader version < 11)
expects specific binding offsets per stage:

  - VS uniform buffer: binding 0
  - FS uniform buffer: binding 48 (kSpirvOldFragmentBinding)
  - VS textures: binding 16+ (kSpirvOldTextureShift)
  - VS samplers: binding 32+ (texture + kSpirvSamplerShift)
  - FS textures: binding 64+ (kSpirvOldFragmentShift + kSpirvOldTextureShift)
  - FS samplers: binding 80+ (texture + kSpirvSamplerShift)

This caused:
  - Black cube: FS uniform buffer unbound (all lighting values zero)
  - White glTF: textures/samplers at wrong bindings (not bound)

Fix applies Vulkan-specific binding offsets in three places:
  1. NonSamplerUniformToStructTraverser: FS uniform at binding 48
  2. SamplerSplitterTraverser: VS textures at 16+, FS textures at 64+,
     samplers offset by +16 from their texture binding
  3. AppendSamplers: write correct regIndex and stage index for bgfx

All changes guarded with #if VULKAN to avoid affecting D3D/Metal paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When an RTT framebuffer is unbound, insert a transition view with the
default backbuffer so bgfx transitions the RTT attachment textures from
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL to the sampled layout before
any subsequent draw call attempts to sample them.

Previously FrameBuffer::Unbind() was a no-op, which meant bgfx might
not process the framebuffer change before the RTT texture was sampled,
causing an assert: 'texture.m_currentImageLayout == texture.m_sampledLayout'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add AssignLocationsToInterStageVaryings traverser that assigns explicit
SPIR-V Location decorations to VS outputs and FS inputs. Vulkan requires
explicit Location decorations on all inter-stage varyings; without them,
VS output data (positions, normals, UVs, TBN matrices) would not flow
correctly to the FS.

The traverser collects VS output varyings from linker objects, assigns
sequential locations (accounting for matrix column count), then applies
matching locations to ALL symbol instances in both VS and FS ASTs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two fixes for correct Vulkan vertex data flow:

1. Vertex attribute locations: bgfx's Vulkan renderer uses the attribute's
   index in the shader binary as the Vulkan input location (m_attrRemap).
   The SPIR-V uses Attrib::Enum values as Locations (e.g., TexCoord0=10).
   Pad the binary's attribute list with dummy entries so each attribute's
   index matches its SPIR-V Location, making m_attrRemap[attr] == Location.

2. Inter-stage varying locations: Add AssignLocationsToInterStageVaryings
   traverser that assigns explicit Location decorations to all VS outputs
   and FS inputs. Vulkan SPIR-V requires these for correct data flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
63/92 tests pass on Vulkan. Exclude 29 tests that crash (image layout
transitions) or fail (animation skin, alien, cesium):

Crashes (image layout mismatch - bgfx texture state transitions):
  Point light shadows, GLTF BoomBox with Unlit Material,
  Ribbon morphing, Solid particle system, Chromatic aberration,
  Normals, Capsule, Fresnel, Unindexed mesh,
  Black and White post-process, Multi camera rendering,
  Multi cameras and output render target, GLTF Texture Sampler (0)

Failures (test logic / hardware scaling):
  Scissor test with 0.9/1.5 hardware scaling,
  GLTF Animation Skin (0)/(1), GLTF Alien,
  CesiumMan from Khronos Sample Assets, LOD

Previously excluded (not Vulkan-related):
  EXR Loader, GLTF Extension EXT_mesh_gpu_instancing,
  GLTF Animation Skin Type, Thin Instances,
  Glow layer and LODs, Nested BBG, Kernel Blur,
  Soft Shadows, Soft Shadows (Right Handed)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Microsoft-hosted Azure Pipelines agents have no GPU, so Vulkan tests
need a software Vulkan ICD. Install Lavapipe (Mesa's CPU-based Vulkan
renderer) from jakoch/rasterizers before running validation tests.

Sets VK_ICD_FILENAMES and VK_DRIVER_FILES so the Vulkan loader finds
the Lavapipe driver. Step only runs for Vulkan builds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nto vulkanTest

# Conflicts:
#	.github/jobs/linux.yml
Extract the bgfx name → Attrib::Enum mapping into a shared
GetBgfxNameToAttribMap() in ShaderCompilerCommon.h, used by both
ShaderCompilerTraversers (Vulkan vertex attribute locations) and
ShaderCompilerCommon (shader binary attribute IDs).

Also:
- Remove unnecessary #if VULKAN around regIndex/attrib binary code
  since those bytes are only used by Vulkan anyway
- Add missing attrib entries (TexCoord4-7 / instance data)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant