Skip to content

Commit 5046fa0

Browse files
authored
Upgrade BGFX (#8)
1 parent c278855 commit 5046fa0

File tree

422 files changed

+33747
-30319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+33747
-30319
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ Minimal is `0.14.0-dev.2577+271452d22` a.k.a `2024.11.0-mach`. But you know try
4141

4242
## Bgfx version
4343

44-
- [BX](https://github.com/bkaradzic/bx/commit/b8741eaf6f90ee3b332e36e9e9d958645e916ef0)
45-
- [BImg](https://github.com/bkaradzic/bimg/commit/aaf9125234e657393f504404a279289669d89fcb)
46-
- [BGFX](https://github.com/bkaradzic/bgfx/commit/dd4199bcb37426326e0e31419e99c10701e96c58)
44+
- [BX](https://github.com/bkaradzic/bx//compare/01c99ddd0912c5ecf56d9522f287c6c67aa3ad14...master)
45+
- [BImg](https://github.com/bkaradzic/bimg/compare/c5c7b6e1874cf60caa18b643391f5122f89a4ca8...master)
46+
- [BGFX](https://github.com/bkaradzic/bgfx/compare/de56398919b875b27b629c0b62f119c338c081d8...master)
4747

4848
## Getting started
4949

build.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn build(b: *std.Build) !void {
4343
"-Wno-microsoft-const-init",
4444
"-Wno-deprecated-declarations",
4545
"-Wno-tautological-constant-compare",
46+
"-Wno-error=date-time",
4647
};
4748
const cxx_options = common_options ++ [_][]const u8{
4849
"-std=c++17",
@@ -792,6 +793,7 @@ const spirv_opt_files = .{
792793
spirv_opt_path ++ "source/name_mapper.cpp",
793794
spirv_opt_path ++ "source/opcode.cpp",
794795
spirv_opt_path ++ "source/operand.cpp",
796+
spirv_opt_path ++ "source/to_string.cpp",
795797
spirv_opt_path ++ "source/opt/aggressive_dead_code_elim_pass.cpp",
796798
spirv_opt_path ++ "source/opt/amd_ext_to_khr.cpp",
797799
spirv_opt_path ++ "source/opt/analyze_live_input_pass.cpp",
@@ -911,6 +913,7 @@ const spirv_opt_files = .{
911913
spirv_opt_path ++ "source/opt/workaround1209.cpp",
912914
spirv_opt_path ++ "source/opt/wrap_opkill.cpp",
913915
spirv_opt_path ++ "source/opt/opextinst_forward_ref_fixup_pass.cpp",
916+
spirv_opt_path ++ "source/opt/struct_packing_pass.cpp",
914917
spirv_opt_path ++ "source/parsed_operand.cpp",
915918
spirv_opt_path ++ "source/print.cpp",
916919
spirv_opt_path ++ "source/reduce/change_operand_reduction_opportunity.cpp",
@@ -1000,4 +1003,5 @@ const spirv_opt_files = .{
10001003
spirv_opt_path ++ "source/val/validate_small_type_uses.cpp",
10011004
spirv_opt_path ++ "source/val/validate_type.cpp",
10021005
spirv_opt_path ++ "source/val/validation_state.cpp",
1006+
spirv_opt_path ++ "source/val/validate_tensor_layout.cpp",
10031007
};

libs/bgfx/3rdparty/cgltf/cgltf.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,14 @@ typedef struct cgltf_iridescence
500500
cgltf_texture_view iridescence_thickness_texture;
501501
} cgltf_iridescence;
502502

503+
typedef struct cgltf_diffuse_transmission
504+
{
505+
cgltf_texture_view diffuse_transmission_texture;
506+
cgltf_float diffuse_transmission_factor;
507+
cgltf_float diffuse_transmission_color_factor[3];
508+
cgltf_texture_view diffuse_transmission_color_texture;
509+
} cgltf_diffuse_transmission;
510+
503511
typedef struct cgltf_anisotropy
504512
{
505513
cgltf_float anisotropy_strength;
@@ -525,6 +533,7 @@ typedef struct cgltf_material
525533
cgltf_bool has_sheen;
526534
cgltf_bool has_emissive_strength;
527535
cgltf_bool has_iridescence;
536+
cgltf_bool has_diffuse_transmission;
528537
cgltf_bool has_anisotropy;
529538
cgltf_bool has_dispersion;
530539
cgltf_pbr_metallic_roughness pbr_metallic_roughness;
@@ -537,6 +546,7 @@ typedef struct cgltf_material
537546
cgltf_volume volume;
538547
cgltf_emissive_strength emissive_strength;
539548
cgltf_iridescence iridescence;
549+
cgltf_diffuse_transmission diffuse_transmission;
540550
cgltf_anisotropy anisotropy;
541551
cgltf_dispersion dispersion;
542552
cgltf_texture_view normal_texture;
@@ -844,6 +854,8 @@ void cgltf_node_transform_world(const cgltf_node* node, cgltf_float* out_matrix)
844854

845855
const uint8_t* cgltf_buffer_view_data(const cgltf_buffer_view* view);
846856

857+
const cgltf_accessor* cgltf_find_accessor(const cgltf_primitive* prim, cgltf_attribute_type type, cgltf_int index);
858+
847859
cgltf_bool cgltf_accessor_read_float(const cgltf_accessor* accessor, cgltf_size index, cgltf_float* out, cgltf_size element_size);
848860
cgltf_bool cgltf_accessor_read_uint(const cgltf_accessor* accessor, cgltf_size index, cgltf_uint* out, cgltf_size element_size);
849861
cgltf_size cgltf_accessor_read_index(const cgltf_accessor* accessor, cgltf_size index);
@@ -2312,6 +2324,18 @@ const uint8_t* cgltf_buffer_view_data(const cgltf_buffer_view* view)
23122324
return result;
23132325
}
23142326

2327+
const cgltf_accessor* cgltf_find_accessor(const cgltf_primitive* prim, cgltf_attribute_type type, cgltf_int index)
2328+
{
2329+
for (cgltf_size i = 0; i < prim->attributes_count; ++i)
2330+
{
2331+
const cgltf_attribute* attr = &prim->attributes[i];
2332+
if (attr->type == type && attr->index == index)
2333+
return attr->data;
2334+
}
2335+
2336+
return NULL;
2337+
}
2338+
23152339
cgltf_bool cgltf_accessor_read_float(const cgltf_accessor* accessor, cgltf_size index, cgltf_float* out, cgltf_size element_size)
23162340
{
23172341
if (accessor->is_sparse)
@@ -4278,6 +4302,52 @@ static int cgltf_parse_json_iridescence(cgltf_options* options, jsmntok_t const*
42784302
return i;
42794303
}
42804304

4305+
static int cgltf_parse_json_diffuse_transmission(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_diffuse_transmission* out_diff_transmission)
4306+
{
4307+
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4308+
int size = tokens[i].size;
4309+
++i;
4310+
4311+
// Defaults
4312+
cgltf_fill_float_array(out_diff_transmission->diffuse_transmission_color_factor, 3, 1.0f);
4313+
out_diff_transmission->diffuse_transmission_factor = 0.f;
4314+
4315+
for (int j = 0; j < size; ++j)
4316+
{
4317+
CGLTF_CHECK_KEY(tokens[i]);
4318+
4319+
if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionFactor") == 0)
4320+
{
4321+
++i;
4322+
out_diff_transmission->diffuse_transmission_factor = cgltf_json_to_float(tokens + i, json_chunk);
4323+
++i;
4324+
}
4325+
else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionTexture") == 0)
4326+
{
4327+
i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_diff_transmission->diffuse_transmission_texture);
4328+
}
4329+
else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionColorFactor") == 0)
4330+
{
4331+
i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_diff_transmission->diffuse_transmission_color_factor, 3);
4332+
}
4333+
else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionColorTexture") == 0)
4334+
{
4335+
i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_diff_transmission->diffuse_transmission_color_texture);
4336+
}
4337+
else
4338+
{
4339+
i = cgltf_skip_json(tokens, i + 1);
4340+
}
4341+
4342+
if (i < 0)
4343+
{
4344+
return i;
4345+
}
4346+
}
4347+
4348+
return i;
4349+
}
4350+
42814351
static int cgltf_parse_json_anisotropy(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_anisotropy* out_anisotropy)
42824352
{
42834353
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
@@ -4766,6 +4836,11 @@ static int cgltf_parse_json_material(cgltf_options* options, jsmntok_t const* to
47664836
out_material->has_iridescence = 1;
47674837
i = cgltf_parse_json_iridescence(options, tokens, i + 1, json_chunk, &out_material->iridescence);
47684838
}
4839+
else if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_materials_diffuse_transmission") == 0)
4840+
{
4841+
out_material->has_diffuse_transmission = 1;
4842+
i = cgltf_parse_json_diffuse_transmission(options, tokens, i + 1, json_chunk, &out_material->diffuse_transmission);
4843+
}
47694844
else if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_materials_anisotropy") == 0)
47704845
{
47714846
out_material->has_anisotropy = 1;
@@ -6629,6 +6704,9 @@ static int cgltf_fixup_pointers(cgltf_data* data)
66296704
CGLTF_PTRFIXUP(data->materials[i].iridescence.iridescence_texture.texture, data->textures, data->textures_count);
66306705
CGLTF_PTRFIXUP(data->materials[i].iridescence.iridescence_thickness_texture.texture, data->textures, data->textures_count);
66316706

6707+
CGLTF_PTRFIXUP(data->materials[i].diffuse_transmission.diffuse_transmission_texture.texture, data->textures, data->textures_count);
6708+
CGLTF_PTRFIXUP(data->materials[i].diffuse_transmission.diffuse_transmission_color_texture.texture, data->textures, data->textures_count);
6709+
66326710
CGLTF_PTRFIXUP(data->materials[i].anisotropy.anisotropy_texture.texture, data->textures, data->textures_count);
66336711
}
66346712

libs/bgfx/3rdparty/cgltf/cgltf_write.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
8888
#define CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY (1 << 16)
8989
#define CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION (1 << 17)
9090
#define CGLTF_EXTENSION_FLAG_TEXTURE_WEBP (1 << 18)
91+
#define CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION (1 << 19)
9192

9293
typedef struct {
9394
char* buffer;
@@ -656,6 +657,11 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
656657
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE;
657658
}
658659

660+
if (material->has_diffuse_transmission)
661+
{
662+
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION;
663+
}
664+
659665
if (material->has_anisotropy)
660666
{
661667
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY;
@@ -681,7 +687,7 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
681687
cgltf_write_line(context, "}");
682688
}
683689

684-
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)
690+
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 || material->has_diffuse_transmission)
685691
{
686692
cgltf_write_line(context, "\"extensions\": {");
687693
if (material->has_clearcoat)
@@ -792,6 +798,19 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
792798
CGLTF_WRITE_TEXTURE_INFO("iridescenceThicknessTexture", params->iridescence_thickness_texture);
793799
cgltf_write_line(context, "}");
794800
}
801+
if (material->has_diffuse_transmission)
802+
{
803+
const cgltf_diffuse_transmission* params = &material->diffuse_transmission;
804+
cgltf_write_line(context, "\"KHR_materials_diffuse_transmission\": {");
805+
CGLTF_WRITE_TEXTURE_INFO("diffuseTransmissionTexture", params->diffuse_transmission_texture);
806+
cgltf_write_floatprop(context, "diffuseTransmissionFactor", params->diffuse_transmission_factor, 0.f);
807+
if (cgltf_check_floatarray(params->diffuse_transmission_color_factor, 3, 1.f))
808+
{
809+
cgltf_write_floatarrayprop(context, "diffuseTransmissionColorFactor", params->diffuse_transmission_color_factor, 3);
810+
}
811+
CGLTF_WRITE_TEXTURE_INFO("diffuseTransmissionColorTexture", params->diffuse_transmission_color_texture);
812+
cgltf_write_line(context, "}");
813+
}
795814
if (material->has_anisotropy)
796815
{
797816
cgltf_write_line(context, "\"KHR_materials_anisotropy\": {");
@@ -1298,6 +1317,9 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
12981317
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE) {
12991318
cgltf_write_stritem(context, "KHR_materials_iridescence");
13001319
}
1320+
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION) {
1321+
cgltf_write_stritem(context, "KHR_materials_diffuse_transmission");
1322+
}
13011323
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY) {
13021324
cgltf_write_stritem(context, "KHR_materials_anisotropy");
13031325
}

0 commit comments

Comments
 (0)