Skip to content

Commit be91c76

Browse files
OndraVovesOndra Voves
authored andcommitted
Upgrade BGFX. (#5)
Reviewed-on: https://codeberg.org/cyberegoorg/zbgfx/pulls/5 Co-authored-by: Ondra Voves <email@ondravoves.cz> Co-committed-by: Ondra Voves <email@ondravoves.cz>
1 parent 99a09cb commit be91c76

7 files changed

Lines changed: 37 additions & 36 deletions

File tree

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
timeout-minutes: 3
3939
steps:
4040
- name: Checkout
41-
uses: actions/checkout@v4
41+
uses: actions/checkout@v5
4242
with:
4343
submodules: true
4444

@@ -63,7 +63,7 @@ jobs:
6363
timeout-minutes: 15
6464
steps:
6565
- name: Checkout
66-
uses: actions/checkout@v4
66+
uses: actions/checkout@v5
6767
with:
6868
submodules: false
6969

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Minimal is `0.15.1`. But you know try your version and believe.
4040

4141
- [BX](https://github.com/bkaradzic/bx/compare/cac72f6cfa0893393ea12692ebfacb4495f8c826...master)
4242
- [BImg](https://github.com/bkaradzic/bimg/compare/9114b47f532ce59cd0c6c9f8932df2c48888d4c1...master)
43-
- [BGFX](https://github.com/bkaradzic/bgfx/compare/a7016487e5970c5299bb837f1af42dcb24909a67...master)
43+
- [BGFX](https://github.com/bkaradzic/bgfx/compare/8532b2c45d2f4332a9ac9734b85c2ea2253cb8d5...master)
4444

4545
## Getting started
4646

@@ -55,16 +55,15 @@ or use `zig fetch --save ...` way.
5555
Then in your `build.zig` add:
5656

5757
```zig
58+
const zbgfx = @import("zbgfx");
59+
5860
pub fn build(b: *std.Build) void {
5961
const exe = b.addExecutable(.{ ... });
6062
61-
const zbgfx = b.dependency("zbgfx", .{});
62-
exe.root_module.addImport("zbgfx", zbgfx.module("zbgfx"));
63+
const zbgfx_dep = b.dependency("zbgfx", .{});
64+
exe.root_module.addImport("zbgfx", zbgfx_dep.module("zbgfx"));
6365
exe.linkLibrary(zbgfx.artifact("bgfx"));
64-
65-
// This install shaderc to install dir
66-
// For shader build in build =D check examples
67-
// b.installArtifact(zbgfx.artifact("shaderc"));
66+
_ = try zbgfx.build_step.installShaderc(b, zbgfx_dep);
6867
}
6968
```
7069

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .zbgfx,
33
.fingerprint = 0xc48ed871c4086e4a,
4-
.version = "0.9.0",
4+
.version = "0.10.0",
55
.minimum_zig_version = "0.15.2",
66
.paths = .{
77
"includes",

libs/bgfx/src/bgfx.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,8 @@ namespace bgfx
24052405
if (_forceNewEncoder
24062406
|| BGFX_API_THREAD_MAGIC != s_threadIndex)
24072407
{
2408-
bx::MutexScope scopeLock(m_encoderApiLock);
2408+
bx::MutexScope beginLockScope(m_encoderBeginLock);
2409+
bx::MutexScope encoderApiScope(m_encoderApiLock);
24092410

24102411
uint16_t idx = m_encoderHandle->alloc();
24112412
if (kInvalidHandle == idx)
@@ -2442,14 +2443,20 @@ namespace bgfx
24422443
m_encoder[0].end(true);
24432444

24442445
#if BGFX_CONFIG_MULTITHREADED
2445-
bx::MutexScope resourceApiScope(m_resourceApiLock);
2446-
2447-
encoderApiWait();
2446+
m_encoderBeginLock.lock(); // don't let any bgfx::begin calls...
2447+
encoderApiWait(); // wait for all started encoders to return...
24482448
bx::MutexScope encoderApiScope(m_encoderApiLock);
2449+
m_encoderBeginLock.unlock();
2450+
2451+
bx::MutexScope resourceApiScope(m_resourceApiLock);
24492452
#else
24502453
encoderApiWait();
24512454
#endif // BGFX_CONFIG_MULTITHREADED
24522455

2456+
m_encoderHandle->reset();
2457+
const uint16_t idx = m_encoderHandle->alloc();
2458+
BX_ASSERT(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx);
2459+
24532460
if (0 != (_flags & BGFX_FRAME_DISCARD) )
24542461
{
24552462
m_submit->m_numRenderItems = 0;
@@ -3344,7 +3351,7 @@ namespace bgfx
33443351
uint8_t skip;
33453352
_cmdbuf.read(skip);
33463353

3347-
uintptr_t external;
3354+
uint64_t external;
33483355
_cmdbuf.read(external);
33493356

33503357
void* ptr = m_renderCtx->createTexture(handle, mem, flags, skip, external);

libs/bgfx/src/bgfx_p.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5921,16 +5921,13 @@ namespace bgfx
59215921
}
59225922

59235923
m_submit->m_perfStats.numEncoders = uint8_t(numEncoders);
5924-
5925-
m_encoderHandle->reset();
5926-
uint16_t idx = m_encoderHandle->alloc();
5927-
BX_ASSERT(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx);
59285924
}
59295925

59305926
bx::Semaphore m_renderSem;
59315927
bx::Semaphore m_apiSem;
59325928
bx::Semaphore m_encoderEndSem;
59335929
bx::Mutex m_encoderApiLock;
5930+
bx::Mutex m_encoderBeginLock;
59345931
bx::Mutex m_resourceApiLock;
59355932
bx::Thread m_thread;
59365933
#else

libs/bgfx/src/renderer_mtl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
784784
g_caps.formats[TextureFormat::RGBA32F] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA);
785785
}
786786

787-
s_textureFormat[TextureFormat::D24S8].m_fmt = m_device->isDepth24Stencil8PixelFormatSupported()
787+
s_textureFormat[TextureFormat::D24S8].m_fmt = BX_ENABLED(BX_PLATFORM_OSX) && m_device->isDepth24Stencil8PixelFormatSupported()
788788
? MTL::PixelFormatDepth24Unorm_Stencil8
789789
: MTL::PixelFormatDepth32Float_Stencil8
790790
;

libs/bgfx/tools/shaderc/shaderc.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,11 +2452,24 @@ namespace bgfx
24522452

24532453
bx::stringPrintf(code, "#version %d\n", need130 ? 130 : glsl_profile);
24542454

2455-
if (need130)
2455+
if (need130
2456+
|| glsl_profile >= 130)
24562457
{
2458+
bx::stringPrintf(code, "#define attribute in\n");
24572459
bx::stringPrintf(code, "#define varying %s\n"
24582460
, 'f' == _options.shaderType ? "in" : "out"
24592461
);
2462+
bx::stringPrintf(code
2463+
, "#define bgfxShadow2D(_sampler, _coord) vec4_splat(texture(_sampler, _coord) )\n"
2464+
"#define bgfxShadow2DProj(_sampler, _coord) vec4_splat(textureProj(_sampler, _coord) )\n"
2465+
);
2466+
}
2467+
else
2468+
{
2469+
bx::stringPrintf(code
2470+
, "#define bgfxShadow2D shadow2D\n"
2471+
"#define bgfxShadow2DProj shader2DProj\n"
2472+
);
24602473
}
24612474

24622475
if (usesInstanceID)
@@ -2547,21 +2560,6 @@ namespace bgfx
25472560
"#define textureCubeGrad textureCubeGradEXT\n"
25482561
);
25492562
}
2550-
2551-
if (need130 || (glsl_profile >= 130) )
2552-
{
2553-
bx::stringPrintf(code
2554-
, "#define bgfxShadow2D(_sampler, _coord) vec4_splat(texture(_sampler, _coord) )\n"
2555-
"#define bgfxShadow2DProj(_sampler, _coord) vec4_splat(textureProj(_sampler, _coord) )\n"
2556-
);
2557-
}
2558-
else
2559-
{
2560-
bx::stringPrintf(code
2561-
, "#define bgfxShadow2D shadow2D\n"
2562-
"#define bgfxShadow2DProj shader2DProj\n"
2563-
);
2564-
}
25652563
}
25662564
else
25672565
{

0 commit comments

Comments
 (0)