Commit Graph

9263 Commits

Author SHA1 Message Date
Branimir Karadžić
7b8927049a Fix updateTexture2D pitch handling for compressed textures. Fixed #3705. (#3722) 2026-06-02 04:22:46 +00:00
Jaziel Guerrero
0d4141d03a Updated C3 binding script to generate C3 binding based on C3 v0.8.0 (#3720) 2026-05-28 20:38:35 -07:00
Branimir Karadžić
5f85da1e59 Added .ktx2 support. (#3721) 2026-05-28 20:38:10 -07:00
Branimir Karadžić
ccd0d04c9e Metal: Guard against null vertexAttributes for shaders with no inputs. (#3719) 2026-05-28 17:04:05 +00:00
Branimir Karadžić
ba17ab3825 Added webp support. (#3718) 2026-05-27 05:03:03 +00:00
Branimir Karadžić
7d03e160fa Fix MSAA + mipmaps combination on D3D11/D3D12/Vulkan/Metal. (#3717) 2026-05-21 22:53:17 +00:00
Branimir Karadžić
526b886105 Metal: Fix maxFrameLatency setting. (#3715) 2026-05-21 06:19:41 +00:00
Branimir Karadžić
0158b15c23 Metal: Fixed freeze when BGFX_FRAME_FLUSH is used. (#3714) 2026-05-21 06:18:36 +00:00
Branimir Karadžić
f17b06fc00 Metal: Clamp texture update rect to destination mip extent. (#3713) 2026-05-21 05:26:06 +00:00
Branimir Karadžić
651985d860 Metal: Warn about drawable size mismatch. (#3712) 2026-05-20 19:33:01 -07:00
Branimir Karadžić
de332e5937 VK: Fixed VK_EXT_swapchain_maintenance1 missing instance exp deps, and timer query inside render pass. (#3711)
* Fixed dynamic frame vsync on RADV.

* Fix timer query inside render pass.
2026-05-17 23:51:31 +00:00
Branimir Karadžić
d4c91be81d Cleanup. (#3710) 2026-05-17 16:43:20 +00:00
Branimir Karadžić
4997ad09ed Metal: Dynamic frame VSync to match #3706. (#3709) 2026-05-17 16:23:00 +00:00
Vincent Bousquet
a8250ceaf9 Lighter per frame VSync on/off for D3D11, D3D12 & Vulkan (#3706) 2026-05-17 15:44:33 +00:00
Branimir Karadžić
9849fe96cb CI: Remove osx-x64. (#3703) 2026-05-04 07:54:11 -07:00
Branimir Karadžić
4a8489a549 Match CI with bx. (#3702) 2026-05-03 18:39:29 -07:00
Branimir Karadžić
87c1929d71 Fix zero-vertex regression in setVertexBuffer. (#3701) 2026-05-03 15:33:51 -07:00
Branimir Karadžić
65f9425d8c Updated to new SIMD. (#3699) 2026-05-03 18:51:10 +00:00
Branimir Karadžić
b7d5c2572c Metal: Improve feature detection. (#3697) 2026-05-02 04:44:31 +00:00
Kyle Emmerich
7abefde6bd Metal: Honor BGFX_RESET_DEPTH_CLAMP via setDepthClipMode:. (#3696)
The flag was already in `maskFlags` but never wired to any rasterizer
state, so it was a no-op on Metal. Set MTLDepthClipModeClamp on each
render command encoder when requested. Capability-gated: macOS always,
Apple-GPU platforms gated by GPUFamilyApple4+.
2026-05-02 03:35:39 +00:00
Ernes Budiman
5761ae09e4 Update README.md (#3695)
Add Match Morphosis game into readme
2026-04-29 14:35:50 +00:00
Branimir Karadžić
58faaadf1c VK: Split FrameBufferVK::acquire into swap-chain acquire + markDirty(). (#3694) 2026-04-27 18:32:53 +00:00
attilaz
b2a7d94d57 Update renderer_vk.cpp (#3693)
Fix PROFILE_SCOPE typo
2026-04-27 14:22:28 +00:00
Branimir Karadžić
331783cf9a Renamed bx::uint32_min/max/clamp/cntlz/cnttz/mod to typed equivalents. (#3692) 2026-04-27 04:19:08 +00:00
ShuangLiu1992
43fbfaba41 docs: clarify readTexture's READ_BACK flag is CPU-only (#3691)
Per maintainer feedback, distill the @attention block down to the
essence: it's a texture for CPU readback, and can't be a GPU resource
at the same time. Add a one-line pointer to examples/30-picking for
the rendered-content case rather than spelling out the blit-to-staging
sequence inline.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 15:42:53 +00:00
ShuangLiu1992
cceedb60cf Fix: reset s_renderFrameCalled in bgfx::shutdown() to allow re-init (#3690)
bgfx::renderFrame() sets s_renderFrameCalled = true on its first call
(line 1541) and never clears it. bgfx::shutdown() resets s_threadIndex
to 0 (line 3958) but leaves s_renderFrameCalled sticky, which means
that on a 2nd renderFrame after shutdown the gate at line 1534 still
runs BGFX_CHECK_RENDER_THREAD(). That assertion checks
(s_ctx != NULL && single-threaded) || (~BGFX_API_THREAD_MAGIC == s_threadIndex);
both branches fail post-shutdown (s_ctx is NULL, s_threadIndex is 0),
and the assertion fires in debug builds — blocking re-init of the
bgfx context within the same process.

Adding the symmetric s_renderFrameCalled reset to shutdown() makes
shutdown leave bgfx in the same state as a fresh process, so a
subsequent renderFrame()+init() pair behaves like the first one.

Verified locally: a downstream test that constructs an SDL+bgfx
context, runs a frame, destroys it, then constructs another from the
same thread now passes in debug builds with this patch (it asserts at
line 1536 without it).
2026-04-25 20:15:29 -07:00
Gary Hsu
ac54f48d4d Fix UBSan undefined-behavior hits in bgfx_p.h (#3688)
* Default-initialize SortKey members to eliminate UBSan bool hit

SortKey data members had no initializers; the only initialization path
was an explicit reset() call. Reading m_hasAlphaRef (bool) before
reset() ran surfaced under BabylonNative's -fno-sanitize-recover=all
UBSan as 'load of value 190, which is not a valid value for type bool'.
Integer siblings had the same hazard, but UBSan only flags bools.

Add in-class default initializers matching reset()'s values. Zero
runtime cost where reset() immediately follows. No API/ABI change.

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

* Avoid shift-by-width UB in BitMaskToIndexIteratorT

UBSan on macOS flags the shifts at bgfx_p.h:854 and :862. bx::countTrailingZeros returns the type width (e.g. 32 for uint32_t) when its argument is zero, and that value was fed directly into the shift operator, producing shift-by-width UB.

Guard each shift against a zero mask so the width-valued ntz is never used as a shift exponent. Behavior is preserved for every input that previously avoided UB, and callers see isDone() == true in exactly the same iterations as before.

* Address review feedback: tighter BitMask ternary + SortKey reset() in EncoderImpl ctor

Per review on bkaradzic/bgfx#3688:

- BitMask: use branchless ternary (0 == _mask ? 0 : _mask >> ntz) in place of early-return guard.

- SortKey: drop in-class default initializers; initialize via m_key.reset() in EncoderImpl() ctor, which is the narrower location where the UB read originates.

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 21:48:41 +00:00
Branimir Karadžić
461622ab26 Metal: Fixed dynamic buffer alignment. Fixed #3684. (#3685) 2026-04-23 16:38:20 +00:00
Branimir Karadžić
d6458ee253 Metal: Fixed depth/stencil store action on the main swap chain when using MSAA. (#3683) 2026-04-22 16:34:12 -07:00
Branimir Karadžić
50bf41b224 Fixed stremMask check. (#3682) 2026-04-21 11:21:40 -07:00
Branimir Karadžić
e528e9d880 Fixed stremMask check. (#3681) 2026-04-21 11:15:04 -07:00
Branimir Karadžić
633ceb1247 VertexLayout: Fix bad remap table. (#3680) 2026-04-21 11:11:04 -07:00
Branimir Karadžić
c9e98db704 Cleanup. (#3679) 2026-04-21 03:58:53 +00:00
Branimir Karadžić
6294e59293 Metal: Fixed instancing mapping. (#3678) 2026-04-21 03:51:39 +00:00
Branimir Karadžić
8a22a19d2e Metal: Check if framebuffer has depth before setting depth state. (#3677) 2026-04-21 00:27:07 +00:00
Branimir Karadžić
78076b02eb WebGPU: Fixed formats. (#3676) 2026-04-19 16:35:06 -07:00
unravel-dev
4212c8ed27 Fix BGFX_RESET_VSYNC not affecting secondary swap chains on D3D11, Vulkan, OpenGL (#3675)
Toggling BGFX_RESET_VSYNC via bgfx::reset() only updated the main/init swap
chain. Secondary swap chains created through createFrameBuffer(nwh, ...) kept
their initial vsync state, leaving framerate capped at refresh rate. D3D12
already handled this correctly.

D3D11: forward present flags to FrameBufferD3D11::present so it can pass
DXGI_PRESENT_ALLOW_TEARING alongside syncInterval=0. Compute presentFlags once
in flip() and reuse for both secondary framebuffers and the main swap chain.

Vulkan: in updateResolution, iterate m_windows and call FrameBufferVK::update
on each valid secondary framebuffer so SwapChainVK::update sees the new
BGFX_RESET_VSYNC and recreates the swapchain with the correct present mode.

OpenGL (WGL/EGL): wglSwapIntervalEXT is per-context, eglSwapInterval is
per-surface. Cache the desired interval in GlContext::m_swapInterval and
re-apply it in makeCurrent() whenever a different context/surface becomes
current, so secondary SwapChainGL instances pick up the current value. Also
honor the initial BGFX_RESET_VSYNC flag in create() instead of hard-coding 0.
2026-04-19 22:35:57 +00:00
Branimir Karadžić
4481b9b46b Cleanup. (#3674) 2026-04-19 16:49:37 +00:00
Vincent Bousquet
d0def7d137 DX12: use discard instead of sequential flip (#3667) 2026-04-19 16:46:31 +00:00
Branimir Karadžić
6c820091e4 macOS: Fixed deprecated warning. (#3672) 2026-04-19 01:36:19 +00:00
Branimir Karadžić
234281e4ec Metal: Improved texture format caps. (#3671) 2026-04-18 12:34:25 -07:00
Branimir Karadžić
ef52d84ca4 Cleanup. (#3670) 2026-04-18 18:43:48 +00:00
Branimir Karadžić
c5df1d91e8 Cleanup. (#3669) 2026-04-18 06:11:44 +00:00
Branimir Karadžić
f89839ddb8 Use uint32_t for stream mask instead of uint8_t. (#3668) 2026-04-17 23:51:33 +00:00
Branimir Karadžić
a721b869ea WebGPU: Populate texture format caps from specs. (#3665) 2026-04-17 06:19:03 +00:00
Branimir Karadžić
0b0ddb7f6b Added generate mips on frame buffer resolve. (#3664) 2026-04-17 05:04:57 +00:00
MatthewBeshay
a2d3c83f0d Fix D3D12 fragment shader constant buffer misalignment (#3663)
The fragment shader CBV address was computed as gpuAddress + vsh->m_size,
but D3D12 requires constant buffer view addresses to be 256-byte aligned
(D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT). When the vertex shader
constant buffer exceeds 256 bytes without being a multiple of 256, the
fragment shader reads from a misaligned address, producing corrupt uniform
values.

This causes rendering artifacts or completely black output for any shader
program where the VS constant buffer size is not a multiple of 256 bytes,
since the fragment shader receives incorrect uniform data (e.g. a non-zero
alpha reference threshold that discards all pixels).

The fix aligns the VS constant buffer size to 256 bytes before placing the
FS constants, and uses the aligned offset when computing the FS CBV address
in both the main render loop and the blitter path.
2026-04-15 21:10:01 +00:00
Vincent Bousquet
e9a4f671bc DX12: fix invalid state when creating a BLIT_DST texture without mem block (#3656)
* DX12: fix invalid state when creating a BLIT_DST texture without mem block

* Only set state when it's not external texture.

---------

Co-authored-by: Branimir Karadžić <branimirkaradzic@gmail.com>
2026-04-14 23:28:37 +00:00
Branimir Karadžić
cc109f587b GLES: Fixed D32 RBO format. (#3662) 2026-04-14 03:59:42 +00:00
Бранимир Караџић
e21258414d Updated ImGui. 2026-04-12 22:41:36 -07:00