Skip to content

Commit

Permalink
Upgrade BGFX (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraVoves committed Aug 23, 2024
1 parent 2e9e96d commit 08401c1
Show file tree
Hide file tree
Showing 206 changed files with 13,472 additions and 5,456 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ contributed to the project prior to the project being hosted on GitHub. See the
GitHub commit log for a list of recent contributors. We would like to thank
everyone who has contributed to the project in any way.

* __[Sam Loeschen](https://github.com/samloeschen)__
* __[Sam Loeschen](https://github.com/samloeschen)__
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ When [zig](https://github.com/ziglang/zig) meets [bgfx](https://github.com/bkara
- [x] `shaderc` as build artifact.
- [x] Shader compile in `build.zig` to `*.bin.h`.
- [x] Shader compile in `build.zig` and embed as zig module. (this is zig equivalent of `*.bin.h`)
- [x] Shader compile from code (in memory solution, no tmp files).
- [ ] Shader compile from runtime via `shaderc` as child process.
- [x] Experimental shader compile from runtime via embeded `shaderc`.
- [x] Binding for [DebugDraw API](https://github.com/bkaradzic/bgfx/tree/master/examples/common/debugdraw)
- [x] `imgui` render backend. Use build option `imgui_include` to enable. ex. for
zgui: `.imgui_include = zgui.path("libs").getPath(b),`
Expand All @@ -38,6 +39,12 @@ Zig binding is licensed by [WTFPL](LICENSE)

Minimal is `0.13.0`. But you know try your version and believe.

## Bgfx version

- [BX](https://github.com/bkaradzic/bx/commit/e7ede513dc8b90386960587e348c73b241f7735d)
- [BImg](https://github.com/bkaradzic/bimg/commit/2afa64c14c1e3dd5d28412ee03bee0dfe7242f03)
- [BGFX](https://github.com/bkaradzic/bgfx/commit/74e7edccdc340a56e862c1234626dbb276e88553)

## Getting started

Copy `zbgfx` to a subdirectory of your project and add the following to your `build.zig.zon` .dependencies:
Expand Down
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub fn build(b: *std.Build) !void {

"-Wno-microsoft-enum-value",
"-Wno-microsoft-const-init",
"-Wno-deprecated-declarations",
"-Wno-tautological-constant-compare",
};
const cxx_options = common_options ++ [_][]const u8{
"-std=c++17",
Expand Down Expand Up @@ -921,6 +923,7 @@ const spirv_opt_files = .{
spirv_opt_path ++ "source/opt/vector_dce.cpp",
spirv_opt_path ++ "source/opt/workaround1209.cpp",
spirv_opt_path ++ "source/opt/wrap_opkill.cpp",
spirv_opt_path ++ "source/opt/opextinst_forward_ref_fixup_pass.cpp",
spirv_opt_path ++ "source/parsed_operand.cpp",
spirv_opt_path ++ "source/print.cpp",
spirv_opt_path ++ "source/reduce/change_operand_reduction_opportunity.cpp",
Expand Down
37 changes: 37 additions & 0 deletions libs/bgfx/3rdparty/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
root = true

[etc1/*]
indent_style = space
indent_size = 4

[fcpp/*]
indent_style = space
indent_size = 2

[iqa/*]
indent_style = tab
indent_size = 4

[libsquish/*]
indent_style = tab
indent_size = 4

[dear-imgui/*]
indent_style = space
indent_size = 4

[dear-imgui/*.inl]
indent_style = space
indent_size = 4

[pvrtc/*]
indent_style = space
indent_size = 4

[remotery/*]
indent_style = space
indent_size = 4

[glsl-optimizer/*]
indent_style = space
indent_size = 3
60 changes: 58 additions & 2 deletions libs/bgfx/3rdparty/cgltf/cgltf.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* cgltf - a single-file glTF 2.0 parser written in C99.
*
* Version: 1.13
* Version: 1.14
*
* Website: https://github.com/jkuhlmann/cgltf
*
Expand Down Expand Up @@ -505,6 +505,11 @@ typedef struct cgltf_anisotropy
cgltf_texture_view anisotropy_texture;
} cgltf_anisotropy;

typedef struct cgltf_dispersion
{
cgltf_float dispersion;
} cgltf_dispersion;

typedef struct cgltf_material
{
char* name;
Expand All @@ -519,6 +524,7 @@ typedef struct cgltf_material
cgltf_bool has_emissive_strength;
cgltf_bool has_iridescence;
cgltf_bool has_anisotropy;
cgltf_bool has_dispersion;
cgltf_pbr_metallic_roughness pbr_metallic_roughness;
cgltf_pbr_specular_glossiness pbr_specular_glossiness;
cgltf_clearcoat clearcoat;
Expand All @@ -530,6 +536,7 @@ typedef struct cgltf_material
cgltf_emissive_strength emissive_strength;
cgltf_iridescence iridescence;
cgltf_anisotropy anisotropy;
cgltf_dispersion dispersion;
cgltf_texture_view normal_texture;
cgltf_texture_view occlusion_texture;
cgltf_texture_view emissive_texture;
Expand Down Expand Up @@ -1690,7 +1697,20 @@ cgltf_result cgltf_validate(cgltf_data* data)
{
if (data->nodes[i].weights && data->nodes[i].mesh)
{
CGLTF_ASSERT_IF (data->nodes[i].mesh->primitives_count && data->nodes[i].mesh->primitives[0].targets_count != data->nodes[i].weights_count, cgltf_result_invalid_gltf);
CGLTF_ASSERT_IF(data->nodes[i].mesh->primitives_count && data->nodes[i].mesh->primitives[0].targets_count != data->nodes[i].weights_count, cgltf_result_invalid_gltf);
}

if (data->nodes[i].has_mesh_gpu_instancing)
{
CGLTF_ASSERT_IF(data->nodes[i].mesh == NULL, cgltf_result_invalid_gltf);
CGLTF_ASSERT_IF(data->nodes[i].mesh_gpu_instancing.attributes_count == 0, cgltf_result_invalid_gltf);

cgltf_accessor* first = data->nodes[i].mesh_gpu_instancing.attributes[0].data;

for (cgltf_size k = 0; k < data->nodes[i].mesh_gpu_instancing.attributes_count; ++k)
{
CGLTF_ASSERT_IF(data->nodes[i].mesh_gpu_instancing.attributes[k].data->count != first->count, cgltf_result_invalid_gltf);
}
}
}

Expand Down Expand Up @@ -4297,6 +4317,37 @@ static int cgltf_parse_json_anisotropy(cgltf_options* options, jsmntok_t const*
return i;
}

static int cgltf_parse_json_dispersion(jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_dispersion* out_dispersion)
{
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
int size = tokens[i].size;
++i;


for (int j = 0; j < size; ++j)
{
CGLTF_CHECK_KEY(tokens[i]);

if (cgltf_json_strcmp(tokens + i, json_chunk, "dispersion") == 0)
{
++i;
out_dispersion->dispersion = cgltf_json_to_float(tokens + i, json_chunk);
++i;
}
else
{
i = cgltf_skip_json(tokens, i + 1);
}

if (i < 0)
{
return i;
}
}

return i;
}

static int cgltf_parse_json_image(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_image* out_image)
{
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
Expand Down Expand Up @@ -4690,6 +4741,11 @@ static int cgltf_parse_json_material(cgltf_options* options, jsmntok_t const* to
out_material->has_anisotropy = 1;
i = cgltf_parse_json_anisotropy(options, tokens, i + 1, json_chunk, &out_material->anisotropy);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_materials_dispersion") == 0)
{
out_material->has_dispersion = 1;
i = cgltf_parse_json_dispersion(tokens, i + 1, json_chunk, &out_material->dispersion);
}
else
{
i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_material->extensions[out_material->extensions_count++]));
Expand Down
20 changes: 18 additions & 2 deletions libs/bgfx/3rdparty/cgltf/cgltf_write.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* cgltf_write - a single-file glTF 2.0 writer written in C99.
*
* Version: 1.13
* Version: 1.14
*
* Website: https://github.com/jkuhlmann/cgltf
*
Expand Down Expand Up @@ -86,6 +86,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
#define CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING (1 << 14)
#define CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE (1 << 15)
#define CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY (1 << 16)
#define CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION (1 << 17)

typedef struct {
char* buffer;
Expand Down Expand Up @@ -659,6 +660,11 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY;
}

if (material->has_dispersion)
{
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION;
}

if (material->has_pbr_metallic_roughness)
{
const cgltf_pbr_metallic_roughness* params = &material->pbr_metallic_roughness;
Expand All @@ -674,7 +680,7 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
cgltf_write_line(context, "}");
}

if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_ior || material->has_specular || material->has_transmission || material->has_sheen || material->has_volume || material->has_emissive_strength || material->has_iridescence || material->has_anisotropy)
if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_ior || material->has_specular || material->has_transmission || material->has_sheen || material->has_volume || material->has_emissive_strength || material->has_iridescence || material->has_anisotropy || material->has_dispersion)
{
cgltf_write_line(context, "\"extensions\": {");
if (material->has_clearcoat)
Expand Down Expand Up @@ -794,6 +800,13 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
CGLTF_WRITE_TEXTURE_INFO("anisotropyTexture", params->anisotropy_texture);
cgltf_write_line(context, "}");
}
if (material->has_dispersion)
{
cgltf_write_line(context, "\"KHR_materials_dispersion\": {");
const cgltf_dispersion* params = &material->dispersion;
cgltf_write_floatprop(context, "dispersion", params->dispersion, 0.f);
cgltf_write_line(context, "}");
}
cgltf_write_line(context, "}");
}

Expand Down Expand Up @@ -1279,6 +1292,9 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
if (extension_flags & CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING) {
cgltf_write_stritem(context, "EXT_mesh_gpu_instancing");
}
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION) {
cgltf_write_stritem(context, "KHR_materials_dispersion");
}
}

cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size size, const cgltf_data* data)
Expand Down
Loading

0 comments on commit 08401c1

Please sign in to comment.