From 2ad67a4dfd721c266d2286ce5ad19a64e1373531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Fri, 29 Mar 2024 16:36:55 -0700 Subject: [PATCH] Cleanup. --- bindings/bf/bgfx.bf | 13 +-- bindings/cs/bgfx.cs | 13 +-- bindings/d/package.d | 18 ++-- bindings/zig/bgfx.zig | 28 ++++--- examples/09-hdr/hdr.cpp | 2 +- examples/33-pom/pom.cpp | 2 +- include/bgfx/bgfx.h | 23 +++-- include/bgfx/c99/bgfx.h | 22 +++-- include/bgfx/defines.h | 2 +- scripts/bgfx.idl | 16 ++-- src/bgfx.cpp | 38 ++++----- src/bgfx.idl.inl | 12 +-- src/bgfx_p.h | 34 ++++---- src/renderer_vk.cpp | 182 +++++++++++++++++++--------------------- src/shader_dxbc.cpp | 2 +- 15 files changed, 218 insertions(+), 189 deletions(-) diff --git a/bindings/bf/bgfx.bf b/bindings/bf/bgfx.bf index f1e634a8d..642e864db 100644 --- a/bindings/bf/bgfx.bf +++ b/bindings/bf/bgfx.bf @@ -3496,9 +3496,10 @@ public static class bgfx /// /// View id. /// View name. + /// View name length (if length is INT32_MAX, it's expected that _name is zero terminated string. /// [LinkName("bgfx_set_view_name")] - public static extern void set_view_name(ViewId _id, char8* _name); + public static extern void set_view_name(ViewId _id, char8* _name, int _len); /// /// Set view rectangle. Draw primitive outside view will be clipped. @@ -3651,10 +3652,11 @@ public static class bgfx /// graphics debugging tools. /// /// - /// Marker string. + /// Marker name. + /// Marker name length (if length is INT32_MAX, it's expected that _name is zero terminated string. /// [LinkName("bgfx_encoder_set_marker")] - public static extern void encoder_set_marker(Encoder* _this, char8* _marker); + public static extern void encoder_set_marker(Encoder* _this, char8* _name, int _len); /// /// Set render states for draw primitive. @@ -4219,10 +4221,11 @@ public static class bgfx /// graphics debugging tools. /// /// - /// Marker string. + /// Marker name. + /// Marker name length (if length is INT32_MAX, it's expected that _name is zero terminated string. /// [LinkName("bgfx_set_marker")] - public static extern void set_marker(char8* _marker); + public static extern void set_marker(char8* _name, int _len); /// /// Set render states for draw primitive. diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index ed5430ff8..c228ee5d3 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -3452,9 +3452,10 @@ public static partial class bgfx /// /// View id. /// View name. + /// View name length (if length is INT32_MAX, it's expected that _name is zero terminated string. /// [DllImport(DllName, EntryPoint="bgfx_set_view_name", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void set_view_name(ushort _id, [MarshalAs(UnmanagedType.LPStr)] string _name); + public static extern unsafe void set_view_name(ushort _id, [MarshalAs(UnmanagedType.LPStr)] string _name, int _len); /// /// Set view rectangle. Draw primitive outside view will be clipped. @@ -3607,10 +3608,11 @@ public static partial class bgfx /// graphics debugging tools. /// /// - /// Marker string. + /// Marker name. + /// Marker name length (if length is INT32_MAX, it's expected that _name is zero terminated string. /// [DllImport(DllName, EntryPoint="bgfx_encoder_set_marker", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void encoder_set_marker(Encoder* _this, [MarshalAs(UnmanagedType.LPStr)] string _marker); + public static extern unsafe void encoder_set_marker(Encoder* _this, [MarshalAs(UnmanagedType.LPStr)] string _name, int _len); /// /// Set render states for draw primitive. @@ -4175,10 +4177,11 @@ public static partial class bgfx /// graphics debugging tools. /// /// - /// Marker string. + /// Marker name. + /// Marker name length (if length is INT32_MAX, it's expected that _name is zero terminated string. /// [DllImport(DllName, EntryPoint="bgfx_set_marker", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void set_marker([MarshalAs(UnmanagedType.LPStr)] string _marker); + public static extern unsafe void set_marker([MarshalAs(UnmanagedType.LPStr)] string _name, int _len); /// /// Set render states for draw primitive. diff --git a/bindings/d/package.d b/bindings/d/package.d index ebb3a204e..7679f9a60 100644 --- a/bindings/d/package.d +++ b/bindings/d/package.d @@ -10,7 +10,7 @@ import bindbc.bgfx.config; import bindbc.common.types: c_int64, c_uint64, va_list; static import bgfx.fakeenum; -enum uint apiVersion = 126; +enum uint apiVersion = 127; alias ViewID = ushort; @@ -1386,9 +1386,11 @@ extern(C++, "bgfx") struct Encoder{ Sets a debug marker. This allows you to group graphics calls together for easy browsing in graphics debugging tools. Params: - marker = Marker string. + name = Marker name. + len = Marker name length (if length is INT32_MAX, it's expected + that _name is zero terminated string. */ - {q{void}, q{setMarker}, q{const(char)* marker}, ext: `C++`}, + {q{void}, q{setMarker}, q{const(char)* name, int len=int.max}, ext: `C++`}, /** Set render states for draw primitive. @@ -2872,8 +2874,10 @@ mixin(joinFnBinds((){ Params: id = View id. name = View name. + len = View name length (if length is INT32_MAX, it's expected + that _name is zero terminated string. */ - {q{void}, q{setViewName}, q{ViewID id, const(char)* name}, ext: `C++, "bgfx"`}, + {q{void}, q{setViewName}, q{ViewID id, const(char)* name, int len=int.max}, ext: `C++, "bgfx"`}, /** * Set view rectangle. Draw primitive outside view will be clipped. @@ -3084,9 +3088,11 @@ mixin(joinFnBinds((){ * Sets a debug marker. This allows you to group graphics calls together for easy browsing in * graphics debugging tools. Params: - marker = Marker string. + name = Marker name. + len = Marker name length (if length is INT32_MAX, it's expected + that _name is zero terminated string. */ - {q{void}, q{setMarker}, q{const(char)* marker}, ext: `C++, "bgfx"`}, + {q{void}, q{setMarker}, q{const(char)* name, int len=int.max}, ext: `C++, "bgfx"`}, /** * Set render states for draw primitive. diff --git a/bindings/zig/bgfx.zig b/bindings/zig/bgfx.zig index 8114e0a25..62b058f6f 100644 --- a/bindings/zig/bgfx.zig +++ b/bindings/zig/bgfx.zig @@ -1549,9 +1549,10 @@ pub const Init = extern struct { pub const Encoder = opaque { /// Sets a debug marker. This allows you to group graphics calls together for easy browsing in /// graphics debugging tools. - /// Marker string. - pub inline fn setMarker(self: ?*Encoder, _marker: [*c]const u8) void { - return bgfx_encoder_set_marker(self, _marker); + /// Marker name. + /// Marker name length (if length is INT32_MAX, it's expected that _name is zero terminated string. + pub inline fn setMarker(self: ?*Encoder, _name: [*c]const u8, _len: i32) void { + return bgfx_encoder_set_marker(self, _name, _len); } /// Set render states for draw primitive. /// @remarks @@ -2811,10 +2812,11 @@ extern fn bgfx_set_palette_color_rgba8(_index: u8, _rgba: u32) void; /// +------ view id /// View id. /// View name. -pub inline fn setViewName(_id: ViewId, _name: [*c]const u8) void { - return bgfx_set_view_name(_id, _name); +/// View name length (if length is INT32_MAX, it's expected that _name is zero terminated string. +pub inline fn setViewName(_id: ViewId, _name: [*c]const u8, _len: i32) void { + return bgfx_set_view_name(_id, _name, _len); } -extern fn bgfx_set_view_name(_id: ViewId, _name: [*c]const u8) void; +extern fn bgfx_set_view_name(_id: ViewId, _name: [*c]const u8, _len: i32) void; /// Set view rectangle. Draw primitive outside view will be clipped. /// View id. @@ -2941,8 +2943,9 @@ extern fn bgfx_encoder_end(_encoder: ?*Encoder) void; /// Sets a debug marker. This allows you to group graphics calls together for easy browsing in /// graphics debugging tools. -/// Marker string. -extern fn bgfx_encoder_set_marker(self: ?*Encoder, _marker: [*c]const u8) void; +/// Marker name. +/// Marker name length (if length is INT32_MAX, it's expected that _name is zero terminated string. +extern fn bgfx_encoder_set_marker(self: ?*Encoder, _name: [*c]const u8, _len: i32) void; /// Set render states for draw primitive. /// @remarks @@ -3303,11 +3306,12 @@ extern fn bgfx_override_internal_texture(_handle: TextureHandle, _width: u16, _h /// Sets a debug marker. This allows you to group graphics calls together for easy browsing in /// graphics debugging tools. -/// Marker string. -pub inline fn setMarker(_marker: [*c]const u8) void { - return bgfx_set_marker(_marker); +/// Marker name. +/// Marker name length (if length is INT32_MAX, it's expected that _name is zero terminated string. +pub inline fn setMarker(_name: [*c]const u8, _len: i32) void { + return bgfx_set_marker(_name, _len); } -extern fn bgfx_set_marker(_marker: [*c]const u8) void; +extern fn bgfx_set_marker(_name: [*c]const u8, _len: i32) void; /// Set render states for draw primitive. /// @remarks diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 52a29a0f6..5d4d1a1c1 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -362,7 +362,7 @@ public: if (bgfx::isValid(m_rb) ) { - struct Packed { uint8_t bgra[4]; } arr = bx::bit_cast(m_lumBgra8); + struct Packed { uint8_t bgra[4]; } arr = bx::bitCast(m_lumBgra8); float exponent = arr.bgra[3] / 255.0f * 255.0f - 128.0f; float lumAvg = arr.bgra[2] / 255.0f * bx::exp2(exponent); diff --git a/examples/33-pom/pom.cpp b/examples/33-pom/pom.cpp index f4a810ace..de12003d6 100644 --- a/examples/33-pom/pom.cpp +++ b/examples/33-pom/pom.cpp @@ -45,7 +45,7 @@ uint32_t packF4u(float _x, float _y = 0.0f, float _z = 0.0f, float _w = 0.0f) arr.value[2] = uint8_t(_z * 127.0f + 128.0f); arr.value[3] = uint8_t(_w * 127.0f + 128.0f); - return bx::bit_cast(arr); + return bx::bitCast(arr); } static PosTangentBitangentTexcoordVertex s_cubeVertices[24] = diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 9369748a1..49cf0699f 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -1053,13 +1053,16 @@ namespace bgfx /// struct Encoder { - /// Sets a debug marker. This allows you to group - /// graphics calls together for easy browsing in - /// graphics debugging tools. + /// Sets a debug marker. This allows you to group graphics calls together for easy + /// browsing in graphics debugging tools. + /// + /// @param[in] _name Marker name. + /// @param[in] _len Marker name length (if length is INT32_MAX, it's expected that _name + /// is zero terminated string. /// /// @attention C99's equivalent binding is `bgfx_encoder_set_marker`. /// - void setMarker(const char* _marker); + void setMarker(const char* _name, int32_t _len = INT32_MAX); /// Set render states for draw primitive. /// @@ -3337,6 +3340,8 @@ namespace bgfx /// /// @param[in] _id View id. /// @param[in] _name View name. + /// @param[in] _len View name length (if length is INT32_MAX, it's expected that _name + /// is zero terminated string. /// /// @remarks /// This is debug only feature. @@ -3354,6 +3359,7 @@ namespace bgfx void setViewName( ViewId _id , const char* _name + , int32_t _len = INT32_MAX ); /// Set view rectangle. Draw primitive outside view will be clipped. @@ -3534,11 +3540,16 @@ namespace bgfx /// void resetView(ViewId _id); - /// Sets debug marker. + /// Sets a debug marker. This allows you to group graphics calls together for easy + /// browsing in graphics debugging tools. + /// + /// @param[in] _name Marker name. + /// @param[in] _len Marker name length (if length is INT32_MAX, it's expected that _name + /// is zero terminated string. /// /// @attention C99's equivalent binding is `bgfx_set_marker`. /// - void setMarker(const char* _marker); + void setMarker(const char* _name, int32_t _len = INT32_MAX); /// Set render states for draw primitive. /// diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index dc8f9180b..83354d46d 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -2225,9 +2225,11 @@ BGFX_C_API void bgfx_set_palette_color_rgba8(uint8_t _index, uint32_t _rgba); * * @param[in] _id View id. * @param[in] _name View name. + * @param[in] _len View name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string. * */ -BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name); +BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name, int32_t _len); /** * Set view rectangle. Draw primitive outside view will be clipped. @@ -2377,10 +2379,12 @@ BGFX_C_API void bgfx_encoder_end(bgfx_encoder_t* _encoder); * Sets a debug marker. This allows you to group graphics calls together for easy browsing in * graphics debugging tools. * - * @param[in] _marker Marker string. + * @param[in] _name Marker name. + * @param[in] _len Marker name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string. * */ -BGFX_C_API void bgfx_encoder_set_marker(bgfx_encoder_t* _this, const char* _marker); +BGFX_C_API void bgfx_encoder_set_marker(bgfx_encoder_t* _this, const char* _name, int32_t _len); /** * Set render states for draw primitive. @@ -2947,10 +2951,12 @@ BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handl * Sets a debug marker. This allows you to group graphics calls together for easy browsing in * graphics debugging tools. * - * @param[in] _marker Marker string. + * @param[in] _name Marker name. + * @param[in] _len Marker name length (if length is INT32_MAX, it's expected + * that _name is zero terminated string. * */ -BGFX_C_API void bgfx_set_marker(const char* _marker); +BGFX_C_API void bgfx_set_marker(const char* _name, int32_t _len); /** * Set render states for draw primitive. @@ -3733,7 +3739,7 @@ struct bgfx_interface_vtbl void (*destroy_occlusion_query)(bgfx_occlusion_query_handle_t _handle); void (*set_palette_color)(uint8_t _index, const float _rgba[4]); void (*set_palette_color_rgba8)(uint8_t _index, uint32_t _rgba); - void (*set_view_name)(bgfx_view_id_t _id, const char* _name); + void (*set_view_name)(bgfx_view_id_t _id, const char* _name, int32_t _len); void (*set_view_rect)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); void (*set_view_rect_ratio)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio); void (*set_view_scissor)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); @@ -3746,7 +3752,7 @@ struct bgfx_interface_vtbl void (*reset_view)(bgfx_view_id_t _id); bgfx_encoder_t* (*encoder_begin)(bool _forThread); void (*encoder_end)(bgfx_encoder_t* _encoder); - void (*encoder_set_marker)(bgfx_encoder_t* _this, const char* _marker); + void (*encoder_set_marker)(bgfx_encoder_t* _this, const char* _name, int32_t _len); void (*encoder_set_state)(bgfx_encoder_t* _this, uint64_t _state, uint32_t _rgba); void (*encoder_set_condition)(bgfx_encoder_t* _this, bgfx_occlusion_query_handle_t _handle, bool _visible); void (*encoder_set_stencil)(bgfx_encoder_t* _this, uint32_t _fstencil, uint32_t _bstencil); @@ -3792,7 +3798,7 @@ struct bgfx_interface_vtbl const bgfx_internal_data_t* (*get_internal_data)(void); uintptr_t (*override_internal_texture_ptr)(bgfx_texture_handle_t _handle, uintptr_t _ptr); uintptr_t (*override_internal_texture)(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint64_t _flags); - void (*set_marker)(const char* _marker); + void (*set_marker)(const char* _name, int32_t _len); void (*set_state)(uint64_t _state, uint32_t _rgba); void (*set_condition)(bgfx_occlusion_query_handle_t _handle, bool _visible); void (*set_stencil)(uint32_t _fstencil, uint32_t _bstencil); diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 089221489..abf552e7e 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -15,7 +15,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(126) +#define BGFX_API_VERSION UINT32_C(127) /** * Color RGB/alpha/depth write. When it's not specified write will be disabled. diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index b8ba53dbf..a3053b16e 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -1,7 +1,7 @@ -- vim: syntax=lua -- bgfx interface -version(126) +version(127) typedef "bool" typedef "char" @@ -2017,8 +2017,10 @@ func.setPaletteColor { cname = "set_palette_color_rgba8" } --- func.setViewName "void" - .id "ViewId" --- View id. - .name "const char*" --- View name. + .id "ViewId" --- View id. + .name "const char*" --- View name. + .len "int32_t" --- View name length (if length is INT32_MAX, it's expected + { default = INT32_MAX } --- that _name is zero terminated string. --- Set view rectangle. Draw primitive outside view will be clipped. func.setViewRect @@ -2154,7 +2156,9 @@ func["end"] { cname = "encoder_end" } --- graphics debugging tools. func.Encoder.setMarker "void" - .marker "const char*" --- Marker string. + .name "const char*" --- Marker name. + .len "int32_t" --- Marker name length (if length is INT32_MAX, it's expected + { default = INT32_MAX } --- that _name is zero terminated string. --- Set render states for draw primitive. --- @@ -2724,7 +2728,9 @@ func.overrideInternal { cname = "override_internal_texture" } --- graphics debugging tools. func.setMarker "void" - .marker "const char*" --- Marker string. + .name "const char*" --- Marker name. + .len "int32_t" --- Marker name length (if length is INT32_MAX, it's expected + { default = INT32_MAX } --- that _name is zero terminated string. --- Set render states for draw primitive. --- diff --git a/src/bgfx.cpp b/src/bgfx.cpp index f049fbb82..5a8e51a43 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -225,15 +225,6 @@ namespace bgfx if (kNaturalAlignment >= _align) { -#if BGFX_CONFIG_MEMORY_TRACKING - if (NULL == _ptr) - { - bx::MutexScope scope(m_mutex); - ++m_numBlocks; - m_maxBlocks = bx::max(m_maxBlocks, m_numBlocks); - } -#endif // BGFX_CONFIG_MEMORY_TRACKING - return ::realloc(_ptr, _size); } @@ -1514,24 +1505,26 @@ namespace bgfx void UniformBuffer::writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num) { - uint32_t opcode = encodeOpcode(_type, _loc, _num, true); + const uint32_t opcode = encodeOpcode(_type, _loc, _num, true); write(opcode); write(_value, g_uniformTypeSize[_type]*_num); } void UniformBuffer::writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num) { - uint32_t opcode = encodeOpcode(_type, _loc, _num, false); + const uint32_t opcode = encodeOpcode(_type, _loc, _num, false); write(opcode); write(&_handle, sizeof(UniformHandle) ); } - void UniformBuffer::writeMarker(const char* _marker) + void UniformBuffer::writeMarker(const bx::StringView& _name) { - uint16_t num = (uint16_t)bx::strLen(_marker)+1; - uint32_t opcode = encodeOpcode(bgfx::UniformType::Count, 0, num, true); + const uint16_t num = bx::narrowCast(_name.getLength()+1); + const uint32_t opcode = encodeOpcode(bgfx::UniformType::Count, 0, num, true); write(opcode); - write(_marker, num); + write(_name.getPtr(), num-1); + const char zero = '\0'; + write(&zero, 1); } struct CapsFlags @@ -2521,8 +2514,9 @@ namespace bgfx uint16_t copy; UniformBuffer::decodeOpcode(opcode, type, loc, num, copy); - uint32_t size = g_uniformTypeSize[type]*num; + const uint32_t size = g_uniformTypeSize[type]*num; const char* data = _uniformBuffer->read(size); + if (UniformType::Count > type) { if (copy) @@ -3661,9 +3655,9 @@ namespace bgfx #define BGFX_ENCODER(_func) reinterpret_cast(this)->_func - void Encoder::setMarker(const char* _marker) + void Encoder::setMarker(const char* _name, int32_t _len) { - BGFX_ENCODER(setMarker(_marker) ); + BGFX_ENCODER(setMarker(bx::StringView(_name, _len) ) ); } void Encoder::setState(uint64_t _state, uint32_t _rgba) @@ -5215,10 +5209,10 @@ namespace bgfx return id < BGFX_CONFIG_MAX_VIEWS; } - void setViewName(ViewId _id, const char* _name) + void setViewName(ViewId _id, const char* _name, int32_t _len) { BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); - s_ctx->setViewName(_id, _name); + s_ctx->setViewName(_id, bx::StringView(_name, _len) ); } void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) @@ -5290,10 +5284,10 @@ namespace bgfx BGFX_FATAL(NULL != s_ctx->m_encoder0, Fatal::DebugCheck \ , "bgfx is configured to allow only encoder API. See: `BGFX_CONFIG_ENCODER_API_ONLY`.") - void setMarker(const char* _marker) + void setMarker(const char* _name, int32_t _len) { BGFX_CHECK_ENCODER0(); - s_ctx->m_encoder0->setMarker(_marker); + s_ctx->m_encoder0->setMarker(_name, _len); } void setState(uint64_t _state, uint32_t _rgba) diff --git a/src/bgfx.idl.inl b/src/bgfx.idl.inl index 06bef38ba..929f179b6 100644 --- a/src/bgfx.idl.inl +++ b/src/bgfx.idl.inl @@ -625,9 +625,9 @@ BGFX_C_API void bgfx_set_palette_color_rgba8(uint8_t _index, uint32_t _rgba) bgfx::setPaletteColor(_index, _rgba); } -BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name) +BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name, int32_t _len) { - bgfx::setViewName((bgfx::ViewId)_id, _name); + bgfx::setViewName((bgfx::ViewId)_id, _name, _len); } BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) @@ -691,10 +691,10 @@ BGFX_C_API void bgfx_encoder_end(bgfx_encoder_t* _encoder) bgfx::end((bgfx::Encoder*)_encoder); } -BGFX_C_API void bgfx_encoder_set_marker(bgfx_encoder_t* _this, const char* _marker) +BGFX_C_API void bgfx_encoder_set_marker(bgfx_encoder_t* _this, const char* _name, int32_t _len) { bgfx::Encoder* This = (bgfx::Encoder*)_this; - This->setMarker(_marker); + This->setMarker(_name, _len); } BGFX_C_API void bgfx_encoder_set_state(bgfx_encoder_t* _this, uint64_t _state, uint32_t _rgba) @@ -999,9 +999,9 @@ BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handl return bgfx::overrideInternal(handle.cpp, _width, _height, _numMips, (bgfx::TextureFormat::Enum)_format, _flags); } -BGFX_C_API void bgfx_set_marker(const char* _marker) +BGFX_C_API void bgfx_set_marker(const char* _name, int32_t _len) { - bgfx::setMarker(_marker); + bgfx::setMarker(_name, _len); } BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 9ca1912ec..7639dafdd 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -671,8 +671,8 @@ namespace bgfx || m_small != _small) { m_small = _small; - m_width = (uint16_t)width; - m_height = (uint16_t)height; + m_width = bx::narrowCast(width); + m_height = bx::narrowCast(height); uint32_t size = m_size; m_size = m_width * m_height; @@ -947,6 +947,14 @@ namespace bgfx write(reinterpret_cast(&_in), sizeof(Type) ); } + void write(const bx::StringView& _str) + { + const uint16_t len = bx::narrowCast(_str.getLength()+1); + write(len); + write(_str.getPtr(), len-1); + write('\0'); + } + void read(void* _data, uint32_t _size) { BX_ASSERT(m_pos + _size <= m_size @@ -1382,7 +1390,7 @@ namespace bgfx uint32_t first = bx::atomicFetchAndAddsat(&m_num, num, BGFX_CONFIG_MAX_MATRIX_CACHE - 1); BX_WARN(first+num < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache overflow. %d (max: %d)", first+num, BGFX_CONFIG_MAX_MATRIX_CACHE); num = bx::min(num, BGFX_CONFIG_MAX_MATRIX_CACHE-1-first); - *_num = (uint16_t)num; + *_num = bx::narrowCast(num); return first; } @@ -1576,7 +1584,7 @@ namespace bgfx void writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num = 1); void writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num = 1); - void writeMarker(const char* _marker); + void writeMarker(const bx::StringView& _name); private: UniformBuffer(uint32_t _size) @@ -2478,7 +2486,7 @@ namespace bgfx } } - void setMarker(const char* _name) + void setMarker(const bx::StringView& _name) { UniformBuffer::update(&m_frame->m_uniformBuffer[m_uniformIdx]); UniformBuffer* uniformBuffer = m_frame->m_uniformBuffer[m_uniformIdx]; @@ -2494,7 +2502,7 @@ namespace bgfx , _handle.idx , getName(_handle) ); - m_uniformSet.insert(_handle.idx); +// m_uniformSet.insert(_handle.idx); } UniformBuffer::update(&m_frame->m_uniformBuffer[m_uniformIdx]); @@ -2543,7 +2551,7 @@ namespace bgfx uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { - uint16_t scissor = (uint16_t)m_frame->m_frameCache.m_rectCache.add(_x, _y, _width, _height); + uint16_t scissor = bx::narrowCast(m_frame->m_frameCache.m_rectCache.add(_x, _y, _width, _height) ); m_draw.m_scissor = scissor; return scissor; } @@ -3086,7 +3094,7 @@ namespace bgfx virtual void updateViewName(ViewId _id, const char* _name) = 0; virtual void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) = 0; virtual void invalidateOcclusionQuery(OcclusionQueryHandle _handle) = 0; - virtual void setMarker(const char* _marker, uint16_t _len) = 0; + virtual void setMarker(const char* _name, uint16_t _len) = 0; virtual void setName(Handle _handle, const char* _name, uint16_t _len) = 0; virtual void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) = 0; virtual void blitSetup(TextVideoMemBlitter& _blitter) = 0; @@ -4906,7 +4914,7 @@ namespace bgfx cmdbuf.write(handle); cmdbuf.write(uniform.m_type); cmdbuf.write(uniform.m_num); - uint8_t len = (uint8_t)bx::strLen(_name)+1; + uint8_t len = bx::narrowCast(bx::strLen(_name)+1); cmdbuf.write(len); cmdbuf.write(_name, len); } @@ -4938,7 +4946,7 @@ namespace bgfx cmdbuf.write(handle); cmdbuf.write(_type); cmdbuf.write(_num); - uint8_t len = (uint8_t)bx::strLen(_name)+1; + uint8_t len = bx::narrowCast(bx::strLen(_name)+1); cmdbuf.write(len); cmdbuf.write(_name, len); @@ -5075,15 +5083,13 @@ namespace bgfx m_colorPaletteDirty = 2; } - BGFX_API_FUNC(void setViewName(ViewId _id, const char* _name) ) + BGFX_API_FUNC(void setViewName(ViewId _id, const bx::StringView& _name) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::UpdateViewName); cmdbuf.write(_id); - uint16_t len = (uint16_t)bx::strLen(_name)+1; - cmdbuf.write(len); - cmdbuf.write(_name, len); + cmdbuf.write(_name); } BGFX_API_FUNC(void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) ) diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index bbfef901a..c2bdb5b37 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -277,6 +277,25 @@ VK_IMPORT_DEVICE }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); + struct ImageTest + { + VkImageType type; + VkImageUsageFlags usage; + VkImageCreateFlags flags; + uint32_t formatCaps[2]; + }; + + static const ImageTest s_imageTest[] = + { + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_2D, BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB } }, + { VK_IMAGE_TYPE_3D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_3D, BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, { BGFX_CAPS_FORMAT_TEXTURE_CUBE, BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER, 0 } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER, 0 } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_STORAGE_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ, 0 } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_STORAGE_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE, 0 } }, + }; + struct LayerInfo { bool m_supported; @@ -535,30 +554,25 @@ VK_IMPORT_DEVICE static void* VKAPI_PTR allocationFunction(void* _userData, size_t _size, size_t _alignment, VkSystemAllocationScope _allocationScope) { - BX_UNUSED(_userData); - return bx::alignedAlloc(g_allocator, _size, bx::max(kMinAlignment, _alignment), bx::Location(s_allocScopeName[_allocationScope], 0) ); + bx::AllocatorI* allocator = (bx::AllocatorI*)_userData; + return allocator->realloc(NULL, _size, bx::max(kMinAlignment, _alignment), s_allocScopeName[_allocationScope], 0); } static void* VKAPI_PTR reallocationFunction(void* _userData, void* _original, size_t _size, size_t _alignment, VkSystemAllocationScope _allocationScope) { - BX_UNUSED(_userData); - if (_size == 0) { - bx::alignedFree(g_allocator, _original, 0); - return NULL; - } - return bx::alignedRealloc(g_allocator, _original, _size, bx::max(kMinAlignment, _alignment), bx::Location(s_allocScopeName[_allocationScope], 0) ); + bx::AllocatorI* allocator = (bx::AllocatorI*)_userData; + return allocator->realloc(_original, _size, bx::max(kMinAlignment, _alignment), s_allocScopeName[_allocationScope], 0); } static void VKAPI_PTR freeFunction(void* _userData, void* _memory) { - BX_UNUSED(_userData); - if (NULL == _memory) { return; } - bx::alignedFree(g_allocator, _memory, 0); + bx::AllocatorI* allocator = (bx::AllocatorI*)_userData; + allocator->realloc(_memory, 0, 0, "vkFree", 0); } static void VKAPI_PTR internalAllocationNotification(void* _userData, size_t _size, VkInternalAllocationType _allocationType, VkSystemAllocationScope _allocationScope) @@ -636,26 +650,17 @@ VK_IMPORT_DEVICE }; VkBool32 VKAPI_PTR debugReportCb( - VkDebugReportFlagsEXT _flags, - VkDebugReportObjectTypeEXT _objectType, - uint64_t _object, - size_t _location, - int32_t _messageCode, - const char* _layerPrefix, - const char* _message, - void* _userData - ) + VkDebugReportFlagsEXT _flags + , VkDebugReportObjectTypeEXT _objectType + , uint64_t _object + , size_t _location + , int32_t _messageCode + , const char* _layerPrefix + , const char* _message + , void* _userData + ) { - BX_UNUSED(_flags - , _objectType - , _object - , _location - , _messageCode - , _layerPrefix - , _message - , _userData - , s_debugReportObjectType - ); + BX_UNUSED(_flags, _objectType, _object, _location, _messageCode, _layerPrefix, _message, _userData, s_debugReportObjectType); // For more info about 'VUID-VkSwapchainCreateInfoKHR-imageExtent-01274' // check https://github.com/KhronosGroup/Vulkan-Docs/issues/1144 @@ -666,6 +671,7 @@ VK_IMPORT_DEVICE { return VK_FALSE; } + BX_TRACE("%c%c%c%c%c %19s, %s, %d: %s" , 0 != (_flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT ) ? 'I' : '-' , 0 != (_flags & VK_DEBUG_REPORT_WARNING_BIT_EXT ) ? 'W' : '-' @@ -677,6 +683,7 @@ VK_IMPORT_DEVICE , _messageCode , _message ); + return VK_FALSE; } @@ -774,6 +781,7 @@ VK_IMPORT_DEVICE , layerProperties[layer].implementationVersion , layerProperties[layer].description ); + uint32_t numExtensionProperties; result = enumerateExtensionProperties(_physicalDevice , layerProperties[layer].layerName @@ -793,7 +801,7 @@ VK_IMPORT_DEVICE for (uint32_t extension = 0; extension < numExtensionProperties; ++extension) { - bool supported = updateExtension( + const bool supported = updateExtension( extensionProperties[extension].extensionName , extensionProperties[extension].specVersion , VK_NULL_HANDLE == _physicalDevice @@ -1077,7 +1085,8 @@ VK_IMPORT_DEVICE imb.subresourceRange.levelCount = _levelCount; imb.subresourceRange.baseArrayLayer = _baseArrayLayer; imb.subresourceRange.layerCount = _layerCount; - vkCmdPipelineBarrier(_commandBuffer + vkCmdPipelineBarrier( + _commandBuffer , srcStageMask , dstStageMask , 0 @@ -1308,6 +1317,7 @@ VK_IMPORT if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { + s_allocationCb.pUserData = g_allocator; m_allocatorCb = &s_allocationCb; BX_UNUSED(s_allocationCb); } @@ -1637,83 +1647,63 @@ VK_IMPORT_INSTANCE } } + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { - struct ImageTest + uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; + + const bool depth = bimg::isDepth(bimg::TextureFormat::Enum(ii) ); + VkFormat fmt = depth + ? s_textureFormat[ii].m_fmtDsv + : s_textureFormat[ii].m_fmt + ; + + for (uint32_t jj = 0, num = depth ? 1 : 2; jj < num; ++jj) { - VkImageType type; - VkImageUsageFlags usage; - VkImageCreateFlags flags; - uint32_t formatCaps[2]; - }; - - const ImageTest imageTest[] = - { - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_2D, BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB } }, - { VK_IMAGE_TYPE_3D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_3D, BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB } }, - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, { BGFX_CAPS_FORMAT_TEXTURE_CUBE, BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB } }, - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER, 0 } }, - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER, 0 } }, - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_STORAGE_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ, 0 } }, - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_STORAGE_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE, 0 } }, - }; - - for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) - { - uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; - - const bool depth = bimg::isDepth(bimg::TextureFormat::Enum(ii) ); - VkFormat fmt = depth - ? s_textureFormat[ii].m_fmtDsv - : s_textureFormat[ii].m_fmt - ; - - for (uint32_t jj = 0, num = depth ? 1 : 2; jj < num; ++jj) + if (VK_FORMAT_UNDEFINED != fmt) { - if (VK_FORMAT_UNDEFINED != fmt) + for (uint32_t test = 0; test < BX_COUNTOF(s_imageTest); ++test) { - for (uint32_t test = 0; test < BX_COUNTOF(imageTest); ++test) + const ImageTest& it = s_imageTest[test]; + + VkImageFormatProperties ifp; + result = vkGetPhysicalDeviceImageFormatProperties( + m_physicalDevice + , fmt + , it.type + , VK_IMAGE_TILING_OPTIMAL + , it.usage + , it.flags + , &ifp + ); + + if (VK_SUCCESS == result) { - const ImageTest& it = imageTest[test]; + support |= it.formatCaps[jj]; - VkImageFormatProperties ifp; - result = vkGetPhysicalDeviceImageFormatProperties(m_physicalDevice - , fmt - , it.type - , VK_IMAGE_TILING_OPTIMAL - , it.usage - , it.flags - , &ifp - ); - - if (VK_SUCCESS == result) + const bool multisample = VK_SAMPLE_COUNT_1_BIT < ifp.sampleCounts; + if (it.usage & VK_IMAGE_USAGE_SAMPLED_BIT) { - support |= it.formatCaps[jj]; + support |= 0 + | BGFX_CAPS_FORMAT_TEXTURE_VERTEX + | (multisample ? BGFX_CAPS_FORMAT_TEXTURE_MSAA : 0) + ; + } - const bool multisample = VK_SAMPLE_COUNT_1_BIT < ifp.sampleCounts; - if (it.usage & VK_IMAGE_USAGE_SAMPLED_BIT) - { - support |= 0 - | BGFX_CAPS_FORMAT_TEXTURE_VERTEX - | (multisample ? BGFX_CAPS_FORMAT_TEXTURE_MSAA : 0) - ; - } - - if (it.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ) - { - support |= 0 - | BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN - | (multisample ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA : 0) - ; - } + if (it.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ) + { + support |= 0 + | BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN + | (multisample ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA : 0) + ; } } } - - fmt = s_textureFormat[ii].m_fmtSrgb; } - g_caps.formats[ii] = support; + fmt = s_textureFormat[ii].m_fmtSrgb; } + + g_caps.formats[ii] = support; } vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &m_memoryProperties); @@ -1844,7 +1834,7 @@ VK_IMPORT_INSTANCE dci.ppEnabledLayerNames = enabledLayer; dci.enabledExtensionCount = numEnabledExtensions; dci.ppEnabledExtensionNames = enabledExtension; - dci.pEnabledFeatures = &m_deviceFeatures; + dci.pEnabledFeatures = &m_deviceFeatures; result = vkCreateDevice( m_physicalDevice diff --git a/src/shader_dxbc.cpp b/src/shader_dxbc.cpp index 21af08f7d..7dadd43d3 100644 --- a/src/shader_dxbc.cpp +++ b/src/shader_dxbc.cpp @@ -1726,7 +1726,7 @@ namespace bgfx size += bx::snprintf(&_out[size], bx::uint32_imax(0, _size-size) , "%s%f" , 0 == jj ? "(" : ", " - , bx::bit_cast(operand.un.imm32[jj]) + , bx::bitCast(operand.un.imm32[jj]) ); }