diff options
Diffstat (limited to '3rdparty/bgfx/src')
28 files changed, 1251 insertions, 663 deletions
diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp index 3c008902c1f..5886e842443 100644 --- a/3rdparty/bgfx/src/bgfx.cpp +++ b/3rdparty/bgfx/src/bgfx.cpp @@ -20,6 +20,8 @@ #endif // BGFX_CONFIG_PROFILER_REMOTERY_BUILD_LIB #include <bx/crtimpl.h> +#include <bx/mutex.h> + #include "topology.h" BX_ERROR_RESULT(BGFX_ERROR_TEXTURE_VALIDATION, BX_MAKEFOURCC('b', 'g', 0, 1) ); @@ -76,7 +78,7 @@ namespace bgfx if ( (int32_t)sizeof(temp) < total) { out = (char*)alloca(total+1); - memcpy(out, temp, len); + bx::memCopy(out, temp, len); bx::vsnprintf(out + len, total-len, _format, _argList); } out[total] = '\0'; @@ -116,7 +118,7 @@ namespace bgfx BX_UNUSED(_filePath, _width, _height, _pitch, _data, _size, _yflip); #if BX_CONFIG_CRT_FILE_READER_WRITER - const size_t len = bx::strnlen(_filePath)+5; + const int32_t len = bx::strnlen(_filePath)+5; char* filePath = (char*)alloca(len); bx::strlncpy(filePath, len, _filePath); bx::strlncat(filePath, len, ".tga"); @@ -169,7 +171,7 @@ namespace bgfx { #if BGFX_CONFIG_MEMORY_TRACKING { - bx::LwMutexScope scope(m_mutex); + bx::MutexScope scope(m_mutex); BX_CHECK(m_numBlocks > 0, "Number of blocks is 0. Possible alloc/free mismatch?"); --m_numBlocks; } @@ -191,7 +193,7 @@ namespace bgfx { #if BGFX_CONFIG_MEMORY_TRACKING { - bx::LwMutexScope scope(m_mutex); + bx::MutexScope scope(m_mutex); ++m_numBlocks; m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks); } @@ -208,7 +210,7 @@ namespace bgfx #if BGFX_CONFIG_MEMORY_TRACKING if (NULL == _ptr) { - bx::LwMutexScope scope(m_mutex); + bx::MutexScope scope(m_mutex); ++m_numBlocks; m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks); } @@ -224,7 +226,7 @@ namespace bgfx protected: #if BGFX_CONFIG_MEMORY_TRACKING - bx::LwMutex m_mutex; + bx::Mutex m_mutex; uint32_t m_numBlocks; uint32_t m_maxBlocks; #endif // BGFX_CONFIG_MEMORY_TRACKING @@ -315,7 +317,7 @@ namespace bgfx , "Only backbuffer pointer and native window handle can be changed after initialization!" ); } - memcpy(&g_platformData, &_data, sizeof(PlatformData) ); + bx::memCopy(&g_platformData, &_data, sizeof(PlatformData) ); g_platformDataChangedSinceReset = true; } @@ -463,7 +465,7 @@ namespace bgfx { for (const EmbeddedShader* es = _es; NULL != es->name; ++es) { - if (0 == strcmp(_name, es->name) ) + if (0 == bx::strncmp(_name, es->name) ) { for (const EmbeddedShader::Data* esd = es->data; RendererType::Count != esd->type; ++esd) { @@ -492,7 +494,7 @@ namespace bgfx for (uint32_t xx = 0; xx < 8; ++xx) { uint8_t bit = 1<<(7-xx); - memset(&pix[xx*_bpp], _charset[ii*_height+yy]&bit ? 255 : 0, _bpp); + bx::memSet(&pix[xx*_bpp], _charset[ii*_height+yy]&bit ? 255 : 0, _bpp); } pix += _pitch; @@ -502,13 +504,13 @@ namespace bgfx static uint8_t parseAttrTo(char*& _ptr, char _to, uint8_t _default) { - const char* str = strchr(_ptr, _to); + const char* str = bx::strnchr(_ptr, _to); if (NULL != str && 3 > str-_ptr) { char tmp[4]; - ptrdiff_t len = str-_ptr; + int32_t len = int32_t(str-_ptr); bx::strlncpy(tmp, sizeof(tmp), _ptr, len); uint8_t attr = uint8_t(atoi(tmp) ); @@ -709,7 +711,7 @@ namespace bgfx { (xx )*8.0f, (yy+1)*fontHeight, 0.0f, fg, bg, (ch )*8.0f*texelWidth - texelWidthHalf, ubottom }, }; - memcpy(vertex, vert, sizeof(vert) ); + bx::memCopy(vertex, vert, sizeof(vert) ); vertex += 4; indices[0] = uint16_t(startVertex+0); @@ -808,7 +810,7 @@ namespace bgfx for (uint32_t ii = 0; ii < UniformType::Count; ++ii) { if (NULL != s_uniformTypeName[ii] - && 0 == strcmp(_name, s_uniformTypeName[ii]) ) + && 0 == bx::strncmp(_name, s_uniformTypeName[ii]) ) { return UniformType::Enum(ii); } @@ -842,7 +844,7 @@ namespace bgfx { for (uint32_t ii = 0; ii < PredefinedUniform::Count; ++ii) { - if (0 == strcmp(_name, s_predefinedName[ii]) ) + if (0 == bx::strncmp(_name, s_predefinedName[ii]) ) { return PredefinedUniform::Enum(ii); } @@ -1030,16 +1032,16 @@ namespace bgfx } BGFX_CHECK_RENDER_THREAD(); - if (s_ctx->renderFrame() ) + RenderFrame::Enum result = s_ctx->renderFrame(BGFX_CONFIG_API_SEMAPHORE_TIMEOUT); + if (RenderFrame::Exiting == result) { Context* ctx = s_ctx; ctx->apiSemWait(); s_ctx = NULL; ctx->renderSemPost(); - return RenderFrame::Exiting; } - return RenderFrame::Render; + return result; } BX_CHECK(false, "This call only makes sense if used with multi-threaded renderer."); @@ -1287,8 +1289,12 @@ namespace bgfx TextureFormat::ETC2, TextureFormat::ETC2A, TextureFormat::ETC2A1, + TextureFormat::PTC12, TextureFormat::PTC14, + TextureFormat::PTC12A, TextureFormat::PTC14A, + TextureFormat::PTC22, + TextureFormat::PTC24, TextureFormat::BGRA8, // GL doesn't support BGRA8 without extensions. TextureFormat::RGBA8, // D3D9 doesn't support RGBA8 }; @@ -1467,7 +1473,7 @@ namespace bgfx m_render->destroy(); #endif // BGFX_CONFIG_MULTITHREADED - memset(&g_internalData, 0, sizeof(InternalData) ); + bx::memSet(&g_internalData, 0, sizeof(InternalData) ); s_ctx = NULL; m_submit->destroy(); @@ -1511,6 +1517,12 @@ namespace bgfx destroyDynamicVertexBufferInternal(m_freeDynamicVertexBufferHandle[ii]); } m_numFreeDynamicVertexBufferHandles = 0; + + for (uint16_t ii = 0, num = m_numFreeOcclusionQueryHandles; ii < num; ++ii) + { + m_occlusionQueryHandle.free(m_freeOcclusionQueryHandle[ii].idx); + } + m_numFreeOcclusionQueryHandles = 0; } void Context::freeAllHandles(Frame* _frame) @@ -1595,24 +1607,24 @@ namespace bgfx m_resolution.m_flags &= ~BGFX_RESET_INTERNAL_FORCE; m_submit->m_debug = m_debug; - memcpy(m_submit->m_viewRemap, m_viewRemap, sizeof(m_viewRemap) ); - memcpy(m_submit->m_fb, m_fb, sizeof(m_fb) ); - memcpy(m_submit->m_clear, m_clear, sizeof(m_clear) ); - memcpy(m_submit->m_rect, m_rect, sizeof(m_rect) ); - memcpy(m_submit->m_scissor, m_scissor, sizeof(m_scissor) ); - memcpy(m_submit->m_view, m_view, sizeof(m_view) ); - memcpy(m_submit->m_proj, m_proj, sizeof(m_proj) ); - memcpy(m_submit->m_viewFlags, m_viewFlags, sizeof(m_viewFlags) ); + bx::memCopy(m_submit->m_viewRemap, m_viewRemap, sizeof(m_viewRemap) ); + bx::memCopy(m_submit->m_fb, m_fb, sizeof(m_fb) ); + bx::memCopy(m_submit->m_clear, m_clear, sizeof(m_clear) ); + bx::memCopy(m_submit->m_rect, m_rect, sizeof(m_rect) ); + bx::memCopy(m_submit->m_scissor, m_scissor, sizeof(m_scissor) ); + bx::memCopy(m_submit->m_view, m_view, sizeof(m_view) ); + bx::memCopy(m_submit->m_proj, m_proj, sizeof(m_proj) ); + bx::memCopy(m_submit->m_viewFlags, m_viewFlags, sizeof(m_viewFlags) ); if (m_colorPaletteDirty > 0) { --m_colorPaletteDirty; - memcpy(m_submit->m_colorPalette, m_clearColor, sizeof(m_clearColor) ); + bx::memCopy(m_submit->m_colorPalette, m_clearColor, sizeof(m_clearColor) ); } m_submit->finish(); bx::xchg(m_render, m_submit); - memcpy(m_render->m_occlusion, m_submit->m_occlusion, sizeof(m_submit->m_occlusion) ); + bx::memCopy(m_render->m_occlusion, m_submit->m_occlusion, sizeof(m_submit->m_occlusion) ); if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) || m_singleThreaded) @@ -1623,7 +1635,7 @@ namespace bgfx m_frames++; m_submit->start(); - memset(m_seq, 0, sizeof(m_seq) ); + bx::memSet(m_seq, 0, sizeof(m_seq) ); freeAllHandles(m_submit); m_submit->resetFreeHandles(); @@ -1638,7 +1650,7 @@ namespace bgfx return m_uniformRef[_handle.idx].m_name.getPtr(); } - bool Context::renderFrame() + RenderFrame::Enum Context::renderFrame(int32_t _msecs) { BGFX_PROFILER_SCOPE(bgfx, render_frame, 0xff2040ff); @@ -1650,7 +1662,7 @@ namespace bgfx m_flipped = true; } - if (apiSemWait(BGFX_CONFIG_API_SEMAPHORE_TIMEOUT) ) + if (apiSemWait(_msecs) ) { rendererExecCommands(m_render->m_cmdPre); if (m_rendererInitialized) @@ -1670,8 +1682,15 @@ namespace bgfx m_flipped = true; } } + else + { + return RenderFrame::Timeout; + } - return m_exit; + return m_exit + ? RenderFrame::Exiting + : RenderFrame::Render + ; } void rendererUpdateUniforms(RendererContextI* _renderCtx, UniformBuffer* _uniformBuffer, uint32_t _begin, uint32_t _end) @@ -1843,7 +1862,7 @@ namespace bgfx }; OSVERSIONINFOEXA ovi; - memset(&ovi, 0, sizeof(ovi) ); + bx::memSet(&ovi, 0, sizeof(ovi) ); ovi.dwOSVersionInfoSize = sizeof(ovi); // _WIN32_WINNT_WINBLUE 0x0603 // _WIN32_WINNT_WIN8 0x0602 @@ -1937,7 +1956,7 @@ namespace bgfx } } - qsort(scores, numScores, sizeof(int32_t), compareDescending); + bx::quickSort(scores, numScores, sizeof(int32_t), compareDescending); RendererContextI* renderCtx = NULL; for (uint32_t ii = 0; ii < numScores; ++ii) @@ -2432,14 +2451,17 @@ namespace bgfx } break; - case CommandBuffer::SaveScreenShot: + case CommandBuffer::RequestScreenShot: { + FrameBufferHandle handle; + _cmdbuf.read(handle); + uint16_t len; _cmdbuf.read(len); const char* filePath = (const char*)_cmdbuf.skip(len); - m_renderCtx->saveScreenShot(filePath); + m_renderCtx->requestScreenShot(handle, filePath); } break; @@ -2457,6 +2479,15 @@ namespace bgfx } break; + case CommandBuffer::InvalidateOcclusionQuery: + { + OcclusionQueryHandle handle; + _cmdbuf.read(handle); + + m_renderCtx->invalidateOcclusionQuery(handle); + } + break; + default: BX_CHECK(false, "Invalid command: %d", command); break; @@ -2566,7 +2597,7 @@ namespace bgfx goto error; } - memset(&g_caps, 0, sizeof(g_caps) ); + bx::memSet(&g_caps, 0, sizeof(g_caps) ); g_caps.limits.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS; g_caps.limits.maxBlits = BGFX_CONFIG_MAX_BLIT_ITEMS; g_caps.limits.maxViews = BGFX_CONFIG_MAX_VIEWS; @@ -2713,7 +2744,7 @@ error: { BX_CHECK(0 < _size, "Invalid memory operation. _size is 0."); const Memory* mem = alloc(_size); - memcpy(mem->data, _data, _size); + bx::memCopy(mem->data, _data, _size); return mem; } @@ -3105,48 +3136,7 @@ error: void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format) { - const ImageBlockInfo& blockInfo = getBlockInfo(_format); - const uint8_t bpp = blockInfo.bitsPerPixel; - const uint16_t blockWidth = blockInfo.blockWidth; - const uint16_t blockHeight = blockInfo.blockHeight; - const uint16_t minBlockX = blockInfo.minBlockX; - const uint16_t minBlockY = blockInfo.minBlockY; - - _width = bx::uint16_max(blockWidth * minBlockX, ( (_width + blockWidth - 1) / blockWidth)*blockWidth); - _height = bx::uint16_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight); - _depth = bx::uint16_max(1, _depth); - const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth); - const uint32_t sides = _cubeMap ? 6 : 1; - - uint32_t width = _width; - uint32_t height = _height; - uint32_t depth = _depth; - uint32_t size = 0; - - for (uint32_t lod = 0; lod < numMips; ++lod) - { - width = bx::uint32_max(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth); - height = bx::uint32_max(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight); - depth = bx::uint32_max(1, depth); - - size += width*height*depth*bpp/8 * sides; - - width >>= 1; - height >>= 1; - depth >>= 1; - } - - size *= _numLayers; - - _info.format = _format; - _info.width = _width; - _info.height = _height; - _info.depth = _depth; - _info.numMips = numMips; - _info.numLayers = _numLayers; - _info.cubeMap = _cubeMap; - _info.storageSize = size; - _info.bitsPerPixel = bpp; + imageGetSize(&_info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, _format); } TextureHandle createTexture(const Memory* _mem, uint32_t _flags, uint8_t _skip, TextureInfo* _info) @@ -3180,7 +3170,11 @@ error: bx::Error err; isTextureValid(0, false, _numLayers, _format, _flags, &err); - BX_CHECK(err.isOk(), "%s", err.getMessage().getPtr() ); + BX_CHECK(err.isOk(), "%s (layers %d, format %s)" + , err.getMessage().getPtr() + , _numLayers + , getName(_format) + ); if (BackbufferRatio::Count != _ratio) { @@ -3470,11 +3464,11 @@ error: return s_ctx->createOcclusionQuery(); } - OcclusionQueryResult::Enum getResult(OcclusionQueryHandle _handle) + OcclusionQueryResult::Enum getResult(OcclusionQueryHandle _handle, int32_t* _result) { BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_CAPS(BGFX_CAPS_OCCLUSION_QUERY, "Occlusion query is not supported!"); - return s_ctx->getResult(_handle); + return s_ctx->getResult(_handle, _result); } void destroyOcclusionQuery(OcclusionQueryHandle _handle) @@ -3787,6 +3781,7 @@ error: uint32_t submit(uint8_t _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState) { BGFX_CHECK_MAIN_THREAD(); + BGFX_CHECK_CAPS(BGFX_CAPS_DRAW_INDIRECT, "Draw indirect is not supported! Use bgfx::getCaps to check BGFX_CAPS_DRAW_INDIRECT backend renderer capabilities."); return s_ctx->submit(_id, _program, _indirectHandle, _start, _num, _depth, _preserveState); } @@ -3835,12 +3830,15 @@ error: uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) { BGFX_CHECK_MAIN_THREAD(); + BGFX_CHECK_CAPS(BGFX_CAPS_COMPUTE, "Compute is not supported! Use bgfx::getCaps to check BGFX_CAPS_COMPUTE backend renderer capabilities."); return s_ctx->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); } uint32_t dispatch(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { BGFX_CHECK_MAIN_THREAD(); + BGFX_CHECK_CAPS(BGFX_CAPS_DRAW_INDIRECT, "Dispatch indirect is not supported! Use bgfx::getCaps to check BGFX_CAPS_DRAW_INDIRECT backend renderer capabilities."); + BGFX_CHECK_CAPS(BGFX_CAPS_COMPUTE, "Compute is not supported! Use bgfx::getCaps to check BGFX_CAPS_COMPUTE backend renderer capabilities."); return s_ctx->dispatch(_id, _handle, _indirectHandle, _start, _num, _flags); } @@ -3862,10 +3860,10 @@ error: s_ctx->blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); } - void saveScreenShot(const char* _filePath) + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) { BGFX_CHECK_MAIN_THREAD(); - s_ctx->saveScreenShot(_filePath); + s_ctx->requestScreenShot(_handle, _filePath); } } // namespace bgfx @@ -4518,10 +4516,10 @@ BGFX_C_API bgfx_occlusion_query_handle_t bgfx_create_occlusion_query() return handle.c; } -BGFX_C_API bgfx_occlusion_query_result_t bgfx_get_result(bgfx_occlusion_query_handle_t _handle) +BGFX_C_API bgfx_occlusion_query_result_t bgfx_get_result(bgfx_occlusion_query_handle_t _handle, int32_t* _result) { union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; - return bgfx_occlusion_query_result_t(bgfx::getResult(handle.cpp) ); + return bgfx_occlusion_query_result_t(bgfx::getResult(handle.cpp, _result) ); } BGFX_C_API void bgfx_destroy_occlusion_query(bgfx_occlusion_query_handle_t _handle) @@ -4793,9 +4791,10 @@ BGFX_C_API void bgfx_blit(uint8_t _id, bgfx_texture_handle_t _dst, uint8_t _dstM bgfx::blit(_id, dst.cpp, _dstMip, _dstX, _dstY, _dstZ, src.cpp, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); } -BGFX_C_API void bgfx_save_screen_shot(const char* _filePath) +BGFX_C_API void bgfx_request_screen_shot(bgfx_frame_buffer_handle _handle, const char* _filePath) { - bgfx::saveScreenShot(_filePath); + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; + bgfx::requestScreenShot(handle.cpp, _filePath); } BGFX_C_API bgfx_render_frame_t bgfx_render_frame() @@ -4962,7 +4961,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) BGFX_IMPORT_FUNC(dispatch_indirect) \ BGFX_IMPORT_FUNC(discard) \ BGFX_IMPORT_FUNC(blit) \ - BGFX_IMPORT_FUNC(save_screen_shot) + BGFX_IMPORT_FUNC(request_screen_shot) static bgfx_interface_vtbl_t s_bgfx_interface = { diff --git a/3rdparty/bgfx/src/bgfx_compute.sh b/3rdparty/bgfx/src/bgfx_compute.sh index 45799cbdce1..641dda89a31 100644 --- a/3rdparty/bgfx/src/bgfx_compute.sh +++ b/3rdparty/bgfx/src/bgfx_compute.sh @@ -57,7 +57,7 @@ _type imageLoad( RWTexture3D<_textureType> _image, ivec3 _uvw, _type _value) { return _image[_uvw]._loadComponents; } \ void imageStore( RWTexture2D<_textureType> _image, ivec2 _uv, _type _value) { _image[_uv ] = _value._storeComponents; } \ void imageStore(RWTexture2DArray<_textureType> _image, ivec3 _uvw, _type _value) { _image[_uvw] = _value._storeComponents; } \ - void imageStore( RWTexture3D<_textureType> _image, ivec3 _uvw, _type _value) { _image[_uvw] = _value._storeComponents; } + void imageStore( RWTexture3D<_textureType> _image, ivec3 _uvw, _type _value) { _image[_uvw] = _value._storeComponents; } __IMAGE_IMPL(float, x, vec4, xxxx) __IMAGE_IMPL(vec2, xy, vec4, xyyy) @@ -188,31 +188,31 @@ uint atomicCompSwap(uint _mem, uint _compare, uint _data) #endif // BGFX_SHADER_LANGUAGE_HLSL #define dispatchIndirect(_buffer \ - , _offset \ - , _numX \ - , _numY \ - , _numZ \ - ) \ + , _offset \ + , _numX \ + , _numY \ + , _numZ \ + ) \ _buffer[_offset*2+0] = uvec4(_numX, _numY, _numZ, 0u) #define drawIndirect(_buffer \ - , _offset \ - , _numVertices \ - , _numInstances \ - , _startVertex \ + , _offset \ + , _numVertices \ + , _numInstances \ + , _startVertex \ , _startInstance \ - ) \ + ) \ _buffer[_offset*2+0] = uvec4(_numVertices, _numInstances, _startVertex, _startInstance) #define drawIndexedIndirect(_buffer \ - , _offset \ - , _numIndices \ - , _numInstances \ - , _startIndex \ - , _startVertex \ - , _startInstance \ - ) \ - _buffer[_offset*2+0] = uvec4(_numIndices, _numInstances, _startIndex, _startInstance); \ + , _offset \ + , _numIndices \ + , _numInstances \ + , _startIndex \ + , _startVertex \ + , _startInstance \ + ) \ + _buffer[_offset*2+0] = uvec4(_numIndices, _numInstances, _startIndex, _startVertex); \ _buffer[_offset*2+1] = uvec4(_startInstance, 0u, 0u, 0u) #endif // __cplusplus diff --git a/3rdparty/bgfx/src/bgfx_p.h b/3rdparty/bgfx/src/bgfx_p.h index dcef0afdcb3..775cd157caa 100644 --- a/3rdparty/bgfx/src/bgfx_p.h +++ b/3rdparty/bgfx/src/bgfx_p.h @@ -23,8 +23,6 @@ #include "config.h" #include <inttypes.h> -#include <stdarg.h> // va_list -#include <alloca.h> // Check handle, cannot be bgfx::invalidHandle and must be valid. #define BGFX_CHECK_HANDLE(_desc, _handleAlloc, _handle) \ @@ -124,7 +122,7 @@ namespace bgfx #include <bx/endian.h> #include <bx/handlealloc.h> #include <bx/hash.h> -#include <bx/radixsort.h> +#include <bx/sort.h> #include <bx/ringbuffer.h> #include <bx/uint32_t.h> #include <bx/readerwriter.h> @@ -273,6 +271,18 @@ namespace bgfx struct Rect { + Rect() + { + } + + Rect(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) + : m_x(_x) + , m_y(_y) + , m_width(_width) + , m_height(_height) + { + } + void clear() { m_x = @@ -294,7 +304,15 @@ namespace bgfx ; } - void intersect(const Rect& _a, const Rect& _b) + void set(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) + { + m_x = _x; + m_y = _y; + m_width = _width; + m_height = _height; + } + + void setIntersect(const Rect& _a, const Rect& _b) { using namespace bx; const uint16_t sx = uint16_max(_a.m_x, _b.m_x); @@ -307,6 +325,11 @@ namespace bgfx m_height = (uint16_t)uint32_satsub(ey, sy); } + void intersect(const Rect& _a) + { + setIntersect(*this, _a); + } + uint16_t m_x; uint16_t m_y; uint16_t m_width; @@ -418,7 +441,7 @@ namespace bgfx if (size < m_size) { - memset(&m_mem[size], 0, m_size-size); + bx::memSet(&m_mem[size], 0, m_size-size); } } } @@ -474,7 +497,6 @@ namespace bgfx TransientIndexBuffer* m_ib; VertexDecl m_decl; ProgramHandle m_program; - bool m_init; }; struct RendererContextI; @@ -610,6 +632,7 @@ namespace bgfx CreateFrameBuffer, CreateUniform, UpdateViewName, + InvalidateOcclusionQuery, End, RendererShutdownEnd, DestroyVertexDecl, @@ -623,14 +646,14 @@ namespace bgfx DestroyFrameBuffer, DestroyUniform, ReadTexture, - SaveScreenShot, + RequestScreenShot, }; void write(const void* _data, uint32_t _size) { BX_CHECK(m_size == BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE, "Called write outside start/finish?"); BX_CHECK(m_pos < m_size, "CommandBuffer::write error (pos: %d, size: %d).", m_pos, m_size); - memcpy(&m_buffer[m_pos], _data, _size); + bx::memCopy(&m_buffer[m_pos], _data, _size); m_pos += _size; } @@ -644,7 +667,7 @@ namespace bgfx void read(void* _data, uint32_t _size) { BX_CHECK(m_pos < m_size, "CommandBuffer::read error (pos: %d, size: %d).", m_pos, m_size); - memcpy(_data, &m_buffer[m_pos], _size); + bx::memCopy(_data, &m_buffer[m_pos], _size); m_pos += _size; } @@ -885,7 +908,7 @@ namespace bgfx void setIdentity() { - memset(un.val, 0, sizeof(un.val) ); + bx::memSet(un.val, 0, sizeof(un.val) ); un.val[0] = un.val[5] = un.val[10] = un.val[15] = 1.0f; } }; @@ -922,7 +945,7 @@ namespace bgfx if (NULL != _mtx) { uint32_t first = reserve(&_num); - memcpy(&m_cache[first], _mtx, sizeof(Matrix4)*_num); + bx::memCopy(&m_cache[first], _mtx, sizeof(Matrix4)*_num); return first; } @@ -1047,7 +1070,7 @@ namespace bgfx if (m_pos + _size < m_size) { - memcpy(&m_buffer[m_pos], _data, _size); + bx::memCopy(&m_buffer[m_pos], _data, _size); m_pos += _size; } } @@ -1068,7 +1091,7 @@ namespace bgfx uint32_t read() { uint32_t result; - memcpy(&result, read(sizeof(uint32_t) ), sizeof(uint32_t) ); + bx::memCopy(&result, read(sizeof(uint32_t) ), sizeof(uint32_t) ); return result; } @@ -1120,8 +1143,8 @@ namespace bgfx UniformHandle m_handle; }; - class UniformRegistry - { + class UniformRegistry + { public: UniformRegistry() { @@ -1402,7 +1425,7 @@ namespace bgfx term.m_program = invalidHandle; m_sortKeys[BGFX_CONFIG_MAX_DRAW_CALLS] = term.encodeDraw(); m_sortValues[BGFX_CONFIG_MAX_DRAW_CALLS] = BGFX_CONFIG_MAX_DRAW_CALLS; - memset(m_occlusion, 0xff, sizeof(m_occlusion) ); + bx::memSet(m_occlusion, 0xff, sizeof(m_occlusion) ); } ~Frame() @@ -1601,7 +1624,7 @@ namespace bgfx void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _num) { - m_draw.m_instanceDataOffset = _idb->offset; + m_draw.m_instanceDataOffset = _idb->offset; m_draw.m_instanceDataStride = _idb->stride; m_draw.m_numInstances = bx::uint32_min(_idb->num, _num); m_draw.m_instanceDataBuffer = _idb->handle; @@ -1809,7 +1832,7 @@ namespace bgfx Matrix4 m_view[BGFX_CONFIG_MAX_VIEWS]; Matrix4 m_proj[2][BGFX_CONFIG_MAX_VIEWS]; uint8_t m_viewFlags[BGFX_CONFIG_MAX_VIEWS]; - uint8_t m_occlusion[BGFX_CONFIG_MAX_OCCLUSION_QUERIES]; + int32_t m_occlusion[BGFX_CONFIG_MAX_OCCLUSION_QUERIES]; uint64_t m_sortKeys[BGFX_CONFIG_MAX_DRAW_CALLS+1]; RenderItemCount m_sortValues[BGFX_CONFIG_MAX_DRAW_CALLS+1]; @@ -1930,8 +1953,8 @@ namespace bgfx void init() { - memset(m_vertexDeclRef, 0, sizeof(m_vertexDeclRef) ); - memset(m_vertexBufferRef, 0xff, sizeof(m_vertexBufferRef) ); + bx::memSet(m_vertexDeclRef, 0, sizeof(m_vertexDeclRef) ); + bx::memSet(m_vertexBufferRef, 0xff, sizeof(m_vertexBufferRef) ); } template <uint16_t MaxHandlesT> @@ -2143,10 +2166,11 @@ namespace bgfx virtual void destroyFrameBuffer(FrameBufferHandle _handle) = 0; virtual void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) = 0; virtual void destroyUniform(UniformHandle _handle) = 0; - virtual void saveScreenShot(const char* _filePath) = 0; + virtual void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) = 0; virtual void updateViewName(uint8_t _id, const char* _name) = 0; virtual void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) = 0; virtual void setMarker(const char* _marker, uint32_t _size) = 0; + virtual void invalidateOcclusionQuery(OcclusionQueryHandle _handle) = 0; virtual void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) = 0; virtual void blitSetup(TextVideoMemBlitter& _blitter) = 0; virtual void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) = 0; @@ -2171,6 +2195,7 @@ namespace bgfx , m_submit(&m_frame[BGFX_CONFIG_MULTITHREADED ? 1 : 0]) , m_numFreeDynamicIndexBufferHandles(0) , m_numFreeDynamicVertexBufferHandles(0) + , m_numFreeOcclusionQueryHandles(0) , m_colorPaletteDirty(0) , m_instBufferCount(0) , m_frames(0) @@ -2227,7 +2252,7 @@ namespace bgfx m_flipAfterRender = !!(_flags & BGFX_RESET_FLIP_AFTER_RENDER); - memset(m_fb, 0xff, sizeof(m_fb) ); + bx::memSet(m_fb, 0xff, sizeof(m_fb) ); for (uint16_t ii = 0, num = m_textureHandle.getNumHandles(); ii < num; ++ii) { @@ -2620,7 +2645,7 @@ namespace bgfx BGFX_CHECK_HANDLE("updateDynamicVertexBuffer", m_dynamicVertexBufferHandle, _handle); DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[_handle.idx]; - BX_CHECK(0 == (dvb.m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE), "Can't update GPU buffer from CPU."); + BX_CHECK(0 == (dvb.m_flags & BGFX_BUFFER_COMPUTE_WRITE), "Can't update GPU write buffer from CPU."); if (dvb.m_size < _mem->size && 0 != (dvb.m_flags & BGFX_BUFFER_ALLOW_RESIZE) ) @@ -2953,7 +2978,7 @@ namespace bgfx { uint32_t size = sr.m_num*sizeof(UniformHandle); sr.m_uniforms = (UniformHandle*)BX_ALLOC(g_allocator, size); - memcpy(sr.m_uniforms, uniforms, size); + bx::memCopy(sr.m_uniforms, uniforms, size); } CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateShader); @@ -2975,7 +3000,7 @@ namespace bgfx ShaderRef& sr = m_shaderRef[_handle.idx]; if (NULL != _uniforms) { - memcpy(_uniforms, sr.m_uniforms, bx::uint16_min(_max, sr.m_num)*sizeof(UniformHandle) ); + bx::memCopy(_uniforms, sr.m_uniforms, bx::uint16_min(_max, sr.m_num)*sizeof(UniformHandle) ); } return sr.m_num; @@ -3065,7 +3090,7 @@ namespace bgfx } ProgramHandle handle; - handle.idx = m_programHandle.alloc(); + handle.idx = m_programHandle.alloc(); BX_WARN(isValid(handle), "Failed to allocate program handle."); if (isValid(handle) ) @@ -3378,7 +3403,7 @@ namespace bgfx FrameBufferRef& ref = m_frameBufferRef[handle.idx]; ref.m_window = false; - memset(ref.un.m_th, 0xff, sizeof(ref.un.m_th) ); + bx::memSet(ref.un.m_th, 0xff, sizeof(ref.un.m_th) ); BackbufferRatio::Enum bbRatio = BackbufferRatio::Enum(m_textureRef[_attachment[0].handle.idx].m_bbRatio); for (uint32_t ii = 0; ii < _num; ++ii) { @@ -3475,6 +3500,8 @@ namespace bgfx return handle; } + _num = bx::uint16_max(1, _num); + uint16_t idx = m_uniformHashMap.find(bx::hashMurmur2A(_name) ); if (UniformHashMap::invalid != idx) { @@ -3575,20 +3602,29 @@ namespace bgfx OcclusionQueryHandle handle = { m_occlusionQueryHandle.alloc() }; if (isValid(handle) ) { - m_submit->m_occlusion[handle.idx] = UINT8_MAX; + m_submit->m_occlusion[handle.idx] = INT32_MIN; + + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::InvalidateOcclusionQuery); + cmdbuf.write(handle); } + return handle; } - BGFX_API_FUNC(OcclusionQueryResult::Enum getResult(OcclusionQueryHandle _handle) ) + BGFX_API_FUNC(OcclusionQueryResult::Enum getResult(OcclusionQueryHandle _handle, int32_t* _result) ) { BGFX_CHECK_HANDLE("getResult", m_occlusionQueryHandle, _handle); switch (m_submit->m_occlusion[_handle.idx]) { case 0: return OcclusionQueryResult::Invisible; - case UINT8_MAX: return OcclusionQueryResult::NoResult; - default:; + case INT32_MIN: return OcclusionQueryResult::NoResult; + default: break; + } + + if (NULL != _result) + { + *_result = m_submit->m_occlusion[_handle.idx]; } return OcclusionQueryResult::Visible; @@ -3597,13 +3633,27 @@ namespace bgfx BGFX_API_FUNC(void destroyOcclusionQuery(OcclusionQueryHandle _handle) ) { BGFX_CHECK_HANDLE("destroyOcclusionQuery", m_occlusionQueryHandle, _handle); - m_occlusionQueryHandle.free(_handle.idx); + + m_freeOcclusionQueryHandle[m_numFreeOcclusionQueryHandles++] = _handle; } - BGFX_API_FUNC(void saveScreenShot(const char* _filePath) ) + BGFX_API_FUNC(void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) ) { - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SaveScreenShot); + BGFX_CHECK_HANDLE_INVALID_OK("requestScreenShot", m_frameBufferHandle, _handle); + + if (isValid(_handle) ) + { + FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; + if (!ref.m_window) + { + BX_TRACE("requestScreenShot can be done only for window frame buffer handles (handle: %d).", _handle.idx); + return; + } + } + + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RequestScreenShot); uint16_t len = (uint16_t)bx::strnlen(_filePath)+1; + cmdbuf.write(_handle); cmdbuf.write(len); cmdbuf.write(_filePath, len); } @@ -3614,7 +3664,7 @@ namespace bgfx , _index , BGFX_CONFIG_MAX_COLOR_PALETTE ); - memcpy(&m_clearColor[_index][0], _rgba, 16); + bx::memCopy(&m_clearColor[_index][0], _rgba, 16); m_colorPaletteDirty = 2; } @@ -3630,8 +3680,8 @@ namespace bgfx BGFX_API_FUNC(void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) ) { Rect& rect = m_rect[_id]; - rect.m_x = _x; - rect.m_y = _y; + rect.m_x = (uint16_t)bx::uint32_imax(int16_t(_x), 0); + rect.m_y = (uint16_t)bx::uint32_imax(int16_t(_y), 0); rect.m_width = bx::uint16_max(_width, 1); rect.m_height = bx::uint16_max(_height, 1); } @@ -3647,6 +3697,11 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) { + BX_CHECK(bx::fequal(_depth, bx::fclamp(_depth, 0.0f, 1.0f), 0.0001f) + , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." + , _depth + ); + Clear& clear = m_clear[_id]; clear.m_flags = _flags; clear.m_index[0] = uint8_t(_rgba>>24); @@ -3659,6 +3714,11 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(uint8_t _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_CHECK(bx::fequal(_depth, bx::fclamp(_depth, 0.0f, 1.0f), 0.0001f) + , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." + , _depth + ); + Clear& clear = m_clear[_id]; clear.m_flags = (_flags & ~BGFX_CLEAR_COLOR) | (0xff != (_0&_1&_2&_3&_4&_5&_6&_7) ? BGFX_CLEAR_COLOR|BGFX_CLEAR_COLOR_USE_PALETTE : 0) @@ -3692,7 +3752,7 @@ namespace bgfx if (NULL != _view) { - memcpy(m_view[_id].un.val, _view, sizeof(Matrix4) ); + bx::memCopy(m_view[_id].un.val, _view, sizeof(Matrix4) ); } else { @@ -3701,7 +3761,7 @@ namespace bgfx if (NULL != _proj) { - memcpy(m_proj[0][_id].un.val, _proj, sizeof(Matrix4) ); + bx::memCopy(m_proj[0][_id].un.val, _proj, sizeof(Matrix4) ); } else { @@ -3710,11 +3770,11 @@ namespace bgfx if (NULL != _proj1) { - memcpy(m_proj[1][_id].un.val, _proj1, sizeof(Matrix4) ); + bx::memCopy(m_proj[1][_id].un.val, _proj1, sizeof(Matrix4) ); } else { - memcpy(m_proj[1][_id].un.val, m_proj[0][_id].un.val, sizeof(Matrix4) ); + bx::memCopy(m_proj[1][_id].un.val, m_proj[0][_id].un.val, sizeof(Matrix4) ); } } @@ -3742,7 +3802,7 @@ namespace bgfx } else { - memcpy(&m_viewRemap[_id], _order, num); + bx::memCopy(&m_viewRemap[_id], _order, num); } } @@ -4006,7 +4066,7 @@ namespace bgfx const char* getName(UniformHandle _handle) const; // render thread - bool renderFrame(); + RenderFrame::Enum renderFrame(int32_t _msecs = -1); void flushTextureUpdateBatch(CommandBuffer& _cmdbuf); void rendererExecCommands(CommandBuffer& _cmdbuf); @@ -4097,8 +4157,10 @@ namespace bgfx uint16_t m_numFreeDynamicIndexBufferHandles; uint16_t m_numFreeDynamicVertexBufferHandles; - DynamicIndexBufferHandle m_freeDynamicIndexBufferHandle[BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS]; + uint16_t m_numFreeOcclusionQueryHandles; + DynamicIndexBufferHandle m_freeDynamicIndexBufferHandle[BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS]; DynamicVertexBufferHandle m_freeDynamicVertexBufferHandle[BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS]; + OcclusionQueryHandle m_freeOcclusionQueryHandle[BGFX_CONFIG_MAX_OCCLUSION_QUERIES]; NonLocalAllocator m_dynIndexBufferAllocator; bx::HandleAllocT<BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS> m_dynamicIndexBufferHandle; diff --git a/3rdparty/bgfx/src/bgfx_shader.sh b/3rdparty/bgfx/src/bgfx_shader.sh index 2cab0ca0d76..3ee69e85e35 100644 --- a/3rdparty/bgfx/src/bgfx_shader.sh +++ b/3rdparty/bgfx/src/bgfx_shader.sh @@ -53,12 +53,12 @@ # define dFdyFine(_y) ddy_fine(-_y) # endif // BGFX_SHADER_LANGUAGE_HLSL > 4 -# if BGFX_SHADER_LANGUAGE_HLSL +# if BGFX_SHADER_LANGUAGE_HLSL float intBitsToFloat(int _x) { return asfloat(_x); } vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); } vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); } vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); } -# endif // BGFX_SHADER_LANGUAGE_HLSL +# endif // BGFX_SHADER_LANGUAGE_HLSL float uintBitsToFloat(uint _x) { return asfloat(_x); } vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); } @@ -80,7 +80,7 @@ uint2 bitfieldReverse(uint2 _x) { return reversebits(_x); } uint3 bitfieldReverse(uint3 _x) { return reversebits(_x); } uint4 bitfieldReverse(uint4 _x) { return reversebits(_x); } -#if !BGFX_SHADER_LANGUAGE_SPIRV +# if !BGFX_SHADER_LANGUAGE_SPIRV uint packHalf2x16(vec2 _x) { return (f32tof16(_x.x)<<16) | f32tof16(_x.y); @@ -90,7 +90,7 @@ vec2 unpackHalf2x16(uint _x) { return vec2(f16tof32(_x >> 16), f16tof32(_x) ); } -#endif // !BGFX_SHADER_LANGUAGE_SPIRV +# endif // !BGFX_SHADER_LANGUAGE_SPIRV struct BgfxSampler2D { @@ -169,6 +169,11 @@ vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec4 _coord) return _sampler.m_texture.Sample(_sampler.m_sampler, coord); } +vec4 bgfxTexture2DGrad(BgfxSampler2D _sampler, vec2 _coord, vec2 _dPdx, vec2 _dPdy) +{ + return _sampler.m_texture.SampleGrad(_sampler.m_sampler, _coord, _dPdx, _dPdy); +} + vec4 bgfxTexture2DArray(BgfxSampler2DArray _sampler, vec3 _coord) { return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); @@ -263,6 +268,7 @@ vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod) # define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord) # define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level) # define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) +# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) bgfxTexture2DGrad(_sampler, _coord, _dPdx, _dPdy) # define SAMPLER2DARRAY(_name, _reg) \ uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ @@ -360,10 +366,12 @@ float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) # if BGFX_SHADER_LANGUAGE_HLSL == 2 # define texture2DLod(_sampler, _coord, _level) tex2D(_sampler, (_coord).xy) +# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2D(_sampler, _coord) # define texture3DLod(_sampler, _coord, _level) tex3D(_sampler, (_coord).xyz) # define textureCubeLod(_sampler, _coord, _level) texCUBE(_sampler, (_coord).xyz) # else # define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) +# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2Dgrad(_sampler, _coord, _dPdx, _dPdy) # define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) # define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) # endif // BGFX_SHADER_LANGUAGE_HLSL == 2 diff --git a/3rdparty/bgfx/src/glcontext_egl.cpp b/3rdparty/bgfx/src/glcontext_egl.cpp index 69ce6f4398b..ef03ec594ab 100644 --- a/3rdparty/bgfx/src/glcontext_egl.cpp +++ b/3rdparty/bgfx/src/glcontext_egl.cpp @@ -195,6 +195,9 @@ EGL_IMPORT BX_TRACE("Supported EGL extensions:"); dumpExtensions(extensions); + // https://www.khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_recordable.txt + const bool hasEglAndroidRecordable = !!bx::findIdentifierMatch(extensions, "EGL_ANDROID_recordable"); + EGLint attrs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, @@ -206,6 +209,10 @@ EGL_IMPORT # endif // BX_PLATFORM_ EGL_STENCIL_SIZE, 8, + // Android Recordable surface + hasEglAndroidRecordable ? 0x3142 : EGL_NONE, + hasEglAndroidRecordable ? 1 : EGL_NONE, + EGL_NONE }; diff --git a/3rdparty/bgfx/src/glcontext_wgl.cpp b/3rdparty/bgfx/src/glcontext_wgl.cpp index 9d162cda9b6..d20b8449dd1 100644 --- a/3rdparty/bgfx/src/glcontext_wgl.cpp +++ b/3rdparty/bgfx/src/glcontext_wgl.cpp @@ -59,7 +59,7 @@ namespace bgfx { namespace gl static HGLRC createContext(HDC _hdc) { PIXELFORMATDESCRIPTOR pfd; - memset(&pfd, 0, sizeof(pfd) ); + bx::memSet(&pfd, 0, sizeof(pfd) ); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; @@ -245,7 +245,7 @@ namespace bgfx { namespace gl BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create context 0x%08x.", GetLastError() ); BX_STATIC_ASSERT(sizeof(contextAttrs) == sizeof(m_contextAttrs) ); - memcpy(m_contextAttrs, contextAttrs, sizeof(contextAttrs) ); + bx::memCopy(m_contextAttrs, contextAttrs, sizeof(contextAttrs) ); } wglMakeCurrent(NULL, NULL); diff --git a/3rdparty/bgfx/src/hmd_ovr.cpp b/3rdparty/bgfx/src/hmd_ovr.cpp index ba8268fc2f8..0898d9d65be 100644 --- a/3rdparty/bgfx/src/hmd_ovr.cpp +++ b/3rdparty/bgfx/src/hmd_ovr.cpp @@ -104,7 +104,7 @@ namespace bgfx for (int eye = 0; eye < 2; ++eye) { BX_STATIC_ASSERT(sizeof(_desc->m_eyeFov[eye]) == sizeof(hmdDesc.DefaultEyeFov[eye])); - memcpy(&_desc->m_eyeFov[eye], &hmdDesc.DefaultEyeFov[eye], sizeof(_desc->m_eyeFov[eye])); + bx::memCopy(&_desc->m_eyeFov[eye], &hmdDesc.DefaultEyeFov[eye], sizeof(_desc->m_eyeFov[eye])); _desc->m_eyeSize[eye].m_w = eyeSize[eye].w; _desc->m_eyeSize[eye].m_h = eyeSize[eye].h; } diff --git a/3rdparty/bgfx/src/image.cpp b/3rdparty/bgfx/src/image.cpp index 61cfd413b6d..e6c9e074a2c 100644 --- a/3rdparty/bgfx/src/image.cpp +++ b/3rdparty/bgfx/src/image.cpp @@ -263,7 +263,7 @@ namespace bgfx return uint8_t(numMips); } - uint32_t imageGetSize(TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth, uint16_t _numLayers, bool _cubeMap, uint8_t _numMips) + uint32_t imageGetSize(TextureInfo* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format) { const ImageBlockInfo& blockInfo = getBlockInfo(_format); const uint8_t bpp = blockInfo.bitsPerPixel; @@ -272,17 +272,18 @@ namespace bgfx const uint16_t minBlockX = blockInfo.minBlockX; const uint16_t minBlockY = blockInfo.minBlockY; - _width = bx::uint16_max(blockWidth * minBlockX, ( (_width + blockWidth - 1) / blockWidth)*blockWidth); - _height = bx::uint16_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight); - _depth = bx::uint16_max(1, _depth); + _width = bx::uint16_max(blockWidth * minBlockX, ( (_width + blockWidth - 1) / blockWidth)*blockWidth); + _height = bx::uint16_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight); + _depth = bx::uint16_max(1, _depth); + const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth); + const uint32_t sides = _cubeMap ? 6 : 1; uint32_t width = _width; uint32_t height = _height; uint32_t depth = _depth; - uint32_t sides = _cubeMap ? 6 : 1; uint32_t size = 0; - for (uint32_t lod = 0; lod < _numMips; ++lod) + for (uint32_t lod = 0; lod < numMips; ++lod) { width = bx::uint32_max(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth); height = bx::uint32_max(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight); @@ -295,7 +296,22 @@ namespace bgfx depth >>= 1; } - return size * _numLayers; + size *= _numLayers; + + if (NULL != _info) + { + _info->format = _format; + _info->width = _width; + _info->height = _height; + _info->depth = _depth; + _info->numMips = numMips; + _info->numLayers = _numLayers; + _info->cubeMap = _cubeMap; + _info->storageSize = size; + _info->bitsPerPixel = bpp; + } + + return size; } void imageSolid(void* _dst, uint32_t _width, uint32_t _height, uint32_t _solid) @@ -661,7 +677,7 @@ namespace bgfx for (uint32_t yy = 0; yy < _height; ++yy, src += _srcPitch, dst += _dstPitch) { - memcpy(dst, src, pitch); + bx::memCopy(dst, src, pitch); } } @@ -820,9 +836,97 @@ namespace bgfx bool imageConvert(void* _dst, TextureFormat::Enum _dstFormat, const void* _src, TextureFormat::Enum _srcFormat, uint32_t _width, uint32_t _height) { const uint32_t srcBpp = s_imageBlockInfo[_srcFormat].bitsPerPixel; + + if (_dstFormat == _srcFormat) + { + bx::memCopy(_dst, _src, _width*_height*srcBpp/8); + return true; + } + return imageConvert(_dst, _dstFormat, _src, _srcFormat, _width, _height, _width*srcBpp/8); } + ImageContainer* imageConvert(bx::AllocatorI* _allocator, TextureFormat::Enum _dstFormat, const ImageContainer& _input) + { + ImageContainer* output = imageAlloc(_allocator + , _dstFormat + , uint16_t(_input.m_width) + , uint16_t(_input.m_height) + , uint16_t(_input.m_depth) + , _input.m_numLayers + , _input.m_cubeMap + , 1 < _input.m_numMips + ); + + const uint8_t bpp = getBitsPerPixel(_dstFormat); + const uint16_t numSides = _input.m_numLayers * (_input.m_cubeMap ? 6 : 1); + + uint8_t* dst = (uint8_t*)output->m_data ; + for (uint16_t side = 0; side < numSides; ++side) + { + for (uint8_t lod = 0, num = _input.m_numMips; lod < num; ++lod) + { + ImageMip mip; + if (imageGetRawData(_input, side, lod, _input.m_data, _input.m_size, mip) ) + { + bool ok = imageConvert(dst + , _dstFormat + , mip.m_data + , mip.m_format + , mip.m_width + , mip.m_height + ); + BX_CHECK(ok, "Conversion from %s to %s failed!" + , getName(_input.m_format) + , getName(output->m_format) + ); + BX_UNUSED(ok); + + dst += mip.m_width*mip.m_height*bpp/8; + } + } + } + + return output; + } + + ImageContainer* imageParseBgfx(bx::AllocatorI* _allocator, const void* _src, uint32_t _size) + { + ImageContainer imageContainer; + if (!imageParse(imageContainer, _src, _size) ) + { + return NULL; + } + + ImageContainer* output = imageAlloc(_allocator + , imageContainer.m_format + , uint16_t(imageContainer.m_width) + , uint16_t(imageContainer.m_height) + , uint16_t(imageContainer.m_depth) + , imageContainer.m_numLayers + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + ); + + const uint16_t numSides = imageContainer.m_numLayers * (imageContainer.m_cubeMap ? 6 : 1); + uint8_t* dst = (uint8_t*)output->m_data; + + for (uint16_t side = 0; side < numSides; ++side) + { + for (uint8_t lod = 0, num = imageContainer.m_numMips; lod < num; ++lod) + { + ImageMip mip; + if (imageGetRawData(imageContainer, side, lod, _src, _size, mip) ) + { + bx::memCopy(dst, mip.m_data, mip.m_size); + dst += mip.m_size; + } + } + } + + return output; + } + uint8_t bitRangeConvert(uint32_t _in, uint32_t _from, uint32_t _to) { using namespace bx; @@ -1607,7 +1711,7 @@ namespace bgfx } } - const Memory* imageAlloc(ImageContainer& _imageContainer, TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth, uint16_t _numLayers, bool _cubeMap, bool _generateMips) + ImageContainer* imageAlloc(bx::AllocatorI* _allocator, TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth, uint16_t _numLayers, bool _cubeMap, bool _hasMips, const void* _data) { const ImageBlockInfo& blockInfo = getBlockInfo(_format); const uint16_t blockWidth = blockInfo.blockWidth; @@ -1620,31 +1724,38 @@ namespace bgfx _depth = bx::uint16_max(1, _depth); _numLayers = bx::uint16_max(1, _numLayers); - const uint8_t numMips = _generateMips ? imageGetNumMips(_format, _width, _height) : 1; - uint32_t size = imageGetSize(_format, _width, _height, _depth, _numLayers, _cubeMap, numMips); - const Memory* image = alloc(size); - - _imageContainer.m_data = image->data; - _imageContainer.m_format = _format; - _imageContainer.m_size = image->size; - _imageContainer.m_offset = 0; - _imageContainer.m_width = _width; - _imageContainer.m_height = _height; - _imageContainer.m_depth = _depth; - _imageContainer.m_numLayers = _numLayers; - _imageContainer.m_numMips = numMips; - _imageContainer.m_hasAlpha = false; - _imageContainer.m_cubeMap = _cubeMap; - _imageContainer.m_ktx = false; - _imageContainer.m_ktxLE = false; - _imageContainer.m_srgb = false; + const uint8_t numMips = _hasMips ? imageGetNumMips(_format, _width, _height) : 1; + uint32_t size = imageGetSize(NULL, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, _format); + + ImageContainer* imageContainer = (ImageContainer*)BX_ALLOC(_allocator, size + sizeof(ImageContainer) ); + + imageContainer->m_allocator = _allocator; + imageContainer->m_data = imageContainer + 1; + imageContainer->m_format = _format; + imageContainer->m_size = size; + imageContainer->m_offset = 0; + imageContainer->m_width = _width; + imageContainer->m_height = _height; + imageContainer->m_depth = _depth; + imageContainer->m_numLayers = _numLayers; + imageContainer->m_numMips = numMips; + imageContainer->m_hasAlpha = false; + imageContainer->m_cubeMap = _cubeMap; + imageContainer->m_ktx = false; + imageContainer->m_ktxLE = false; + imageContainer->m_srgb = false; + + if (NULL != _data) + { + bx::memCopy(imageContainer->m_data, _data, imageContainer->m_size); + } - return image; + return imageContainer; } - void imageFree(const Memory* _memory) + void imageFree(ImageContainer* _imageContainer) { - release(_memory); + BX_FREE(_imageContainer->m_allocator, _imageContainer); } // DDS @@ -1988,6 +2099,7 @@ namespace bgfx } } + _imageContainer.m_allocator = NULL; _imageContainer.m_data = NULL; _imageContainer.m_size = 0; _imageContainer.m_offset = (uint32_t)bx::seek(_reader); @@ -2297,6 +2409,7 @@ namespace bgfx } } + _imageContainer.m_allocator = NULL; _imageContainer.m_data = NULL; _imageContainer.m_size = 0; _imageContainer.m_offset = (uint32_t)offset; @@ -2447,6 +2560,7 @@ namespace bgfx } } + _imageContainer.m_allocator = NULL; _imageContainer.m_data = NULL; _imageContainer.m_size = 0; _imageContainer.m_offset = (uint32_t)offset; @@ -2489,6 +2603,7 @@ namespace bgfx _imageContainer.m_format = tc.m_format; _imageContainer.m_offset = UINT32_MAX; + _imageContainer.m_allocator = NULL; if (NULL == tc.m_mem) { _imageContainer.m_data = NULL; @@ -2544,10 +2659,10 @@ namespace bgfx src += 8; uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2563,10 +2678,10 @@ namespace bgfx src += 8; uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2582,10 +2697,10 @@ namespace bgfx src += 8; uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2599,10 +2714,10 @@ namespace bgfx src += 8; uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2627,10 +2742,10 @@ namespace bgfx } uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2645,10 +2760,10 @@ namespace bgfx src += 8; uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2681,10 +2796,10 @@ namespace bgfx decodeBlockPtc14(temp, src, xx, yy, width, height); uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2697,10 +2812,10 @@ namespace bgfx decodeBlockPtc14A(temp, src, xx, yy, width, height); uint8_t* block = &dst[(yy*_pitch+xx*4)*4]; - memcpy(&block[0*_pitch], &temp[ 0], 16); - memcpy(&block[1*_pitch], &temp[16], 16); - memcpy(&block[2*_pitch], &temp[32], 16); - memcpy(&block[3*_pitch], &temp[48], 16); + bx::memCopy(&block[0*_pitch], &temp[ 0], 16); + bx::memCopy(&block[1*_pitch], &temp[16], 16); + bx::memCopy(&block[2*_pitch], &temp[32], 16); + bx::memCopy(&block[3*_pitch], &temp[48], 16); } } break; @@ -2720,7 +2835,7 @@ namespace bgfx break; case TextureFormat::BGRA8: - memcpy(_dst, _src, _pitch*_height); + bx::memCopy(_dst, _src, _pitch*_height); break; default: @@ -2742,7 +2857,7 @@ namespace bgfx switch (_format) { case TextureFormat::RGBA8: - memcpy(_dst, _src, _pitch*_height); + bx::memCopy(_dst, _src, _pitch*_height); break; case TextureFormat::BGRA8: @@ -2862,7 +2977,7 @@ namespace bgfx break; case TextureFormat::RGBA32F: - memcpy(_dst, _src, _pitch*_height); + bx::memCopy(_dst, _src, _pitch*_height); break; case TextureFormat::RGBA8: @@ -2872,7 +2987,8 @@ namespace bgfx default: if (isCompressed(_format) ) { - void* temp = BX_ALLOC(_allocator, imageGetSize(_format, uint16_t(_pitch/4), uint16_t(_height) ) ); + uint32_t size = imageGetSize(NULL, uint16_t(_pitch/4), uint16_t(_height), 0, false, false, 1, _format); + void* temp = BX_ALLOC(_allocator, size); imageDecodeToRgba8(temp, _src, _width, _height, _pitch, _format); imageRgba8ToRgba32f(_dst, _width, _height, _pitch, temp); BX_FREE(_allocator, temp); diff --git a/3rdparty/bgfx/src/image.h b/3rdparty/bgfx/src/image.h index 7d708ccb8b0..ef05a1f2ba7 100644 --- a/3rdparty/bgfx/src/image.h +++ b/3rdparty/bgfx/src/image.h @@ -6,15 +6,17 @@ #ifndef BGFX_IMAGE_H_HEADER_GUARD #define BGFX_IMAGE_H_HEADER_GUARD -#include <stdint.h> #include <bx/pixelformat.h> namespace bgfx { struct ImageContainer { - void* m_data; + bx::AllocatorI* m_allocator; + void* m_data; + TextureFormat::Enum m_format; + uint32_t m_size; uint32_t m_offset; uint32_t m_width; @@ -88,18 +90,19 @@ namespace bgfx , uint16_t _width , uint16_t _height , uint16_t _depth = 0 - ); + ); /// Returns image size. uint32_t imageGetSize( - TextureFormat::Enum _format + TextureInfo* _info , uint16_t _width , uint16_t _height - , uint16_t _depth = 0 - , uint16_t _numLayers = 1 - , bool _cubeMap = false - , uint8_t _numMips = 1 - ); + , uint16_t _depth + , bool _cubeMap + , bool _hasMips + , uint16_t _numLayers + , TextureFormat::Enum _format + ); /// void imageSolid(void* _dst, uint32_t _width, uint32_t _height, uint32_t _solid); @@ -135,37 +138,95 @@ namespace bgfx bool imageConvert(TextureFormat::Enum _dstFormat, TextureFormat::Enum _srcFormat); /// - void imageConvert(void* _dst, uint32_t _bpp, bx::PackFn _pack, const void* _src, bx::UnpackFn _unpack, uint32_t _size); - - /// - void imageConvert(void* _dst, uint32_t _dstBpp, bx::PackFn _pack, const void* _src, uint32_t _srcBpp, bx::UnpackFn _unpack, uint32_t _width, uint32_t _height, uint32_t _srcPitch); - - /// - bool imageConvert(void* _dst, TextureFormat::Enum _dstFormat, const void* _src, TextureFormat::Enum _srcFormat, uint32_t _width, uint32_t _height); - - /// - const Memory* imageAlloc( - ImageContainer& _imageContainer + void imageConvert( + void* _dst + , uint32_t _bpp + , bx::PackFn _pack + , const void* _src + , bx::UnpackFn _unpack + , uint32_t _size + ); + + /// + void imageConvert( + void* _dst + , uint32_t _dstBpp + , bx::PackFn _pack + , const void* _src + , uint32_t _srcBpp + , bx::UnpackFn _unpack + , uint32_t _width + , uint32_t _height + , uint32_t _srcPitch + ); + + /// + bool imageConvert( + void* _dst + , TextureFormat::Enum _dstFormat + , const void* _src + , TextureFormat::Enum _srcFormat + , uint32_t _width + , uint32_t _height + ); + + /// + ImageContainer* imageConvert( + bx::AllocatorI* _allocator + , TextureFormat::Enum _dstFormat + , const void* _src + , uint32_t _size + ); + + /// + ImageContainer* imageAlloc( + bx::AllocatorI* _allocator , TextureFormat::Enum _format , uint16_t _width , uint16_t _height - , uint16_t _depth = 0 - , uint16_t _numLayers = 1 - , bool _cubeMap = false - , bool _generateMips = false - ); + , uint16_t _depth + , uint16_t _numLayers + , bool _cubeMap + , bool _hasMips + , const void* _data = NULL + ); /// - void imageFree(const Memory* _memory); + void imageFree(ImageContainer* _imageContainer); /// - void imageWriteTga(bx::WriterI* _writer, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, bool _grayscale, bool _yflip, bx::Error* _err = NULL); + void imageWriteTga( + bx::WriterI* _writer + , uint32_t _width + , uint32_t _height + , uint32_t _pitch + , const void* _src + , bool _grayscale + , bool _yflip + , bx::Error* _err = NULL + ); /// - void imageWriteKtx(bx::WriterI* _writer, TextureFormat::Enum _format, bool _cubeMap, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, const void* _src, bx::Error* _err = NULL); - - /// - void imageWriteKtx(bx::WriterI* _writer, ImageContainer& _imageContainer, const void* _data, uint32_t _size, bx::Error* _err = NULL); + void imageWriteKtx( + bx::WriterI* _writer + , TextureFormat::Enum _format + , bool _cubeMap + , uint32_t _width + , uint32_t _height + , uint32_t _depth + , uint8_t _numMips + , const void* _src + , bx::Error* _err = NULL + ); + + /// + void imageWriteKtx( + bx::WriterI* _writer + , ImageContainer& _imageContainer + , const void* _data + , uint32_t _size + , bx::Error* _err = NULL + ); /// bool imageParse(ImageContainer& _imageContainer, bx::ReaderSeekerI* _reader); diff --git a/3rdparty/bgfx/src/makefile b/3rdparty/bgfx/src/makefile index 2475a5104d4..8f017d2d9c0 100644 --- a/3rdparty/bgfx/src/makefile +++ b/3rdparty/bgfx/src/makefile @@ -27,7 +27,7 @@ define shader-embedded @echo [$(<)] $(SILENT) $(SHADERC) --type $(1) --platform linux -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_glsl @cat $(SHADER_TMP) > $(@) - -$(SILENT) $(SHADERC) --type $(1) --platform windows -p spirv -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_spv + -$(SILENT) $(SHADERC) --type $(1) --platform linux -p spirv -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_spv -@cat $(SHADER_TMP) >> $(@) -$(SILENT) $(SHADERC) --type $(1) --platform windows -p $(2) -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_dx9 -@cat $(SHADER_TMP) >> $(@) diff --git a/3rdparty/bgfx/src/renderer.h b/3rdparty/bgfx/src/renderer.h index 1beadce2ff9..1bf8fbba072 100644 --- a/3rdparty/bgfx/src/renderer.h +++ b/3rdparty/bgfx/src/renderer.h @@ -57,7 +57,7 @@ namespace bgfx } else { - memcpy(&m_view[0][ii].un.f4x4, &_frame->m_view[ii].un.f4x4, sizeof(Matrix4) ); + bx::memCopy(&m_view[0][ii].un.f4x4, &_frame->m_view[ii].un.f4x4, sizeof(Matrix4) ); } } } diff --git a/3rdparty/bgfx/src/renderer_d3d11.cpp b/3rdparty/bgfx/src/renderer_d3d11.cpp index ea8e18bfb37..2a65c2a2c1d 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.cpp +++ b/3rdparty/bgfx/src/renderer_d3d11.cpp @@ -70,7 +70,7 @@ namespace bgfx { namespace d3d11 { Zero() { - memset(this, 0, sizeof(Zero) ); + bx::memSet(this, 0, sizeof(Zero) ); } ID3D11Buffer* m_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; @@ -364,7 +364,7 @@ namespace bgfx { namespace d3d11 { if (UINT16_MAX != _decl.m_attributes[attr]) { - memcpy(elem, &s_attrib[attr], sizeof(D3D11_INPUT_ELEMENT_DESC) ); + bx::memCopy(elem, &s_attrib[attr], sizeof(D3D11_INPUT_ELEMENT_DESC) ); if (0 == _decl.m_attributes[attr]) { @@ -397,8 +397,8 @@ namespace bgfx { namespace d3d11 void clear() { - memset(m_srv, 0, sizeof(m_srv) ); - memset(m_sampler, 0, sizeof(m_sampler) ); + bx::memSet(m_srv, 0, sizeof(m_srv) ); + bx::memSet(m_sampler, 0, sizeof(m_sampler) ); } ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; @@ -463,7 +463,7 @@ namespace bgfx { namespace d3d11 char temp[2048]; va_list argList; va_start(argList, _format); - int size = bx::uint32_min(sizeof(temp)-1, vsnprintf(temp, sizeof(temp), _format, argList) ); + int size = bx::uint32_min(sizeof(temp)-1, bx::vsnprintf(temp, sizeof(temp), _format, argList) ); va_end(argList); temp[size] = '\0'; @@ -675,9 +675,9 @@ namespace bgfx { namespace d3d11 , m_timerQuerySupport(false) { m_fbh.idx = invalidHandle; - memset(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); - memset(&m_scd, 0, sizeof(m_scd) ); - memset(&m_windows, 0xff, sizeof(m_windows) ); + bx::memSet(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); + bx::memSet(&m_scd, 0, sizeof(m_scd) ); + bx::memSet(&m_windows, 0xff, sizeof(m_windows) ); } ~RendererContextD3D11() @@ -712,8 +712,8 @@ namespace bgfx { namespace d3d11 } m_fbh.idx = invalidHandle; - memset(m_uniforms, 0, sizeof(m_uniforms) ); - memset(&m_resolution, 0, sizeof(m_resolution) ); + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); m_ags = NULL; m_agsdll = bx::dlopen( @@ -1124,7 +1124,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_RELEASE(device, 2); } - memset(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); + bx::memSet(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); hr = adapter->GetDesc(&m_adapterDesc); BX_WARN(SUCCEEDED(hr), "Adapter GetDesc failed 0x%08x.", hr); @@ -1145,7 +1145,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); goto error; } - memset(&m_scd, 0, sizeof(m_scd) ); + bx::memSet(&m_scd, 0, sizeof(m_scd) ); m_scd.Width = BGFX_DEFAULT_WIDTH; m_scd.Height = BGFX_DEFAULT_HEIGHT; m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; @@ -1205,7 +1205,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); goto error; } - memset(&m_scd, 0, sizeof(m_scd) ); + bx::memSet(&m_scd, 0, sizeof(m_scd) ); m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; m_scd.BufferDesc.RefreshRate.Numerator = 60; @@ -1236,7 +1236,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } else { - memset(&m_scd, 0, sizeof(m_scd) ); + bx::memSet(&m_scd, 0, sizeof(m_scd) ); m_scd.SampleDesc.Count = 1; m_scd.SampleDesc.Quality = 0; setBufferSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); @@ -1258,7 +1258,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, false); D3D11_INFO_QUEUE_FILTER filter; - memset(&filter, 0, sizeof(filter) ); + bx::memSet(&filter, 0, sizeof(filter) ); D3D11_MESSAGE_CATEGORY catlist[] = { @@ -1763,7 +1763,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) BX_OVERRIDE { VertexDecl& decl = m_vertexDecls[_handle.idx]; - memcpy(&decl, &_decl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); dump(decl); } @@ -1869,7 +1869,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); for (uint32_t yy = 0, height = srcHeight; yy < height; ++yy) { - memcpy(dst, src, pitch); + bx::memCopy(dst, src, pitch); src += srcPitch; dst += dstPitch; @@ -1963,7 +1963,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num); void* data = BX_ALLOC(g_allocator, size); - memset(data, 0, size); + bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; m_uniformReg.add(_handle, _name, data); } @@ -1975,22 +1975,27 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_uniformReg.remove(_handle); } - void saveScreenShot(const char* _filePath) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) BX_OVERRIDE { - if (NULL == m_swapChain) + IDXGISwapChain* swapChain = isValid(_handle) + ? m_frameBuffers[_handle.idx].m_swapChain + : m_swapChain + ; + + if (NULL == swapChain) { BX_TRACE("Unable to capture screenshot %s.", _filePath); return; } ID3D11Texture2D* backBuffer; - DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&backBuffer) ); + DX_CHECK(swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&backBuffer) ); D3D11_TEXTURE2D_DESC backBufferDesc; backBuffer->GetDesc(&backBufferDesc); D3D11_TEXTURE2D_DESC desc; - memcpy(&desc, &backBufferDesc, sizeof(desc) ); + bx::memCopy(&desc, &backBufferDesc, sizeof(desc) ); desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = D3D11_USAGE_STAGING; @@ -2062,7 +2067,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE { - memcpy(m_uniforms[_loc], _data, _size); + bx::memCopy(m_uniforms[_loc], _data, _size); } void setMarker(const char* _marker, uint32_t _size) BX_OVERRIDE @@ -2076,6 +2081,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } } + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE + { + m_occlusionQuery.invalidate(_handle); + } + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE; void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE @@ -2527,12 +2537,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { if (_flags&BGFX_UNIFORM_FRAGMENTBIT) { - memcpy(&m_fsScratch[_regIndex], _val, _numRegs*16); + bx::memCopy(&m_fsScratch[_regIndex], _val, _numRegs*16); m_fsChanges += _numRegs; } else { - memcpy(&m_vsScratch[_regIndex], _val, _numRegs*16); + bx::memCopy(&m_vsScratch[_regIndex], _val, _numRegs*16); m_vsChanges += _numRegs; } } @@ -2661,7 +2671,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); D3D11_INPUT_ELEMENT_DESC vertexElements[Attrib::Count+1+BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; VertexDecl decl; - memcpy(&decl, &_vertexDecl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_vertexDecl, sizeof(VertexDecl) ); const uint16_t* attrMask = _program.m_vsh->m_attrMask; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) @@ -2685,7 +2695,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); for (jj = 0; jj < num; ++jj) { curr = &vertexElements[jj]; - if (0 == strcmp(curr->SemanticName, "TEXCOORD") + if (0 == bx::strncmp(curr->SemanticName, "TEXCOORD") && curr->SemanticIndex == index) { break; @@ -2698,7 +2708,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); ++elem; } - memcpy(curr, &inst, sizeof(D3D11_INPUT_ELEMENT_DESC) ); + bx::memCopy(curr, &inst, sizeof(D3D11_INPUT_ELEMENT_DESC) ); curr->InputSlot = 1; curr->SemanticIndex = index; curr->AlignedByteOffset = ii*16; @@ -2798,7 +2808,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { for (uint32_t ii = 1; ii < BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS; ++ii) { - memcpy(&desc.RenderTarget[ii], drt, sizeof(D3D11_RENDER_TARGET_BLEND_DESC) ); + bx::memCopy(&desc.RenderTarget[ii], drt, sizeof(D3D11_RENDER_TARGET_BLEND_DESC) ); } } @@ -2849,7 +2859,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (NULL == dss) { D3D11_DEPTH_STENCIL_DESC desc; - memset(&desc, 0, sizeof(desc) ); + bx::memSet(&desc, 0, sizeof(desc) ); desc.DepthEnable = 0 != func; desc.DepthWriteMask = !!(BGFX_STATE_DEPTH_WRITE & _state) ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; desc.DepthFunc = s_cmpFunc[func]; @@ -2989,7 +2999,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { D3D11_SAMPLER_DESC sd; sampler->GetDesc(&sd); - if (0 != memcmp(_rgba, sd.BorderColor, 16) ) + if (0 != bx::memCmp(_rgba, sd.BorderColor, 16) ) { // Sampler will be released when updated sampler // is added to cache. @@ -3229,7 +3239,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); backBuffer->GetDesc(&backBufferDesc); D3D11_TEXTURE2D_DESC desc; - memcpy(&desc, &backBufferDesc, sizeof(desc) ); + bx::memCopy(&desc, &backBufferDesc, sizeof(desc) ); desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = D3D11_USAGE_STAGING; @@ -3327,7 +3337,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); else { UniformHandle handle; - memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); data = (const char*)m_uniforms[handle.idx]; } @@ -3451,7 +3461,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - memcpy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClear[ii], _palette[index], 16); } deviceCtx->UpdateSubresource(fsh->m_buffer, 0, 0, mrtClear, 0, 0); @@ -3672,7 +3682,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); , m_textureSwapChain(NULL) , m_mirrorTexture(NULL) { - memset(m_eyeRtv, 0, sizeof(m_eyeRtv)); + bx::memSet(m_eyeRtv, 0, sizeof(m_eyeRtv)); } bool VRImplOVRD3D11::createSwapChain(const VRDesc& _desc, int _msaaSamples, int _mirrorWidth, int _mirrorHeight) @@ -4085,7 +4095,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); : D3D11_MAP_WRITE_NO_OVERWRITE ; DX_CHECK(deviceCtx->Map(m_ptr, 0, type, 0, &mapped) ); - memcpy( (uint8_t*)mapped.pData + _offset, _data, _size); + bx::memCopy( (uint8_t*)mapped.pData + _offset, _data, _size); deviceCtx->Unmap(m_ptr, 0); #endif // 0 } @@ -4276,7 +4286,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); uint8_t numAttrs = 0; bx::read(&reader, numAttrs); - memset(m_attrMask, 0, sizeof(m_attrMask) ); + bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); for (uint32_t ii = 0; ii < numAttrs; ++ii) { @@ -4437,7 +4447,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); ; D3D11_SHADER_RESOURCE_VIEW_DESC srvd; - memset(&srvd, 0, sizeof(srvd) ); + bx::memSet(&srvd, 0, sizeof(srvd) ); DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; if (swizzle) @@ -4572,12 +4582,28 @@ BX_PRAGMA_DIAGNOSTIC_POP(); desc.CPUAccessFlags = 0; desc.MiscFlags = 0; + if (renderTarget) + { + desc.BindFlags |= D3D11_BIND_RENDER_TARGET; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.MiscFlags |= 0 + | (1 < numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) + ; + } + if (computeWrite) { desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS; desc.Usage = D3D11_USAGE_DEFAULT; } + if (readBack) + { + desc.BindFlags = 0; + desc.Usage = D3D11_USAGE_STAGING; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + } + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; srvd.Texture3D.MipLevels = numMips; @@ -4740,7 +4766,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_denseIdx = UINT16_MAX; m_numTh = _num; m_needPresent = false; - memcpy(m_attachment, _attachment, _num*sizeof(Attachment) ); + bx::memCopy(m_attachment, _attachment, _num*sizeof(Attachment) ); postReset(); } @@ -4748,7 +4774,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void FrameBufferD3D11::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) { DXGI_SWAP_CHAIN_DESC scd; - memcpy(&scd, &s_renderD3D11->m_scd, sizeof(DXGI_SWAP_CHAIN_DESC) ); + bx::memCopy(&scd, &s_renderD3D11->m_scd, sizeof(DXGI_SWAP_CHAIN_DESC) ); scd.BufferDesc.Width = _width; scd.BufferDesc.Height = _height; scd.OutputWindow = (HWND)_nwh; @@ -5215,18 +5241,36 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { Query& query = m_query[m_control.m_read]; - uint64_t result = 0; - HRESULT hr = deviceCtx->GetData(query.m_ptr, &result, sizeof(result), _wait ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH); - if (S_FALSE == hr) + if (isValid(query.m_handle) ) { - break; + uint64_t result = 0; + HRESULT hr = deviceCtx->GetData(query.m_ptr, &result, sizeof(result), _wait ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH); + if (S_FALSE == hr) + { + break; + } + + _render->m_occlusion[query.m_handle.idx] = int32_t(result); } - _render->m_occlusion[query.m_handle.idx] = 0 < result; m_control.consume(1); } } + void OcclusionQueryD3D11::invalidate(OcclusionQueryHandle _handle) + { + const uint32_t size = m_control.m_size; + + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + Query& query = m_query[(m_control.m_read + ii) % size]; + if (query.m_handle.idx == _handle.idx) + { + query.m_handle.idx = bgfx::invalidHandle; + } + } + } + void RendererContextD3D11::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { if (updateResolution(_render->m_resolution) ) @@ -5754,7 +5798,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); else { Rect scissorRect; - scissorRect.intersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); + scissorRect.setIntersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); if (scissorRect.isZeroArea() ) { continue; diff --git a/3rdparty/bgfx/src/renderer_d3d11.h b/3rdparty/bgfx/src/renderer_d3d11.h index 2ee0a8787ac..852a69e11c0 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.h +++ b/3rdparty/bgfx/src/renderer_d3d11.h @@ -182,14 +182,14 @@ namespace bgfx { namespace d3d11 { BX_CHECK(NULL != _vsh->m_ptr, "Vertex shader doesn't exist."); m_vsh = _vsh; - memcpy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform) ); + bx::memCopy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform) ); m_numPredefined = _vsh->m_numPredefined; if (NULL != _fsh) { BX_CHECK(NULL != _fsh->m_ptr, "Fragment shader doesn't exist."); m_fsh = _fsh; - memcpy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform) ); + bx::memCopy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform) ); m_numPredefined += _fsh->m_numPredefined; } } @@ -338,6 +338,7 @@ namespace bgfx { namespace d3d11 void begin(Frame* _render, OcclusionQueryHandle _handle); void end(); void resolve(Frame* _render, bool _wait = false); + void invalidate(OcclusionQueryHandle _handle); struct Query { diff --git a/3rdparty/bgfx/src/renderer_d3d12.cpp b/3rdparty/bgfx/src/renderer_d3d12.cpp index 3ba3619561c..cf001166b4c 100644 --- a/3rdparty/bgfx/src/renderer_d3d12.cpp +++ b/3rdparty/bgfx/src/renderer_d3d12.cpp @@ -316,7 +316,7 @@ namespace bgfx { namespace d3d12 { if (UINT16_MAX != _decl.m_attributes[attr]) { - memcpy(elem, &s_attrib[attr], sizeof(D3D12_INPUT_ELEMENT_DESC) ); + bx::memCopy(elem, &s_attrib[attr], sizeof(D3D12_INPUT_ELEMENT_DESC) ); if (0 == _decl.m_attributes[attr]) { @@ -439,7 +439,7 @@ namespace bgfx { namespace d3d12 char temp[2048]; va_list argList; va_start(argList, _format); - int size = bx::uint32_min(sizeof(temp)-1, vsnprintf(temp, sizeof(temp), _format, argList) ); + int size = bx::uint32_min(sizeof(temp)-1, bx::vsnprintf(temp, sizeof(temp), _format, argList) ); va_end(argList); temp[size] = '\0'; @@ -498,11 +498,11 @@ namespace bgfx { namespace d3d12 ErrorState::Enum errorState = ErrorState::Default; LUID luid; -// m_renderdocdll = loadRenderDoc(); + m_renderdocdll = loadRenderDoc(); m_fbh.idx = invalidHandle; - memset(m_uniforms, 0, sizeof(m_uniforms) ); - memset(&m_resolution, 0, sizeof(m_resolution) ); + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); #if USE_D3D12_DYNAMIC_LIB m_kernel32dll = bx::dlopen("kernel32.dll"); @@ -684,7 +684,7 @@ namespace bgfx { namespace d3d12 if (NULL != m_factory) { - memset(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); + bx::memSet(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); luid = m_device->GetAdapterLuid(); #if BX_PLATFORM_WINDOWS IDXGIAdapter3* adapter; @@ -730,7 +730,7 @@ namespace bgfx { namespace d3d12 ); if (0 == ii) { - memcpy(&m_architecture, &architecture, sizeof(architecture) ); + bx::memCopy(&m_architecture, &architecture, sizeof(architecture) ); } } } @@ -895,7 +895,7 @@ namespace bgfx { namespace d3d12 m_infoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, false); D3D12_INFO_QUEUE_FILTER filter; - memset(&filter, 0, sizeof(filter) ); + bx::memSet(&filter, 0, sizeof(filter) ); D3D12_MESSAGE_CATEGORY catlist[] = { @@ -1319,7 +1319,7 @@ namespace bgfx { namespace d3d12 void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) BX_OVERRIDE { VertexDecl& decl = m_vertexDecls[_handle.idx]; - memcpy(&decl, &_decl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); dump(decl); } @@ -1456,7 +1456,7 @@ namespace bgfx { namespace d3d12 for (uint32_t yy = 0, height = srcHeight; yy < height; ++yy) { - memcpy(dst, src, pitch); + bx::memCopy(dst, src, pitch); src += srcPitch; dst += dstPitch; @@ -1547,7 +1547,7 @@ namespace bgfx { namespace d3d12 uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type] * _num); void* data = BX_ALLOC(g_allocator, size); - memset(data, 0, size); + bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; m_uniformReg.add(_handle, _name, data); } @@ -1559,8 +1559,10 @@ namespace bgfx { namespace d3d12 m_uniformReg.remove(_handle); } - void saveScreenShot(const char* _filePath) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) BX_OVERRIDE { + BX_UNUSED(_handle); + uint32_t idx = (m_backBufferColorIdx-1) % m_scd.BufferCount; m_cmd.finish(m_backBufferColorFence[idx]); ID3D12Resource* backBuffer = m_backBufferColor[idx]; @@ -1630,13 +1632,18 @@ namespace bgfx { namespace d3d12 void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE { - memcpy(m_uniforms[_loc], _data, _size); + bx::memCopy(m_uniforms[_loc], _data, _size); } void setMarker(const char* /*_marker*/, uint32_t /*_size*/) BX_OVERRIDE { } + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE + { + m_occlusionQuery.invalidate(_handle); + } + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE; void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE @@ -1762,7 +1769,7 @@ namespace bgfx { namespace d3d12 void postReset() { - memset(m_backBufferColorFence, 0, sizeof(m_backBufferColorFence) ); + bx::memSet(m_backBufferColorFence, 0, sizeof(m_backBufferColorFence) ); uint32_t rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); @@ -1835,7 +1842,7 @@ namespace bgfx { namespace d3d12 uint32_t msaa = s_checkMsaa[ii]; D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS data; - memset(&data, 0, sizeof(msaa) ); + bx::memSet(&data, 0, sizeof(msaa) ); data.Format = getBufferFormat(); data.SampleCount = msaa; data.Flags = D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE; @@ -1945,12 +1952,12 @@ data.NumQualityLevels = 0; { if (_flags&BGFX_UNIFORM_FRAGMENTBIT) { - memcpy(&m_fsScratch[_regIndex], _val, _numRegs*16); + bx::memCopy(&m_fsScratch[_regIndex], _val, _numRegs*16); m_fsChanges += _numRegs; } else { - memcpy(&m_vsScratch[_regIndex], _val, _numRegs*16); + bx::memCopy(&m_vsScratch[_regIndex], _val, _numRegs*16); m_vsChanges += _numRegs; } } @@ -1977,7 +1984,7 @@ data.NumQualityLevels = 0; { uint32_t size = program.m_vsh->m_size; - memcpy(data, m_vsScratch, size); + bx::memCopy(data, m_vsScratch, size); data += size; m_vsChanges = 0; @@ -1985,7 +1992,7 @@ data.NumQualityLevels = 0; if (NULL != program.m_fsh) { - memcpy(data, m_fsScratch, program.m_fsh->m_size); + bx::memCopy(data, m_fsScratch, program.m_fsh->m_size); m_fsChanges = 0; } @@ -2149,7 +2156,7 @@ data.NumQualityLevels = 0; { for (uint32_t ii = 1; ii < BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS; ++ii) { - memcpy(&_desc.RenderTarget[ii], drt, sizeof(D3D12_RENDER_TARGET_BLEND_DESC) ); + bx::memCopy(&_desc.RenderTarget[ii], drt, sizeof(D3D12_RENDER_TARGET_BLEND_DESC) ); } } } @@ -2181,7 +2188,7 @@ data.NumQualityLevels = 0; { const uint32_t fstencil = unpackStencil(0, _stencil); - memset(&_desc, 0, sizeof(_desc) ); + bx::memSet(&_desc, 0, sizeof(_desc) ); uint32_t func = (_state&BGFX_STATE_DEPTH_TEST_MASK)>>BGFX_STATE_DEPTH_TEST_SHIFT; _desc.DepthEnable = 0 != func; _desc.DepthWriteMask = !!(BGFX_STATE_DEPTH_WRITE & _state) @@ -2212,7 +2219,7 @@ data.NumQualityLevels = 0; uint32_t setInputLayout(D3D12_INPUT_ELEMENT_DESC* _vertexElements, const VertexDecl& _vertexDecl, const ProgramD3D12& _program, uint8_t _numInstanceData) { VertexDecl decl; - memcpy(&decl, &_vertexDecl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_vertexDecl, sizeof(VertexDecl) ); const uint16_t* attrMask = _program.m_vsh->m_attrMask; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) @@ -2236,7 +2243,7 @@ data.NumQualityLevels = 0; for (jj = 0; jj < num; ++jj) { curr = &_vertexElements[jj]; - if (0 == strcmp(curr->SemanticName, "TEXCOORD") + if (0 == bx::strncmp(curr->SemanticName, "TEXCOORD") && curr->SemanticIndex == index) { break; @@ -2249,7 +2256,7 @@ data.NumQualityLevels = 0; ++elem; } - memcpy(curr, &inst, sizeof(D3D12_INPUT_ELEMENT_DESC) ); + bx::memCopy(curr, &inst, sizeof(D3D12_INPUT_ELEMENT_DESC) ); curr->InputSlot = 1; curr->SemanticIndex = index; curr->AlignedByteOffset = ii*16; @@ -2291,7 +2298,7 @@ data.NumQualityLevels = 0; } D3D12_COMPUTE_PIPELINE_STATE_DESC desc; - memset(&desc, 0, sizeof(desc) ); + bx::memSet(&desc, 0, sizeof(desc) ); desc.pRootSignature = m_rootSignature; @@ -2330,7 +2337,7 @@ data.NumQualityLevels = 0; _stencil &= packStencil(~BGFX_STENCIL_FUNC_REF_MASK, BGFX_STENCIL_MASK); VertexDecl decl; - memcpy(&decl, &m_vertexDecls[_declIdx], sizeof(VertexDecl) ); + bx::memCopy(&decl, &m_vertexDecls[_declIdx], sizeof(VertexDecl) ); const uint16_t* attrMask = program.m_vsh->m_attrMask; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) @@ -2361,7 +2368,7 @@ data.NumQualityLevels = 0; } D3D12_GRAPHICS_PIPELINE_STATE_DESC desc; - memset(&desc, 0, sizeof(desc) ); + bx::memSet(&desc, 0, sizeof(desc) ); desc.pRootSignature = m_rootSignature; @@ -2369,7 +2376,7 @@ data.NumQualityLevels = 0; desc.VS.BytecodeLength = program.m_vsh->m_code->size; const Memory* temp = alloc(program.m_fsh->m_code->size); - memset(temp->data, 0, temp->size); + bx::memSet(temp->data, 0, temp->size); bx::MemoryReader rd(program.m_fsh->m_code->data, program.m_fsh->m_code->size); bx::StaticMemoryBlockWriter wr(temp->data, temp->size); @@ -2388,14 +2395,14 @@ data.NumQualityLevels = 0; dxbcHash(temp->data + 20, temp->size - 20, temp->data + 4); - patchShader = 0 == memcmp(program.m_fsh->m_code->data, temp->data, 16); + patchShader = 0 == bx::memCmp(program.m_fsh->m_code->data, temp->data, 16); BX_CHECK(patchShader, "DXBC fragment shader patching error (ShaderHandle: %d).", program.m_fsh - m_shaders); if (!patchShader) { for (uint32_t ii = 20; ii < temp->size; ii += 16) { - if (0 != memcmp(&program.m_fsh->m_code->data[ii], &temp->data[ii], 16) ) + if (0 != bx::memCmp(&program.m_fsh->m_code->data[ii], &temp->data[ii], 16) ) { // bx::debugPrintfData(&program.m_fsh->m_code->data[ii], temp->size-ii, ""); // bx::debugPrintfData(&temp->data[ii], temp->size-ii, ""); @@ -2410,7 +2417,7 @@ data.NumQualityLevels = 0; if (patchShader) { - memcpy(temp->data, program.m_fsh->m_code->data, program.m_fsh->m_code->size); + bx::memCopy(temp->data, program.m_fsh->m_code->data, program.m_fsh->m_code->size); bx::seek(&wr, 0, bx::Whence::Begin); union { uint32_t offset; void* ptr; } cast = @@ -2509,7 +2516,7 @@ data.NumQualityLevels = 0; if (FAILED(hr) ) { BX_TRACE("Failed to load cached PSO (HRESULT 0x%08x).", hr); - memset(&desc.CachedPSO, 0, sizeof(desc.CachedPSO) ); + bx::memSet(&desc.CachedPSO, 0, sizeof(desc.CachedPSO) ); } } } @@ -2632,7 +2639,7 @@ data.NumQualityLevels = 0; else { UniformHandle handle; - memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); data = (const char*)m_uniforms[handle.idx]; } @@ -2977,7 +2984,7 @@ data.NumQualityLevels = 0; D3D12_SHADER_RESOURCE_VIEW_DESC* srvd = &_texture.m_srvd; if (0 != _mip) { - memcpy(&tmpSrvd, srvd, sizeof(tmpSrvd) ); + bx::memCopy(&tmpSrvd, srvd, sizeof(tmpSrvd) ); srvd = &tmpSrvd; switch (_texture.m_srvd.ViewDimension) @@ -3023,7 +3030,7 @@ data.NumQualityLevels = 0; if (0 != _mip) { - memcpy(&tmpUavd, uavd, sizeof(tmpUavd) ); + bx::memCopy(&tmpUavd, uavd, sizeof(tmpUavd) ); uavd = &tmpUavd; switch (_texture.m_uavd.ViewDimension) @@ -3473,7 +3480,7 @@ data.NumQualityLevels = 0; } else { - memset(&cmd.vbv[1], 0, sizeof(cmd.vbv[1]) ); + bx::memSet(&cmd.vbv[1], 0, sizeof(cmd.vbv[1]) ); } cmd.draw.InstanceCount = _draw.m_numInstances; cmd.draw.VertexCountPerInstance = numVertices; @@ -3514,7 +3521,7 @@ data.NumQualityLevels = 0; } else { - memset(&cmd.vbv[1], 0, sizeof(cmd.vbv[1]) ); + bx::memSet(&cmd.vbv[1], 0, sizeof(cmd.vbv[1]) ); } cmd.drawIndexed.IndexCountPerInstance = numIndices; cmd.drawIndexed.InstanceCount = _draw.m_numInstances; @@ -3579,9 +3586,9 @@ data.NumQualityLevels = 0; _commandList->SetGraphicsRootConstantBufferView(Rdt::CBV, cmd.cbv); } - if (0 != memcmp(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ) ) + if (0 != bx::memCmp(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ) ) { - memcpy(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ); + bx::memCopy(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ); _commandList->IASetVertexBuffers(0 , 0 == cmd.vbv[1].BufferLocation ? 1 : 2 , cmd.vbv @@ -3609,18 +3616,18 @@ data.NumQualityLevels = 0; _commandList->SetGraphicsRootConstantBufferView(Rdt::CBV, cmd.cbv); } - if (0 != memcmp(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ) ) + if (0 != bx::memCmp(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ) ) { - memcpy(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ); + bx::memCopy(m_current.vbv, cmd.vbv, sizeof(cmd.vbv) ); _commandList->IASetVertexBuffers(0 , 0 == cmd.vbv[1].BufferLocation ? 1 : 2 , cmd.vbv ); } - if (0 != memcmp(&m_current.ibv, &cmd.ibv, sizeof(cmd.ibv) ) ) + if (0 != bx::memCmp(&m_current.ibv, &cmd.ibv, sizeof(cmd.ibv) ) ) { - memcpy(&m_current.ibv, &cmd.ibv, sizeof(cmd.ibv) ); + bx::memCopy(&m_current.ibv, &cmd.ibv, sizeof(cmd.ibv) ); _commandList->IASetIndexBuffer(&cmd.ibv); } @@ -3644,14 +3651,14 @@ data.NumQualityLevels = 0; if (_clean) { - memset(&m_current, 0, sizeof(m_current) ); + bx::memSet(&m_current, 0, sizeof(m_current) ); } } void BatchD3D12::begin() { - memset(&m_stats, 0, sizeof(m_stats) ); - memset(&m_current, 0, sizeof(m_current) ); + bx::memSet(&m_stats, 0, sizeof(m_stats) ); + bx::memSet(&m_current, 0, sizeof(m_current) ); } void BatchD3D12::end(ID3D12GraphicsCommandList* _commandList) @@ -3772,7 +3779,7 @@ data.NumQualityLevels = 0; ID3D12Resource* staging = createCommittedResource(s_renderD3D12->m_device, HeapProperty::Upload, _size); uint8_t* data; DX_CHECK(staging->Map(0, NULL, (void**)&data) ); - memcpy(data, _data, _size); + bx::memCopy(data, _data, _size); staging->Unmap(0, NULL); D3D12_RESOURCE_STATES state = setState(_commandList, D3D12_RESOURCE_STATE_COPY_DEST); @@ -3933,7 +3940,7 @@ data.NumQualityLevels = 0; uint8_t numAttrs = 0; bx::read(&reader, numAttrs); - memset(m_attrMask, 0, sizeof(m_attrMask) ); + bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); for (uint32_t ii = 0; ii < numAttrs; ++ii) { @@ -4128,7 +4135,7 @@ data.NumQualityLevels = 0; const uint32_t msaaQuality = bx::uint32_satsub( (m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; - memset(&m_srvd, 0, sizeof(m_srvd) ); + bx::memSet(&m_srvd, 0, sizeof(m_srvd) ); m_srvd.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; m_srvd.Format = s_textureFormat[m_textureFormat].m_fmtSrv; DXGI_FORMAT format = s_textureFormat[m_textureFormat].m_fmt; @@ -4263,7 +4270,8 @@ data.NumQualityLevels = 0; break; case Texture3D: - resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; + resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; + resourceDesc.DepthOrArraySize = uint16_t(m_depth); m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; m_srvd.Texture3D.MostDetailedMip = 0; m_srvd.Texture3D.MipLevels = numMips; @@ -4385,7 +4393,7 @@ data.NumQualityLevels = 0; DX_CHECK(staging->Map(0, NULL, (void**)&data) ); for (uint32_t ii = 0, height = _rect.m_height; ii < height; ++ii) { - memcpy(&data[ii*rowPitch], &_mem->data[ii*srcpitch], srcpitch); + bx::memCopy(&data[ii*rowPitch], &_mem->data[ii*srcpitch], srcpitch); } staging->Unmap(0, NULL); @@ -4431,7 +4439,7 @@ data.NumQualityLevels = 0; { m_denseIdx = UINT16_MAX; m_numTh = _num; - memcpy(m_attachment, _attachment, _num*sizeof(Attachment) ); + bx::memCopy(m_attachment, _attachment, _num*sizeof(Attachment) ); postReset(); } @@ -4716,7 +4724,10 @@ data.NumQualityLevels = 0; while (0 == m_control.reserve(1) ) { OcclusionQueryHandle handle = m_handle[m_control.m_read]; - _render->m_occlusion[handle.idx] = 0 < m_result[handle.idx]; + if (isValid(handle) ) + { + _render->m_occlusion[handle.idx] = int32_t(m_result[handle.idx]); + } m_control.consume(1); } @@ -4744,6 +4755,20 @@ data.NumQualityLevels = 0; m_control.commit(1); } + void OcclusionQueryD3D12::invalidate(OcclusionQueryHandle _handle) + { + const uint32_t size = m_control.m_size; + + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + OcclusionQueryHandle& handle = m_handle[(m_control.m_read + ii) % size]; + if (handle.idx == _handle.idx) + { + handle.idx = bgfx::invalidHandle; + } + } + } + struct Bind { D3D12_GPU_DESCRIPTOR_HANDLE m_srvHandle; @@ -4909,7 +4934,7 @@ data.NumQualityLevels = 0; if (BGFX_CLEAR_NONE != clr.m_flags) { Rect clearRect = rect; - clearRect.intersect(rect, viewScissorRect); + clearRect.setIntersect(rect, viewScissorRect); clearQuad(clearRect, clr, _render->m_colorPalette); } @@ -5286,7 +5311,7 @@ data.NumQualityLevels = 0; } else { - memcpy(&srvHandle[stage], &srvHandle[0], sizeof(D3D12_GPU_DESCRIPTOR_HANDLE) ); + bx::memCopy(&srvHandle[stage], &srvHandle[0], sizeof(D3D12_GPU_DESCRIPTOR_HANDLE) ); samplerFlags[stage] = 0; } } @@ -5372,7 +5397,7 @@ data.NumQualityLevels = 0; { restoreScissor = true; Rect scissorRect; - scissorRect.intersect(viewScissorRect,_render->m_rectCache.m_cache[scissor]); + scissorRect.setIntersect(viewScissorRect,_render->m_rectCache.m_cache[scissor]); if (scissorRect.isZeroArea() ) { continue; @@ -5545,27 +5570,34 @@ data.NumQualityLevels = 0; ); #if BX_PLATFORM_WINDOWS - DXGI_QUERY_VIDEO_MEMORY_INFO memInfo; - DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &memInfo) ); + DXGI_QUERY_VIDEO_MEMORY_INFO vmi[2]; + DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &vmi[0]) ); + DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &vmi[1]) ); - char budget[16]; - bx::prettify(budget, BX_COUNTOF(budget), memInfo.Budget); + for (uint32_t ii = 0; ii < BX_COUNTOF(vmi); ++ii) + { + const DXGI_QUERY_VIDEO_MEMORY_INFO& memInfo = vmi[ii]; - char currentUsage[16]; - bx::prettify(currentUsage, BX_COUNTOF(currentUsage), memInfo.CurrentUsage); + char budget[16]; + bx::prettify(budget, BX_COUNTOF(budget), memInfo.Budget); - char availableForReservation[16]; - bx::prettify(availableForReservation, BX_COUNTOF(currentUsage), memInfo.AvailableForReservation); + char currentUsage[16]; + bx::prettify(currentUsage, BX_COUNTOF(currentUsage), memInfo.CurrentUsage); - char currentReservation[16]; - bx::prettify(currentReservation, BX_COUNTOF(currentReservation), memInfo.CurrentReservation); + char availableForReservation[16]; + bx::prettify(availableForReservation, BX_COUNTOF(currentUsage), memInfo.AvailableForReservation); - tvm.printf(0, pos++, 0x8f, " Budget: %s, Usage: %s, AvailRes: %s, CurrRes: %s " - , budget - , currentUsage - , availableForReservation - , currentReservation - ); + char currentReservation[16]; + bx::prettify(currentReservation, BX_COUNTOF(currentReservation), memInfo.CurrentReservation); + + tvm.printf(0, pos++, 0x8f, " %s - Budget: %10s, Usage: %10s, AvailRes: %10s, CurrRes: %10s " + , 0 == ii ? "Local " : "Non-local" + , budget + , currentUsage + , availableForReservation + , currentReservation + ); + } #endif // BX_PLATFORM_WINDOWS pos = 10; diff --git a/3rdparty/bgfx/src/renderer_d3d12.h b/3rdparty/bgfx/src/renderer_d3d12.h index 8a490ab7860..25de46c80bb 100644 --- a/3rdparty/bgfx/src/renderer_d3d12.h +++ b/3rdparty/bgfx/src/renderer_d3d12.h @@ -231,14 +231,14 @@ namespace bgfx { namespace d3d12 { BX_CHECK(NULL != _vsh->m_code, "Vertex shader doesn't exist."); m_vsh = _vsh; - memcpy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform)); + bx::memCopy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform)); m_numPredefined = _vsh->m_numPredefined; if (NULL != _fsh) { BX_CHECK(NULL != _fsh->m_code, "Fragment shader doesn't exist."); m_fsh = _fsh; - memcpy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform)); + bx::memCopy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform)); m_numPredefined += _fsh->m_numPredefined; } } @@ -271,8 +271,8 @@ namespace bgfx { namespace d3d12 , m_state(D3D12_RESOURCE_STATE_COMMON) , m_numMips(0) { - memset(&m_srvd, 0, sizeof(m_srvd) ); - memset(&m_uavd, 0, sizeof(m_uavd) ); + bx::memSet(&m_srvd, 0, sizeof(m_srvd) ); + bx::memSet(&m_uavd, 0, sizeof(m_uavd) ); } void create(const Memory* _mem, uint32_t _flags, uint8_t _skip); @@ -380,7 +380,7 @@ namespace bgfx { namespace d3d12 , m_minIndirect(0) , m_flushPerBatch(0) { - memset(m_num, 0, sizeof(m_num) ); + bx::memSet(m_num, 0, sizeof(m_num) ); } ~BatchD3D12() @@ -481,6 +481,7 @@ namespace bgfx { namespace d3d12 void shutdown(); void begin(ID3D12GraphicsCommandList* _commandList, Frame* _render, OcclusionQueryHandle _handle); void end(ID3D12GraphicsCommandList* _commandList); + void invalidate(OcclusionQueryHandle _handle); ID3D12Resource* m_readback; ID3D12QueryHeap* m_queryHeap; diff --git a/3rdparty/bgfx/src/renderer_d3d9.cpp b/3rdparty/bgfx/src/renderer_d3d9.cpp index 58e45db9032..4f4267be9ad 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.cpp +++ b/3rdparty/bgfx/src/renderer_d3d9.cpp @@ -329,13 +329,13 @@ namespace bgfx { namespace d3d9 ErrorState::Enum errorState = ErrorState::Default; m_fbh.idx = invalidHandle; - memset(m_uniforms, 0, sizeof(m_uniforms) ); - memset(&m_resolution, 0, sizeof(m_resolution) ); + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); D3DFORMAT adapterFormat = D3DFMT_X8R8G8B8; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172588%28v=vs.85%29.aspx - memset(&m_params, 0, sizeof(m_params) ); + bx::memSet(&m_params, 0, sizeof(m_params) ); m_params.BackBufferWidth = BGFX_DEFAULT_WIDTH; m_params.BackBufferHeight = BGFX_DEFAULT_HEIGHT; m_params.BackBufferFormat = adapterFormat; @@ -1023,7 +1023,7 @@ namespace bgfx { namespace d3d9 for (uint32_t yy = 0, height = srcHeight; yy < height; ++yy) { - memcpy(dst, src, pitch); + bx::memCopy(dst, src, pitch); src += srcPitch; dst += dstPitch; @@ -1117,7 +1117,7 @@ namespace bgfx { namespace d3d9 uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num); void* data = BX_ALLOC(g_allocator, size); - memset(data, 0, size); + bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; m_uniformReg.add(_handle, _name, data); } @@ -1129,9 +1129,23 @@ namespace bgfx { namespace d3d9 m_uniformReg.remove(_handle); } - void saveScreenShot(const char* _filePath) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) BX_OVERRIDE { #if BX_PLATFORM_WINDOWS + IDirect3DSwapChain9* swapChain = isValid(_handle) + ? m_frameBuffers[_handle.idx].m_swapChain + : m_swapChain + ; + + if (NULL == swapChain) + { + BX_TRACE("Unable to capture screenshot %s.", _filePath); + return; + } + + D3DPRESENT_PARAMETERS params; + DX_CHECK(swapChain->GetPresentParameters(¶ms)); + IDirect3DSurface9* surface; D3DDEVICE_CREATION_PARAMETERS dcp; DX_CHECK(m_device->GetCreationParameters(&dcp) ); @@ -1147,8 +1161,14 @@ namespace bgfx { namespace d3d9 , NULL ) ); + HWND nwh = params.hDeviceWindow; + + SetWindowPos(nwh, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + DX_CHECK(m_device->GetFrontBufferData(0, surface) ); + SetWindowPos(nwh, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + D3DLOCKED_RECT rect; DX_CHECK(surface->LockRect(&rect , NULL @@ -1156,25 +1176,27 @@ namespace bgfx { namespace d3d9 ) ); RECT rc; - GetClientRect( (HWND)g_platformData.nwh, &rc); + GetClientRect(nwh, &rc); POINT point; point.x = rc.left; point.y = rc.top; - ClientToScreen( (HWND)g_platformData.nwh, &point); + ClientToScreen(nwh, &point); uint8_t* data = (uint8_t*)rect.pBits; uint32_t bytesPerPixel = rect.Pitch/dm.Width; g_callback->screenShot(_filePath - , m_params.BackBufferWidth - , m_params.BackBufferHeight + , params.BackBufferWidth + , params.BackBufferHeight , rect.Pitch , &data[point.y*rect.Pitch+point.x*bytesPerPixel] - , m_params.BackBufferHeight*rect.Pitch + , params.BackBufferHeight*rect.Pitch , false ); DX_CHECK(surface->UnlockRect() ); DX_RELEASE(surface, 0); +#else + BX_UNUSED(_handle, _filePath); #endif // BX_PLATFORM_WINDOWS } @@ -1196,7 +1218,7 @@ namespace bgfx { namespace d3d9 void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE { - memcpy(m_uniforms[_loc], _data, _size); + bx::memCopy(m_uniforms[_loc], _data, _size); } void setMarker(const char* _marker, uint32_t _size) BX_OVERRIDE @@ -1210,6 +1232,11 @@ namespace bgfx { namespace d3d9 BX_UNUSED(_marker, _size); } + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE + { + m_occlusionQuery.invalidate(_handle); + } + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE; void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE @@ -1760,7 +1787,7 @@ namespace bgfx { namespace d3d9 else { UniformHandle handle; - memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); data = (const char*)m_uniforms[handle.idx]; } @@ -2004,7 +2031,7 @@ namespace bgfx { namespace d3d9 for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, _clear.m_index[ii]); - memcpy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClear[ii], _palette[index], 16); } } else @@ -2019,7 +2046,7 @@ namespace bgfx { namespace d3d9 for (uint32_t ii = 0; ii < numMrt; ++ii) { - memcpy(mrtClear[ii], rgba, 16); + bx::memCopy(mrtClear[ii], rgba, 16); } } @@ -2311,7 +2338,7 @@ namespace bgfx { namespace d3d9 bool asInt; _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); - memcpy(elem, &s_attrib[attr], sizeof(D3DVERTEXELEMENT9) ); + bx::memCopy(elem, &s_attrib[attr], sizeof(D3DVERTEXELEMENT9) ); elem->Type = s_attribType[type][num-1][normalized]; elem->Offset = _decl.m_offset[attr]; @@ -2331,13 +2358,13 @@ namespace bgfx { namespace d3d9 for (uint8_t ii = 0; ii < _numInstanceData; ++ii) { - memcpy(elem, &inst, sizeof(D3DVERTEXELEMENT9) ); + bx::memCopy(elem, &inst, sizeof(D3DVERTEXELEMENT9) ); elem->UsageIndex = uint8_t(7-ii); // TEXCOORD7 = i_data0, TEXCOORD6 = i_data1, etc. elem->Offset = ii*16; ++elem; } - memcpy(elem, &s_attrib[Attrib::Count], sizeof(D3DVERTEXELEMENT9) ); + bx::memCopy(elem, &s_attrib[Attrib::Count], sizeof(D3DVERTEXELEMENT9) ); IDirect3DVertexDeclaration9* ptr; DX_CHECK(s_renderD3D9->m_device->CreateVertexDeclaration(vertexElements, &ptr) ); @@ -2346,7 +2373,7 @@ namespace bgfx { namespace d3d9 void VertexDeclD3D9::create(const VertexDecl& _decl) { - memcpy(&m_decl, &_decl, sizeof(VertexDecl) ); + bx::memCopy(&m_decl, &_decl, sizeof(VertexDecl) ); dump(m_decl); m_ptr = createVertexDeclaration(_decl, 0); } @@ -2990,7 +3017,7 @@ namespace bgfx { namespace d3d9 break; default: - memcpy(bits, mip.m_data, size); + bx::memCopy(bits, mip.m_data, size); break; } } @@ -3052,7 +3079,7 @@ namespace bgfx { namespace d3d9 break; default: - memcpy(dst, src, rectpitch); + bx::memCopy(dst, src, rectpitch); break; } src += srcpitch; @@ -3159,7 +3186,7 @@ namespace bgfx { namespace d3d9 m_num = 0; m_numTh = _num; m_needResolve = false; - memcpy(m_attachment, _attachment, _num*sizeof(Attachment) ); + bx::memCopy(m_attachment, _attachment, _num*sizeof(Attachment) ); for (uint32_t ii = 0; ii < _num; ++ii) { @@ -3216,7 +3243,7 @@ namespace bgfx { namespace d3d9 m_height = bx::uint32_max(_height, 16); D3DPRESENT_PARAMETERS params; - memcpy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); + bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); params.BackBufferWidth = m_width; params.BackBufferHeight = m_height; @@ -3326,7 +3353,7 @@ namespace bgfx { namespace d3d9 if (NULL != m_hwnd) { D3DPRESENT_PARAMETERS params; - memcpy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); + bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); params.BackBufferWidth = m_width; params.BackBufferHeight = m_height; @@ -3547,18 +3574,36 @@ namespace bgfx { namespace d3d9 { Query& query = m_query[m_control.m_read]; - uint32_t result; - HRESULT hr = query.m_ptr->GetData(&result, sizeof(result), 0); - if (S_FALSE == hr) + if (isValid(query.m_handle) ) { - break; + uint32_t result; + HRESULT hr = query.m_ptr->GetData(&result, sizeof(result), 0); + if (S_FALSE == hr) + { + break; + } + + _render->m_occlusion[query.m_handle.idx] = int32_t(result); } - _render->m_occlusion[query.m_handle.idx] = 0 < result; m_control.consume(1); } } + void OcclusionQueryD3D9::invalidate(OcclusionQueryHandle _handle) + { + const uint32_t size = m_control.m_size; + + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + Query& query = m_query[(m_control.m_read + ii) % size]; + if (query.m_handle.idx == _handle.idx) + { + query.m_handle.idx = bgfx::invalidHandle; + } + } + } + void RendererContextD3D9::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { IDirect3DDevice9* device = m_device; @@ -3795,7 +3840,7 @@ namespace bgfx { namespace d3d9 else { Rect scissorRect; - scissorRect.intersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); + scissorRect.setIntersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); if (scissorRect.isZeroArea() ) { continue; diff --git a/3rdparty/bgfx/src/renderer_d3d9.h b/3rdparty/bgfx/src/renderer_d3d9.h index 93c42c853a1..2aa9b64dcb9 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.h +++ b/3rdparty/bgfx/src/renderer_d3d9.h @@ -144,7 +144,7 @@ namespace bgfx { namespace d3d9 , _discard || (m_dynamic && 0 == _offset && m_size == _size) ? D3DLOCK_DISCARD : 0 ) ); - memcpy(buffer, _data, _size); + bx::memCopy(buffer, _data, _size); DX_CHECK(m_ptr->Unlock() ); } @@ -185,7 +185,7 @@ namespace bgfx { namespace d3d9 , _discard || (m_dynamic && 0 == _offset && m_size == _size) ? D3DLOCK_DISCARD : 0 ) ); - memcpy(buffer, _data, _size); + bx::memCopy(buffer, _data, _size); DX_CHECK(m_ptr->Unlock() ); } @@ -276,8 +276,8 @@ namespace bgfx { namespace d3d9 BX_CHECK(NULL != _fsh.m_pixelShader, "Fragment shader doesn't exist."); m_fsh = &_fsh; - memcpy(&m_predefined[0], _vsh.m_predefined, _vsh.m_numPredefined*sizeof(PredefinedUniform) ); - memcpy(&m_predefined[_vsh.m_numPredefined], _fsh.m_predefined, _fsh.m_numPredefined*sizeof(PredefinedUniform) ); + bx::memCopy(&m_predefined[0], _vsh.m_predefined, _vsh.m_numPredefined*sizeof(PredefinedUniform) ); + bx::memCopy(&m_predefined[_vsh.m_numPredefined], _fsh.m_predefined, _fsh.m_numPredefined*sizeof(PredefinedUniform) ); m_numPredefined = _vsh.m_numPredefined + _fsh.m_numPredefined; } @@ -468,6 +468,7 @@ namespace bgfx { namespace d3d9 void begin(Frame* _render, OcclusionQueryHandle _handle); void end(); void resolve(Frame* _render, bool _wait = false); + void invalidate(OcclusionQueryHandle _handle); struct Query { diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp index 93a714ea194..8f4903a2cb1 100644 --- a/3rdparty/bgfx/src/renderer_gl.cpp +++ b/3rdparty/bgfx/src/renderer_gl.cpp @@ -851,10 +851,16 @@ namespace bgfx { namespace gl static const char* s_ARB_shader_texture_lod[] = { "texture2DLod", + "texture2DArrayLod", // BK - interacts with ARB_texture_array. "texture2DProjLod", + "texture2DGrad", + "texture2DProjGrad", "texture3DLod", "texture3DProjLod", + "texture3DGrad", + "texture3DProjGrad", "textureCubeLod", + "textureCubeGrad", "shadow2DLod", "shadow2DProjLod", NULL @@ -869,10 +875,10 @@ namespace bgfx { namespace gl "texture2DLod", "texture2DProjLod", "textureCubeLod", + "texture2DGrad", + "texture2DProjGrad", + "textureCubeGrad", NULL - // "texture2DGrad", - // "texture2DProjGrad", - // "textureCubeGrad", }; static const char* s_EXT_shadow_samplers[] = @@ -1055,7 +1061,7 @@ namespace bgfx { namespace gl while (pos < end) { uint32_t len; - const char* space = strchr(pos, ' '); + const char* space = bx::strnchr(pos, ' '); if (NULL != space) { len = bx::uint32_min(sizeof(name), (uint32_t)(space - pos) ); @@ -1065,7 +1071,7 @@ namespace bgfx { namespace gl len = bx::uint32_min(sizeof(name), (uint32_t)bx::strnlen(pos) ); } - strncpy(name, pos, len); + bx::strlncpy(name, BX_COUNTOF(name), pos, len); name[len] = '\0'; BX_TRACE("\t%s", name); @@ -1349,12 +1355,12 @@ namespace bgfx { namespace gl && extension.m_initialize) { const char* ext = _name; - if (0 == strncmp(ext, "GL_", 3) ) // skip GL_ + if (0 == bx::strncmp(ext, "GL_", 3) ) // skip GL_ { ext += 3; } - if (0 == strcmp(ext, extension.m_name) ) + if (0 == bx::strncmp(ext, extension.m_name) ) { extension.m_supported = true; supported = true; @@ -1437,7 +1443,7 @@ namespace bgfx { namespace gl , m_backBufferFbo(0) , m_msaaBackBufferFbo(0) { - memset(m_msaaBackBufferRbos, 0, sizeof(m_msaaBackBufferRbos) ); + bx::memSet(m_msaaBackBufferRbos, 0, sizeof(m_msaaBackBufferRbos) ); } ~RendererContextGL() @@ -1449,8 +1455,8 @@ namespace bgfx { namespace gl m_renderdocdll = loadRenderDoc(); m_fbh.idx = invalidHandle; - memset(m_uniforms, 0, sizeof(m_uniforms) ); - memset(&m_resolution, 0, sizeof(m_resolution) ); + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); setRenderContextSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); @@ -1469,7 +1475,7 @@ namespace bgfx { namespace gl for (uint32_t ii = 0; ii < BX_COUNTOF(s_vendorIds); ++ii) { const VendorId& vendorId = s_vendorIds[ii]; - if (0 == strncmp(vendorId.name, m_vendor, bx::strnlen(vendorId.name) ) ) + if (0 == bx::strncmp(vendorId.name, m_vendor, bx::strnlen(vendorId.name) ) ) { g_caps.vendorId = vendorId.id; break; @@ -1543,8 +1549,8 @@ namespace bgfx { namespace gl ; if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 31) - && 0 == strcmp(m_vendor, "Imagination Technologies") - && NULL != strstr(m_version, "(SDK 3.5@3510720)") ) + && 0 == bx::strncmp(m_vendor, "Imagination Technologies") + && NULL != bx::strnstr(m_version, "(SDK 3.5@3510720)") ) { // Skip initializing extensions that are broken in emulator. s_extension[Extension::ARB_program_interface_query ].m_initialize = @@ -1564,7 +1570,7 @@ namespace bgfx { namespace gl while (pos < end) { uint32_t len; - const char* space = strchr(pos, ' '); + const char* space = bx::strnchr(pos, ' '); if (NULL != space) { len = bx::uint32_min(sizeof(name), (uint32_t)(space - pos) ); @@ -1574,7 +1580,7 @@ namespace bgfx { namespace gl len = bx::uint32_min(sizeof(name), (uint32_t)bx::strnlen(pos) ); } - strncpy(name, pos, len); + bx::strlncpy(name, BX_COUNTOF(name), pos, len); name[len] = '\0'; updateExtension(name); @@ -1607,7 +1613,7 @@ namespace bgfx { namespace gl } // Allow all texture filters. - memset(s_textureFilter, true, BX_COUNTOF(s_textureFilter) ); + bx::memSet(s_textureFilter, true, BX_COUNTOF(s_textureFilter) ); bool bc123Supported = 0 || s_extension[Extension::EXT_texture_compression_s3tc ].m_supported @@ -2290,6 +2296,9 @@ namespace bgfx { namespace gl m_ovr.flip(); m_ovr.swap(_hmd); + // Ensure the back buffer is bound as the source of the flip + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo)); + // need to swap GL render context even if OVR is enabled to get // the mirror texture in the output m_glctx.swap(); @@ -2311,7 +2320,7 @@ namespace bgfx { namespace gl void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) BX_OVERRIDE { VertexDecl& decl = m_vertexDecls[_handle.idx]; - memcpy(&decl, &_decl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); dump(decl); } @@ -2508,7 +2517,7 @@ namespace bgfx { namespace gl uint32_t size = g_uniformTypeSize[_type]*_num; void* data = BX_ALLOC(g_allocator, size); - memset(data, 0, size); + bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; m_uniformReg.add(_handle, _name, m_uniforms[_handle.idx]); } @@ -2520,14 +2529,24 @@ namespace bgfx { namespace gl m_uniformReg.remove(_handle); } - void saveScreenShot(const char* _filePath) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) BX_OVERRIDE { - uint32_t length = m_resolution.m_width*m_resolution.m_height*4; - uint8_t* data = (uint8_t*)BX_ALLOC(g_allocator, length); - + SwapChainGL* swapChain = NULL; uint32_t width = m_resolution.m_width; uint32_t height = m_resolution.m_height; + if (isValid(_handle) ) + { + const FrameBufferGL& frameBuffer = m_frameBuffers[_handle.idx]; + swapChain = frameBuffer.m_swapChain; + width = frameBuffer.m_width; + height = frameBuffer.m_height; + } + m_glctx.makeCurrent(swapChain); + + uint32_t length = width*height*4; + uint8_t* data = (uint8_t*)BX_ALLOC(g_allocator, length); + GL_CHECK(glReadPixels(0 , 0 , width @@ -2563,7 +2582,7 @@ namespace bgfx { namespace gl void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE { - memcpy(m_uniforms[_loc], _data, _size); + bx::memCopy(m_uniforms[_loc], _data, _size); } void setMarker(const char* _marker, uint32_t _size) BX_OVERRIDE @@ -2571,6 +2590,11 @@ namespace bgfx { namespace gl GL_CHECK(glInsertEventMarker(_size, _marker) ); } + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE + { + m_occlusionQuery.invalidate(_handle); + } + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE; void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE @@ -2638,7 +2662,9 @@ namespace bgfx { namespace gl GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib.m_id) ); ProgramGL& program = m_program[_blitter.m_program.idx]; + program.bindAttributesBegin(); program.bindAttributes(_blitter.m_decl, 0); + program.bindAttributesEnd(); GL_CHECK(glDrawElements(GL_TRIANGLES , _numIndices @@ -3205,7 +3231,7 @@ namespace bgfx { namespace gl else { UniformHandle handle; - memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); data = (const char*)m_uniforms[handle.idx]; } @@ -3391,7 +3417,9 @@ namespace bgfx { namespace gl ProgramGL& program = m_program[_clearQuad.m_program[numMrt-1].idx]; GL_CHECK(glUseProgram(program.m_id) ); + program.bindAttributesBegin(); program.bindAttributes(vertexDecl, 0); + program.bindAttributesEnd(); float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; @@ -3400,7 +3428,7 @@ namespace bgfx { namespace gl for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - memcpy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClear[ii], _palette[index], 16); } } else @@ -3415,7 +3443,7 @@ namespace bgfx { namespace gl for (uint32_t ii = 0; ii < numMrt; ++ii) { - memcpy(mrtClear[ii], rgba, 16); + bx::memCopy(mrtClear[ii], rgba, 16); } } @@ -3536,7 +3564,7 @@ namespace bgfx { namespace gl , m_textureSwapChain(NULL) , m_mirrorTexture(NULL) { - memset(&m_eyeTarget, 0, sizeof(m_eyeTarget) ); + bx::memSet(&m_eyeTarget, 0, sizeof(m_eyeTarget) ); } static void setDefaultSamplerState() @@ -3980,7 +4008,7 @@ namespace bgfx { namespace gl { BX_WARN(0 != _vsh.m_id, "Invalid vertex/compute shader."); GL_CHECK(glDeleteProgram(m_id) ); - m_used[0] = Attrib::Count; + m_usedCount = 0; m_id = 0; return; } @@ -4105,7 +4133,7 @@ namespace bgfx { namespace gl GLint num; }; VariableInfo vi; - GLenum props[] ={ GL_TYPE, GL_LOCATION, GL_ARRAY_SIZE }; + GLenum props[] = { GL_TYPE, GL_LOCATION, GL_ARRAY_SIZE }; GLenum gltype; GLint num; @@ -4144,13 +4172,13 @@ namespace bgfx { namespace gl num = bx::uint32_max(num, 1); int offset = 0; - char* array = strchr(name, '['); + char* array = const_cast<char*>(bx::strnchr(name, '[') ); if (NULL != array) { BX_TRACE("--- %s", name); *array = '\0'; array++; - char* end = strchr(array, ']'); + char* end = const_cast<char*>(bx::strnchr(array, ']') ); if (NULL != end) { // Some devices (Amazon Fire) might not return terminating brace. *end = '\0'; @@ -4298,7 +4326,7 @@ namespace bgfx { namespace gl } } - memset(m_attributes, 0xff, sizeof(m_attributes) ); + bx::memSet(m_attributes, 0xff, sizeof(m_attributes) ); uint32_t used = 0; for (uint8_t ii = 0; ii < Attrib::Count; ++ii) { @@ -4310,11 +4338,8 @@ namespace bgfx { namespace gl m_used[used++] = ii; } } - BX_CHECK(used < BX_COUNTOF(m_used), "Out of bounds %d > array size %d." - , used - , BX_COUNTOF(m_used) - ); - m_used[used] = Attrib::Count; + BX_CHECK(used < BX_COUNTOF(m_used), "Out of bounds %d > array size %d.", used, Attrib::Count); + m_usedCount = (uint8_t)used; used = 0; for (uint32_t ii = 0; ii < BX_COUNTOF(s_instanceDataName); ++ii) @@ -4333,9 +4358,9 @@ namespace bgfx { namespace gl m_instanceData[used] = 0xffff; } - void ProgramGL::bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex) const + void ProgramGL::bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex) { - for (uint32_t ii = 0; Attrib::Count != m_used[ii]; ++ii) + for (uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii) { Attrib::Enum attr = Attrib::Enum(m_used[ii]); GLint loc = m_attributes[attr]; @@ -4375,10 +4400,8 @@ namespace bgfx { namespace gl , (void*)(uintptr_t)baseVertex) ); } - } - else - { - GL_CHECK(glDisableVertexAttribArray(loc) ); + + m_unboundUsedAttrib[ii] = Attrib::Count; } } } @@ -4667,6 +4690,7 @@ namespace bgfx { namespace gl GL_CHECK(glGenTextures(1, &m_id) ); BX_CHECK(0 != m_id, "Failed to generate texture id."); GL_CHECK(glBindTexture(_target, m_id) ); + GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) ); const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat]; m_fmt = tfi.m_fmt; @@ -5312,8 +5336,8 @@ namespace bgfx { namespace gl void strins(char* _str, const char* _insert) { size_t len = bx::strnlen(_insert); - memmove(&_str[len], _str, bx::strnlen(_str)+1); - memcpy(_str, _insert, len); + bx::memMove(&_str[len], _str, bx::strnlen(_str)+1); + bx::memCopy(_str, _insert, len); } void ShaderGL::create(Memory* _mem) @@ -5481,15 +5505,20 @@ namespace bgfx { namespace gl if (usesTextureLod) { - BX_WARN(s_extension[Extension::EXT_shader_texture_lod].m_supported, "EXT_shader_texture_lod is used but not supported by GLES2 driver."); - if (s_extension[Extension::EXT_shader_texture_lod].m_supported - /*&& GL_VERTEX_SHADER == m_type*/) + BX_WARN(s_extension[Extension::ARB_shader_texture_lod].m_supported + , "ARB_shader_texture_lod is used but not supported by GLES2 driver." + ); + + if (s_extension[Extension::ARB_shader_texture_lod].m_supported) { writeString(&writer - , "#extension GL_EXT_shader_texture_lod : enable\n" - "#define texture2DLod texture2DLodEXT\n" - "#define texture2DProjLod texture2DProjLodEXT\n" - "#define textureCubeLod textureCubeLodEXT\n" + , "#extension GL_ARB_shader_texture_lod : enable\n" + "#define texture2DLod texture2DLodARB\n" + "#define texture2DProjLod texture2DProjLodARB\n" + "#define textureCubeLod textureCubeLodARB\n" + "#define texture2DGrad texture2DGradARB\n" + "#define texture2DProjGrad texture2DProjGradARB\n" + "#define textureCubeGrad textureCubeGradARB\n" ); } else @@ -5523,10 +5552,10 @@ namespace bgfx { namespace gl if (insertFragDepth) { - char* entry = strstr(temp, "void main ()"); + const char* entry = bx::strnstr(temp, "void main ()"); if (NULL != entry) { - char* brace = strstr(entry, "{"); + char* brace = const_cast<char*>(bx::strnstr(entry, "{") ); if (NULL != brace) { const char* end = bx::strmb(brace, '{', '}'); @@ -5543,7 +5572,7 @@ namespace bgfx { namespace gl { char* insert = const_cast<char*>(fragDepth); strins(insert, "bg"); - memcpy(insert + 2, "fx", 2); + bx::memCopy(insert + 2, "fx", 2); } } else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) @@ -5561,7 +5590,7 @@ namespace bgfx { namespace gl const bool usesPacking = !!bx::findIdentifierMatch(code, s_ARB_shading_language_packing); uint32_t version = - usesIUsamplers || usesTexelFetch ? 130 + usesIUsamplers || usesTexelFetch || usesGpuShader5 ? 130 : usesTextureLod ? 120 : 120 ; @@ -5575,7 +5604,12 @@ namespace bgfx { namespace gl { if (m_type == GL_FRAGMENT_SHADER) { - writeString(&writer, "#extension GL_ARB_shader_texture_lod : enable\n"); + writeString(&writer + , "#extension GL_ARB_shader_texture_lod : enable\n" + "#define texture2DGrad texture2DGradARB\n" + "#define texture2DProjGrad texture2DProjGradARB\n" + "#define textureCubeGrad textureCubeGradARB\n" + ); } } @@ -5619,7 +5653,7 @@ namespace bgfx { namespace gl { char tmpFragData[16]; bx::snprintf(tmpFragData, BX_COUNTOF(tmpFragData), "gl_FragData[%d]", ii); - fragData = bx::uint32_max(fragData, NULL == strstr(code, tmpFragData) ? 0 : ii+1); + fragData = bx::uint32_max(fragData, NULL == bx::strnstr(code, tmpFragData) ? 0 : ii+1); } BGFX_FATAL(0 != fragData, Fatal::InvalidShader, "Unable to find and patch gl_FragData!"); @@ -5677,9 +5711,12 @@ namespace bgfx { namespace gl writeString(&writer, "#version 140\n"); } - writeString(&writer, "#define texture2DLod textureLod\n"); - writeString(&writer, "#define texture3DLod textureLod\n"); - writeString(&writer, "#define textureCubeLod textureLod\n"); + writeString(&writer, "#define texture2DLod textureLod\n"); + writeString(&writer, "#define texture3DLod textureLod\n"); + writeString(&writer, "#define textureCubeLod textureLod\n"); + writeString(&writer, "#define texture2DGrad textureGrad\n"); + writeString(&writer, "#define texture3DGrad textureGrad\n"); + writeString(&writer, "#define textureCubeGrad textureGrad\n"); if (m_type == GL_FRAGMENT_SHADER) { @@ -5709,7 +5746,7 @@ namespace bgfx { namespace gl { char tmpFragData[16]; bx::snprintf(tmpFragData, BX_COUNTOF(tmpFragData), "gl_FragData[%d]", ii); - fragData = bx::uint32_max(fragData, NULL == strstr(code, tmpFragData) ? 0 : ii+1); + fragData = bx::uint32_max(fragData, NULL == bx::strnstr(code, tmpFragData) ? 0 : ii+1); } BGFX_FATAL(0 != fragData, Fatal::InvalidShader, "Unable to find and patch gl_FragData!"); @@ -5814,7 +5851,7 @@ namespace bgfx { namespace gl m_denseIdx = UINT16_MAX; m_numTh = _num; - memcpy(m_attachment, _attachment, _num*sizeof(Attachment) ); + bx::memCopy(m_attachment, _attachment, _num*sizeof(Attachment) ); m_needPresent = false; @@ -5988,7 +6025,7 @@ namespace bgfx { namespace gl m_swapChain = NULL; } - memset(m_fbo, 0, sizeof(m_fbo) ); + bx::memSet(m_fbo, 0, sizeof(m_fbo) ); uint16_t denseIdx = m_denseIdx; m_denseIdx = UINT16_MAX; m_needPresent = false; @@ -6112,24 +6149,43 @@ namespace bgfx { namespace gl while (0 != m_control.available() ) { Query& query = m_query[m_control.m_read]; - int32_t result; - if (!_wait) + if (isValid(query.m_handle) ) { - GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT_AVAILABLE, &result) ); + int32_t result; - if (!result) + if (!_wait) { - break; + GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT_AVAILABLE, &result) ); + + if (!result) + { + break; + } } + + GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT, &result) ); + _render->m_occlusion[query.m_handle.idx] = int32_t(result); } - GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT, &result) ); - _render->m_occlusion[query.m_handle.idx] = 0 < result; m_control.consume(1); } } + void OcclusionQueryGL::invalidate(OcclusionQueryHandle _handle) + { + const uint32_t size = m_control.m_size; + + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + Query& query = m_query[(m_control.m_read + ii) % size]; + if (query.m_handle.idx == _handle.idx) + { + query.m_handle.idx = bgfx::invalidHandle; + } + } + } + void RendererContextGL::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit"); @@ -6223,7 +6279,6 @@ namespace bgfx { namespace gl : GL_FILL ) ); - uint32_t baseVertex = 0; GLuint currentVao = 0; bool wasCompute = false; bool viewHasScissor = false; @@ -6601,7 +6656,7 @@ namespace bgfx { namespace gl else { Rect scissorRect; - scissorRect.intersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); + scissorRect.setIntersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); if (scissorRect.isZeroArea() ) { continue; @@ -6951,27 +7006,63 @@ namespace bgfx { namespace gl && 0 == draw.m_stream[0].m_startVertex && 0 == draw.m_instanceDataOffset) { + bool diffStartVertex = false; + bool diffStreamHandles = false; + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) + { + streamMask >>= ntz; + idx += ntz; + + if (currentState.m_stream[idx].m_handle.idx != draw.m_stream[idx].m_handle.idx) + { + diffStreamHandles = true; + break; + } + + if (currentState.m_stream[idx].m_startVertex != draw.m_stream[idx].m_startVertex) + { + diffStartVertex = true; + break; + } + } + if (programChanged - || baseVertex != draw.m_stream[0].m_startVertex || currentState.m_streamMask != draw.m_streamMask - || currentState.m_stream[0].m_handle.idx != draw.m_stream[0].m_handle.idx || currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx || currentState.m_instanceDataOffset != draw.m_instanceDataOffset || currentState.m_instanceDataStride != draw.m_instanceDataStride - || currentState.m_instanceDataBuffer.idx != draw.m_instanceDataBuffer.idx) + || currentState.m_instanceDataBuffer.idx != draw.m_instanceDataBuffer.idx + || diffStartVertex + || diffStreamHandles) { bx::HashMurmur2A murmur; murmur.begin(); - const Stream& stream = draw.m_stream[0]; - murmur.add(stream.m_handle.idx); - - if (isValid(stream.m_handle) ) + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) { - const VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx]; - uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx; - murmur.add(decl); + streamMask >>= ntz; + idx += ntz; + + const Stream& stream = draw.m_stream[idx]; + murmur.add(stream.m_handle.idx); + + if (isValid(stream.m_handle) ) + { + const VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx]; + uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx; + murmur.add(decl); + } + + currentState.m_stream[idx].m_handle = stream.m_handle; + currentState.m_stream[idx].m_startVertex = stream.m_startVertex; } + currentState.m_streamMask = draw.m_streamMask; murmur.add(draw.m_indexBuffer.idx); murmur.add(draw.m_instanceDataBuffer.idx); @@ -6980,11 +7071,7 @@ namespace bgfx { namespace gl murmur.add(programIdx); uint32_t hash = murmur.end(); - currentState.m_streamMask = draw.m_streamMask; - currentState.m_stream[0].m_handle = stream.m_handle; - baseVertex = stream.m_startVertex; - - currentState.m_indexBuffer = draw.m_indexBuffer; + currentState.m_indexBuffer = draw.m_indexBuffer; currentState.m_instanceDataOffset = draw.m_instanceDataOffset; currentState.m_instanceDataStride = draw.m_instanceDataStride; @@ -7002,14 +7089,26 @@ namespace bgfx { namespace gl program.add(hash); - if (isValid(stream.m_handle) ) + program.bindAttributesBegin(); + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) { - VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx]; - vb.add(hash); - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); + streamMask >>= ntz; + idx += ntz; - uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx; - program.bindAttributes(m_vertexDecls[decl], stream.m_startVertex); + const Stream& stream = draw.m_stream[idx]; + + if (isValid(stream.m_handle) ) + { + VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx]; + vb.add(hash); + + uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx; + GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); + program.bindAttributes(m_vertexDecls[decl], stream.m_startVertex); + } if (isValid(draw.m_instanceDataBuffer) ) { @@ -7019,10 +7118,7 @@ namespace bgfx { namespace gl program.bindInstanceData(draw.m_instanceDataStride, draw.m_instanceDataOffset); } } - else - { - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); - } + program.bindAttributesEnd(); if (isValid(draw.m_indexBuffer) ) { @@ -7043,37 +7139,56 @@ namespace bgfx { namespace gl && 0 != currentVao) { GL_CHECK(glBindVertexArray(defaultVao) ); - currentState.m_streamMask = 0; - currentState.m_stream[0].m_handle.idx = invalidHandle; - currentState.m_indexBuffer.idx = invalidHandle; + currentState.m_streamMask = 0; + for (size_t ii = 0; ii < BGFX_CONFIG_MAX_VERTEX_STREAMS; ++ii) + { + currentState.m_stream[ii].m_handle.idx = invalidHandle; + } + currentState.m_indexBuffer.idx = invalidHandle; bindAttribs = true; currentVao = 0; } + bool diffStreamHandles = false; + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) + { + streamMask >>= ntz; + idx += ntz; + + if (currentState.m_stream[idx].m_handle.idx != draw.m_stream[idx].m_handle.idx) + { + diffStreamHandles = true; + break; + } + } + if (programChanged || currentState.m_streamMask != draw.m_streamMask - || currentState.m_stream[0].m_handle.idx != draw.m_stream[0].m_handle.idx || currentState.m_instanceDataBuffer.idx != draw.m_instanceDataBuffer.idx || currentState.m_instanceDataOffset != draw.m_instanceDataOffset - || currentState.m_instanceDataStride != draw.m_instanceDataStride) + || currentState.m_instanceDataStride != draw.m_instanceDataStride + || diffStreamHandles) { currentState.m_streamMask = draw.m_streamMask; - currentState.m_stream[0].m_handle = draw.m_stream[0].m_handle; currentState.m_instanceDataBuffer.idx = draw.m_instanceDataBuffer.idx; currentState.m_instanceDataOffset = draw.m_instanceDataOffset; currentState.m_instanceDataStride = draw.m_instanceDataStride; - uint16_t handle = draw.m_stream[0].m_handle.idx; - if (invalidHandle != handle) - { - VertexBufferGL& vb = m_vertexBuffers[handle]; - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); - bindAttribs = true; - } - else + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) { - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); + streamMask >>= ntz; + idx += ntz; + + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; } + + bindAttribs = true; } if (currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx) @@ -7094,13 +7209,41 @@ namespace bgfx { namespace gl if (0 != currentState.m_streamMask) { - if (baseVertex != draw.m_stream[0].m_startVertex - || bindAttribs) + bool diffStartVertex = false; + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) + { + streamMask >>= ntz; + idx += ntz; + + if (currentState.m_stream[idx].m_startVertex != draw.m_stream[idx].m_startVertex) + { + diffStartVertex = true; + break; + } + } + + if (bindAttribs || diffStartVertex) { - baseVertex = draw.m_stream[0].m_startVertex; - const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[0].m_handle.idx]; - uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[0].m_decl.idx : vb.m_decl.idx; - program.bindAttributes(m_vertexDecls[decl], draw.m_stream[0].m_startVertex); + program.bindAttributesBegin(); + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) + { + streamMask >>= ntz; + idx += ntz; + + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + + const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx]; + uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; + GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); + program.bindAttributes(m_vertexDecls[decl], draw.m_stream[idx].m_startVertex); + } + program.bindAttributesEnd(); if (isValid(draw.m_instanceDataBuffer) ) { @@ -7116,10 +7259,20 @@ namespace bgfx { namespace gl uint32_t numVertices = draw.m_numVertices; if (UINT32_MAX == numVertices) { - const VertexBufferGL& vb = m_vertexBuffers[currentState.m_stream[0].m_handle.idx]; - uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[0].m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = m_vertexDecls[decl]; - numVertices = vb.m_size/vertexDecl.m_stride; + for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ) + { + streamMask >>= ntz; + idx += ntz; + + const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx]; + uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; + const VertexDecl& vertexDecl = m_vertexDecls[decl]; + + numVertices = bx::uint32_min(numVertices, vb.m_size/vertexDecl.m_stride); + } } uint32_t numIndices = 0; diff --git a/3rdparty/bgfx/src/renderer_gl.h b/3rdparty/bgfx/src/renderer_gl.h index 8dbb24fa2f7..4d9778a0c4d 100644 --- a/3rdparty/bgfx/src/renderer_gl.h +++ b/3rdparty/bgfx/src/renderer_gl.h @@ -1310,7 +1310,7 @@ namespace bgfx { namespace gl , m_num(0) , m_needPresent(false) { - memset(m_fbo, 0, sizeof(m_fbo) ); + bx::memSet(m_fbo, 0, sizeof(m_fbo) ); } void create(uint8_t _num, const Attachment* _attachment); @@ -1343,9 +1343,28 @@ namespace bgfx { namespace gl void create(const ShaderGL& _vsh, const ShaderGL& _fsh); void destroy(); void init(); - void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0) const; void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const; + void bindAttributesBegin() + { + bx::memCopy(m_unboundUsedAttrib, m_used, sizeof(m_unboundUsedAttrib) ); + } + + void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0); + + void bindAttributesEnd() + { + for (uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii) + { + if (Attrib::Count != m_unboundUsedAttrib[ii]) + { + Attrib::Enum attr = Attrib::Enum(m_unboundUsedAttrib[ii]); + GLint loc = m_attributes[attr]; + GL_CHECK(glDisableVertexAttribArray(loc) ); + } + } + } + void add(uint32_t _hash) { m_vcref.add(_hash); @@ -1353,8 +1372,10 @@ namespace bgfx { namespace gl GLuint m_id; - uint8_t m_used[Attrib::Count+1]; // dense - GLint m_attributes[Attrib::Count]; // sparse + uint8_t m_unboundUsedAttrib[Attrib::Count]; // For tracking unbound used attributes between begin()/end(). + uint8_t m_usedCount; + uint8_t m_used[Attrib::Count]; // Dense. + GLint m_attributes[Attrib::Count]; // Sparse. GLint m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT+1]; GLint m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; @@ -1484,6 +1505,7 @@ namespace bgfx { namespace gl void begin(Frame* _render, OcclusionQueryHandle _handle); void end(); void resolve(Frame* _render, bool _wait = false); + void invalidate(OcclusionQueryHandle _handle); struct Query { diff --git a/3rdparty/bgfx/src/renderer_mtl.h b/3rdparty/bgfx/src/renderer_mtl.h index 4aca08a02dd..86893f70e4c 100644 --- a/3rdparty/bgfx/src/renderer_mtl.h +++ b/3rdparty/bgfx/src/renderer_mtl.h @@ -896,6 +896,7 @@ namespace bgfx { namespace mtl void begin(RenderCommandEncoder& _rce, Frame* _render, OcclusionQueryHandle _handle); void end(RenderCommandEncoder& _rce); void resolve(Frame* _render, bool _wait = false); + void invalidate(OcclusionQueryHandle _handle); struct Query { diff --git a/3rdparty/bgfx/src/renderer_mtl.mm b/3rdparty/bgfx/src/renderer_mtl.mm index 1c174970073..fbfcdf287f7 100644 --- a/3rdparty/bgfx/src/renderer_mtl.mm +++ b/3rdparty/bgfx/src/renderer_mtl.mm @@ -9,7 +9,6 @@ #include "renderer_mtl.h" #include "renderer.h" -#include "bx/bx.h" #if BX_PLATFORM_OSX # include <Cocoa/Cocoa.h> @@ -371,8 +370,8 @@ namespace bgfx { namespace mtl BX_TRACE("Init."); m_fbh.idx = invalidHandle; - memset(m_uniforms, 0, sizeof(m_uniforms) ); - memset(&m_resolution, 0, sizeof(m_resolution) ); + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); if (NULL != NSClassFromString(@"MTKView") ) { @@ -706,7 +705,7 @@ namespace bgfx { namespace mtl void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) BX_OVERRIDE { VertexDecl& decl = m_vertexDecls[_handle.idx]; - memcpy(&decl, &_decl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); dump(decl); } @@ -892,7 +891,7 @@ namespace bgfx { namespace mtl uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num); void* data = BX_ALLOC(g_allocator, size); - memset(data, 0, size); + bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; m_uniformReg.add(_handle, _name, data); } @@ -905,17 +904,21 @@ namespace bgfx { namespace mtl } //cmdPre - void saveScreenShotPre(const char* _filePath) BX_OVERRIDE + void requestScreenShotPre(const char* _filePath) BX_OVERRIDE { BX_UNUSED(_filePath); m_saveScreenshot = true; } //cmdPost - void saveScreenShot(const char* _filePath) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) BX_OVERRIDE { + BX_UNUSED(_handle); + if (NULL == m_screenshotTarget) + { return; + } m_cmd.kick(false, true); m_commandBuffer = 0; @@ -956,7 +959,7 @@ namespace bgfx { namespace mtl void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE { - memcpy(m_uniforms[_loc], _data, _size); + bx::memCopy(m_uniforms[_loc], _data, _size); } void setMarker(const char* _marker, uint32_t /*_size*/) BX_OVERRIDE @@ -967,6 +970,11 @@ namespace bgfx { namespace mtl } } + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE + { + m_occlusionQuery.invalidate(_handle); + } + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE; void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE @@ -1302,7 +1310,7 @@ namespace bgfx { namespace mtl : m_uniformBufferVertexOffset ; uint8_t* dst = (uint8_t*)m_uniformBuffer.contents(); - memcpy(&dst[offset + _loc], _val, _numRegs*16); + bx::memCopy(&dst[offset + _loc], _val, _numRegs*16); } void setShaderUniform4f(uint8_t _flags, uint32_t _loc, const void* _val, uint32_t _numRegs) @@ -1342,7 +1350,7 @@ namespace bgfx { namespace mtl else { UniformHandle handle; - memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); data = (const char*)m_uniforms[handle.idx]; } @@ -1458,10 +1466,10 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - memcpy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClear[ii], _palette[index], 16); } - memcpy((uint8_t*)m_uniformBuffer.contents() + m_uniformBufferFragmentOffset, + bx::memCopy((uint8_t*)m_uniformBuffer.contents() + m_uniformBufferFragmentOffset, mrtClear, bx::uint32_min(fragmentUniformBufferSize, sizeof(mrtClear))); } @@ -1475,7 +1483,7 @@ namespace bgfx { namespace mtl _clear.m_index[3]*1.0f/255.0f, }; - memcpy((uint8_t*)m_uniformBuffer.contents() + m_uniformBufferFragmentOffset, + bx::memCopy((uint8_t*)m_uniformBuffer.contents() + m_uniformBufferFragmentOffset, rgba, bx::uint32_min(fragmentUniformBufferSize, sizeof(rgba))); } @@ -1689,7 +1697,6 @@ namespace bgfx { namespace mtl return _visible == (0 != _render->m_occlusion[_handle.idx]); } - BlitCommandEncoder getBlitCommandEncoder() { if ( m_blitCommandEncoder == NULL) @@ -1899,7 +1906,7 @@ namespace bgfx { namespace mtl } // get attributes - memset(m_attributes, 0xff, sizeof(m_attributes) ); + bx::memSet(m_attributes, 0xff, sizeof(m_attributes) ); uint32_t used = 0; uint32_t instUsed = 0; if (NULL != _vsh->m_function.m_obj ) @@ -1914,7 +1921,7 @@ namespace bgfx { namespace mtl for (uint8_t ii = 0; ii < Attrib::Count; ++ii) { - if (!strcmp(s_attribName[ii],name)) + if (0 == bx::strncmp(s_attribName[ii],name)) { m_attributes[ii] = loc; m_used[used++] = ii; @@ -1924,7 +1931,7 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < BX_COUNTOF(s_instanceDataName); ++ii) { - if (!strcmp(s_instanceDataName[ii],name)) + if (0 == bx::strncmp(s_instanceDataName[ii],name)) { m_instanceData[instUsed++] = loc; } @@ -2199,7 +2206,7 @@ namespace bgfx { namespace mtl if (arg.active) { if (arg.type == MTLArgumentTypeBuffer - && 0 == strcmp(utf8String(arg.name), SHADER_UNIFORM_NAME) ) + && 0 == bx::strncmp(utf8String(arg.name), SHADER_UNIFORM_NAME) ) { BX_CHECK( arg.index == 0, "Uniform buffer must be in the buffer slot 0."); BX_CHECK( MTLDataTypeStruct == arg.bufferDataType, "%s's type must be a struct",SHADER_UNIFORM_NAME ); @@ -2333,7 +2340,7 @@ namespace bgfx { namespace mtl if ( m_dynamic && _discard ) { m_bufferIndex = (m_bufferIndex + 1) % MTL_MAX_FRAMES_IN_FLIGHT; - memcpy( (uint8_t*)getBuffer().contents() + _offset, _data, _size); + bx::memCopy( (uint8_t*)getBuffer().contents() + _offset, _data, _size); } else if ( NULL != s_renderMtl->m_renderCommandEncoder ) { @@ -2345,7 +2352,7 @@ namespace bgfx { namespace mtl { const void* oldContent = m_buffers[m_bufferIndex].contents(); m_buffers[m_bufferIndex] = s_renderMtl->m_device.newBufferWithBytes(oldContent, m_size, 0); - memcpy( (uint8_t*)m_buffers[m_bufferIndex].contents() + _offset, _data, _size); + bx::memCopy( (uint8_t*)m_buffers[m_bufferIndex].contents() + _offset, _data, _size); } } else @@ -2643,7 +2650,7 @@ namespace bgfx { namespace mtl for (uint32_t yy = 0; yy < _rect.m_height; ++yy, src += srcpitch, dst += dstpitch) { - memcpy(dst, src, rectpitch); + bx::memCopy(dst, src, rectpitch); } bce.copyFromBuffer( @@ -2929,18 +2936,35 @@ namespace bgfx { namespace mtl { Query& query = m_query[m_control.m_read]; - uint64_t result = ( (uint64_t*)m_buffer.contents() )[query.m_handle.idx]; - _render->m_occlusion[query.m_handle.idx] = 0 < result; + if (isValid(query.m_handle) ) + { + uint64_t result = ( (uint64_t*)m_buffer.contents() )[query.m_handle.idx]; + _render->m_occlusion[query.m_handle.idx] = int32_t(result); + } + m_control.consume(1); } } + void OcclusionQueryMTL::invalidate(OcclusionQueryHandle _handle) + { + const uint32_t size = m_control.m_size; + + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + Query& query = m_query[(m_control.m_read + ii) % size]; + if (query.m_handle.idx == _handle.idx) + { + query.m_handle.idx = bgfx::invalidHandle; + } + } + } + void RendererContextMtl::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE { m_cmd.finish(false); - - if ( m_commandBuffer == NULL ) + if (m_commandBuffer == NULL) { m_commandBuffer = m_cmd.alloc(); } @@ -2950,7 +2974,7 @@ namespace bgfx { namespace mtl m_gpuTimer.addHandlers(m_commandBuffer); - if ( m_blitCommandEncoder ) + if (m_blitCommandEncoder) { m_blitCommandEncoder.endEncoding(); m_blitCommandEncoder = 0; @@ -2958,18 +2982,19 @@ namespace bgfx { namespace mtl updateResolution(_render->m_resolution); - if ( m_saveScreenshot || NULL != m_capture ) + if (m_saveScreenshot + || NULL != m_capture) { - if ( m_screenshotTarget ) + if (m_screenshotTarget) { - if ( m_screenshotTarget.width() != m_resolution.m_width || - m_screenshotTarget.height() != m_resolution.m_height ) + if (m_screenshotTarget.width() != m_resolution.m_width + || m_screenshotTarget.height() != m_resolution.m_height) { MTL_RELEASE(m_screenshotTarget); } } - if ( NULL == m_screenshotTarget) + if (NULL == m_screenshotTarget) { m_textureDescriptor.textureType = MTLTextureType2D; m_textureDescriptor.pixelFormat = m_metalLayer.pixelFormat; @@ -2982,13 +3007,16 @@ namespace bgfx { namespace mtl if ( m_iOS9Runtime || m_macOS11Runtime ) { m_textureDescriptor.cpuCacheMode = MTLCPUCacheModeDefaultCache; - m_textureDescriptor.storageMode = (MTLStorageMode)(((BX_ENABLED(BX_PLATFORM_IOS)) ? 0 /* MTLStorageModeShared */ : 1 /*MTLStorageModeManaged*/) - ); - m_textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead; + m_textureDescriptor.storageMode = (MTLStorageMode)(BX_ENABLED(BX_PLATFORM_IOS) + ? 0 /* MTLStorageModeShared */ + : 1 /*MTLStorageModeManaged*/ + ); + m_textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead; } - m_screenshotTarget = m_device.newTextureWithDescriptor(m_textureDescriptor); + m_screenshotTarget = m_device.newTextureWithDescriptor(m_textureDescriptor); } + m_saveScreenshot = false; } else @@ -3416,7 +3444,7 @@ namespace bgfx { namespace mtl else { Rect scissorRect; - scissorRect.intersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); + scissorRect.setIntersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); if (scissorRect.isZeroArea() ) { continue; diff --git a/3rdparty/bgfx/src/renderer_noop.cpp b/3rdparty/bgfx/src/renderer_noop.cpp index 4cc40185672..24fbfb4859d 100644 --- a/3rdparty/bgfx/src/renderer_noop.cpp +++ b/3rdparty/bgfx/src/renderer_noop.cpp @@ -177,7 +177,7 @@ namespace bgfx { namespace noop { } - void saveScreenShot(const char* /*_filePath*/) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle /*_handle*/, const char* /*_filePath*/) BX_OVERRIDE { } @@ -193,6 +193,10 @@ namespace bgfx { namespace noop { } + void invalidateOcclusionQuery(OcclusionQueryHandle /*_handle*/) BX_OVERRIDE + { + } + void submit(Frame* /*_render*/, ClearQuad& /*_clearQuad*/, TextVideoMemBlitter& /*_textVideoMemBlitter*/) BX_OVERRIDE { } diff --git a/3rdparty/bgfx/src/renderer_vk.cpp b/3rdparty/bgfx/src/renderer_vk.cpp index 7609b43d506..8e2f66c513f 100644 --- a/3rdparty/bgfx/src/renderer_vk.cpp +++ b/3rdparty/bgfx/src/renderer_vk.cpp @@ -726,8 +726,8 @@ VK_IMPORT_DEVICE ErrorState::Enum errorState = ErrorState::Default; m_fbh.idx = invalidHandle; - memset(m_uniforms, 0, sizeof(m_uniforms) ); - memset(&m_resolution, 0, sizeof(m_resolution) ); + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); bool imported = true; VkResult result; @@ -928,7 +928,7 @@ VK_IMPORT_INSTANCE vkGetPhysicalDeviceMemoryProperties(physicalDevices[ii], &pdmp); BX_TRACE("\tMemory type count: %d", pdmp.memoryTypeCount); - for (uint32_t jj = 0; jj < pdmp.memoryHeapCount; ++jj) + for (uint32_t jj = 0; jj < pdmp.memoryTypeCount; ++jj) { BX_TRACE("\t%3d: flags 0x%08x, index %d" , jj @@ -937,7 +937,7 @@ VK_IMPORT_INSTANCE ); } - BX_TRACE("\tMemory type count: %d", pdmp.memoryHeapCount); + BX_TRACE("\tMemory heap count: %d", pdmp.memoryHeapCount); for (uint32_t jj = 0; jj < pdmp.memoryHeapCount; ++jj) { char size[16]; @@ -1029,20 +1029,6 @@ VK_IMPORT_INSTANCE } vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &m_memoryProperties); - - for (uint32_t ii = 0, num = m_memoryProperties.memoryTypeCount; ii < num; ++ii) - { - const VkMemoryType& memoryType = m_memoryProperties.memoryTypes[ii]; - if (0 != (memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) ) - { - m_memHostVisibleIdx = ii; - } - - if (0 != (memoryType.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) ) - { - m_memLocalVisibleIdx = ii; - } - } } { @@ -1462,7 +1448,9 @@ VK_IMPORT_DEVICE ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ma.pNext = NULL; ma.allocationSize = mr.size; - ma.memoryTypeIndex = m_memLocalVisibleIdx; + ma.memoryTypeIndex = selectMemoryType(mr.memoryTypeBits + , VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT + ); result = vkAllocateMemory(m_device , &ma , m_allocatorCb @@ -1634,14 +1622,6 @@ VK_IMPORT_DEVICE VkCommandBuffer commandBuffer = m_commandBuffers[0]; VK_CHECK(vkBeginCommandBuffer(commandBuffer, &cbbi) ); - VkClearValue clearValue[2]; - clearValue[0].color.float32[0] = 0.0f; - clearValue[0].color.float32[1] = 0.0f; - clearValue[0].color.float32[2] = 0.0f; - clearValue[0].color.float32[3] = 1.0f; - clearValue[1].depthStencil.depth = 0.0f; - clearValue[1].depthStencil.stencil = 0; - VkRenderPassBeginInfo rpbi; rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; rpbi.pNext = NULL; @@ -1649,8 +1629,8 @@ VK_IMPORT_DEVICE rpbi.renderArea.offset.x = 0; rpbi.renderArea.offset.y = 0; rpbi.renderArea.extent = m_sci.imageExtent; - rpbi.clearValueCount = BX_COUNTOF(clearValue); - rpbi.pClearValues = clearValue; + rpbi.clearValueCount = 0; + rpbi.pClearValues = NULL; setImageMemoryBarrier(commandBuffer , m_backBufferDepthStencilImage @@ -1969,7 +1949,7 @@ VK_IMPORT_DEVICE void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) BX_OVERRIDE { VertexDecl& decl = m_vertexDecls[_handle.idx]; - memcpy(&decl, &_decl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); dump(decl); } @@ -2098,7 +2078,7 @@ VK_IMPORT_DEVICE uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type] * _num); void* data = BX_ALLOC(g_allocator, size); - memset(data, 0, size); + bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; m_uniformReg.add(_handle, _name, data); } @@ -2109,7 +2089,7 @@ VK_IMPORT_DEVICE m_uniforms[_handle.idx] = NULL; } - void saveScreenShot(const char* /*_filePath*/) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle /*_handle*/, const char* /*_filePath*/) BX_OVERRIDE { } @@ -2123,13 +2103,18 @@ VK_IMPORT_DEVICE void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE { - memcpy(m_uniforms[_loc], _data, _size); + bx::memCopy(m_uniforms[_loc], _data, _size); } void setMarker(const char* /*_marker*/, uint32_t /*_size*/) BX_OVERRIDE { } + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE + { + BX_UNUSED(_handle); + } + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE; void blitSetup(TextVideoMemBlitter& /*_blitter*/) BX_OVERRIDE @@ -2224,12 +2209,12 @@ VK_IMPORT_DEVICE BX_UNUSED(_flags, _regIndex, _val, _numRegs); if (_flags&BGFX_UNIFORM_FRAGMENTBIT) { - memcpy(&m_fsScratch[_regIndex], _val, _numRegs*16); + bx::memCopy(&m_fsScratch[_regIndex], _val, _numRegs*16); m_fsChanges += _numRegs; } else { - memcpy(&m_vsScratch[_regIndex], _val, _numRegs*16); + bx::memCopy(&m_vsScratch[_regIndex], _val, _numRegs*16); m_vsChanges += _numRegs; } } @@ -2257,12 +2242,12 @@ VK_IMPORT_DEVICE uint8_t* data = (uint8_t*)m_scratchBuffer[m_backBufferColorIdx].allocUbv(descriptorBufferInfo, total); uint32_t size = program.m_vsh->m_size; - memcpy(data, m_vsScratch, size); + bx::memCopy(data, m_vsScratch, size); data += size; if (NULL != program.m_fsh) { - memcpy(data, m_fsScratch, program.m_fsh->m_size); + bx::memCopy(data, m_fsScratch, program.m_fsh->m_size); } vkCmdBindDescriptorSets(_commandBuffer @@ -2446,7 +2431,7 @@ VK_IMPORT_DEVICE { for (uint32_t ii = 1; ii < numAttachments; ++ii) { - memcpy(&bas[ii], bas, sizeof(VkPipelineColorBlendAttachmentState) ); + bx::memCopy(&bas[ii], bas, sizeof(VkPipelineColorBlendAttachmentState) ); } } @@ -2530,7 +2515,7 @@ VK_IMPORT_DEVICE _vertexInputState.flags = 0; VertexDecl decl; - memcpy(&decl, &_vertexDecl, sizeof(VertexDecl) ); + bx::memCopy(&decl, &_vertexDecl, sizeof(VertexDecl) ); const uint16_t* attrMask = _program.m_vsh->m_attrMask; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) @@ -2551,7 +2536,7 @@ VK_IMPORT_DEVICE uint32_t index = 7 - ii; // TEXCOORD7 = i_data0, TEXCOORD6 = i_data1, etc. BX_UNUSED(index); -// memcpy(curr, &inst, sizeof(D3D12_INPUT_ELEMENT_DESC) ); +// bx::memCopy(curr, &inst, sizeof(D3D12_INPUT_ELEMENT_DESC) ); // curr->InputSlot = 1; // curr->SemanticIndex = index; // curr->AlignedByteOffset = ii*16; @@ -2591,7 +2576,7 @@ VK_IMPORT_DEVICE _stencil &= packStencil(~BGFX_STENCIL_FUNC_REF_MASK, BGFX_STENCIL_MASK); VertexDecl decl; - memcpy(&decl, &m_vertexDecls[_declIdx], sizeof(VertexDecl) ); + bx::memCopy(&decl, &m_vertexDecls[_declIdx], sizeof(VertexDecl) ); const uint16_t* attrMask = program.m_vsh->m_attrMask; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) @@ -2806,7 +2791,7 @@ VK_IMPORT_DEVICE else { UniformHandle handle; - memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); data = (const char*)m_uniforms[handle.idx]; } @@ -2879,7 +2864,6 @@ VK_IMPORT_DEVICE VkClearAttachment attachments[BGFX_CONFIG_MAX_FRAME_BUFFERS]; uint32_t mrt = 0; - attachments[mrt].aspectMask = 0; if (true //NULL != m_currentColor && BGFX_CLEAR_COLOR & _clear.m_flags) @@ -2891,7 +2875,7 @@ VK_IMPORT_DEVICE attachments[mrt].colorAttachment = mrt; attachments[mrt].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - memcpy(&attachments[mrt].clearValue.color.float32, _palette[index], 16); + bx::memCopy(&attachments[mrt].clearValue.color.float32, _palette[index], 16); ++mrt; } } @@ -2909,7 +2893,7 @@ VK_IMPORT_DEVICE { attachments[mrt].colorAttachment = mrt; attachments[mrt].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - memcpy(&attachments[mrt].clearValue.color.float32, frgba, 16); + bx::memCopy(&attachments[mrt].clearValue.color.float32, frgba, 16); ++mrt; } } @@ -2919,6 +2903,7 @@ VK_IMPORT_DEVICE && (BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL) & _clear.m_flags) { attachments[mrt].colorAttachment = mrt; + attachments[mrt].aspectMask = 0; attachments[mrt].aspectMask |= (_clear.m_flags & BGFX_CLEAR_DEPTH ) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0; attachments[mrt].aspectMask |= (_clear.m_flags & BGFX_CLEAR_STENCIL) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0; @@ -2968,6 +2953,21 @@ VK_IMPORT_DEVICE // VK_CHECK(vkWaitForFences(m_device, 1, &m_fence, true, INT64_MAX) ); } + uint32_t selectMemoryType(uint32_t memoryTypeBits, uint32_t propertyFlags) + { + for (uint32_t ii = 0; ii < m_memoryProperties.memoryTypeCount; ++ii) + { + if ( ( ((1<<ii) & memoryTypeBits) != 0) + && ( (m_memoryProperties.memoryTypes[ii].propertyFlags & propertyFlags) == propertyFlags) ) + { + return ii; + } + } + + BX_TRACE("failed to find memory that supports flags 0x%08x", propertyFlags); + return 0; + } + VkAllocationCallbacks* m_allocatorCb; VkDebugReportCallbackEXT m_debugReportCallback; VkInstance m_instance; @@ -2975,8 +2975,6 @@ VK_IMPORT_DEVICE VkPhysicalDeviceProperties m_deviceProperties; VkPhysicalDeviceMemoryProperties m_memoryProperties; - uint32_t m_memHostVisibleIdx; - uint32_t m_memLocalVisibleIdx; VkSwapchainCreateInfoKHR m_sci; VkSurfaceKHR m_surface; @@ -3121,7 +3119,9 @@ VK_DESTROY ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ma.pNext = NULL; ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->m_memHostVisibleIdx; + ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits + , VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + ); VK_CHECK(vkAllocateMemory(device , &ma , allocatorCb @@ -3230,7 +3230,9 @@ VK_DESTROY ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ma.pNext = NULL; ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->m_memLocalVisibleIdx; + ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits + , VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT + ); result = vkAllocateMemory(device , &ma , allocatorCb @@ -3333,7 +3335,9 @@ VK_DESTROY ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ma.pNext = NULL; ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->m_memHostVisibleIdx; + ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits + , VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + ); VK_CHECK(vkAllocateMemory(device , &ma , allocatorCb @@ -3344,7 +3348,7 @@ VK_DESTROY { void* dst; VK_CHECK(vkMapMemory(device, m_deviceMem, 0, ma.allocationSize, 0, &dst) ); - memcpy(dst, _data, _size); + bx::memCopy(dst, _data, _size); vkUnmapMemory(device, m_deviceMem); } @@ -3488,7 +3492,7 @@ VK_DESTROY } } - uint32_t shaderSize; + uint16_t shaderSize; bx::read(&reader, shaderSize); #if 1 @@ -3496,8 +3500,8 @@ VK_DESTROY bx::skip(&reader, shaderSize+1); m_code = alloc( ( (shaderSize+3)/4)*4); - memset(m_code->data, 0, m_code->size); - memcpy(m_code->data + bx::memSet(m_code->data, 0, m_code->size); + bx::memCopy(m_code->data , code , shaderSize+1 ); @@ -3510,7 +3514,7 @@ VK_DESTROY : sizeof(fs_cubes_spv) ; m_code = alloc(shaderSize); - memcpy(m_code->data + bx::memCopy(m_code->data , BGFX_CHUNK_MAGIC_VSH == magic ? vs_cubes_spv : fs_cubes_spv @@ -3526,7 +3530,7 @@ VK_DESTROY smci.pCode = (const uint32_t*)m_code->data; VK_CHECK(vkCreateShaderModule(s_renderVK->m_device, &smci, s_renderVK->m_allocatorCb, &m_module) ); - memset(m_attrMask, 0, sizeof(m_attrMask) ); + bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); m_attrMask[Attrib::Position] = UINT16_MAX; m_attrMask[Attrib::Color0] = UINT16_MAX; iohash = 0; @@ -3805,7 +3809,7 @@ BX_UNUSED(currentSamplerStateIdx); if (BGFX_CLEAR_NONE != clr.m_flags) { Rect clearRect = rect; - clearRect.intersect(rect, viewScissorRect); + clearRect.setIntersect(rect, viewScissorRect); clearQuad(clearRect, clr, _render->m_colorPalette); } @@ -4174,7 +4178,7 @@ BX_UNUSED(currentSamplerStateIdx); // } // else // { -// memcpy(&srvHandle[stage], &srvHandle[0], sizeof(D3D12_GPU_DESCRIPTOR_HANDLE) ); +// bx::memCopy(&srvHandle[stage], &srvHandle[0], sizeof(D3D12_GPU_DESCRIPTOR_HANDLE) ); // samplerFlags[stage] = 0; // } // } @@ -4261,7 +4265,7 @@ BX_UNUSED(currentSamplerStateIdx); { restoreScissor = true; Rect scissorRect; - scissorRect.intersect(viewScissorRect,_render->m_rectCache.m_cache[scissor]); + scissorRect.setIntersect(viewScissorRect,_render->m_rectCache.m_cache[scissor]); if (scissorRect.isZeroArea() ) { continue; diff --git a/3rdparty/bgfx/src/renderer_vk.h b/3rdparty/bgfx/src/renderer_vk.h index bb4f0217c33..90c352b5940 100644 --- a/3rdparty/bgfx/src/renderer_vk.h +++ b/3rdparty/bgfx/src/renderer_vk.h @@ -398,14 +398,14 @@ VK_DESTROY { BX_CHECK(NULL != _vsh->m_code, "Vertex shader doesn't exist."); m_vsh = _vsh; - memcpy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform)); + bx::memCopy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform)); m_numPredefined = _vsh->m_numPredefined; if (NULL != _fsh) { BX_CHECK(NULL != _fsh->m_code, "Fragment shader doesn't exist."); m_fsh = _fsh; - memcpy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform)); + bx::memCopy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform)); m_numPredefined += _fsh->m_numPredefined; } } diff --git a/3rdparty/bgfx/src/shader_dx9bc.cpp b/3rdparty/bgfx/src/shader_dx9bc.cpp index 7aea51fbf05..b3f7c43ba94 100644 --- a/3rdparty/bgfx/src/shader_dx9bc.cpp +++ b/3rdparty/bgfx/src/shader_dx9bc.cpp @@ -749,7 +749,7 @@ namespace bgfx uint8_t* data = (uint8_t*)mb.more(); uint32_t size = uint32_t(bx::getSize(&writer) ); _dst.byteCode.reserve(size); - memcpy(_dst.byteCode.data(), data, size); + bx::memCopy(_dst.byteCode.data(), data, size); } } // namespace bgfx diff --git a/3rdparty/bgfx/src/shader_dxbc.cpp b/3rdparty/bgfx/src/shader_dxbc.cpp index 3ca8c73dfa0..b73b215a325 100644 --- a/3rdparty/bgfx/src/shader_dxbc.cpp +++ b/3rdparty/bgfx/src/shader_dxbc.cpp @@ -730,21 +730,21 @@ namespace bgfx } uint32_t last[16]; - memset(last, 0, sizeof(last) ); + bx::memSet(last, 0, sizeof(last) ); const uint32_t remaining = _size & 0x3f; if (remaining >= 56) { - memcpy(&last[0], data, remaining); + bx::memCopy(&last[0], data, remaining); last[remaining/4] = 0x80; dxbcHashBlock(last, hash); - memset(&last[1], 0, 56); + bx::memSet(&last[1], 0, 56); } else { - memcpy(&last[1], data, remaining); + bx::memCopy(&last[1], data, remaining); last[1 + remaining/4] = 0x80; } @@ -752,7 +752,7 @@ namespace bgfx last[15] = _size * 2 + 1; dxbcHashBlock(last, hash); - memcpy(_digest, hash, 16); + bx::memCopy(_digest, hash, 16); } int32_t read(bx::ReaderI* _reader, DxbcSubOperand& _subOperand, bx::Error* _err) @@ -1928,7 +1928,7 @@ namespace bgfx uint8_t* data = (uint8_t*)mb.more(); uint32_t size = uint32_t(bx::getSize(&writer) ); _dst.byteCode.reserve(size); - memcpy(_dst.byteCode.data(), data, size); + bx::memCopy(_dst.byteCode.data(), data, size); } } // namespace bgfx diff --git a/3rdparty/bgfx/src/topology.cpp b/3rdparty/bgfx/src/topology.cpp index 3123d62fb05..2804bc7ddf4 100644 --- a/3rdparty/bgfx/src/topology.cpp +++ b/3rdparty/bgfx/src/topology.cpp @@ -6,7 +6,7 @@ #include <bx/allocator.h> #include <bx/debug.h> #include <bx/fpumath.h> -#include <bx/radixsort.h> +#include <bx/sort.h> #include <bx/uint32_t.h> #include "config.h" diff --git a/3rdparty/bgfx/src/vertexdecl.cpp b/3rdparty/bgfx/src/vertexdecl.cpp index 70c3aafc67f..a2d88a4ff84 100644 --- a/3rdparty/bgfx/src/vertexdecl.cpp +++ b/3rdparty/bgfx/src/vertexdecl.cpp @@ -3,11 +3,10 @@ * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ -#include <string.h> #include <bx/debug.h> #include <bx/hash.h> #include <bx/readerwriter.h> -#include <bx/radixsort.h> +#include <bx/sort.h> #include <bx/string.h> #include <bx/uint32_t.h> @@ -74,8 +73,8 @@ namespace bgfx { m_hash = _renderer; // use hash to store renderer type while building VertexDecl. m_stride = 0; - memset(m_attributes, 0xff, sizeof(m_attributes) ); - memset(m_offset, 0, sizeof(m_offset) ); + bx::memSet(m_attributes, 0xff, sizeof(m_attributes) ); + bx::memSet(m_offset, 0, sizeof(m_offset) ); return *this; } @@ -513,7 +512,7 @@ namespace bgfx break; case AttribType::Float: - memcpy(data, _input, num*sizeof(float) ); + bx::memCopy(data, _input, num*sizeof(float) ); break; } } @@ -522,7 +521,7 @@ namespace bgfx { if (!_decl.has(_attr) ) { - memset(_output, 0, 4*sizeof(float) ); + bx::memSet(_output, 0, 4*sizeof(float) ); return; } @@ -630,7 +629,7 @@ namespace bgfx break; case AttribType::Float: - memcpy(_output, data, num*sizeof(float) ); + bx::memCopy(_output, data, num*sizeof(float) ); _output += num; break; } @@ -648,7 +647,7 @@ namespace bgfx { if (_destDecl.m_hash == _srcDecl.m_hash) { - memcpy(_destData, _srcData, _srcDecl.getSize(_num) ); + bx::memCopy(_destData, _srcData, _srcDecl.getSize(_num) ); return; } @@ -721,11 +720,11 @@ namespace bgfx switch (cop.op) { case ConvertOp::Set: - memset(dest + cop.dest, 0, cop.size); + bx::memSet(dest + cop.dest, 0, cop.size); break; case ConvertOp::Copy: - memcpy(dest + cop.dest, src + cop.src, cop.size); + bx::memCopy(dest + cop.dest, src + cop.src, cop.size); break; case ConvertOp::Convert: @@ -755,7 +754,7 @@ namespace bgfx const float epsilonSq = _epsilon*_epsilon; uint32_t numVertices = 0; - memset(_output, 0xff, _num*sizeof(uint16_t) ); + bx::memSet(_output, 0xff, _num*sizeof(uint16_t) ); for (uint32_t ii = 0; ii < _num; ++ii) { @@ -800,7 +799,7 @@ namespace bgfx const uint32_t size = sizeof(uint16_t)*(hashSize + _num); uint16_t* hashTable = (uint16_t*)alloca(size); - memset(hashTable, 0xff, size); + bx::memSet(hashTable, 0xff, size); uint16_t* next = hashTable + hashSize; |