Commit Graph

9240 Commits

Author SHA1 Message Date
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
Бранимир Караџић
f05eef4900 Updated Vulkan headers. 2026-04-12 22:41:36 -07:00
Бранимир Караџић
8e560ad663 Updated spirv-tools. 2026-04-12 22:41:36 -07:00
Бранимир Караџић
19e597d991 Updated spirv-cross. 2026-04-12 22:41:36 -07:00
Бранимир Караџић
dd28ebda36 Updated spirv-headers. 2026-04-12 22:41:36 -07:00
Бранимир Караџић
fe9c1c93db Updated glslang. 2026-04-12 22:41:36 -07:00
Branimir Karadžić
6c8954f7da Set default project properly. (#3660) 2026-04-13 01:31:53 +00:00
Branimir Karadžić
f3ad0e91af Removed bgfx::weldVertices. (#3659) 2026-04-13 01:30:57 +00:00
Branimir Karadžić
2e49e0e38a GLES: Fixed ANGLE issues. (#3658) 2026-04-10 04:05:34 +00:00
Vincent Bousquet
173be4d0fa DX12: fix blitting inside a texture 2D array (#3657) 2026-04-09 21:21:17 +00:00
Vincent Bousquet
8a070c8e27 Vulkan: fix missing swapchain image acquire semaphore (#3655) 2026-04-09 21:20:28 +00:00
Branimir Karadžić
48a1f88bcc VK: Lazy transition texture state, instead of bitching about it. (#3653) 2026-04-07 21:03:08 +00:00
Branimir Karadžić
23afca44d8 Expand cone to pass overlap test. (#3652) 2026-04-04 21:54:19 -07:00
Branimir Karadžić
7c0d813b83 Remove unused shader parsers. (#3651)
* Removed shader parsers.

* Removed shader parsers.
2026-04-05 02:54:27 +00:00
Any
fc29f359f3 Fix out-of-bounds access in the bndCaretPosition->nvgTextGlyphPositions of the nanovg example. (#3650) 2026-04-02 16:12:57 +00:00
Branimir Karadžić
9a1ce9c60b Fixed #3647. (#3648) 2026-03-31 16:34:09 -07:00
Branimir Karadžić
8532b2c45d Fix race between bgfx::begin and bgfx::frame encoder allocation. (#3646)
* Fix race between bgfx::begin and bgfx::frame encoder allocation.

* Update src/bgfx.cpp

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

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-25 21:36:02 -07:00
Jason Millard
9c98438372 metal: isDepth24Stencil8PixelFormatSupported is only available on macOS (#3645) 2026-03-24 23:09:10 +00:00
Branimir Karadžić
f1ff08a799 shaderc: Fixed GLSL 140. (#3644) 2026-03-24 05:32:52 +00:00
Matteo Valdina
fd8d480b28 Fix x86 crash: CreateTexture command buffer read uses wrong type (#3643)
The _external parameter is written to the command buffer as uint64_t (8 bytes)
but read back as uintptr_t (4 bytes on 32-bit). This causes a 4-byte
deserialization misalignment on x86, corrupting all subsequent command
buffer reads and leading to EXCEPTION_ACCESS_VIOLATION (0xC0000005) during
D3D11 initialization.

Co-authored-by: Matteo Valdina <mavaldin@microsoft.com>
2026-03-23 16:05:18 +00:00
Branimir Karadžić
a7016487e5 Added 51-gpufont example. (#3641) 2026-03-23 02:34:05 +00:00
Branimir Karadžić
3118337be2 VK: Fixed crash when using BGFX_FRAME_FLUSH. (#3640) 2026-03-22 07:09:15 +00:00
Branimir Karadžić
681320668d Add GPU device info. (#3639) 2026-03-21 22:39:57 +00:00
Branimir Karadžić
f3f4e04636 Makefile: Detect if sh is present. (#3638) 2026-03-21 21:59:03 +00:00