Commit Graph

9183 Commits

Author SHA1 Message Date
Branimir Karadžić
608713739b Metal: Switched to metal-cpp. (#3624)
* Metal: Switched to metal-cpp.

* Cleanup.

* Remove more Obj-C code.

* Add metal-cpp license.

* Cleanup.

* Reduce number of leak reports.

* Reducing Obj-C code.

* renderer_mtl.mm -> .cpp

* Cleanup.

* Cleanup.
2026-03-08 23:33:43 +00:00
Branimir Karadžić
b28febb4a8 NonLocalAllocator: Remove orphaned slabs. Fixed #2867. (#3625) 2026-03-08 04:02:40 +00:00
Branimir Karadžić
2721c747ae Added BGFX_FRAME_FLUSH. (#3623) 2026-03-07 04:50:46 +00:00
Branimir Karadžić
ae080bc634 D3D11: Fix SRV for external texture. (#3622) 2026-03-06 23:41:29 +00:00
Branimir Karadžić
298f5b0202 Improved docs on bgfx::begin/end. (#3621) 2026-03-06 05:37:34 +00:00
Gary Hsu
8e68ab9a83 Add null checks for mtl when no swap chain (#3620) 2026-03-05 21:16:53 +00:00
Branimir Karadžić
de17eda241 Improved documentation. Added IDL docs. (#3619) 2026-03-05 06:55:05 +00:00
Branimir Karadžić
ccdbacdb74 IDL: Docs cleanup. (#3618) 2026-03-02 18:22:08 +00:00
Ondřej Voves
b7d18c5ca7 Fix slow shaderc. (#3617) 2026-03-02 16:38:58 +00:00
Branimir Karadžić
0b1c1ecaca IDL: Generate C++ header. (#3616) 2026-03-01 00:23:13 +00:00
Branimir Karadžić
0c45d90ca7 Updated bindings. (#3615) 2026-02-28 23:35:50 +00:00
Branimir Karadžić
3e6455e6b0 IDL: Improve docs. (#3614) 2026-02-28 23:34:30 +00:00
Branimir Karadžić
c10271dc28 IDL: Added docs generator. (#3613) 2026-02-28 22:29:20 +00:00
Branimir Karadžić
26bae47dbe IDL: C++ generator improvements. (#3612) 2026-02-28 20:48:33 +00:00
Branimir Karadžić
874a013bf0 Updated bindings. (#3611) 2026-02-28 08:10:19 +00:00
Branimir Karadžić
7600e5e0eb IDL: Fixed C++ generator. (#3610) 2026-02-28 07:58:25 +00:00
Бранимир Караџић
b121263362 VK: Fix default texture state. 2026-02-24 07:32:35 -08:00
Бранимир Караџић
33930ac14a VK: Add external texture. 2026-02-23 22:28:11 -08:00
Бранимир Караџић
a059eb2967 Tint: Fixed MSVC 32-bit build. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
36ddff3264 Updated Vulkan headers. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
de0cdd0740 Updated Tint. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
651c7711b1 Updated spirv-cross. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
b9dff93496 Updated spirv-tools. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
7147583ad7 Updated spirv-headers. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
8f79485b97 Updated glslang. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
9a7c4a9842 Updated cgltf. 2026-02-21 19:54:05 -08:00
Бранимир Караџић
da166eba4c Updated ImGui. 2026-02-21 19:54:05 -08:00
Branimir Karadžić
91814c9729 Added flag for texture formats that can be used as back-buffer format. (#3605) 2026-02-22 02:44:26 +00:00
Branimir Karadžić
651c203116 Undo default back buffer format. Fix VK. (#3604) 2026-02-20 03:14:27 +00:00
Branimir Karadžić
856208328c Use back buffer format when capturing screen shot. (#3603) 2026-02-20 00:46:41 +00:00
Branimir Karadžić
4cb794eade VK: Initialize texture flags to 0. (#3602) 2026-02-19 17:47:48 +00:00
Martijn Courteaux
b03bd2d698 [shaderc] Make SPIRV, HLSL, DXIL, Metal backends optional to allow for leaner builds. (#3594)
* Make SPIRV, HLSL, DXIL, Metal backends optional to allow for leaner builds.

* New and automatic detection of available compilers to enable backends.

* Forgot to fixup Metal.

* Cleanup. Check for glsl-optimizer likewise.
2026-02-19 01:43:03 +00:00
Branimir Karadžić
c85fa25266 Added BGFX_FRAME_* flags to add ability to discard all draw calls. (#3599) 2026-02-19 01:42:31 +00:00
Branimir Karadžić
2800f17970 Cleanup. (#3598) 2026-02-18 21:01:18 +00:00
Martijn Courteaux
f3bc108efe Restore Vulkan 1.0 compatibility. (#3597)
* vulkan: Do not hard-depend on Vulkan 1.2 and Vulkan 1.1.

* fix(ub): vector iterators are not the same as taking address of position.

* fix(ub): Mask bit iterator had implicit promotion bug.

* fix(ub): Vulkan backend shouldn't copy fragment shader source if there is none.
2026-02-18 20:12:49 +00:00
Branimir Karadžić
40e614c45d Added external texture parameter. (#3596)
* Added external texture parameter.

* Use uint64_t instead of uintptr_t for external texture because VkImage is always 64-bit.
2026-02-18 20:12:37 +00:00
Quaylyn Rimer
02e04fb458 Optimize NonLocalAllocator: sorted vector + immediate coalescing (#3593)
Replace stl::list (tinystl::vector with O(n) push_front) with a sorted
stl::vector free list that maintains address-order invariant.

Key improvements:
- free(): uses bx::upperBound for O(log n) sorted insertion + immediate
  adjacent-block coalescing instead of O(n) push_front with deferred merge
- compact(): O(1) check (m_used empty?) instead of O(n log n) sort +
  O(n) linear merge pass on every call
- alloc(): first-fit scan over cache-friendly contiguous memory instead
  of pointer-chasing through fragmented list
- add(): sorted insert with coalescing via bx::upperBound, same as free()

Uses bx::upperBound from the bx foundation library for binary search,
no std:: usage. Added operator> to Free struct for bx::compareAscending
compatibility.

The public API and behavioral semantics are unchanged. All existing
callers (dynamic index/vertex buffer allocators, uniform cache store
allocator) continue to work identically.
2026-02-17 19:27:10 +00:00
Martijn Courteaux
611baeb183 Fix iterator (#3590)
* Fix iterator

* Enters.
2026-02-12 18:12:43 +00:00
unravel-dev
4cec34f4a1 Add Unravel Engine section to README (#3588)
Added a section about Unravel Engine, detailing its features and capabilities.
2026-02-09 03:18:13 +00:00
Branimir Karadžić
4ab38c657a Updated version. (#3587) 2026-02-08 01:46:54 +00:00
Branimir Karadžić
90d61887ac D3D11: Renamed dx11 to dxbc. (#3586) 2026-02-08 01:45:18 +00:00
Branimir Karadžić
562ece68a7 shaderc: Fixed DXIL compiler path. (#3585) 2026-02-08 01:21:16 +00:00
Branimir Karadžić
252efb73d9 Rebuilt 16-shadowmaps shaders. (#3584) 2026-02-08 00:41:24 +00:00
unravel-dev
6e3186ae6a Added pcss shadow implementation. Improved pcf blur samples with poisson disk rotation (#3583) 2026-02-08 00:16:51 +00:00
unravel-dev
0f6983be58 Improvement to the shadowmaps example for cascades and stability. (#3582)
* Improvement to the shadowmaps example for cascades and stability.

* Fixed unused variable
2026-02-07 16:28:17 +00:00
Branimir Karadžić
8b13337c6f d3d4linux: Added binaries. (#3581) 2026-02-06 16:32:04 +00:00
Quaylyn Rimer
6187b36185 Feature/d3d4linux integration (#3578)
* Add d3d4linux to 3rdparty for Linux HLSL shader compilation

- Added d3d4linux wrapper library for D3DCompiler access on Linux
- Includes Microsoft D3DCompiler DLLs (versions 43 and 47)
- Source from https://github.com/samhocevar/d3d4linux
- Commit: c9b1ca9 (Handle D3DReflect() regardless of DLL version)
- Enables HLSL shader cross-compilation on Linux via Wine

This is the first step toward implementing issue #1869:
Enable DirectX shader compilation on Linux platforms without
requiring Windows machines in the build pipeline.

Components included:
- d3d4linux.cpp - Wine-based D3DCompiler wrapper
- d3dcompiler_43.dll & d3dcompiler_47.dll - MS compiler DLLs
- Header files for D3D API compatibility
- Makefile for building the wrapper library
- Test files for validation

* Fix d3d4linux struct alignment for D3DReflect compatibility

- Add D3D_MIN_PRECISION enum to d3d4linux_enums.h
- Add MinPrecision field and padding to D3D11_SIGNATURE_PARAMETER_DESC
- Fixes struct size mismatch (32 bytes -> 40 bytes) with d3dcompiler_47.dll
- All 4 D3D functions now work: D3DCompile, D3DReflect, D3DStripShader, D3DDisassemble
- Add implementation_log.md documenting the integration process

Part of issue #1869: Enable HLSL shader compilation on Linux via Wine

* Integrate d3d4linux with bgfx shaderc for Linux HLSL compilation

Add support for HLSL shader compilation on Linux via d3d4linux (Wine-based).
This enables building D3D11/D3D12 shaders on Linux without Windows.

Changes:
- shaderc.h: Add SHADERC_CONFIG_HLSL_D3D4LINUX option to enable HLSL on Linux
- shaderc_hlsl.cpp: Add d3d4linux code path with conditional compilation
  - Uses d3d4linux inline functions instead of Windows DLL loading
  - load() returns d3d4linux compiler info on Linux
  - unload() is no-op on d3d4linux (no DLL to close)
- shaderc.lua: Add d3d4linux include path for Linux/macOS builds

Usage:
  Build with -DSHADERC_CONFIG_HLSL_D3D4LINUX=1
  Set D3D4LINUX_WINE, D3D4LINUX_EXE, D3D4LINUX_DLL environment variables

Requires: Wine, d3d4linux.exe, d3dcompiler_47.dll

Part of issue #1869: Enable HLSL shader compilation on Linux

* d3d4linux: Complete shaderc HLSL integration with Wine

Full working HLSL shader compilation on Linux via d3dcompiler_47.dll and Wine.

d3d4linux fixes:
- Add D3D_MIN_PRECISION enum and MinPrecision field to D3D11_SIGNATURE_PARAMETER_DESC
  (fixes struct size mismatch: 32 bytes -> 40 bytes to match Windows ABI)
- Add missing D3DCOMPILE_* flags used by shaderc
- Add ID3D11ShaderReflectionType struct with GetType() support
- Wine 11+ compatibility: default path changed from wine64 to wine with fallback
- Fix D3DDisassemble IPC protocol bug (only write comment string when present)

shaderc integration:
- Add SHADERC_CONFIG_HLSL_D3D4LINUX=1 define for Linux/macOS builds
- Restructure shaderc_hlsl.cpp with conditional compilation for d3d4linux vs Windows
- Fix null pointer crash when D3DCompile returns error without message
- Initialize ID3DBlob pointers to NULL

Usage:
  D3D4LINUX_EXE=/path/to/d3d4linux.exe shaderc -f shader.sc -o out.bin \
    --type vertex --platform windows -p s_5_0

Tested with vs_cubes.sc, fs_cubes.sc, vs_bump.sc - all compile successfully.
D3DCompile, D3DReflect, D3DStripShader, D3DDisassemble all working.

Implements: bkaradzic/bgfx#1869

* docs: Add d3d4linux documentation

- docs/d3d4linux-shaderc-support.md: User guide explaining prerequisites,
  installation, usage, environment variables, and troubleshooting for
  compiling HLSL shaders on Linux/macOS via Wine

- implementation_log.md: Updated with shaderc integration completion details,
  including all code changes made, test results, and commit references

* docs: Add EditorConfig/eclint notes to implementation log

Documents that eclint reports some style issues in modified files, but these
are pre-existing in the original codebase (copyright header comments using
spaces, line length in shaderc files). Our changes follow the existing code
style and do not introduce new violations.

* Fix d3d4linux integration after rebase onto upstream master

This commit fixes build issues that arose after rebasing onto the updated
upstream master which includes the TINT library and directx-headers.

Changes in this commit:

## shaderc.h
- Disable DXIL (DXC compiler) when d3d4linux is enabled
  - DXIL uses DirectX Compiler (DXC) which requires directx-headers
  - d3d4linux uses D3DCompiler via Wine which is a different compilation path
  - These two approaches are mutually exclusive on Linux

## shaderc.lua
- Removed directx-headers include paths for Linux builds
  - d3d4linux provides its own D3D type definitions
  - directx-headers conflicts with d3d4linux headers (duplicate typedefs)

## shaderc_hlsl.cpp
- Made all D3D-related includes conditional on SHADERC_CONFIG_HLSL_D3D4LINUX
  - Use <d3d4linux.h> when d3d4linux is enabled
  - Use <d3dcompiler.h> and <d3d11shader.h> on Windows
  - PFN_D3D_* function pointer typedefs (use WINAPI calling convention)
  - D3DCompiler struct with IID_ID3D11ShaderReflection member
  - s_d3dcompiler[] array of DLL versions
  - s_d3dcompilerdll handle
- Added simplified D3DCompiler struct for d3d4linux path (fileName only)
- Fixed D3DReflect call to use d3d4linux's integer IID macro

## Testing
- Successfully compiled shaderc with SHADERC_CONFIG_HLSL_D3D4LINUX=1
- Successfully compiled vs_cubes.sc to D3D11 bytecode (DXBC format)
- Output verified with xxd showing VSH header and DXBC signature

* Cleanup d3d4linux integration per maintainer feedback

Simplified changes:
- Remove SHADERC_CONFIG_HLSL_D3D4LINUX define, use BX_PLATFORM_* directly
- SHADERC_CONFIG_HLSL now enabled on Windows/Linux/macOS
- SHADERC_CONFIG_DXIL now Windows-only (DXC needs native D3D)

Removed files:
- d3d4linux test files (compile-hlsl.cpp, ps_sample.hlsl)
- d3d4linux extras (UE4 patches)
- d3d4linux.Build.cs (UE4 build file)
- d3dcompiler_43.dll (only 47 needed)
- implementation_log.md
- docs/d3d4linux-shaderc-support.md

Build and test verified on Linux with Wine 11.0.

* Enable DXIL on Linux/macOS and configure d3d4linux paths

Changes:
- shaderc.h: Enable SHADERC_CONFIG_DXIL on Linux and macOS (previously Windows-only)
  This allows Shader Model 6.0+ compilation via DXC on non-Windows platforms

- shaderc.lua: Configure d3d4linux and directx-headers for Linux/macOS
  - Add directx-headers include paths for DXIL support
  - Add WSL stubs include path for COM compatibility types
  - Define D3D4LINUX_EXE path pointing to 3rdparty/d3d4linux/d3d4linux.exe
  - Define D3D4LINUX_DLL path for d3dcompiler_47.dll (Wine Z: drive prefix)

Prerequisites for HLSL compilation on Linux:
1. Wine installed (/usr/bin/wine or /usr/bin/wine64)
2. Build d3d4linux.exe: cd 3rdparty/d3d4linux && make
   (requires mingw-w64 cross-compiler: x86_64-w64-mingw32-c++)
3. d3dcompiler_47.dll in 3rdparty/d3d4linux/

Tested: SM 5.0 vertex shader compilation works via Wine/d3d4linux
DXIL (SM 6.0+) requires native DXC library installation

* Remove macOS from DXIL config (no DXC library available)

Microsoft's DXC releases only include:
- Windows: dxcompiler.dll
- Linux: libdxcompiler.so

There is no libdxcompiler.dylib for macOS. Updated SHADERC_CONFIG_DXIL
to only enable DXIL on Windows and Linux.

macOS still supports legacy HLSL (SM 5.0) via d3d4linux.

* Remove d3d4linux build files from bgfx repo

Users should obtain d3d4linux.exe and d3dcompiler_47.dll from:
https://github.com/killerdevildog/d3d4linux

Only headers are needed for bgfx compilation.

* Fix d3d4linux reflection: deserialize D3D11_SHADER_TYPE_DESC

Fixes uniform extraction bug where type info was not being read from
the IPC stream. This is required for bgfx to properly determine uniform
types and array element counts via findUniformType().

* Add d3d4linux source with reflection serialization fix

Include d3d4linux.cpp and Makefile with fixes for D3D11_SHADER_TYPE_DESC
serialization. This allows building shaderc with proper uniform extraction
while upstream PR is pending: https://github.com/samhocevar/d3d4linux/pull/1

* Apply maintainer cleanup: unified code paths and header guards

* Force D3D_SVF_USED flag on all uniform variables

This forces all uniform variables to be marked as 'used' during reflection
deserialization, ensuring bgfx extracts type info for all uniforms.

Note: This deviates from native D3D compiler behavior where unused uniforms
do not have the D3D_SVF_USED flag set. Native behavior would skip extraction
for uniforms not actually referenced in shader code.

* Fix D3DDisassemble serialization mismatch

Only write comment string when szComments is non-null to match
server-side read behavior. Fixes 'bad message received' error.

* shaderc: Improve d3d4linux integration and error handling

This commit enhances the d3d4linux integration for HLSL shader compilation
on Linux and macOS platforms with several key improvements:

Key Changes:
- Dynamic path detection for d3d4linux binaries instead of hardcoded paths
- Relocate d3dcompiler_47.dll from 3rdparty/d3d4linux/ to tools/bin/windows/
- Remove d3d4linux.exe from 3rdparty (now managed separately)
- Improved error handling with proper null checks and user feedback
- Enhanced logging using BX_TRACE for consistency
- Remove --verbose flag from shader compilation make rules for cleaner output
- Automatic environment variable setup (D3D4LINUX_EXE, D3D4LINUX_DLL)

Technical Details:
- shaderc_hlsl.cpp now dynamically locates d3d4linux.exe and d3dcompiler_47.dll
  relative to the executable directory
- Proper error messages when required files are not found
- Simplified Makefile in 3rdparty/d3d4linux/
- Removed hardcoded D3D4LINUX_EXE and D3D4LINUX_DLL defines from shaderc.lua

Files Modified:
- 3rdparty/d3d4linux/Makefile: Simplified build rules
- scripts/shader.mk: Removed --verbose flags from compilation commands
- scripts/shaderc.lua: Removed hardcoded path defines
- tools/shaderc/shaderc_hlsl.cpp: Enhanced d3d4linux integration logic

Files Deleted:
- 3rdparty/d3d4linux/d3d4linux.exe
- 3rdparty/d3d4linux/d3dcompiler_47.dll

This improves portability and makes the build system more maintainable
by removing hardcoded paths and improving runtime binary discovery.

Credit: bkaradzic provided patch

* Delete d3d4linux.md

* Delete examples/runtime/shaders/dx11/vs_cubes.bin

* Remove macOS.

---------

Co-authored-by: Branimir Karadžić <branimirkaradzic@gmail.com>
2026-02-06 16:28:04 +00:00
Branimir Karadžić
e22fac6794 shaderc: Fix getUniformTypeName. (#3580) 2026-02-05 02:01:52 +00:00
Branimir Karadžić
011ede6b42 shaderc: HLSL/DXBC needs unorm float image load/store. (#3576) 2026-02-03 00:39:35 +00:00
Branimir Karadžić
4942e65bf9 shaderc: select (u)int variants are just for higher versions of GLSL. (#3575) 2026-02-02 22:32:11 +00:00