diff options
Diffstat (limited to '3rdparty/bgfx/src')
-rw-r--r-- | 3rdparty/bgfx/src/bgfx.cpp | 176 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/bgfx_p.h | 27 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/bgfx_shader.sh | 72 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_nsgl.mm | 25 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/hmd_openvr.cpp | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/image.cpp | 168 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/image.h | 31 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_d3d.h | 8 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_d3d11.cpp | 122 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_d3d12.cpp | 122 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_d3d9.cpp | 38 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_gl.cpp | 773 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_gl.h | 40 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_mtl.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_mtl.mm | 128 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/shader_dxbc.cpp | 4 |
16 files changed, 1140 insertions, 598 deletions
diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp index 90c6cee6113..627c90b85b2 100644 --- a/3rdparty/bgfx/src/bgfx.cpp +++ b/3rdparty/bgfx/src/bgfx.cpp @@ -352,14 +352,14 @@ namespace bgfx bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = uint8_t(bx::uint16_max(1, _numMips) ); - tc.m_format = _format; - tc.m_cubeMap = false; - tc.m_mem = NULL; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = 1; + tc.m_numMips = uint8_t(bx::uint16_max(1, _numMips) ); + tc.m_format = _format; + tc.m_cubeMap = false; + tc.m_mem = NULL; bx::write(&writer, tc); rci->destroyTexture(_handle); @@ -472,7 +472,7 @@ namespace bgfx uint8_t* rgba = mem->data; charsetFillTexture(vga8x8, rgba, 8, pitch, bpp); charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp); - m_texture = createTexture2D(width, height, 1, TextureFormat::R8 + m_texture = createTexture2D(width, height, false, 1, TextureFormat::R8 , BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT @@ -1101,6 +1101,8 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_OCCLUSION_QUERY), CAPS_FLAGS(BGFX_CAPS_ALPHA_TO_COVERAGE), CAPS_FLAGS(BGFX_CAPS_CONSERVATIVE_RASTER), + CAPS_FLAGS(BGFX_CAPS_TEXTURE_2D_ARRAY), + CAPS_FLAGS(BGFX_CAPS_TEXTURE_CUBE_ARRAY), #undef CAPS_FLAGS }; @@ -2882,7 +2884,7 @@ error: s_ctx->destroyProgram(_handle); } - void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, TextureFormat::Enum _format) + 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; @@ -2894,15 +2896,15 @@ error: _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); - _numMips = uint8_t(bx::uint16_max(1, _numMips) ); + 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); @@ -2915,12 +2917,15 @@ error: depth >>= 1; } + size *= _numLayers; + _info.format = _format; _info.width = _width; _info.height = _height; _info.depth = _depth; - _info.numMips = _numMips; - _info.cubeMap = _cubeMap; + _info.numMips = numMips; + _info.numLayers = _numLayers; + _info.cubeMap = _cubeMap; _info.storageSize = size; _info.bitsPerPixel = bpp; } @@ -2950,7 +2955,7 @@ error: _height = bx::uint16_max(1, _height); } - static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) + static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) { BGFX_CHECK_MAIN_THREAD(); @@ -2961,6 +2966,12 @@ error: , "Format %s is not supported for 2D texture. Use bgfx::getCaps to check available texture formats." , getName(_format) ); + BX_CHECK(false + || 1 >= _numLayers + || 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_2D_ARRAY) + , "_numLayers is %d. Texture 2D array is not supported! Use bgfx::getCaps to check BGFX_CAPS_TEXTURE_2D_ARRAY backend renderer capabilities." + , _numLayers + ); if (BackbufferRatio::Count != _ratio) { @@ -2969,13 +2980,14 @@ error: getTextureSizeFromRatio(_ratio, _width, _height); } - _numMips = calcNumMips(_numMips, _width, _height); + const uint8_t numMips = calcNumMips(_hasMips, _width, _height); + _numLayers = bx::uint16_max(_numLayers, 1); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) { TextureInfo ti; - calcTextureSize(ti, _width, _height, 1, false, _numMips, _format); + calcTextureSize(ti, _width, _height, 1, false, _hasMips, _numLayers, _format); BX_CHECK(ti.storageSize == _mem->size , "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize @@ -2991,32 +3003,32 @@ error: bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = _format; - tc.m_cubeMap = false; - tc.m_mem = _mem; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = _numLayers; + tc.m_numMips = numMips; + tc.m_format = _format; + tc.m_cubeMap = false; + tc.m_mem = _mem; bx::write(&writer, tc); return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio); } - TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) + TextureHandle createTexture2D(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) { BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height); - return createTexture2D(BackbufferRatio::Count, _width, _height, _numMips, _format, _flags, _mem); + return createTexture2D(BackbufferRatio::Count, _width, _height, _hasMips, _numLayers, _format, _flags, _mem); } - TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags) + TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags) { BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); - return createTexture2D(_ratio, 0, 0, _numMips, _format, _flags, NULL); + return createTexture2D(_ratio, 0, 0, _hasMips, _numLayers, _format, _flags, NULL); } - TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) + TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) { BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_3D, "Texture3D is not supported!"); @@ -3025,13 +3037,13 @@ error: , getName(_format) ); - _numMips = calcNumMips(_numMips, _width, _height, _depth); + const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) { TextureInfo ti; - calcTextureSize(ti, _width, _height, _depth, false, _numMips, _format); + calcTextureSize(ti, _width, _height, _depth, false, _hasMips, 1, _format); BX_CHECK(ti.storageSize == _mem->size , "createTexture3D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize @@ -3047,34 +3059,41 @@ error: bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = _depth; - tc.m_numMips = _numMips; - tc.m_format = _format; - tc.m_cubeMap = false; - tc.m_mem = _mem; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = _depth; + tc.m_numLayers = 1; + tc.m_numMips = numMips; + tc.m_format = _format; + tc.m_cubeMap = false; + tc.m_mem = _mem; bx::write(&writer, tc); return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count); } - TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) + TextureHandle createTextureCube(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(0 != (g_caps.formats[_format] & (BGFX_CAPS_FORMAT_TEXTURE_CUBE|BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED|BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB) ) , "Format %s is not supported for cube texture. Use bgfx::getCaps to check available texture formats." , getName(_format) ); + BX_CHECK(false + || 1 >= _numLayers + || 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_CUBE_ARRAY) + , "_numLayers is %d. Texture cube array is not supported! Use bgfx::getCaps to check BGFX_CAPS_TEXTURE_CUBE_ARRAY backend renderer capabilities." + , _numLayers + ); - _numMips = calcNumMips(_numMips, _size, _size); + const uint8_t numMips = calcNumMips(_hasMips, _size, _size); + _numLayers = bx::uint16_max(_numLayers, 1); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) { TextureInfo ti; - calcTextureSize(ti, _size, _size, 1, true, _numMips, _format); + calcTextureSize(ti, _size, _size, 1, true, _hasMips, _numLayers, _format); BX_CHECK(ti.storageSize == _mem->size , "createTextureCube: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize @@ -3090,14 +3109,14 @@ error: bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _size; - tc.m_height = _size; - tc.m_sides = 6; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = _format; - tc.m_cubeMap = true; - tc.m_mem = _mem; + tc.m_width = _size; + tc.m_height = _size; + tc.m_depth = 0; + tc.m_numLayers = _numLayers; + tc.m_numMips = numMips; + tc.m_format = _format; + tc.m_cubeMap = true; + tc.m_mem = _mem; bx::write(&writer, tc); return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count); @@ -3109,7 +3128,7 @@ error: s_ctx->destroyTexture(_handle); } - void updateTexture2D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) + void updateTexture2D(TextureHandle _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -3120,7 +3139,7 @@ error: } else { - s_ctx->updateTexture(_handle, 0, _mip, _x, _y, 0, _width, _height, 1, _pitch, _mem); + s_ctx->updateTexture(_handle, 0, _mip, _x, _y, _layer, _width, _height, 1, _pitch, _mem); } } @@ -3142,7 +3161,7 @@ error: } } - void updateTextureCube(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) + void updateTextureCube(TextureHandle _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -3154,7 +3173,7 @@ error: } else { - s_ctx->updateTexture(_handle, _side, _mip, _x, _y, 0, _width, _height, 1, _pitch, _mem); + s_ctx->updateTexture(_handle, _side, _mip, _x, _y, _layer, _width, _height, 1, _pitch, _mem); } } @@ -3177,7 +3196,7 @@ error: FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags) { _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; - TextureHandle th = createTexture2D(_width, _height, 1, _format, _textureFlags); + TextureHandle th = createTexture2D(_width, _height, false, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); } @@ -3185,7 +3204,7 @@ error: { BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; - TextureHandle th = createTexture2D(_ratio, 1, _format, _textureFlags); + TextureHandle th = createTexture2D(_ratio, false, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); } @@ -3971,6 +3990,11 @@ BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, co va_end(argList); } +BGFX_C_API void bgfx_dbg_text_vprintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList) +{ + bgfx::dbgTextPrintfVargs(_x, _y, _attr, _format, _argList); +} + BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch) { bgfx::dbgTextImage(_x, _y, _width, _height, _data, _pitch); @@ -4156,10 +4180,10 @@ BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle) bgfx::destroyProgram(handle.cpp); } -BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format) +BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format) { bgfx::TextureInfo& info = *(bgfx::TextureInfo*)_info; - bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _numMips, bgfx::TextureFormat::Enum(_format) ); + bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format) ); } BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info) @@ -4170,38 +4194,38 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, return handle.c; } -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTexture2D(_width, _height, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createTexture2D(_width, _height, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); return handle.c; } -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags) +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _numMips, bgfx::TextureFormat::Enum(_format), _flags); + handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags); return handle.c; } -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTexture3D(_width, _height, _depth, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createTexture3D(_width, _height, _depth, _hasMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); return handle.c; } -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTextureCube(_size, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createTextureCube(_size, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); return handle.c; } -BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) +BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::updateTexture2D(handle.cpp, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); + bgfx::updateTexture2D(handle.cpp, _layer, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); } BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem) @@ -4210,10 +4234,10 @@ BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _m bgfx::updateTexture3D(handle.cpp, _mip, _x, _y, _z, _width, _height, _depth, (const bgfx::Memory*)_mem); } -BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) +BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::updateTextureCube(handle.cpp, _side, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); + bgfx::updateTextureCube(handle.cpp, _layer, _side, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); } BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data) @@ -4248,6 +4272,13 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backb return handle.c; } +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTextures) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; + handle.cpp = bgfx::createFrameBuffer(_num, (const bgfx::TextureHandle*)_handles, _destroyTextures); + return handle.c; +} + BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_attachment(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTextures) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; @@ -4655,6 +4686,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) BGFX_IMPORT_FUNC(set_debug) \ BGFX_IMPORT_FUNC(dbg_text_clear) \ BGFX_IMPORT_FUNC(dbg_text_printf) \ + BGFX_IMPORT_FUNC(dbg_text_vprintf) \ BGFX_IMPORT_FUNC(dbg_text_image) \ BGFX_IMPORT_FUNC(create_index_buffer) \ BGFX_IMPORT_FUNC(destroy_index_buffer) \ diff --git a/3rdparty/bgfx/src/bgfx_p.h b/3rdparty/bgfx/src/bgfx_p.h index e624dba372d..561a9fa2c99 100644 --- a/3rdparty/bgfx/src/bgfx_p.h +++ b/3rdparty/bgfx/src/bgfx_p.h @@ -320,8 +320,8 @@ namespace bgfx TextureFormat::Enum m_format; uint16_t m_width; uint16_t m_height; - uint16_t m_sides; uint16_t m_depth; + uint16_t m_numLayers; uint8_t m_numMips; bool m_cubeMap; const Memory* m_mem; @@ -364,9 +364,9 @@ namespace bgfx ; } - inline uint8_t calcNumMips(uint8_t _numMips, uint16_t _width, uint16_t _height, uint16_t _depth = 1) + inline uint8_t calcNumMips(bool _hasMips, uint16_t _width, uint16_t _height, uint16_t _depth = 1) { - if (1 < _numMips) + if (_hasMips) { const uint32_t max = bx::uint32_max(bx::uint32_max(_width, _height), _depth); const uint32_t num = 1 + uint32_t(bx::flog2(float(max) ) ); @@ -3097,7 +3097,8 @@ namespace bgfx , (uint16_t)imageContainer.m_height , (uint16_t)imageContainer.m_depth , imageContainer.m_cubeMap - , imageContainer.m_numMips + , imageContainer.m_numMips > 1 + , imageContainer.m_numLayers , TextureFormat::Enum(imageContainer.m_format) ); } @@ -3170,7 +3171,7 @@ namespace bgfx BX_CHECK(BackbufferRatio::Count != textureRef.m_bbRatio, ""); getTextureSizeFromRatio(BackbufferRatio::Enum(textureRef.m_bbRatio), _width, _height); - _numMips = calcNumMips(_numMips, _width, _height); + _numMips = calcNumMips(1 < _numMips, _width, _height); BX_TRACE("Resize %3d: %4dx%d %s" , _handle.idx @@ -3214,7 +3215,19 @@ namespace bgfx } } - BGFX_API_FUNC(void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, uint16_t _pitch, const Memory* _mem) ) + BGFX_API_FUNC(void updateTexture( + TextureHandle _handle + , uint8_t _side + , uint8_t _mip + , uint16_t _x + , uint16_t _y + , uint16_t _z + , uint16_t _width + , uint16_t _height + , uint16_t _depth + , uint16_t _pitch + , const Memory* _mem + ) ) { CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::UpdateTexture); cmdbuf.write(_handle); @@ -3223,7 +3236,7 @@ namespace bgfx Rect rect; rect.m_x = _x; rect.m_y = _y; - rect.m_width = _width; + rect.m_width = _width; rect.m_height = _height; cmdbuf.write(rect); cmdbuf.write(_z); diff --git a/3rdparty/bgfx/src/bgfx_shader.sh b/3rdparty/bgfx/src/bgfx_shader.sh index e8a909d4be1..f607f17d74e 100644 --- a/3rdparty/bgfx/src/bgfx_shader.sh +++ b/3rdparty/bgfx/src/bgfx_shader.sh @@ -98,6 +98,12 @@ struct BgfxUSampler2D Texture2D<uvec4> m_texture; }; +struct BgfxSampler2DArray +{ + SamplerState m_sampler; + Texture2DArray m_texture; +}; + struct BgfxSampler2DShadow { SamplerComparisonState m_sampler; @@ -153,6 +159,16 @@ vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec4 _coord) return _sampler.m_texture.Sample(_sampler.m_sampler, coord); } +vec4 bgfxTexture2DArray(BgfxSampler2DArray _sampler, vec3 _coord) +{ + return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); +} + +vec4 bgfxTexture2DArrayLod(BgfxSampler2DArray _sampler, vec3 _coord, float _lod) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _lod); +} + float bgfxShadow2D(BgfxSampler2DShadow _sampler, vec3 _coord) { return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z); @@ -238,6 +254,14 @@ vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod) # define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level) # define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) +# define SAMPLER2DARRAY(_name, _reg) \ + uniform SamplerState _name ## Sampler : register(s[_reg]); \ + uniform Texture2DArray _name ## Texture : register(t[_reg]); \ + static BgfxSampler2DArray _name = { _name ## Sampler, _name ## Texture } +# define sampler2DArray BgfxSampler2DArray +# define texture2DArray(_sampler, _coord) bgfxTexture2DArray(_sampler, _coord) +# define texture2DArrayLod(_sampler, _coord, _lod) bgfxTexture2DArrayLod(_sampler, _coord, _lod) + # define SAMPLER2DMS(_name, _reg) \ uniform Texture2DMS<vec4> _name ## Texture : register(t[_reg]); \ static BgfxSampler2DMS _name = { _name ## Texture } @@ -380,50 +404,26 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); } # define atan2(_x, _y) atan(_x, _y) # define mul(_a, _b) ( (_a) * (_b) ) # define saturate(_x) clamp(_x, 0.0, 1.0) -# define SAMPLER2D(_name, _reg) uniform sampler2D _name -# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name -# define SAMPLER3D(_name, _reg) uniform sampler3D _name -# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name +# define SAMPLER2D(_name, _reg) uniform sampler2D _name +# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name +# define SAMPLER3D(_name, _reg) uniform sampler3D _name +# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name # define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name +# define SAMPLER2DARRAY(_name, _reg) uniform sampler2DArray _name +# define SAMPLER2DMSARRAY(_name, _reg) uniform sampler2DMSArray _name +# define SAMPLERCUBEARRAY(_name, _reg) uniform samplerCubeArray _name +# define SAMPLER2DARRAYSHADOW(_name, _reg) uniform sampler2DArrayShadow _name + # if BGFX_SHADER_LANGUAGE_GLSL >= 130 # define ISAMPLER2D(_name, _reg) uniform isampler2D _name # define USAMPLER2D(_name, _reg) uniform usampler2D _name # define ISAMPLER3D(_name, _reg) uniform isampler3D _name # define USAMPLER3D(_name, _reg) uniform usampler3D _name -vec4 bgfxTexture2D(sampler2D _sampler, vec2 _coord) -{ - return texture(_sampler, _coord); -} - -ivec4 bgfxTexture2D(isampler2D _sampler, vec2 _coord) -{ - return texture(_sampler, _coord); -} - -uvec4 bgfxTexture2D(usampler2D _sampler, vec2 _coord) -{ - return texture(_sampler, _coord); -} - -vec4 bgfxTexture3D(sampler3D _sampler, vec3 _coord) -{ - return texture(_sampler, _coord); -} - -ivec4 bgfxTexture3D(isampler3D _sampler, vec3 _coord) -{ - return texture(_sampler, _coord); -} - -uvec4 bgfxTexture3D(usampler3D _sampler, vec3 _coord) -{ - return texture(_sampler, _coord); -} - -# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord) -# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord) +# define texture2D(_sampler, _coord) texture(_sampler, _coord) +# define texture2DArray(_sampler, _coord) texture(_sampler, _coord) +# define texture3D(_sampler, _coord) texture(_sampler, _coord) # endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); } diff --git a/3rdparty/bgfx/src/glcontext_nsgl.mm b/3rdparty/bgfx/src/glcontext_nsgl.mm index ac51bf63157..61a39272253 100644 --- a/3rdparty/bgfx/src/glcontext_nsgl.mm +++ b/3rdparty/bgfx/src/glcontext_nsgl.mm @@ -101,7 +101,24 @@ namespace bgfx { namespace gl NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat]; [pixelFormat release]; - [nsWindow setContentView:glView]; + // GLFW creates a helper contentView that handles things like keyboard and drag and + // drop events. We don't want to clobber that view if it exists. Instead we just + // add ourselves as a subview and make the view resize automatically. + NSView *contentView = [nsWindow contentView]; + if( contentView != nil ) + { + [glView setAutoresizingMask:( NSViewHeightSizable | + NSViewWidthSizable | + NSViewMinXMargin | + NSViewMaxXMargin | + NSViewMinYMargin | + NSViewMaxYMargin )]; + [contentView addSubview:glView]; + } + else + { + [nsWindow setContentView:glView]; + } NSOpenGLContext* glContext = [glView openGLContext]; BGFX_FATAL(NULL != glContext, Fatal::UnableToInitialize, "Failed to initialize GL context."); @@ -109,6 +126,12 @@ namespace bgfx { namespace gl [glContext makeCurrentContext]; GLint interval = 0; [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; + + // When initializing NSOpenGLView programatically (as we are), this sometimes doesn't + // get hooked up properly (especially when there are existing window elements). This ensures + // we are valid. Otherwise, you'll probably get a GL_INVALID_FRAMEBUFFER_OPERATION when + // trying to glClear() for the first time. + [glContext setView:glView]; m_view = glView; m_context = glContext; diff --git a/3rdparty/bgfx/src/hmd_openvr.cpp b/3rdparty/bgfx/src/hmd_openvr.cpp index 9e360cbf18e..59ae813afe8 100644 --- a/3rdparty/bgfx/src/hmd_openvr.cpp +++ b/3rdparty/bgfx/src/hmd_openvr.cpp @@ -5,8 +5,10 @@ #include "hmd_openvr.h" +BX_PRAGMA_DIAGNOSTIC_PUSH() BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wunused-variable") #include <openvr/openvr_capi.h> +BX_PRAGMA_DIAGNOSTIC_POP() namespace bgfx { diff --git a/3rdparty/bgfx/src/image.cpp b/3rdparty/bgfx/src/image.cpp index 4b31a7ba08a..81557c0ea11 100644 --- a/3rdparty/bgfx/src/image.cpp +++ b/3rdparty/bgfx/src/image.cpp @@ -263,7 +263,7 @@ namespace bgfx return numMips; } - uint32_t imageGetSize(TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, 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) { const ImageBlockInfo& blockInfo = getBlockInfo(_format); const uint8_t bpp = blockInfo.bitsPerPixel; @@ -275,7 +275,6 @@ namespace bgfx _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); - _numMips = uint8_t(bx::uint16_max(1, _numMips) ); uint32_t width = _width; uint32_t height = _height; @@ -296,7 +295,7 @@ namespace bgfx depth >>= 1; } - return size; + return size * _numLayers; } void imageSolid(uint32_t _width, uint32_t _height, uint32_t _solid, void* _dst) @@ -2493,7 +2492,7 @@ namespace bgfx } } - const Memory* imageAlloc(ImageContainer& _imageContainer, TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _generateMips) + const Memory* imageAlloc(ImageContainer& _imageContainer, TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth, uint16_t _numLayers, bool _cubeMap, bool _generateMips) { const ImageBlockInfo& blockInfo = getBlockInfo(_format); const uint16_t blockWidth = blockInfo.blockWidth; @@ -2501,27 +2500,29 @@ 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); + _numLayers = bx::uint16_max(1, _numLayers); const uint8_t numMips = _generateMips ? imageGetNumMips(_format, _width, _height) : 1; - uint32_t size = imageGetSize(_format, _width, _height, 0, false, numMips); + 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_numMips = numMips; - _imageContainer.m_hasAlpha = false; - _imageContainer.m_cubeMap = _cubeMap; - _imageContainer.m_ktx = false; - _imageContainer.m_ktxLE = false; - _imageContainer.m_srgb = false; + _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; return image; } @@ -2792,6 +2793,7 @@ namespace bgfx bx::skip(_reader, 4); // reserved uint32_t dxgiFormat = 0; + uint32_t arraySize = 1; if (DDPF_FOURCC == pixelFlags && DDS_DX10 == fourcc) { @@ -2803,7 +2805,6 @@ namespace bgfx uint32_t miscFlags; bx::read(_reader, miscFlags); - uint32_t arraySize; bx::read(_reader, arraySize); uint32_t miscFlags2; @@ -2872,19 +2873,20 @@ namespace bgfx } } - _imageContainer.m_data = NULL; - _imageContainer.m_size = 0; - _imageContainer.m_offset = (uint32_t)bx::seek(_reader); - _imageContainer.m_width = width; - _imageContainer.m_height = height; - _imageContainer.m_depth = depth; - _imageContainer.m_format = format; - _imageContainer.m_numMips = uint8_t( (caps[0] & DDSCAPS_MIPMAP) ? mips : 1); - _imageContainer.m_hasAlpha = hasAlpha; - _imageContainer.m_cubeMap = cubeMap; - _imageContainer.m_ktx = false; - _imageContainer.m_ktxLE = false; - _imageContainer.m_srgb = srgb; + _imageContainer.m_data = NULL; + _imageContainer.m_size = 0; + _imageContainer.m_offset = (uint32_t)bx::seek(_reader); + _imageContainer.m_width = width; + _imageContainer.m_height = height; + _imageContainer.m_depth = depth; + _imageContainer.m_format = format; + _imageContainer.m_numLayers = uint16_t(arraySize); + _imageContainer.m_numMips = uint8_t( (caps[0] & DDSCAPS_MIPMAP) ? mips : 1); + _imageContainer.m_hasAlpha = hasAlpha; + _imageContainer.m_cubeMap = cubeMap; + _imageContainer.m_ktx = false; + _imageContainer.m_ktxLE = false; + _imageContainer.m_srgb = srgb; return TextureFormat::Unknown != format; } @@ -3178,19 +3180,20 @@ namespace bgfx } } - _imageContainer.m_data = NULL; - _imageContainer.m_size = 0; - _imageContainer.m_offset = (uint32_t)offset; - _imageContainer.m_width = width; - _imageContainer.m_height = height; - _imageContainer.m_depth = depth; - _imageContainer.m_format = format; - _imageContainer.m_numMips = uint8_t(bx::uint32_max(numMips, 1) ); - _imageContainer.m_hasAlpha = hasAlpha; - _imageContainer.m_cubeMap = numFaces > 1; - _imageContainer.m_ktx = true; - _imageContainer.m_ktxLE = fromLittleEndian; - _imageContainer.m_srgb = false; + _imageContainer.m_data = NULL; + _imageContainer.m_size = 0; + _imageContainer.m_offset = (uint32_t)offset; + _imageContainer.m_width = width; + _imageContainer.m_height = height; + _imageContainer.m_depth = depth; + _imageContainer.m_format = format; + _imageContainer.m_numLayers = uint16_t(bx::uint32_max(numberOfArrayElements, 1) ); + _imageContainer.m_numMips = uint8_t(bx::uint32_max(numMips, 1) ); + _imageContainer.m_hasAlpha = hasAlpha; + _imageContainer.m_cubeMap = numFaces > 1; + _imageContainer.m_ktx = true; + _imageContainer.m_ktxLE = fromLittleEndian; + _imageContainer.m_srgb = false; return TextureFormat::Unknown != format; } @@ -3327,19 +3330,20 @@ namespace bgfx } } - _imageContainer.m_data = NULL; - _imageContainer.m_size = 0; - _imageContainer.m_offset = (uint32_t)offset; - _imageContainer.m_width = width; - _imageContainer.m_height = height; - _imageContainer.m_depth = depth; - _imageContainer.m_format = format; - _imageContainer.m_numMips = uint8_t(bx::uint32_max(numMips, 1) ); - _imageContainer.m_hasAlpha = hasAlpha; - _imageContainer.m_cubeMap = numFaces > 1; - _imageContainer.m_ktx = false; - _imageContainer.m_ktxLE = false; - _imageContainer.m_srgb = colorSpace > 0; + _imageContainer.m_data = NULL; + _imageContainer.m_size = 0; + _imageContainer.m_offset = (uint32_t)offset; + _imageContainer.m_width = width; + _imageContainer.m_height = height; + _imageContainer.m_depth = depth; + _imageContainer.m_format = format; + _imageContainer.m_numLayers = 1; + _imageContainer.m_numMips = uint8_t(bx::uint32_max(numMips, 1) ); + _imageContainer.m_hasAlpha = hasAlpha; + _imageContainer.m_cubeMap = numFaces > 1; + _imageContainer.m_ktx = false; + _imageContainer.m_ktxLE = false; + _imageContainer.m_srgb = colorSpace > 0; return TextureFormat::Unknown != format; } @@ -3378,15 +3382,16 @@ namespace bgfx _imageContainer.m_data = tc.m_mem->data; _imageContainer.m_size = tc.m_mem->size; } - _imageContainer.m_width = tc.m_width; - _imageContainer.m_height = tc.m_height; - _imageContainer.m_depth = tc.m_depth; - _imageContainer.m_numMips = tc.m_numMips; - _imageContainer.m_hasAlpha = false; - _imageContainer.m_cubeMap = tc.m_cubeMap; - _imageContainer.m_ktx = false; - _imageContainer.m_ktxLE = false; - _imageContainer.m_srgb = false; + _imageContainer.m_width = tc.m_width; + _imageContainer.m_height = tc.m_height; + _imageContainer.m_depth = tc.m_depth; + _imageContainer.m_numLayers = tc.m_numLayers; + _imageContainer.m_numMips = tc.m_numMips; + _imageContainer.m_hasAlpha = false; + _imageContainer.m_cubeMap = tc.m_cubeMap; + _imageContainer.m_ktx = false; + _imageContainer.m_ktxLE = false; + _imageContainer.m_srgb = false; return true; } @@ -3763,7 +3768,7 @@ namespace bgfx } } - bool imageGetRawData(const ImageContainer& _imageContainer, uint8_t _side, uint8_t _lod, const void* _data, uint32_t _size, ImageMip& _mip) + bool imageGetRawData(const ImageContainer& _imageContainer, uint16_t _side, uint8_t _lod, const void* _data, uint32_t _size, ImageMip& _mip) { uint32_t offset = _imageContainer.m_offset; TextureFormat::Enum format = TextureFormat::Enum(_imageContainer.m_format); @@ -3790,6 +3795,7 @@ namespace bgfx } const uint8_t* data = (const uint8_t*)_data; + const uint16_t numSides = _imageContainer.m_numLayers * (_imageContainer.m_cubeMap ? 6 : 1); if (_imageContainer.m_ktx) { @@ -3799,7 +3805,7 @@ namespace bgfx for (uint8_t lod = 0, num = _imageContainer.m_numMips; lod < num; ++lod) { - uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE); + uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE) / _imageContainer.m_numLayers; offset += sizeof(uint32_t); width = bx::uint32_max(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth); @@ -3809,7 +3815,7 @@ namespace bgfx uint32_t size = width*height*depth*bpp/8; BX_CHECK(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize); - for (uint8_t side = 0, numSides = _imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) + for (uint16_t side = 0; side < numSides; ++side) { if (side == _side && lod == _lod) @@ -3838,7 +3844,7 @@ namespace bgfx } else { - for (uint8_t side = 0, numSides = _imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) + for (uint16_t side = 0; side < numSides; ++side) { uint32_t width = _imageContainer.m_width; uint32_t height = _imageContainer.m_height; @@ -3932,19 +3938,19 @@ namespace bgfx int32_t size = 0; size += bx::write(_writer, "\xabKTX 11\xbb\r\n\x1a\n", 12, _err); - size += bx::write(_writer, UINT32_C(0x04030201), _err); - size += bx::write(_writer, UINT32_C(0), _err); // glType - size += bx::write(_writer, UINT32_C(1), _err); // glTypeSize - size += bx::write(_writer, UINT32_C(0), _err); // glFormat + size += bx::write(_writer, uint32_t(0x04030201), _err); + size += bx::write(_writer, uint32_t(0), _err); // glType + size += bx::write(_writer, uint32_t(1), _err); // glTypeSize + size += bx::write(_writer, uint32_t(0), _err); // glFormat size += bx::write(_writer, tfi.m_internalFmt, _err); // glInternalFormat size += bx::write(_writer, tfi.m_fmt, _err); // glBaseInternalFormat size += bx::write(_writer, _width, _err); size += bx::write(_writer, _height, _err); size += bx::write(_writer, _depth, _err); - size += bx::write(_writer, UINT32_C(0), _err); // numberOfArrayElements - size += bx::write(_writer, _cubeMap ? UINT32_C(6) : UINT32_C(0), _err); + size += bx::write(_writer, uint32_t(0), _err); // numberOfArrayElements + size += bx::write(_writer, _cubeMap ? uint32_t(6) : uint32_t(0), _err); size += bx::write(_writer, uint32_t(_numMips), _err); - size += bx::write(_writer, UINT32_C(0), _err); // Meta-data size. + size += bx::write(_writer, uint32_t(0), _err); // Meta-data size. BX_WARN(size == 64, "KTX: Failed to write header size %d (expected: %d).", size, 64); return size; diff --git a/3rdparty/bgfx/src/image.h b/3rdparty/bgfx/src/image.h index 64bbf1c5f29..d9479bb82c4 100644 --- a/3rdparty/bgfx/src/image.h +++ b/3rdparty/bgfx/src/image.h @@ -19,6 +19,7 @@ namespace bgfx uint32_t m_width; uint32_t m_height; uint32_t m_depth; + uint16_t m_numLayers; uint8_t m_numMips; bool m_hasAlpha; bool m_cubeMap; @@ -294,10 +295,23 @@ namespace bgfx TextureFormat::Enum getFormat(const char* _name); /// Returns number of mip-maps required for complete mip-map chain. - uint8_t imageGetNumMips(TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth = 0); + uint8_t imageGetNumMips( + TextureFormat::Enum _format + , uint16_t _width + , uint16_t _height + , uint16_t _depth = 0 + ); /// Returns image size. - uint32_t imageGetSize(TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth = 0, bool _cubeMap = false, uint8_t _numMips = 0); + uint32_t imageGetSize( + TextureFormat::Enum _format + , uint16_t _width + , uint16_t _height + , uint16_t _depth = 0 + , uint16_t _numLayers = 1 + , bool _cubeMap = false + , uint8_t _numMips = 1 + ); /// void imageSolid(uint32_t _width, uint32_t _height, uint32_t _solid, void* _dst); @@ -342,7 +356,16 @@ namespace bgfx bool imageConvert(void* _dst, TextureFormat::Enum _dstFormat, const void* _src, TextureFormat::Enum _srcFormat, uint32_t _width, uint32_t _height); /// - const Memory* imageAlloc(ImageContainer& _imageContainer, TextureFormat::Enum _format, uint16_t _width, uint16_t _height, uint16_t _depth = 0, bool _cubeMap = false, bool _generateMips = false); + const Memory* imageAlloc( + ImageContainer& _imageContainer + , TextureFormat::Enum _format + , uint16_t _width + , uint16_t _height + , uint16_t _depth = 0 + , uint16_t _numLayers = 1 + , bool _cubeMap = false + , bool _generateMips = false + ); /// void imageFree(const Memory* _memory); @@ -372,7 +395,7 @@ namespace bgfx void imageDecodeToRgba32f(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _pitch, TextureFormat::Enum _format); /// - bool imageGetRawData(const ImageContainer& _imageContainer, uint8_t _side, uint8_t _index, const void* _data, uint32_t _size, ImageMip& _mip); + bool imageGetRawData(const ImageContainer& _imageContainer, uint16_t _side, uint8_t _index, const void* _data, uint32_t _size, ImageMip& _mip); } // namespace bgfx diff --git a/3rdparty/bgfx/src/renderer_d3d.h b/3rdparty/bgfx/src/renderer_d3d.h index 97cfb045821..f52fe6a87f6 100644 --- a/3rdparty/bgfx/src/renderer_d3d.h +++ b/3rdparty/bgfx/src/renderer_d3d.h @@ -96,6 +96,14 @@ namespace bgfx # define PIX_ENDEVENT() #endif // BGFX_CONFIG_DEBUG_PIX +#define D3DCOLOR_FRAME D3DCOLOR_RGBA(0xff, 0xd7, 0xc9, 0xff) +#define D3DCOLOR_VIEW D3DCOLOR_RGBA(0xe4, 0xb4, 0x8e, 0xff) +#define D3DCOLOR_VIEW_L D3DCOLOR_RGBA(0xf9, 0xee, 0xe5, 0xff) +#define D3DCOLOR_VIEW_R D3DCOLOR_RGBA(0xe8, 0xd3, 0xc0, 0xff) +#define D3DCOLOR_DRAW D3DCOLOR_RGBA(0xc6, 0xe5, 0xb9, 0xff) +#define D3DCOLOR_COMPUTE D3DCOLOR_RGBA(0xa7, 0xdb, 0xd8, 0xff) +#define D3DCOLOR_MARKER D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff) + inline int getRefCount(IUnknown* _interface) { _interface->AddRef(); diff --git a/3rdparty/bgfx/src/renderer_d3d11.cpp b/3rdparty/bgfx/src/renderer_d3d11.cpp index 5e6fb036dde..6bab23dd024 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.cpp +++ b/3rdparty/bgfx/src/renderer_d3d11.cpp @@ -1251,6 +1251,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); | ( (m_featureLevel >= D3D_FEATURE_LEVEL_9_2) ? BGFX_CAPS_OCCLUSION_QUERY : 0) | BGFX_CAPS_ALPHA_TO_COVERAGE | ( (m_deviceInterfaceVersion >= 3) ? BGFX_CAPS_CONSERVATIVE_RASTER : 0) + | BGFX_CAPS_TEXTURE_2D_ARRAY + | BGFX_CAPS_TEXTURE_CUBE_ARRAY ); m_timerQuerySupport = m_featureLevel >= D3D_FEATURE_LEVEL_10_0; @@ -1850,14 +1852,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); - tc.m_cubeMap = false; - tc.m_mem = NULL; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = 1; + tc.m_numMips = _numMips; + tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); + tc.m_cubeMap = false; + tc.m_mem = NULL; bx::write(&writer, tc); texture.destroy(); @@ -2030,7 +2032,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); uint32_t size = _size*sizeof(wchar_t); wchar_t* name = (wchar_t*)alloca(size); mbstowcs(name, _marker, size-2); - PIX_SETMARKER(D3DCOLOR_RGBA(0xff, 0xff, 0xff, 0xff), name); + PIX_SETMARKER(D3DCOLOR_MARKER, name); } } @@ -4117,23 +4119,23 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { for (uint32_t ii = 0; ii < count; ++ii) { - uint8_t nameSize; + uint8_t nameSize = 0; bx::read(&reader, nameSize); - char name[256]; + char name[256] = { '\0' }; bx::read(&reader, &name, nameSize); name[nameSize] = '\0'; - uint8_t type; + uint8_t type = 0; bx::read(&reader, type); - uint8_t num; + uint8_t num = 0; bx::read(&reader, num); - uint16_t regIndex; + uint16_t regIndex = 0; bx::read(&reader, regIndex); - uint16_t regCount; + uint16_t regCount = 0; bx::read(&reader, regCount); const char* kind = "invalid"; @@ -4211,7 +4213,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); BGFX_FATAL(NULL != m_ptr, bgfx::Fatal::InvalidShader, "Failed to create compute shader."); } - uint8_t numAttrs; + uint8_t numAttrs = 0; bx::read(&reader, numAttrs); memset(m_attrMask, 0, sizeof(m_attrMask) ); @@ -4257,6 +4259,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod); + const uint16_t numLayers = imageContainer.m_numLayers; m_flags = _flags; m_width = textureWidth; @@ -4282,7 +4285,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_numMips = numMips; - uint32_t numSrd = numMips*(imageContainer.m_cubeMap ? 6 : 1); + const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * numMips; D3D11_SUBRESOURCE_DATA* srd = (D3D11_SUBRESOURCE_DATA*)alloca(numSrd*sizeof(D3D11_SUBRESOURCE_DATA) ); uint32_t kk = 0; @@ -4290,10 +4294,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) ); const bool swizzle = TextureFormat::BGRA8 == m_textureFormat && 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE); - BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s%s." + BX_TRACE("Texture %3d: %s (requested: %s), layers %d, %dx%d%s%s%s." , getHandle() , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) + , numLayers , textureWidth , textureHeight , imageContainer.m_cubeMap ? "x6" : "" @@ -4301,7 +4306,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); , swizzle ? " (swizzle BGRA8 -> RGBA8)" : "" ); - for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) + for (uint16_t side = 0; side < numSides; ++side) { uint32_t width = textureWidth; uint32_t height = textureHeight; @@ -4403,6 +4408,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); desc.Width = textureWidth; desc.Height = textureHeight; desc.MipLevels = numMips; + desc.ArraySize = numSides; desc.Format = format; desc.SampleDesc = msaa; desc.Usage = kk == 0 || blit ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE; @@ -4439,22 +4445,46 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (imageContainer.m_cubeMap) { - desc.ArraySize = 6; desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; - srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - srvd.TextureCube.MipLevels = numMips; + if (1 < numLayers) + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; + srvd.TextureCubeArray.MipLevels = numMips; + srvd.TextureCubeArray.NumCubes = numLayers; + } + else + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + srvd.TextureCube.MipLevels = numMips; + } } else { - desc.ArraySize = 1; if (msaaSample) { - srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; + if (1 < numLayers) + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY; + srvd.Texture2DMSArray.ArraySize = numLayers; + } + else + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; + } } else { - srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvd.Texture2D.MipLevels = numMips; + if (1 < numLayers) + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; + srvd.Texture2DArray.MipLevels = numMips; + srvd.Texture2DArray.ArraySize = numLayers; + } + else + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvd.Texture2D.MipLevels = numMips; + } } } @@ -4510,7 +4540,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); && 0 != kk) { kk = 0; - for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) + for (uint16_t side = 0; side < numSides; ++side) { for (uint32_t lod = 0, num = numMips; lod < num; ++lod) { @@ -4552,10 +4582,22 @@ BX_PRAGMA_DIAGNOSTIC_POP(); box.top = _rect.m_y; box.right = box.left + _rect.m_width; box.bottom = box.top + _rect.m_height; - box.front = _z; - box.back = box.front + _depth; - const uint32_t subres = _mip + (_side * m_numMips); + uint32_t layer = 0; + + if (TextureD3D11::Texture3D == m_type) + { + box.front = _z; + box.back = box.front + _depth; + } + else + { + layer = _z * (TextureD3D11::TextureCube == m_type ? 6 : 1); + box.front = 0; + box.back = 1; + } + + const uint32_t subres = _mip + ( (layer + _side) * m_numMips); const uint32_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) ); const uint32_t rectpitch = _rect.m_width*bpp/8; const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; @@ -5104,7 +5146,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); renderDocTriggerCapture(); } - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit"); + PIX_BEGINEVENT(D3DCOLOR_FRAME, L"rendererSubmit"); BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit"); ID3D11DeviceContext* deviceCtx = m_deviceCtx; @@ -5255,7 +5297,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); wchar_t* viewNameW = s_viewNameW[view]; viewNameW[3] = L' '; viewNameW[4] = eye ? L'R' : L'L'; - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + PIX_BEGINEVENT(0 == ( (view*2+eye)&1) + ? D3DCOLOR_VIEW_L + : D3DCOLOR_VIEW_R + , viewNameW + ); } if (m_ovr.isEnabled() ) @@ -5276,7 +5322,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); wchar_t* viewNameW = s_viewNameW[view]; viewNameW[3] = L' '; viewNameW[4] = L' '; - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + PIX_BEGINEVENT(D3DCOLOR_VIEW, viewNameW); } } @@ -5387,7 +5433,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); wchar_t* viewNameW = s_viewNameW[view]; viewNameW[3] = L'C'; PIX_ENDEVENT(); - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + PIX_BEGINEVENT(D3DCOLOR_COMPUTE, viewNameW); } deviceCtx->IASetVertexBuffers(0, 2, s_zero.m_buffer, s_zero.m_zero, s_zero.m_zero); @@ -5539,7 +5585,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); wchar_t* viewNameW = s_viewNameW[view]; viewNameW[3] = L' '; PIX_ENDEVENT(); - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + PIX_BEGINEVENT(D3DCOLOR_DRAW, viewNameW); } programIdx = invalidHandle; @@ -5988,7 +6034,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); wchar_t* viewNameW = s_viewNameW[view]; viewNameW[3] = L'C'; PIX_ENDEVENT(); - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + PIX_BEGINEVENT(D3DCOLOR_DRAW, viewNameW); } invalidateCompute(); @@ -6058,7 +6104,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) { - PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugstats"); + PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugstats"); TextVideoMem& tvm = m_textVideoMem; @@ -6192,7 +6238,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } else if (_render->m_debug & BGFX_DEBUG_TEXT) { - PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugtext"); + PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugtext"); blit(this, _textVideoMemBlitter, _render->m_textVideoMem); diff --git a/3rdparty/bgfx/src/renderer_d3d12.cpp b/3rdparty/bgfx/src/renderer_d3d12.cpp index 5624dc5dc58..f66e735e38f 100644 --- a/3rdparty/bgfx/src/renderer_d3d12.cpp +++ b/3rdparty/bgfx/src/renderer_d3d12.cpp @@ -1008,6 +1008,8 @@ namespace bgfx { namespace d3d12 | BGFX_CAPS_TEXTURE_READ_BACK | BGFX_CAPS_OCCLUSION_QUERY | BGFX_CAPS_ALPHA_TO_COVERAGE + | BGFX_CAPS_TEXTURE_2D_ARRAY + | BGFX_CAPS_TEXTURE_CUBE_ARRAY ); g_caps.maxTextureSize = 16384; g_caps.maxFBAttachments = uint8_t(bx::uint32_min(16, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); @@ -1476,14 +1478,14 @@ namespace bgfx { namespace d3d12 bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); - tc.m_cubeMap = false; - tc.m_mem = NULL; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = 1; + tc.m_numMips = _numMips; + tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); + tc.m_cubeMap = false; + tc.m_mem = NULL; bx::write(&writer, tc); texture.destroy(); @@ -3844,23 +3846,23 @@ data.NumQualityLevels = 0; { for (uint32_t ii = 0; ii < count; ++ii) { - uint8_t nameSize; + uint8_t nameSize = 0; bx::read(&reader, nameSize); - char name[256]; + char name[256] = {}; bx::read(&reader, &name, nameSize); name[nameSize] = '\0'; - uint8_t type; + uint8_t type = 0; bx::read(&reader, type); - uint8_t num; + uint8_t num = 0; bx::read(&reader, num); - uint16_t regIndex; + uint16_t regIndex = 0; bx::read(&reader, regIndex); - uint16_t regCount; + uint16_t regCount = 0; bx::read(&reader, regCount); const char* kind = "invalid"; @@ -3920,7 +3922,7 @@ data.NumQualityLevels = 0; m_code = copy(code, shaderSize); - uint8_t numAttrs; + uint8_t numAttrs = 0; bx::read(&reader, numAttrs); memset(m_attrMask, 0, sizeof(m_attrMask) ); @@ -3961,6 +3963,7 @@ data.NumQualityLevels = 0; const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod); + const uint16_t numLayers = imageContainer.m_numLayers; m_flags = _flags; m_width = textureWidth; @@ -3985,9 +3988,8 @@ data.NumQualityLevels = 0; } m_numMips = numMips; - const uint16_t numSides = imageContainer.m_cubeMap ? 6 : 1; - - uint32_t numSrd = numMips*numSides; + const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * numMips; D3D12_SUBRESOURCE_DATA* srd = (D3D12_SUBRESOURCE_DATA*)alloca(numSrd*sizeof(D3D12_SUBRESOURCE_DATA) ); uint32_t kk = 0; @@ -4185,15 +4187,63 @@ data.NumQualityLevels = 0; switch (m_type) { case Texture2D: + case TextureCube: resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; - m_srvd.ViewDimension = 1 < msaa.Count ? D3D12_SRV_DIMENSION_TEXTURE2DMS : D3D12_SRV_DIMENSION_TEXTURE2D; - m_srvd.Texture2D.MostDetailedMip = 0; - m_srvd.Texture2D.MipLevels = numMips; - m_srvd.Texture2D.ResourceMinLODClamp = 0.0f; - - m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D; - m_uavd.Texture2D.MipSlice = 0; - m_uavd.Texture2D.PlaneSlice = 0; + if (imageContainer.m_cubeMap) + { + if (1 < numLayers) + { + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY; + m_srvd.TextureCubeArray.MostDetailedMip = 0; + m_srvd.TextureCubeArray.MipLevels = numMips; + m_srvd.TextureCubeArray.ResourceMinLODClamp = 0.0f; + m_srvd.TextureCubeArray.NumCubes = numLayers; + } + else + { + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; + m_srvd.TextureCube.MostDetailedMip = 0; + m_srvd.TextureCube.MipLevels = numMips; + m_srvd.TextureCube.ResourceMinLODClamp = 0.0f; + } + } + else + { + if (1 < numLayers) + { + m_srvd.ViewDimension = 1 < msaa.Count + ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY + : D3D12_SRV_DIMENSION_TEXTURE2DARRAY + ; + m_srvd.Texture2DArray.MostDetailedMip = 0; + m_srvd.Texture2DArray.MipLevels = numMips; + m_srvd.Texture2DArray.ResourceMinLODClamp = 0.0f; + m_srvd.Texture2DArray.ArraySize = numLayers; + } + else + { + m_srvd.ViewDimension = 1 < msaa.Count + ? D3D12_SRV_DIMENSION_TEXTURE2DMS + : D3D12_SRV_DIMENSION_TEXTURE2D + ; + m_srvd.Texture2D.MostDetailedMip = 0; + m_srvd.Texture2D.MipLevels = numMips; + m_srvd.Texture2D.ResourceMinLODClamp = 0.0f; + } + } + + if (1 < numLayers) + { + m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; + m_uavd.Texture2DArray.MipSlice = 0; + m_uavd.Texture2DArray.PlaneSlice = 0; + } + else + { + m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D; + m_uavd.Texture2D.MipSlice = 0; + m_uavd.Texture2D.PlaneSlice = 0; + } break; case Texture3D: @@ -4208,18 +4258,6 @@ data.NumQualityLevels = 0; m_uavd.Texture3D.FirstWSlice = 0; m_uavd.Texture3D.WSize = 0; break; - - case TextureCube: - resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; - m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; - m_srvd.TextureCube.MostDetailedMip = 0; - m_srvd.TextureCube.MipLevels = numMips; - m_srvd.TextureCube.ResourceMinLODClamp = 0.0f; - - m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D; - m_uavd.Texture2D.MipSlice = 0; - m_uavd.Texture2D.PlaneSlice = 0; - break; } m_ptr = createCommittedResource(device, HeapProperty::Default, &resourceDesc, clearValue); @@ -4697,7 +4735,7 @@ data.NumQualityLevels = 0; void RendererContextD3D12::submit(Frame* _render, ClearQuad& /*_clearQuad*/, TextVideoMemBlitter& _textVideoMemBlitter) { -// PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit"); +// PIX_BEGINEVENT(D3DCOLOR_FRAME, L"rendererSubmit"); updateResolution(_render->m_resolution); @@ -5133,7 +5171,7 @@ data.NumQualityLevels = 0; // wchar_t* viewNameW = s_viewNameW[view]; // viewNameW[3] = L' '; // PIX_ENDEVENT(); -// PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); +// PIX_BEGINEVENT(D3DCOLOR_DRAW, viewNameW); } commandListChanged = true; @@ -5433,7 +5471,7 @@ data.NumQualityLevels = 0; if (_render->m_debug & (BGFX_DEBUG_IFH | BGFX_DEBUG_STATS) ) { -// PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugstats"); +// PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugstats"); TextVideoMem& tvm = m_textVideoMem; @@ -5599,7 +5637,7 @@ data.NumQualityLevels = 0; } else if (_render->m_debug & BGFX_DEBUG_TEXT) { -// PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugtext"); +// PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugtext"); blit(this, _textVideoMemBlitter, _render->m_textVideoMem); diff --git a/3rdparty/bgfx/src/renderer_d3d9.cpp b/3rdparty/bgfx/src/renderer_d3d9.cpp index 81e53cecba1..be388785ada 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.cpp +++ b/3rdparty/bgfx/src/renderer_d3d9.cpp @@ -1031,14 +1031,14 @@ namespace bgfx { namespace d3d9 bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); - tc.m_cubeMap = false; - tc.m_mem = NULL; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = 1; + tc.m_numMips = _numMips; + tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); + tc.m_cubeMap = false; + tc.m_mem = NULL; bx::write(&writer, tc); texture.destroy(true); @@ -1191,7 +1191,7 @@ namespace bgfx { namespace d3d9 uint32_t size = _size*sizeof(wchar_t); wchar_t* name = (wchar_t*)alloca(size); mbstowcs(name, _marker, size-2); - PIX_SETMARKER(D3DCOLOR_RGBA(0xff, 0xff, 0xff, 0xff), name); + PIX_SETMARKER(D3DCOLOR_MARKER, name); #endif // BGFX_CONFIG_DEBUG_PIX BX_UNUSED(_marker, _size); } @@ -2393,23 +2393,23 @@ namespace bgfx { namespace d3d9 { for (uint32_t ii = 0; ii < count; ++ii) { - uint8_t nameSize; + uint8_t nameSize = 0; bx::read(&reader, nameSize); - char name[256]; + char name[256] = {}; bx::read(&reader, &name, nameSize); name[nameSize] = '\0'; - uint8_t type; + uint8_t type = 0; bx::read(&reader, type); - uint8_t num; + uint8_t num = 0; bx::read(&reader, num); - uint16_t regIndex; + uint16_t regIndex = 0; bx::read(&reader, regIndex); - uint16_t regCount; + uint16_t regCount = 0; bx::read(&reader, regCount); const char* kind = "invalid"; @@ -3522,7 +3522,7 @@ namespace bgfx { namespace d3d9 { IDirect3DDevice9* device = m_device; - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit"); + PIX_BEGINEVENT(D3DCOLOR_FRAME, L"rendererSubmit"); updateResolution(_render->m_resolution); @@ -3633,7 +3633,7 @@ namespace bgfx { namespace d3d9 currentState.m_stencil = newStencil; PIX_ENDEVENT(); - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), s_viewNameW[key.m_view]); + PIX_BEGINEVENT(D3DCOLOR_VIEW, s_viewNameW[key.m_view]); if (item > 0) { BGFX_PROFILER_END(); @@ -4224,7 +4224,7 @@ namespace bgfx { namespace d3d9 if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) { - PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugstats"); + PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugstats"); TextVideoMem& tvm = m_textVideoMem; @@ -4314,7 +4314,7 @@ namespace bgfx { namespace d3d9 } else if (_render->m_debug & BGFX_DEBUG_TEXT) { - PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugtext"); + PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugtext"); blit(this, _textVideoMemBlitter, _render->m_textVideoMem); diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp index 0fea6a7c9d8..75e3a4ef3a7 100644 --- a/3rdparty/bgfx/src/renderer_gl.cpp +++ b/3rdparty/bgfx/src/renderer_gl.cpp @@ -500,6 +500,7 @@ namespace bgfx { namespace gl ARB_shader_texture_lod, ARB_texture_compression_bptc, ARB_texture_compression_rgtc, + ARB_texture_cube_map_array, ARB_texture_float, ARB_texture_multisample, ARB_texture_rg, @@ -555,6 +556,7 @@ namespace bgfx { namespace gl EXT_texture_compression_latc, EXT_texture_compression_rgtc, EXT_texture_compression_s3tc, + EXT_texture_cube_map_array, EXT_texture_filter_anisotropic, EXT_texture_format_BGRA8888, EXT_texture_rg, @@ -614,6 +616,7 @@ namespace bgfx { namespace gl OES_texture_half_float, OES_texture_half_float_linear, OES_texture_stencil8, + OES_texture_storage_multisample_2d_array, OES_vertex_array_object, OES_vertex_half_float, OES_vertex_type_10_10_10_2, @@ -659,185 +662,188 @@ namespace bgfx { namespace gl // static Extension s_extension[] = { - { "AMD_conservative_depth", false, true }, - { "AMD_multi_draw_indirect", false, true }, - - { "ANGLE_depth_texture", false, true }, - { "ANGLE_framebuffer_blit", false, true }, - { "ANGLE_framebuffer_multisample", false, false }, - { "ANGLE_instanced_arrays", false, true }, - { "ANGLE_texture_compression_dxt1", false, true }, - { "ANGLE_texture_compression_dxt3", false, true }, - { "ANGLE_texture_compression_dxt5", false, true }, - { "ANGLE_timer_query", false, true }, - { "ANGLE_translated_shader_source", false, true }, - - { "APPLE_texture_format_BGRA8888", false, true }, - { "APPLE_texture_max_level", false, true }, - - { "ARB_clip_control", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_compute_shader", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_conservative_depth", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, - { "ARB_copy_image", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, - { "ARB_debug_label", false, true }, - { "ARB_debug_output", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_depth_buffer_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_depth_clamp", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, - { "ARB_draw_buffers_blend", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, - { "ARB_draw_indirect", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, - { "ARB_draw_instanced", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_ES3_compatibility", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_get_program_binary", BGFX_CONFIG_RENDERER_OPENGL >= 41, true }, - { "ARB_half_float_pixel", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_half_float_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_instanced_arrays", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_internalformat_query", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, - { "ARB_internalformat_query2", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_invalidate_subdata", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_map_buffer_range", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_multi_draw_indirect", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_multisample", false, true }, - { "ARB_occlusion_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_occlusion_query2", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_program_interface_query", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_sampler_objects", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_seamless_cube_map", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, - { "ARB_shader_bit_encoding", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_shader_image_load_store", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, - { "ARB_shader_storage_buffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "ARB_shader_texture_lod", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_texture_compression_bptc", BGFX_CONFIG_RENDERER_OPENGL >= 44, true }, - { "ARB_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_texture_float", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_texture_multisample", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, - { "ARB_texture_rg", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_texture_rgb10_a2ui", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_texture_stencil8", false, true }, - { "ARB_texture_storage", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, - { "ARB_texture_swizzle", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_timer_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "ARB_uniform_buffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 31, true }, - { "ARB_vertex_array_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "ARB_vertex_type_2_10_10_10_rev", false, true }, - - { "ATI_meminfo", false, true }, - - { "CHROMIUM_color_buffer_float_rgb", false, true }, - { "CHROMIUM_color_buffer_float_rgba", false, true }, - { "CHROMIUM_depth_texture", false, true }, - { "CHROMIUM_framebuffer_multisample", false, true }, - { "CHROMIUM_texture_compression_dxt3", false, true }, - { "CHROMIUM_texture_compression_dxt5", false, true }, - - { "EXT_bgra", false, true }, - { "EXT_blend_color", BGFX_CONFIG_RENDERER_OPENGL >= 31, true }, - { "EXT_blend_minmax", BGFX_CONFIG_RENDERER_OPENGL >= 14, true }, - { "EXT_blend_subtract", BGFX_CONFIG_RENDERER_OPENGL >= 14, true }, - { "EXT_color_buffer_half_float", false, true }, // GLES2 extension. - { "EXT_color_buffer_float", false, true }, // GLES2 extension. - { "EXT_copy_image", false, true }, // GLES2 extension. - { "EXT_compressed_ETC1_RGB8_sub_texture", false, true }, // GLES2 extension. - { "EXT_debug_label", false, true }, - { "EXT_debug_marker", false, true }, - { "EXT_debug_tool", false, true }, // RenderDoc extension. - { "EXT_discard_framebuffer", false, true }, // GLES2 extension. - { "EXT_disjoint_timer_query", false, true }, // GLES2 extension. - { "EXT_draw_buffers", false, true }, // GLES2 extension. - { "EXT_draw_instanced", false, true }, // GLES2 extension. - { "EXT_instanced_arrays", false, true }, // GLES2 extension. - { "EXT_frag_depth", false, true }, // GLES2 extension. - { "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "EXT_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "EXT_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "EXT_gpu_shader4", false, true }, - { "EXT_multi_draw_indirect", false, true }, // GLES3.1 extension. - { "EXT_occlusion_query_boolean", false, true }, // GLES2 extension. - { "EXT_packed_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "EXT_read_format_bgra", false, true }, - { "EXT_shader_image_load_store", false, true }, - { "EXT_shader_texture_lod", false, true }, // GLES2 extension. - { "EXT_shadow_samplers", false, true }, - { "EXT_sRGB_write_control", false, true }, // GLES2 extension. - { "EXT_texture_array", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "EXT_texture_compression_dxt1", false, true }, - { "EXT_texture_compression_latc", false, true }, - { "EXT_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "EXT_texture_compression_s3tc", false, true }, - { "EXT_texture_filter_anisotropic", false, true }, - { "EXT_texture_format_BGRA8888", false, true }, - { "EXT_texture_rg", false, true }, // GLES2 extension. - { "EXT_texture_shared_exponent", false, true }, - { "EXT_texture_snorm", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "EXT_texture_sRGB", false, true }, - { "EXT_texture_storage", false, true }, - { "EXT_texture_swizzle", false, true }, - { "EXT_texture_type_2_10_10_10_REV", false, true }, - { "EXT_timer_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, - { "EXT_unpack_subimage", false, true }, - - { "GOOGLE_depth_texture", false, true }, - - { "GREMEDY_string_marker", false, true }, - { "GREMEDY_frame_terminator", false, true }, - - { "IMG_multisampled_render_to_texture", false, true }, - { "IMG_read_format", false, true }, - { "IMG_shader_binary", false, true }, - { "IMG_texture_compression_pvrtc", false, true }, - { "IMG_texture_compression_pvrtc2", false, true }, - { "IMG_texture_format_BGRA8888", false, true }, - - { "INTEL_fragment_shader_ordering", false, true }, - - { "KHR_debug", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, - { "KHR_no_error", false, true }, - - { "MOZ_WEBGL_compressed_texture_s3tc", false, true }, - { "MOZ_WEBGL_depth_texture", false, true }, - - { "NV_conservative_raster", false, true }, - { "NV_copy_image", false, true }, - { "NV_draw_buffers", false, true }, // GLES2 extension. - { "NV_occlusion_query", false, true }, - { "NV_texture_border_clamp", false, true }, // GLES2 extension. - { "NVX_gpu_memory_info", false, true }, - - { "OES_copy_image", false, true }, - { "OES_compressed_ETC1_RGB8_texture", false, true }, - { "OES_depth24", false, true }, - { "OES_depth32", false, true }, - { "OES_depth_texture", false, true }, - { "OES_element_index_uint", false, true }, - { "OES_fragment_precision_high", false, true }, - { "OES_get_program_binary", false, true }, - { "OES_required_internalformat", false, true }, - { "OES_packed_depth_stencil", false, true }, - { "OES_read_format", false, true }, - { "OES_rgb8_rgba8", false, true }, - { "OES_standard_derivatives", false, true }, - { "OES_texture_3D", false, true }, - { "OES_texture_float", false, true }, - { "OES_texture_float_linear", false, true }, - { "OES_texture_npot", false, true }, - { "OES_texture_half_float", false, true }, - { "OES_texture_half_float_linear", false, true }, - { "OES_texture_stencil8", false, true }, - { "OES_vertex_array_object", false, !BX_PLATFORM_IOS }, - { "OES_vertex_half_float", false, true }, - { "OES_vertex_type_10_10_10_2", false, true }, - - { "WEBGL_color_buffer_float", false, true }, - { "WEBGL_compressed_texture_etc1", false, true }, - { "WEBGL_compressed_texture_s3tc", false, true }, - { "WEBGL_compressed_texture_pvrtc", false, true }, - { "WEBGL_depth_texture", false, true }, - { "WEBGL_draw_buffers", false, true }, - - { "WEBKIT_EXT_texture_filter_anisotropic", false, true }, - { "WEBKIT_WEBGL_compressed_texture_s3tc", false, true }, - { "WEBKIT_WEBGL_depth_texture", false, true }, + { "AMD_conservative_depth", false, true }, + { "AMD_multi_draw_indirect", false, true }, + + { "ANGLE_depth_texture", false, true }, + { "ANGLE_framebuffer_blit", false, true }, + { "ANGLE_framebuffer_multisample", false, false }, + { "ANGLE_instanced_arrays", false, true }, + { "ANGLE_texture_compression_dxt1", false, true }, + { "ANGLE_texture_compression_dxt3", false, true }, + { "ANGLE_texture_compression_dxt5", false, true }, + { "ANGLE_timer_query", false, true }, + { "ANGLE_translated_shader_source", false, true }, + + { "APPLE_texture_format_BGRA8888", false, true }, + { "APPLE_texture_max_level", false, true }, + + { "ARB_clip_control", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_compute_shader", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_conservative_depth", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, + { "ARB_copy_image", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, + { "ARB_debug_label", false, true }, + { "ARB_debug_output", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_depth_buffer_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_depth_clamp", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, + { "ARB_draw_buffers_blend", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, + { "ARB_draw_indirect", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, + { "ARB_draw_instanced", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_ES3_compatibility", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_get_program_binary", BGFX_CONFIG_RENDERER_OPENGL >= 41, true }, + { "ARB_half_float_pixel", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_half_float_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_instanced_arrays", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_internalformat_query", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, + { "ARB_internalformat_query2", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_invalidate_subdata", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_map_buffer_range", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_multi_draw_indirect", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_multisample", false, true }, + { "ARB_occlusion_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_occlusion_query2", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_program_interface_query", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_sampler_objects", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_seamless_cube_map", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, + { "ARB_shader_bit_encoding", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_shader_image_load_store", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, + { "ARB_shader_storage_buffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_shader_texture_lod", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_texture_compression_bptc", BGFX_CONFIG_RENDERER_OPENGL >= 44, true }, + { "ARB_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_texture_cube_map_array", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, + { "ARB_texture_float", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_texture_multisample", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, + { "ARB_texture_rg", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_texture_rgb10_a2ui", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_texture_stencil8", false, true }, + { "ARB_texture_storage", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, + { "ARB_texture_swizzle", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_timer_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_uniform_buffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 31, true }, + { "ARB_vertex_array_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_vertex_type_2_10_10_10_rev", false, true }, + + { "ATI_meminfo", false, true }, + + { "CHROMIUM_color_buffer_float_rgb", false, true }, + { "CHROMIUM_color_buffer_float_rgba", false, true }, + { "CHROMIUM_depth_texture", false, true }, + { "CHROMIUM_framebuffer_multisample", false, true }, + { "CHROMIUM_texture_compression_dxt3", false, true }, + { "CHROMIUM_texture_compression_dxt5", false, true }, + + { "EXT_bgra", false, true }, + { "EXT_blend_color", BGFX_CONFIG_RENDERER_OPENGL >= 31, true }, + { "EXT_blend_minmax", BGFX_CONFIG_RENDERER_OPENGL >= 14, true }, + { "EXT_blend_subtract", BGFX_CONFIG_RENDERER_OPENGL >= 14, true }, + { "EXT_color_buffer_half_float", false, true }, // GLES2 extension. + { "EXT_color_buffer_float", false, true }, // GLES2 extension. + { "EXT_copy_image", false, true }, // GLES2 extension. + { "EXT_compressed_ETC1_RGB8_sub_texture", false, true }, // GLES2 extension. + { "EXT_debug_label", false, true }, + { "EXT_debug_marker", false, true }, + { "EXT_debug_tool", false, true }, // RenderDoc extension. + { "EXT_discard_framebuffer", false, true }, // GLES2 extension. + { "EXT_disjoint_timer_query", false, true }, // GLES2 extension. + { "EXT_draw_buffers", false, true }, // GLES2 extension. + { "EXT_draw_instanced", false, true }, // GLES2 extension. + { "EXT_instanced_arrays", false, true }, // GLES2 extension. + { "EXT_frag_depth", false, true }, // GLES2 extension. + { "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "EXT_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "EXT_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "EXT_gpu_shader4", false, true }, + { "EXT_multi_draw_indirect", false, true }, // GLES3.1 extension. + { "EXT_occlusion_query_boolean", false, true }, // GLES2 extension. + { "EXT_packed_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "EXT_read_format_bgra", false, true }, + { "EXT_shader_image_load_store", false, true }, + { "EXT_shader_texture_lod", false, true }, // GLES2 extension. + { "EXT_shadow_samplers", false, true }, + { "EXT_sRGB_write_control", false, true }, // GLES2 extension. + { "EXT_texture_array", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "EXT_texture_compression_dxt1", false, true }, + { "EXT_texture_compression_latc", false, true }, + { "EXT_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "EXT_texture_compression_s3tc", false, true }, + { "EXT_texture_cube_map_array", false, true }, // GLES3.1 extension. + { "EXT_texture_filter_anisotropic", false, true }, + { "EXT_texture_format_BGRA8888", false, true }, + { "EXT_texture_rg", false, true }, // GLES2 extension. + { "EXT_texture_shared_exponent", false, true }, + { "EXT_texture_snorm", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "EXT_texture_sRGB", false, true }, + { "EXT_texture_storage", false, true }, + { "EXT_texture_swizzle", false, true }, + { "EXT_texture_type_2_10_10_10_REV", false, true }, + { "EXT_timer_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "EXT_unpack_subimage", false, true }, + + { "GOOGLE_depth_texture", false, true }, + + { "GREMEDY_string_marker", false, true }, + { "GREMEDY_frame_terminator", false, true }, + + { "IMG_multisampled_render_to_texture", false, true }, + { "IMG_read_format", false, true }, + { "IMG_shader_binary", false, true }, + { "IMG_texture_compression_pvrtc", false, true }, + { "IMG_texture_compression_pvrtc2", false, true }, + { "IMG_texture_format_BGRA8888", false, true }, + + { "INTEL_fragment_shader_ordering", false, true }, + + { "KHR_debug", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "KHR_no_error", false, true }, + + { "MOZ_WEBGL_compressed_texture_s3tc", false, true }, + { "MOZ_WEBGL_depth_texture", false, true }, + + { "NV_conservative_raster", false, true }, + { "NV_copy_image", false, true }, + { "NV_draw_buffers", false, true }, // GLES2 extension. + { "NV_occlusion_query", false, true }, + { "NV_texture_border_clamp", false, true }, // GLES2 extension. + { "NVX_gpu_memory_info", false, true }, + + { "OES_copy_image", false, true }, + { "OES_compressed_ETC1_RGB8_texture", false, true }, + { "OES_depth24", false, true }, + { "OES_depth32", false, true }, + { "OES_depth_texture", false, true }, + { "OES_element_index_uint", false, true }, + { "OES_fragment_precision_high", false, true }, + { "OES_get_program_binary", false, true }, + { "OES_required_internalformat", false, true }, + { "OES_packed_depth_stencil", false, true }, + { "OES_read_format", false, true }, + { "OES_rgb8_rgba8", false, true }, + { "OES_standard_derivatives", false, true }, + { "OES_texture_3D", false, true }, + { "OES_texture_float", false, true }, + { "OES_texture_float_linear", false, true }, + { "OES_texture_npot", false, true }, + { "OES_texture_half_float", false, true }, + { "OES_texture_half_float_linear", false, true }, + { "OES_texture_stencil8", false, true }, + { "OES_texture_storage_multisample_2d_array", false, true }, + { "OES_vertex_array_object", false, !BX_PLATFORM_IOS }, + { "OES_vertex_half_float", false, true }, + { "OES_vertex_type_10_10_10_2", false, true }, + + { "WEBGL_color_buffer_float", false, true }, + { "WEBGL_compressed_texture_etc1", false, true }, + { "WEBGL_compressed_texture_s3tc", false, true }, + { "WEBGL_compressed_texture_pvrtc", false, true }, + { "WEBGL_depth_texture", false, true }, + { "WEBGL_draw_buffers", false, true }, + + { "WEBKIT_EXT_texture_filter_anisotropic", false, true }, + { "WEBKIT_WEBGL_compressed_texture_s3tc", false, true }, + { "WEBKIT_WEBGL_depth_texture", false, true }, }; BX_STATIC_ASSERT(Extension::Count == BX_COUNTOF(s_extension) ); @@ -910,6 +916,15 @@ namespace bgfx { namespace gl NULL }; + static const char* s_textureArray[] = + { + "sampler2DArray", + "sampler2DMSArray", + "samplerCubeArray", + "sampler2DArrayShadow", + NULL + }; + static const char* s_ARB_texture_multisample[] = { "sampler2DMS", @@ -1074,6 +1089,7 @@ namespace bgfx { namespace gl case GL_DEBUG_SEVERITY_HIGH: return "High"; case GL_DEBUG_SEVERITY_MEDIUM: return "Medium"; case GL_DEBUG_SEVERITY_LOW: return "Low"; + case GL_DEBUG_SEVERITY_NOTIFICATION: return "SPAM"; default: break; } @@ -1083,14 +1099,17 @@ namespace bgfx { namespace gl void GL_APIENTRY debugProcCb(GLenum _source, GLenum _type, GLuint _id, GLenum _severity, GLsizei /*_length*/, const GLchar* _message, const void* /*_userParam*/) { - BX_TRACE("src %s, type %s, id %d, severity %s, '%s'" - , toString(_source) - , toString(_type) - , _id - , toString(_severity) - , _message - ); - BX_UNUSED(_source, _type, _id, _severity, _message); + if (GL_DEBUG_SEVERITY_NOTIFICATION != _severity) + { + BX_TRACE("src %s, type %s, id %d, severity %s, '%s'" + , toString(_source) + , toString(_type) + , _id + , toString(_severity) + , _message + ); + BX_UNUSED(_source, _type, _id, _severity, _message); + } } GLint glGet(GLenum _pname) @@ -1110,6 +1129,11 @@ namespace bgfx { namespace gl tfi.m_type = _type; } + void flushGlError() + { + for (GLenum err = glGetError(); err != 0; err = glGetError()); + } + GLenum initTestTexture(TextureFormat::Enum _format, bool _srgb, bool _mipmaps) { const TextureFormatInfo& tfi = s_textureFormat[_format]; @@ -1121,6 +1145,7 @@ namespace bgfx { namespace gl GLsizei size = (16*16*getBitsPerPixel(_format) )/8; void* data = bx::alignPtr(alloca(size+16), 0, 16); + flushGlError(); GLenum err = 0; if (isCompressed(_format) ) @@ -1200,8 +1225,12 @@ namespace bgfx { namespace gl GLuint id; GL_CHECK(glGenTextures(1, &id) ); GL_CHECK(glBindTexture(GL_TEXTURE_2D, id) ); + + flushGlError(); + GLenum err = 0; + glTexStorage2D(GL_TEXTURE_2D, 1, s_imageFormat[_format], 16, 16); - GLenum err = glGetError(); + err |= glGetError(); if (0 == err) { glBindImageTexture(0 @@ -1212,7 +1241,7 @@ namespace bgfx { namespace gl , GL_READ_WRITE , s_imageFormat[_format] ); - err = glGetError(); + err |= glGetError(); } GL_CHECK(glDeleteTextures(1, &id) ); @@ -1603,6 +1632,7 @@ namespace bgfx { namespace gl if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) ) { setTextureFormat(TextureFormat::RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT); + setTextureFormat(TextureFormat::RGBA32F, GL_RGBA, GL_RGBA, GL_FLOAT); // internalFormat and format must match: // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml setTextureFormat(TextureFormat::RGBA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); @@ -1859,6 +1889,21 @@ namespace bgfx { namespace gl : 0 ; + g_caps.supported |= false + || s_extension[Extension::EXT_texture_array].m_supported + || s_extension[Extension::EXT_gpu_shader4].m_supported + || !!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) + ? BGFX_CAPS_TEXTURE_2D_ARRAY + : 0 + ; + + g_caps.supported |= false + || s_extension[Extension::ARB_texture_cube_map_array].m_supported + || s_extension[Extension::EXT_texture_cube_map_array].m_supported + ? BGFX_CAPS_TEXTURE_CUBE_ARRAY + : 0 + ; + g_caps.maxTextureSize = uint16_t(glGet(GL_MAX_TEXTURE_SIZE) ); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) @@ -2318,14 +2363,14 @@ namespace bgfx { namespace gl bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); - tc.m_cubeMap = false; - tc.m_mem = NULL; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = 1; + tc.m_numMips = _numMips; + tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); + tc.m_cubeMap = false; + tc.m_mem = NULL; bx::write(&writer, tc); texture.destroy(); @@ -3617,8 +3662,19 @@ namespace bgfx { namespace gl GLSL_TYPE(GL_FLOAT_MAT4); GLSL_TYPE(GL_SAMPLER_2D); + GLSL_TYPE(GL_SAMPLER_2D_ARRAY); + GLSL_TYPE(GL_SAMPLER_2D_MULTISAMPLE); + GLSL_TYPE(GL_INT_SAMPLER_2D); + GLSL_TYPE(GL_INT_SAMPLER_2D_ARRAY); + GLSL_TYPE(GL_INT_SAMPLER_2D_MULTISAMPLE); + GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D); + GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY); + GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE); + + GLSL_TYPE(GL_SAMPLER_2D_SHADOW); + GLSL_TYPE(GL_SAMPLER_2D_ARRAY_SHADOW); GLSL_TYPE(GL_SAMPLER_3D); GLSL_TYPE(GL_INT_SAMPLER_3D); @@ -3628,12 +3684,6 @@ namespace bgfx { namespace gl GLSL_TYPE(GL_INT_SAMPLER_CUBE); GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_CUBE); - GLSL_TYPE(GL_SAMPLER_2D_MULTISAMPLE); - GLSL_TYPE(GL_INT_SAMPLER_2D_MULTISAMPLE); - GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE); - - GLSL_TYPE(GL_SAMPLER_2D_SHADOW); - GLSL_TYPE(GL_IMAGE_1D); GLSL_TYPE(GL_INT_IMAGE_1D); GLSL_TYPE(GL_UNSIGNED_INT_IMAGE_1D); @@ -3709,8 +3759,19 @@ namespace bgfx { namespace gl return UniformType::Mat4; case GL_SAMPLER_2D: + case GL_SAMPLER_2D_ARRAY: + case GL_SAMPLER_2D_MULTISAMPLE: + case GL_INT_SAMPLER_2D: + case GL_INT_SAMPLER_2D_ARRAY: + case GL_INT_SAMPLER_2D_MULTISAMPLE: + case GL_UNSIGNED_INT_SAMPLER_2D: + case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_2D_ARRAY_SHADOW: case GL_SAMPLER_3D: case GL_INT_SAMPLER_3D: @@ -3720,12 +3781,6 @@ namespace bgfx { namespace gl case GL_INT_SAMPLER_CUBE: case GL_UNSIGNED_INT_SAMPLER_CUBE: - case GL_SAMPLER_2D_SHADOW: - - case GL_SAMPLER_2D_MULTISAMPLE: - case GL_INT_SAMPLER_2D_MULTISAMPLE: - case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: - case GL_IMAGE_1D: case GL_INT_IMAGE_1D: case GL_UNSIGNED_INT_IMAGE_1D: @@ -3964,8 +4019,19 @@ namespace bgfx { namespace gl switch (gltype) { case GL_SAMPLER_2D: + case GL_SAMPLER_2D_ARRAY: + case GL_SAMPLER_2D_MULTISAMPLE: + case GL_INT_SAMPLER_2D: + case GL_INT_SAMPLER_2D_ARRAY: + case GL_INT_SAMPLER_2D_MULTISAMPLE: + case GL_UNSIGNED_INT_SAMPLER_2D: + case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_2D_ARRAY_SHADOW: case GL_SAMPLER_3D: case GL_INT_SAMPLER_3D: @@ -3975,8 +4041,6 @@ namespace bgfx { namespace gl case GL_INT_SAMPLER_CUBE: case GL_UNSIGNED_INT_SAMPLER_CUBE: - case GL_SAMPLER_2D_SHADOW: - case GL_IMAGE_1D: case GL_INT_IMAGE_1D: case GL_UNSIGNED_INT_IMAGE_1D: @@ -4207,60 +4271,218 @@ namespace bgfx { namespace gl m_vcref.invalidate(s_renderGL->m_vaoStateCache); } - static void texImage(GLenum _target, uint32_t _msaaQuality, GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLsizei _depth, GLint _border, GLenum _format, GLenum _type, const GLvoid* _data) + static void texSubImage( + GLenum _target + , GLint _level + , GLint _xoffset + , GLint _yoffset + , GLint _zoffset + , GLsizei _width + , GLsizei _height + , GLsizei _depth + , GLenum _format + , GLenum _type + , const GLvoid* _data + ) + { + if (_target == GL_TEXTURE_3D + || _target == GL_TEXTURE_2D_ARRAY + || _target == GL_TEXTURE_CUBE_MAP_ARRAY) + { + GL_CHECK(glTexSubImage3D( + _target + , _level + , _xoffset + , _yoffset + , _zoffset + , _width + , _height + , _depth + , _format + , _type + , _data + ) ); + } + else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) + { + } + else + { + BX_UNUSED(_zoffset, _depth); + GL_CHECK(glTexSubImage2D( + _target + , _level + , _xoffset + , _yoffset + , _width + , _height + , _format + , _type + , _data + ) ); + } + } + + static void texImage( + GLenum _target + , uint32_t _msaaQuality + , GLint _level + , GLint _internalFormat + , GLsizei _width + , GLsizei _height + , GLsizei _depth + , GLint _border + , GLenum _format + , GLenum _type + , const GLvoid* _data + ) { if (_target == GL_TEXTURE_3D) { - GL_CHECK(glTexImage3D(_target, _level, _internalFormat, _width, _height, _depth, _border, _format, _type, _data) ); + GL_CHECK(glTexImage3D( + _target + , _level + , _internalFormat + , _width + , _height + , _depth + , _border + , _format + , _type + , _data + ) ); + } + else if (_target == GL_TEXTURE_2D_ARRAY + || _target == GL_TEXTURE_CUBE_MAP_ARRAY) + { + texSubImage(_target, _level, 0, 0, _depth, _width, _height, 1, _format, _type, _data); + } + else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) + { } else if (_target == GL_TEXTURE_2D_MULTISAMPLE) { - GL_CHECK(glTexImage2DMultisample(_target, _msaaQuality, _internalFormat, _width, _height, false) ); + GL_CHECK(glTexImage2DMultisample( + _target + , _msaaQuality + , _internalFormat + , _width + , _height + , false + ) ); } else { - GL_CHECK(glTexImage2D(_target, _level, _internalFormat, _width, _height, _border, _format, _type, _data) ); + GL_CHECK(glTexImage2D( + _target + , _level + , _internalFormat + , _width + , _height + , _border + , _format + , _type + , _data + ) ); } BX_UNUSED(_msaaQuality, _depth, _border, _data); } - static void texSubImage(GLenum _target, GLint _level, GLint _xoffset, GLint _yoffset, GLint _zoffset, GLsizei _width, GLsizei _height, GLsizei _depth, GLenum _format, GLenum _type, const GLvoid* _data) + static void compressedTexSubImage( + GLenum _target + , GLint _level + , GLint _xoffset + , GLint _yoffset + , GLint _zoffset + , GLsizei _width + , GLsizei _height + , GLsizei _depth + , GLenum _format + , GLsizei _imageSize + , const GLvoid* _data + ) { if (_target == GL_TEXTURE_3D) { - GL_CHECK(glTexSubImage3D(_target, _level, _xoffset, _yoffset, _zoffset, _width, _height, _depth, _format, _type, _data) ); + GL_CHECK(glCompressedTexSubImage3D( + _target + , _level + , _xoffset + , _yoffset + , _zoffset + , _width + , _height + , _depth + , _format + , _imageSize + , _data + ) ); } else { BX_UNUSED(_zoffset, _depth); - GL_CHECK(glTexSubImage2D(_target, _level, _xoffset, _yoffset, _width, _height, _format, _type, _data) ); + GL_CHECK(glCompressedTexSubImage2D( + _target + , _level + , _xoffset + , _yoffset + , _width + , _height + , _format + , _imageSize + , _data + ) ); } } - static void compressedTexImage(GLenum _target, GLint _level, GLenum _internalformat, GLsizei _width, GLsizei _height, GLsizei _depth, GLint _border, GLsizei _imageSize, const GLvoid* _data) + static void compressedTexImage( + GLenum _target + , GLint _level + , GLenum _internalformat + , GLsizei _width + , GLsizei _height + , GLsizei _depth + , GLint _border + , GLsizei _imageSize + , const GLvoid* _data + ) { if (_target == GL_TEXTURE_3D) { - GL_CHECK(glCompressedTexImage3D(_target, _level, _internalformat, _width, _height, _depth, _border, _imageSize, _data) ); + GL_CHECK(glCompressedTexImage3D( + _target + , _level + , _internalformat + , _width + , _height + , _depth + , _border + , _imageSize + , _data + ) ); } - else + else if (_target == GL_TEXTURE_2D_ARRAY + || _target == GL_TEXTURE_CUBE_MAP_ARRAY) { - BX_UNUSED(_depth); - GL_CHECK(glCompressedTexImage2D(_target, _level, _internalformat, _width, _height, _border, _imageSize, _data) ); + compressedTexSubImage(_target, _level, 0, 0, _depth, _width, _height, 1, _internalformat, _imageSize, _data); } - } - - static void compressedTexSubImage(GLenum _target, GLint _level, GLint _xoffset, GLint _yoffset, GLint _zoffset, GLsizei _width, GLsizei _height, GLsizei _depth, GLenum _format, GLsizei _imageSize, const GLvoid* _data) - { - if (_target == GL_TEXTURE_3D) + else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) { - GL_CHECK(glCompressedTexSubImage3D(_target, _level, _xoffset, _yoffset, _zoffset, _width, _height, _depth, _format, _imageSize, _data) ); } else { - BX_UNUSED(_zoffset, _depth); - GL_CHECK(glCompressedTexSubImage2D(_target, _level, _xoffset, _yoffset, _width, _height, _format, _imageSize, _data) ); + BX_UNUSED(_depth); + GL_CHECK(glCompressedTexImage2D( + _target + , _level + , _internalformat + , _width + , _height + , _border + , _imageSize + , _data + ) ); } } @@ -4276,6 +4498,10 @@ namespace bgfx { namespace gl const bool writeOnly = 0 != (m_flags&BGFX_TEXTURE_RT_WRITE_ONLY); const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE ); + const bool textureArray = false + || _target == GL_TEXTURE_2D_ARRAY + || _target == GL_TEXTURE_CUBE_MAP_ARRAY + ; if (!writeOnly) { @@ -4305,6 +4531,17 @@ namespace bgfx { namespace gl m_type = tfiRgba8.m_type; } + if (textureArray) + { + GL_CHECK(glTexStorage3D(_target + , _numMips + , s_textureFormat[m_textureFormat].m_internalFmt + , m_width + , m_height + , _depth + ) ); + } + if (computeWrite) { if (_target == GL_TEXTURE_3D) @@ -4397,6 +4634,7 @@ namespace bgfx { namespace gl uint8_t numMips = imageContainer.m_numMips; const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); numMips -= startLod; + const uint16_t numLayers = imageContainer.m_numLayers; uint32_t textureWidth; uint32_t textureHeight; uint32_t textureDepth; @@ -4404,7 +4642,10 @@ namespace bgfx { namespace gl const ImageBlockInfo& ibi = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); textureWidth = bx::uint32_max(ibi.blockWidth, imageContainer.m_width >>startLod); textureHeight = bx::uint32_max(ibi.blockHeight, imageContainer.m_height>>startLod); - textureDepth = imageContainer.m_depth; + textureDepth = 1 < imageContainer.m_depth + ? imageContainer.m_depth + : imageContainer.m_numLayers + ; } m_requestedFormat = uint8_t(imageContainer.m_format); @@ -4427,6 +4668,17 @@ namespace bgfx { namespace gl target = GL_TEXTURE_3D; } + const bool textureArray = 1 < numLayers; + if (textureArray) + { + switch (target) + { + case GL_TEXTURE_CUBE_MAP: target = GL_TEXTURE_CUBE_MAP_ARRAY; + case GL_TEXTURE_2D_MULTISAMPLE: target = GL_TEXTURE_2D_MULTISAMPLE_ARRAY; + default: target = GL_TEXTURE_2D_ARRAY; + } + } + if (!init(target , textureWidth , textureHeight @@ -4438,7 +4690,10 @@ namespace bgfx { namespace gl return; } - target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target; + target = isCubeMap() + ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + : m_target + ; const GLenum internalFmt = srgb ? s_textureFormat[m_textureFormat].m_internalFmtSrgb @@ -4456,11 +4711,12 @@ namespace bgfx { namespace gl || swizzle ; - BX_TRACE("Texture%-4s %3d: %s (requested: %s), %dx%dx%d%s." + BX_TRACE("Texture%-4s %3d: %s (requested: %s), layers %d, %dx%dx%d%s." , imageContainer.m_cubeMap ? "Cube" : (1 < imageContainer.m_depth ? "3D" : "2D") , this - s_renderGL->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) + , numLayers , textureWidth , textureHeight , imageContainer.m_cubeMap ? 6 : (1 < imageContainer.m_depth ? imageContainer.m_depth : 0) @@ -4481,17 +4737,26 @@ namespace bgfx { namespace gl temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4); } - for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) + const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); + + for (uint16_t side = 0; side < numSides; ++side) { uint32_t width = textureWidth; uint32_t height = textureHeight; uint32_t depth = imageContainer.m_depth; + GLenum imageTarget = imageContainer.m_cubeMap && !textureArray + ? target+side + : target + ; for (uint8_t lod = 0, num = numMips; lod < num; ++lod) { width = bx::uint32_max(1, width); height = bx::uint32_max(1, height); - depth = bx::uint32_max(1, depth); + depth = 1 < imageContainer.m_depth + ? bx::uint32_max(1, depth) + : side + ; ImageMip mip; if (imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) ) @@ -4499,7 +4764,7 @@ namespace bgfx { namespace gl if (compressed && !convert) { - compressedTexImage(target+side + compressedTexImage(imageTarget , lod , internalFmt , width @@ -4526,7 +4791,7 @@ namespace bgfx { namespace gl data = temp; } - texImage(target+side + texImage(imageTarget , msaaQuality , lod , internalFmt @@ -4549,7 +4814,7 @@ namespace bgfx { namespace gl * 4*4*getBitsPerPixel(TextureFormat::Enum(m_textureFormat) )/8 ; - compressedTexImage(target+side + compressedTexImage(imageTarget , lod , internalFmt , width @@ -4562,7 +4827,7 @@ namespace bgfx { namespace gl } else { - texImage(target+side + texImage(imageTarget , msaaQuality , lod , internalFmt @@ -4618,8 +4883,6 @@ namespace bgfx { namespace gl void TextureGL::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) { - BX_UNUSED(_z, _depth); - const uint32_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) ); const uint32_t rectpitch = _rect.m_width*bpp/8; uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; @@ -4627,7 +4890,10 @@ namespace bgfx { namespace gl GL_CHECK(glBindTexture(m_target, m_id) ); GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) ); - GLenum target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target; + GLenum target = isCubeMap() + ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + : m_target + ; const bool swizzle = true && TextureFormat::BGRA8 == m_requestedFormat @@ -5128,11 +5394,12 @@ namespace bgfx { namespace gl && s_extension[Extension::ARB_shader_texture_lod].m_supported && bx::findIdentifierMatch(code, s_ARB_shader_texture_lod) ; - const bool usesGpuShader5 = !!bx::findIdentifierMatch(code, s_ARB_gpu_shader5); - const bool usesIUsamplers = !!bx::findIdentifierMatch(code, s_uisamplers); - const bool usesTexelFetch = !!bx::findIdentifierMatch(code, s_texelFetch); - const bool usesTextureMS = !!bx::findIdentifierMatch(code, s_ARB_texture_multisample); - const bool usesPacking = !!bx::findIdentifierMatch(code, s_ARB_shading_language_packing); + const bool usesGpuShader5 = !!bx::findIdentifierMatch(code, s_ARB_gpu_shader5); + const bool usesIUsamplers = !!bx::findIdentifierMatch(code, s_uisamplers); + const bool usesTexelFetch = !!bx::findIdentifierMatch(code, s_texelFetch); + const bool usesTextureArray = !!bx::findIdentifierMatch(code, s_textureArray); + const bool usesTextureMS = !!bx::findIdentifierMatch(code, s_ARB_texture_multisample); + const bool usesPacking = !!bx::findIdentifierMatch(code, s_ARB_shading_language_packing); uint32_t version = usesIUsamplers || usesTexelFetch ? 130 @@ -5168,6 +5435,11 @@ namespace bgfx { namespace gl writeString(&writer, "#extension GL_ARB_texture_multisample : enable\n"); } + if (usesTextureArray) + { + writeString(&writer, "#extension GL_EXT_texture_array : enable\n"); + } + if (130 <= version) { if (m_type == GL_FRAGMENT_SHADER) @@ -5456,7 +5728,7 @@ namespace bgfx { namespace gl } else { - GLenum target = GL_TEXTURE_CUBE_MAP == texture.m_target + GLenum target = texture.isCubeMap() ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + m_attachment[ii].layer : texture.m_target ; @@ -5517,7 +5789,7 @@ namespace bgfx { namespace gl { ++colorIdx; - GLenum target = GL_TEXTURE_CUBE_MAP == texture.m_target + GLenum target = texture.isCubeMap() ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + m_attachment[ii].layer : texture.m_target ; @@ -5935,6 +6207,7 @@ namespace bgfx { namespace gl if (BGFX_CLEAR_NONE != (clear.m_flags & BGFX_CLEAR_MASK) ) { clearQuad(_clearQuad, viewState.m_rect, clear, resolutionHeight, _render->m_colorPalette); + currentVao = UINT32_MAX; // clearQuad will mess with VAO, invalidate it. } GL_CHECK(glDisable(GL_STENCIL_TEST) ); diff --git a/3rdparty/bgfx/src/renderer_gl.h b/3rdparty/bgfx/src/renderer_gl.h index 189c17b29e5..9227d0e00cf 100644 --- a/3rdparty/bgfx/src/renderer_gl.h +++ b/3rdparty/bgfx/src/renderer_gl.h @@ -624,6 +624,14 @@ typedef uint64_t GLuint64; # define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 #endif // GL_UNSIGNED_INT_SAMPLER_2D +#ifndef GL_INT_SAMPLER_2D_ARRAY +# define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#endif // GL_INT_SAMPLER_2D_ARRAY + +#ifndef GL_UNSIGNED_INT_SAMPLER_2D_ARRAY +# define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#endif // GL_UNSIGNED_INT_SAMPLER_2D_ARRAY + #ifndef GL_INT_SAMPLER_3D # define GL_INT_SAMPLER_3D 0x8DCB #endif // GL_INT_SAMPLER_3D @@ -656,6 +664,14 @@ typedef uint64_t GLuint64; # define GL_SAMPLER_2D_SHADOW 0x8B62 #endif // GL_SAMPLER_2D_SHADOW +#ifndef GL_SAMPLER_2D_ARRAY +# define GL_SAMPLER_2D_ARRAY 0x8DC1 +#endif // GL_SAMPLER_2D_ARRAY + +#ifndef GL_SAMPLER_2D_ARRAY_SHADOW +# define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#endif // GL_SAMPLER_2D_ARRAY_SHADOW + #ifndef GL_TEXTURE_MAX_LEVEL # define GL_TEXTURE_MAX_LEVEL 0x813D #endif // GL_TEXTURE_MAX_LEVEL @@ -863,6 +879,18 @@ typedef uint64_t GLuint64; # define GL_CLAMP_TO_BORDER 0x812D #endif // GL_CLAMP_TO_BORDER +#ifndef GL_TEXTURE_2D_ARRAY +# define GL_TEXTURE_2D_ARRAY 0x8C1A +#endif // GL_TEXTURE_2D_ARRAY + +#ifndef GL_TEXTURE_2D_MULTISAMPLE_ARRAY +# define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#endif // GL_TEXTURE_2D_MULTISAMPLE_ARRAY + +#ifndef GL_TEXTURE_CUBE_MAP_ARRAY +# define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 +#endif // GL_TEXTURE_CUBE_MAP_ARRAY + #ifndef GL_TEXTURE_CUBE_MAP_SEAMLESS # define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F #endif // GL_TEXTURE_CUBE_MAP_SEAMLESS @@ -883,6 +911,10 @@ typedef uint64_t GLuint64; # define GL_MAX_NAME_LENGTH 0x92F6 #endif // GL_MAX_NAME_LENGTH +#ifndef GL_DEBUG_SEVERITY_NOTIFICATION +# define GL_DEBUG_SEVERITY_NOTIFICATION 0x826b +#endif // GL_DEBUG_SEVERITY_NOTIFICATION + #if BX_PLATFORM_NACL # include "glcontext_ppapi.h" #elif BX_PLATFORM_WINDOWS @@ -1236,6 +1268,14 @@ namespace bgfx { namespace gl void commit(uint32_t _stage, uint32_t _flags, const float _palette[][4]); void resolve() const; + bool isCubeMap() const + { + return 0 + || GL_TEXTURE_CUBE_MAP == m_target + || GL_TEXTURE_CUBE_MAP_ARRAY == m_target + ; + } + GLuint m_id; GLuint m_rbo; GLenum m_target; diff --git a/3rdparty/bgfx/src/renderer_mtl.h b/3rdparty/bgfx/src/renderer_mtl.h index 13f1bf6b7af..00981372cd0 100644 --- a/3rdparty/bgfx/src/renderer_mtl.h +++ b/3rdparty/bgfx/src/renderer_mtl.h @@ -87,6 +87,7 @@ namespace bgfx { namespace mtl destinationSlice:_destinationSlice destinationLevel:_destinationLevel destinationOrigin:_destinationOrigin]; } +#if BX_PLATFORM_OSX void synchronizeTexture(id<MTLTexture> _texture, NSUInteger _slice, NSUInteger _level) { [m_obj synchronizeTexture:_texture slice:_slice level:_level]; @@ -96,6 +97,7 @@ namespace bgfx { namespace mtl { [m_obj synchronizeResource:_resource]; } +#endif // BX_PLATFORM_OSX void endEncoding() { diff --git a/3rdparty/bgfx/src/renderer_mtl.mm b/3rdparty/bgfx/src/renderer_mtl.mm index ce2bf3b8b51..d3721c9062d 100644 --- a/3rdparty/bgfx/src/renderer_mtl.mm +++ b/3rdparty/bgfx/src/renderer_mtl.mm @@ -310,9 +310,9 @@ namespace bgfx { namespace mtl { MTLPixelFormatRG32Sint, MTLPixelFormatInvalid }, // RG32I { MTLPixelFormatRG32Uint, MTLPixelFormatInvalid }, // RG32U { MTLPixelFormatRG32Float, MTLPixelFormatInvalid }, // RG32F - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8I - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8U + { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8I + { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8U { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8S { MTLPixelFormatRGB9E5Float, MTLPixelFormatInvalid }, // RGB9E5F { MTLPixelFormatBGRA8Unorm, MTLPixelFormatBGRA8Unorm_sRGB }, // BGRA8 @@ -474,26 +474,27 @@ namespace bgfx { namespace mtl m_screenshotBlitRenderPipelineState = m_device.newRenderPipelineStateWithDescriptor(m_renderPipelineDescriptor); g_caps.supported |= (0 - | BGFX_CAPS_TEXTURE_COMPARE_LEQUAL //NOTE: on IOS Gpu Family 1/2 have to set compare in shader - | BGFX_CAPS_TEXTURE_COMPARE_ALL - | BGFX_CAPS_TEXTURE_3D - | BGFX_CAPS_VERTEX_ATTRIB_HALF - | BGFX_CAPS_VERTEX_ATTRIB_UINT10 - | BGFX_CAPS_INSTANCING - | BGFX_CAPS_FRAGMENT_DEPTH - | BGFX_CAPS_BLEND_INDEPENDENT - //| BGFX_CAPS_COMPUTE // TODO: api/hw supports it but metal compute shaders are not yet supported - | BGFX_CAPS_INDEX32 - //| BGFX_CAPS_DRAW_INDIRECT // TODO: support on iOS9+gpu family3+ and on macOS - | BGFX_CAPS_TEXTURE_BLIT - | BGFX_CAPS_TEXTURE_READ_BACK - | BGFX_CAPS_OCCLUSION_QUERY - | BGFX_CAPS_ALPHA_TO_COVERAGE - ); + | BGFX_CAPS_TEXTURE_COMPARE_LEQUAL //NOTE: on IOS Gpu Family 1/2 have to set compare in shader + | BGFX_CAPS_TEXTURE_COMPARE_ALL + | BGFX_CAPS_TEXTURE_3D + | BGFX_CAPS_VERTEX_ATTRIB_HALF + | BGFX_CAPS_VERTEX_ATTRIB_UINT10 + | BGFX_CAPS_INSTANCING + | BGFX_CAPS_FRAGMENT_DEPTH + | BGFX_CAPS_BLEND_INDEPENDENT +// | BGFX_CAPS_COMPUTE // TODO: api/hw supports it but metal compute shaders are not yet supported + | BGFX_CAPS_INDEX32 +// | BGFX_CAPS_DRAW_INDIRECT // TODO: support on iOS9+gpu family3+ and on macOS + | BGFX_CAPS_TEXTURE_BLIT + | BGFX_CAPS_TEXTURE_READ_BACK + | BGFX_CAPS_OCCLUSION_QUERY + | BGFX_CAPS_ALPHA_TO_COVERAGE + | BGFX_CAPS_TEXTURE_2D_ARRAY // supported on all platforms + ); if (BX_ENABLED(BX_PLATFORM_IOS) ) { - if ( iOSVersionEqualOrGreater("9.0.0") ) + if (iOSVersionEqualOrGreater("9.0.0") ) { g_caps.maxTextureSize = m_device.supportsFeatureSet((MTLFeatureSet)4 /* iOS_GPUFamily3_v1 */) ? 16384 : 8192; } @@ -501,20 +502,30 @@ namespace bgfx { namespace mtl { g_caps.maxTextureSize = 4096; } - g_caps.maxFBAttachments = uint8_t(bx::uint32_min(m_device.supportsFeatureSet((MTLFeatureSet)1 /* MTLFeatureSet_iOS_GPUFamily2_v1 */) ? 8 : 4, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS)); - } else if (BX_ENABLED(BX_PLATFORM_OSX) ) + g_caps.maxFBAttachments = uint8_t(bx::uint32_min(m_device.supportsFeatureSet((MTLFeatureSet)1 /* MTLFeatureSet_iOS_GPUFamily2_v1 */) ? 8 : 4, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS)); + } + else if (BX_ENABLED(BX_PLATFORM_OSX) ) { - g_caps.maxTextureSize = 16384; + g_caps.maxTextureSize = 16384; g_caps.maxFBAttachments = 8; + g_caps.supported |= BGFX_CAPS_TEXTURE_CUBE_ARRAY; } //todo: vendor id, device id, gpu enum - m_hasPixelFormatDepth32Float_Stencil8 = (BX_ENABLED(BX_PLATFORM_OSX) || - ( BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ) ); - m_macOS11Runtime = (BX_ENABLED(BX_PLATFORM_OSX) && macOSVersionEqualOrGreater(10,11,0) ); - m_iOS9Runtime = (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ); + m_hasPixelFormatDepth32Float_Stencil8 = false + || BX_ENABLED(BX_PLATFORM_OSX) + || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ) + ; + m_macOS11Runtime = true + && BX_ENABLED(BX_PLATFORM_OSX) + && macOSVersionEqualOrGreater(10,11,0) + ; + m_iOS9Runtime = true + && BX_ENABLED(BX_PLATFORM_IOS) + && iOSVersionEqualOrGreater("9.0.0") + ; if (BX_ENABLED(BX_PLATFORM_OSX) ) { @@ -809,14 +820,14 @@ namespace bgfx { namespace mtl bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); - tc.m_cubeMap = false; - tc.m_mem = NULL; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = 1; + tc.m_numMips = _numMips; + tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); + tc.m_cubeMap = false; + tc.m_mem = NULL; bx::write(&writer, tc); texture.destroy(); @@ -2384,8 +2395,9 @@ namespace bgfx { namespace mtl const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod); + const uint16_t numLayers = imageContainer.m_numLayers; - m_flags = _flags; + m_flags = _flags; m_width = textureWidth; m_height = textureHeight; m_depth = imageContainer.m_depth; @@ -2396,7 +2408,20 @@ namespace bgfx { namespace mtl TextureDescriptor desc = s_renderMtl->m_textureDescriptor; - if (imageContainer.m_cubeMap) + if (1 < numLayers) + { + if (imageContainer.m_cubeMap) + { + desc.textureType = MTLTextureTypeCubeArray; + } + else + { + desc.textureType = MTLTextureType2DArray; + } + + desc.arrayLength = numLayers; + } + else if (imageContainer.m_cubeMap) { desc.textureType = MTLTextureTypeCube; } @@ -2410,23 +2435,28 @@ namespace bgfx { namespace mtl } m_numMips = numMips; + const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); - const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) ); + const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) ); + const bool writeOnly = 0 != (_flags&BGFX_TEXTURE_RT_WRITE_ONLY); + const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); + const bool renderTarget = 0 != (_flags&BGFX_TEXTURE_RT_MASK); + const bool srgb = 0 != (_flags&BGFX_TEXTURE_SRGB) || imageContainer.m_srgb; - BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s." + BX_TRACE("Texture %3d: %s (requested: %s), layers %d, %dx%d%s RT[%c], WO[%c], CW[%c], sRGB[%c]" , this - s_renderMtl->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) + , numLayers , textureWidth , textureHeight , imageContainer.m_cubeMap ? "x6" : "" - , 0 != (_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" + , renderTarget ? 'x' : '.' + , writeOnly ? 'x' : '.' + , computeWrite ? 'x' : '.' + , srgb ? 'x' : '.' ); - const bool writeOnly = 0 != (_flags&BGFX_TEXTURE_RT_WRITE_ONLY); - const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); - const bool renderTarget = 0 != (_flags&BGFX_TEXTURE_RT_MASK); - const bool srgb = 0 != (_flags&BGFX_TEXTURE_SRGB) || imageContainer.m_srgb; const uint32_t msaaQuality = bx::uint32_satsub( (_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); int sampleCount = s_msaa[msaaQuality]; @@ -2455,7 +2485,7 @@ namespace bgfx { namespace mtl if (s_renderMtl->m_iOS9Runtime || s_renderMtl->m_macOS11Runtime) { - desc.cpuCacheMode = MTLCPUCacheModeDefaultCache; + desc.cpuCacheMode = MTLCPUCacheModeDefaultCache; desc.storageMode = (MTLStorageMode)(writeOnly||isDepth(TextureFormat::Enum(m_textureFormat)) ? 2 /*MTLStorageModePrivate*/ @@ -2493,7 +2523,7 @@ namespace bgfx { namespace mtl temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4); } - for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) + for (uint8_t side = 0; side < numSides; ++side) { uint32_t width = textureWidth; uint32_t height = textureHeight; @@ -3023,23 +3053,29 @@ namespace bgfx { namespace mtl uint32_t width = bx::uint32_min(srcWidth, dstWidth); uint32_t height = bx::uint32_min(srcHeight, dstHeight); uint32_t depth = bx::uint32_min(srcDepth, dstDepth); +#if BX_PLATFORM_OSX bool readBack = !!(dst.m_flags & BGFX_TEXTURE_READ_BACK); +#endif // BX_PLATFORM_OSX if ( MTLTextureType3D == src.m_ptr.textureType()) { m_blitCommandEncoder.copyFromTexture(src.m_ptr, 0, 0, MTLOriginMake(blit.m_srcX, blit.m_srcY, blit.m_srcZ), MTLSizeMake(width, height, bx::uint32_imax(depth, 1)), dst.m_ptr, 0, 0, MTLOriginMake(blit.m_dstX, blit.m_dstY, blit.m_dstZ)); +#if BX_PLATFORM_OSX if (m_macOS11Runtime &&readBack) { m_blitCommandEncoder.synchronizeResource(dst.m_ptr); } +#endif // BX_PLATFORM_OSX } else { m_blitCommandEncoder.copyFromTexture(src.m_ptr, blit.m_srcZ, blit.m_srcMip, MTLOriginMake(blit.m_srcX, blit.m_srcY, 0), MTLSizeMake(width, height, 1), dst.m_ptr, blit.m_dstZ, blit.m_dstMip, MTLOriginMake(blit.m_dstX, blit.m_dstY, 0)); +#if BX_PLATFORM_OSX if (m_macOS11Runtime && readBack) { m_blitCommandEncoder.synchronizeTexture(dst.m_ptr, 0, blit.m_dstMip); } +#endif // BX_PLATFORM_OSX } } diff --git a/3rdparty/bgfx/src/shader_dxbc.cpp b/3rdparty/bgfx/src/shader_dxbc.cpp index 1cc948d316e..0ad82cc61a7 100644 --- a/3rdparty/bgfx/src/shader_dxbc.cpp +++ b/3rdparty/bgfx/src/shader_dxbc.cpp @@ -1000,7 +1000,7 @@ namespace bgfx break; } - for (uint32_t ii = 0; ii < _operand.numAddrModes; ++ii) + for (uint32_t ii = 0, num = bx::uint32_min(_operand.numAddrModes, BX_COUNTOF(_operand.addrMode) ); ii < num; ++ii) { switch (_operand.addrMode[ii]) { @@ -1526,7 +1526,7 @@ namespace bgfx ); } - for (uint32_t jj = first; jj < operand.numAddrModes; ++jj) + for (uint32_t jj = first, num = bx::uint32_min(operand.numAddrModes, BX_COUNTOF(operand.addrMode) ); jj < num; ++jj) { switch (operand.addrMode[jj]) { |