From 84a38eede057dbf5dfd234757858c061837f01e1 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: Wed, 13 Oct 2021 19:54:27 -0700 Subject: [PATCH] Cleanup. --- examples/common/bounds.cpp | 2 +- src/bgfx_p.h | 4 +-- src/renderer_vk.cpp | 4 +-- src/vertexlayout.cpp | 54 ++++++++++++++------------------------ 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index 41a9bc723..2481b74ee 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -1057,7 +1057,7 @@ void mtxFromSrt(float* _outMtx, const Srt& _srt) bool isNearZero(float _v) { - return equal(_v, 0.0f, 0.00001f); + return isEqual(_v, 0.0f, 0.00001f); } bool isNearZero(const Vec3& _v) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index e75d07a3a..ff656408c 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -4922,7 +4922,7 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(ViewId _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) { - BX_ASSERT(bx::equal(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) + BX_ASSERT(bx::isEqual(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." , _depth ); @@ -4932,7 +4932,7 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(ViewId _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) ) { - BX_ASSERT(bx::equal(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) + BX_ASSERT(bx::isEqual(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." , _depth ); diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 6bff243f8..f13fc8957 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -6,9 +6,9 @@ #include "bgfx_p.h" #if BGFX_CONFIG_RENDERER_VULKAN +# include # include "renderer_vk.h" # include "shader_spirv.h" -# include #if BX_PLATFORM_OSX # import @@ -1477,7 +1477,7 @@ VK_IMPORT_INSTANCE vkGetPhysicalDeviceFeatures(m_physicalDevice, &supportedFeatures); } - memset(&m_deviceFeatures, 0, sizeof(m_deviceFeatures) ); + bx::memSet(&m_deviceFeatures, 0, sizeof(m_deviceFeatures) ); m_deviceFeatures.fullDrawIndexUint32 = supportedFeatures.fullDrawIndexUint32; m_deviceFeatures.imageCubeArray = supportedFeatures.imageCubeArray && (_init.capabilities & BGFX_CAPS_TEXTURE_CUBE_ARRAY); diff --git a/src/vertexlayout.cpp b/src/vertexlayout.cpp index 35bec28c0..531da58f8 100644 --- a/src/vertexlayout.cpp +++ b/src/vertexlayout.cpp @@ -631,15 +631,7 @@ namespace bgfx struct ConvertOp { - enum Enum - { - Set, - Copy, - Convert, - }; - Attrib::Enum attr; - Enum op; uint32_t src; uint32_t dest; uint32_t size; @@ -648,6 +640,12 @@ namespace bgfx ConvertOp convertOp[Attrib::Count]; uint32_t numOps = 0; + const uint8_t* src = (const uint8_t*)_srcData; + uint32_t srcStride = _srcLayout.getStride(); + + uint8_t* dest = (uint8_t*)_destData; + uint32_t destStride = _destLayout.getStride(); + for (uint32_t ii = 0; ii < Attrib::Count; ++ii) { Attrib::Enum attr = (Attrib::Enum)ii; @@ -668,25 +666,25 @@ namespace bgfx if (_srcLayout.has(attr) ) { cop.src = _srcLayout.getOffset(attr); - cop.op = _destLayout.m_attributes[attr] == _srcLayout.m_attributes[attr] ? ConvertOp::Copy : ConvertOp::Convert; + + if (_destLayout.m_attributes[attr] == _srcLayout.m_attributes[attr]) + { + bx::memCopy(dest + cop.dest, destStride, src + cop.src, srcStride, cop.size, _num); + } + else + { + ++numOps; + } } else { - cop.op = ConvertOp::Set; + bx::memSet(dest + cop.dest, destStride, 0, cop.size, _num); } - - ++numOps; } } if (0 < numOps) { - const uint8_t* src = (const uint8_t*)_srcData; - uint32_t srcStride = _srcLayout.getStride(); - - uint8_t* dest = (uint8_t*)_destData; - uint32_t destStride = _destLayout.getStride(); - float unpacked[4]; for (uint32_t ii = 0; ii < _num; ++ii) @@ -694,25 +692,11 @@ namespace bgfx for (uint32_t jj = 0; jj < numOps; ++jj) { const ConvertOp& cop = convertOp[jj]; - - switch (cop.op) - { - case ConvertOp::Set: - bx::memSet(dest + cop.dest, 0, cop.size); - break; - - case ConvertOp::Copy: - bx::memCopy(dest + cop.dest, src + cop.src, cop.size); - break; - - case ConvertOp::Convert: - vertexUnpack(unpacked, cop.attr, _srcLayout, src); - vertexPack(unpacked, true, cop.attr, _destLayout, dest); - break; - } + vertexUnpack(unpacked, cop.attr, _srcLayout, src); + vertexPack(unpacked, true, cop.attr, _destLayout, dest); } - src += srcStride; + src += srcStride; dest += destStride; } }