diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 775d26bed..5ceadd5a6 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -307,10 +307,10 @@ public: , false , 1 , bgfx::TextureFormat::BGRA8 - , ((msaa + 1) << BGFX_TEXTURE_RT_MSAA_SHIFT) | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP + , (uint64_t(msaa + 1) << BGFX_TEXTURE_RT_MSAA_SHIFT) | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP ); - const uint32_t textureFlags = BGFX_TEXTURE_RT_WRITE_ONLY|( (msaa+1)<createFrameBuffer(handle, nwh, width, height, depthFormat); + m_renderCtx->createFrameBuffer(handle, nwh, width, height, format, depthFormat); } else { @@ -3603,7 +3606,7 @@ error: s_ctx->destroyProgram(_handle); } - static void isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, bx::Error* _err) + static void isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, bx::Error* _err) { BX_ERROR_SCOPE(_err); @@ -3712,7 +3715,7 @@ error: } } - bool isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags) + bool isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags) { bx::Error err; isTextureValid(_depth, _cubeMap, _numLayers, _format, _flags, &err); @@ -3724,7 +3727,7 @@ error: bimg::imageGetSize( (bimg::TextureInfo*)&_info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bimg::TextureFormat::Enum(_format) ); } - TextureHandle createTexture(const Memory* _mem, uint32_t _flags, uint8_t _skip, TextureInfo* _info) + TextureHandle createTexture(const Memory* _mem, uint64_t _flags, uint8_t _skip, TextureInfo* _info) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); return s_ctx->createTexture(_mem, _flags, _skip, _info, BackbufferRatio::Count, false); @@ -3748,7 +3751,7 @@ error: _height = bx::max(1, _height); } - 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) + static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { bx::Error err; isTextureValid(0, false, _numLayers, _format, _flags, &err); @@ -3801,19 +3804,19 @@ error: return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio, NULL != _mem); } - TextureHandle createTexture2D(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, 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, uint64_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, _hasMips, _numLayers, _format, _flags, _mem); } - TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags) + TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags) { BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); return createTexture2D(_ratio, 0, 0, _hasMips, _numLayers, _format, _flags, NULL); } - TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, 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, uint64_t _flags, const Memory* _mem) { bx::Error err; isTextureValid(_depth, false, 1, _format, _flags, &err); @@ -3854,7 +3857,7 @@ error: return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count, NULL != _mem); } - TextureHandle createTextureCube(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) + TextureHandle createTextureCube(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { bx::Error err; isTextureValid(0, true, _numLayers, _format, _flags, &err); @@ -3964,14 +3967,14 @@ error: return s_ctx->readTexture(_handle, _data, _mip); } - FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags) + FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint64_t _textureFlags) { _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; TextureHandle th = createTexture2D(_width, _height, false, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); } - FrameBufferHandle createFrameBuffer(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint32_t _textureFlags) + FrameBufferHandle createFrameBuffer(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint64_t _textureFlags) { BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; @@ -4004,7 +4007,7 @@ error: return s_ctx->createFrameBuffer(_num, _attachment, _destroyTextures); } - FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat) + FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { BGFX_CHECK_CAPS(BGFX_CAPS_SWAP_CHAIN, "Swap chain is not supported!"); BX_WARN(_width > 0 && _height > 0 @@ -4012,10 +4015,19 @@ error: , _width , _height ); + BX_CHECK(_format == TextureFormat::Count || bimg::isColor(bimg::TextureFormat::Enum(_format) ) + , "Invalid texture format for color (%s)." + , bimg::getName(bimg::TextureFormat::Enum(_format) ) + ); + BX_CHECK(_format == TextureFormat::Count || bimg::isDepth(bimg::TextureFormat::Enum(_depthFormat) ) + , "Invalid texture format for depth (%s)." + , bimg::getName(bimg::TextureFormat::Enum(_depthFormat) ) + ); return s_ctx->createFrameBuffer( _nwh , bx::max(_width, 1) , bx::max(_height, 1) + , _format , _depthFormat ); } @@ -5103,7 +5115,7 @@ BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle) bgfx::destroy(handle.cpp); } -BGFX_C_API bool bgfx_is_texture_valid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags) +BGFX_C_API bool bgfx_is_texture_valid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags) { return bgfx::isTextureValid(_depth, _cubeMap, _numLayers, bgfx::TextureFormat::Enum(_format), _flags); } @@ -5114,7 +5126,7 @@ BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _wid 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) +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint64_t _flags, uint8_t _skip, bgfx_texture_info_t* _info) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; bgfx::TextureInfo* info = (bgfx::TextureInfo*)_info; @@ -5122,28 +5134,28 @@ 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, bool _hasMips, uint16_t _numLayers, 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, uint64_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; 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, bool _hasMips, uint16_t _numLayers, 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, uint64_t _flags) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; 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, bool _hasMips, 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, uint64_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; 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, bool _hasMips, uint16_t _numLayers, 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, uint64_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; handle.cpp = bgfx::createTextureCube(_size, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); @@ -5192,14 +5204,14 @@ BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle) bgfx::destroy(handle.cpp); } -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags) +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint64_t _textureFlags) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; handle.cpp = bgfx::createFrameBuffer(_width, _height, bgfx::TextureFormat::Enum(_format), _textureFlags); return handle.c; } -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags) +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint64_t _textureFlags) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; handle.cpp = bgfx::createFrameBuffer(bgfx::BackbufferRatio::Enum(_ratio), bgfx::TextureFormat::Enum(_format), _textureFlags); @@ -5220,10 +5232,10 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_attachment(u return handle.c; } -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat) +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, bgfx_texture_format_t _depthFormat) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; - handle.cpp = bgfx::createFrameBuffer(_nwh, _width, _height, bgfx::TextureFormat::Enum(_depthFormat) ); + handle.cpp = bgfx::createFrameBuffer(_nwh, _width, _height, bgfx::TextureFormat::Enum(_format), bgfx::TextureFormat::Enum(_depthFormat) ); return handle.c; } diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 493fdea7a..b796e8455 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2643,7 +2643,7 @@ namespace bgfx virtual void destroyShader(ShaderHandle _handle) = 0; virtual void createProgram(ProgramHandle _handle, ShaderHandle _vsh, ShaderHandle _fsh) = 0; virtual void destroyProgram(ProgramHandle _handle) = 0; - virtual void* createTexture(TextureHandle _handle, const Memory* _mem, uint32_t _flags, uint8_t _skip) = 0; + virtual void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) = 0; virtual void updateTextureBegin(TextureHandle _handle, uint8_t _side, uint8_t _mip) = 0; virtual void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) = 0; virtual void updateTextureEnd() = 0; @@ -2653,7 +2653,7 @@ namespace bgfx virtual uintptr_t getInternal(TextureHandle _handle) = 0; virtual void destroyTexture(TextureHandle _handle) = 0; virtual void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const Attachment* _attachment) = 0; - virtual void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) = 0; + virtual void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) = 0; virtual void destroyFrameBuffer(FrameBufferHandle _handle) = 0; virtual void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) = 0; virtual void destroyUniform(UniformHandle _handle) = 0; @@ -3854,7 +3854,7 @@ namespace bgfx } } - BGFX_API_FUNC(TextureHandle createTexture(const Memory* _mem, uint32_t _flags, uint8_t _skip, TextureInfo* _info, BackbufferRatio::Enum _ratio, bool _immutable) ) + BGFX_API_FUNC(TextureHandle createTexture(const Memory* _mem, uint64_t _flags, uint8_t _skip, TextureInfo* _info, BackbufferRatio::Enum _ratio, bool _immutable) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); @@ -4161,7 +4161,7 @@ namespace bgfx return handle; } - BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat) ) + BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); @@ -4176,6 +4176,7 @@ namespace bgfx cmdbuf.write(_nwh); cmdbuf.write(_width); cmdbuf.write(_height); + cmdbuf.write(_format); cmdbuf.write(_depthFormat); FrameBufferRef& ref = m_frameBufferRef[handle.idx]; diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index c1067b6c7..2072bd155 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1683,7 +1683,7 @@ namespace bgfx { namespace d3d11 m_program[_handle.idx].destroy(); } - void* createTexture(TextureHandle _handle, const Memory* _mem, uint32_t _flags, uint8_t _skip) override + void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) override { return m_textures[_handle.idx].create(_mem, _flags, _skip); } @@ -1783,11 +1783,11 @@ namespace bgfx { namespace d3d11 m_frameBuffers[_handle.idx].create(_num, _attachment); } - void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) override + void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override { uint16_t denseIdx = m_numWindows++; m_windows[denseIdx] = _handle; - m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); + m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat); } void destroyFrameBuffer(FrameBufferHandle _handle) override @@ -2938,7 +2938,7 @@ namespace bgfx { namespace d3d11 return uav; } - ID3D11ShaderResourceView* getCachedSrv(TextureHandle _handle, uint8_t _mip, bool _compute = false) + ID3D11ShaderResourceView* getCachedSrv(TextureHandle _handle, uint8_t _mip, bool _compute = false, bool _stencil = false) { bx::HashMurmur2A murmur; murmur.begin(); @@ -2946,6 +2946,7 @@ namespace bgfx { namespace d3d11 murmur.add(_mip); murmur.add(0); murmur.add(_compute); + murmur.add(_stencil); uint32_t hash = murmur.end(); IUnknown** ptr = m_srvUavLru.find(hash); @@ -2958,7 +2959,7 @@ namespace bgfx { namespace d3d11 const bool msaaSample = 1 < msaa.Count && 0 != (texture.m_flags&BGFX_TEXTURE_MSAA_SAMPLE); D3D11_SHADER_RESOURCE_VIEW_DESC desc; - desc.Format = texture.getSrvFormat(); + desc.Format = _stencil ? DXGI_FORMAT_X24_TYPELESS_G8_UINT : texture.getSrvFormat(); switch (texture.m_type) { case TextureD3D11::Texture2D: @@ -3990,7 +3991,7 @@ namespace bgfx { namespace d3d11 } } - void* TextureD3D11::create(const Memory* _mem, uint32_t _flags, uint8_t _skip) + void* TextureD3D11::create(const Memory* _mem, uint64_t _flags, uint8_t _skip) { void* directAccessPtr = NULL; @@ -4406,10 +4407,24 @@ namespace bgfx { namespace d3d11 void TextureD3D11::commit(uint8_t _stage, uint32_t _flags, const float _palette[][4]) { TextureStage& ts = s_renderD3D11->m_textureStage; - ts.m_srv[_stage] = m_srv; - uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) + + if (0 != (_flags & BGFX_SAMPLER_SAMPLE_STENCIL) ) + { + ts.m_srv[_stage] = s_renderD3D11->getCachedSrv( + TextureHandle{ uint16_t(this - s_renderD3D11->m_textures) } + , 0 + , false + , true + ); + } + else + { + ts.m_srv[_stage] = m_srv; + } + + const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ? _flags - : m_flags + : uint32_t(m_flags) ; uint32_t index = (flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT; ts.m_sampler[_stage] = s_renderD3D11->getSamplerState(flags @@ -4471,10 +4486,11 @@ namespace bgfx { namespace d3d11 postReset(); } - void FrameBufferD3D11::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) + void FrameBufferD3D11::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { SwapChainDesc scd; bx::memCopy(&scd, &s_renderD3D11->m_scd, sizeof(SwapChainDesc) ); + scd.format = TextureFormat::Count == _format ? scd.format : s_textureFormat[_format].m_fmt; scd.width = _width; scd.height = _height; scd.nwh = _nwh; @@ -5394,7 +5410,7 @@ namespace bgfx { namespace d3d11 else { srv[ii] = s_renderD3D11->getCachedSrv(texture.getHandle(), bind.m_un.m_compute.m_mip, true); - sampler[ii] = s_renderD3D11->getSamplerState(texture.m_flags, NULL); + sampler[ii] = s_renderD3D11->getSamplerState(uint32_t(texture.m_flags), NULL); } } break; diff --git a/src/renderer_d3d11.h b/src/renderer_d3d11.h index 95543fd2c..6740e62bb 100644 --- a/src/renderer_d3d11.h +++ b/src/renderer_d3d11.h @@ -264,7 +264,7 @@ namespace bgfx { namespace d3d11 { } - void* create(const Memory* _mem, uint32_t _flags, uint8_t _skip); + void* create(const Memory* _mem, uint64_t _flags, uint8_t _skip); void destroy(); void overrideInternal(uintptr_t _ptr); void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem); @@ -290,7 +290,7 @@ namespace bgfx { namespace d3d11 ID3D11ShaderResourceView* m_srv; ID3D11UnorderedAccessView* m_uav; - uint32_t m_flags; + uint64_t m_flags; uint32_t m_width; uint32_t m_height; uint32_t m_depth; @@ -315,7 +315,7 @@ namespace bgfx { namespace d3d11 } void create(uint8_t _num, const Attachment* _attachment); - void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat); + void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat); uint16_t destroy(); void preReset(bool _force = false); void postReset(); diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 467a46c90..e36fe4c95 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1523,7 +1523,7 @@ namespace bgfx { namespace d3d12 m_program[_handle.idx].destroy(); } - void* createTexture(TextureHandle _handle, const Memory* _mem, uint32_t _flags, uint8_t _skip) override + void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) override { return m_textures[_handle.idx].create(_mem, _flags, _skip); } @@ -1654,7 +1654,7 @@ namespace bgfx { namespace d3d12 m_frameBuffers[_handle.idx].create(_num, _attachment); } - void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) override + void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override { finishAll(true); @@ -1668,7 +1668,7 @@ namespace bgfx { namespace d3d12 uint16_t denseIdx = m_numWindows++; m_windows[denseIdx] = _handle; - m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); + m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat); } void destroyFrameBuffer(FrameBufferHandle _handle) override @@ -4435,7 +4435,7 @@ namespace bgfx { namespace d3d12 bx::read(&reader, m_size); } - void* TextureD3D12::create(const Memory* _mem, uint32_t _flags, uint8_t _skip) + void* TextureD3D12::create(const Memory* _mem, uint64_t _flags, uint8_t _skip) { bimg::ImageContainer imageContainer; @@ -4892,13 +4892,14 @@ namespace bgfx { namespace d3d12 postReset(); } - void FrameBufferD3D12::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) + void FrameBufferD3D12::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { BX_UNUSED(_nwh, _width, _height, _depthFormat); #if BX_PLATFORM_WINDOWS SwapChainDesc scd; bx::memCopy(&scd, &s_renderD3D12->m_scd, sizeof(DXGI_SWAP_CHAIN_DESC) ); + scd.format = TextureFormat::Count == _format ? scd.format : s_textureFormat[_format].m_fmt; scd.width = _width; scd.height = _height; scd.nwh = _nwh; @@ -5791,7 +5792,7 @@ namespace bgfx { namespace d3d12 { texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); scratchBuffer.allocSrv(srvHandle[ii], texture, bind.m_un.m_compute.m_mip); - samplerFlags[ii] = texture.m_flags; + samplerFlags[ii] = uint32_t(texture.m_flags); } } break; diff --git a/src/renderer_d3d12.h b/src/renderer_d3d12.h index a27aaa128..b7b28cbc1 100644 --- a/src/renderer_d3d12.h +++ b/src/renderer_d3d12.h @@ -311,7 +311,7 @@ namespace bgfx { namespace d3d12 bx::memSet(&m_uavd, 0, sizeof(m_uavd) ); } - void* create(const Memory* _mem, uint32_t _flags, uint8_t _skip); + void* create(const Memory* _mem, uint64_t _flags, uint8_t _skip); void destroy(); void update(ID3D12GraphicsCommandList* _commandList, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem); void resolve(); @@ -322,7 +322,7 @@ namespace bgfx { namespace d3d12 ID3D12Resource* m_ptr; void* m_directAccessPtr; D3D12_RESOURCE_STATES m_state; - uint32_t m_flags; + uint64_t m_flags; uint32_t m_width; uint32_t m_height; uint32_t m_depth; @@ -350,7 +350,7 @@ namespace bgfx { namespace d3d12 } void create(uint8_t _num, const Attachment* _attachment); - void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat); + void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat); uint16_t destroy(); HRESULT present(uint32_t _syncInterval, uint32_t _flags); void preReset(); diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 23743e505..97ecee55f 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -1035,7 +1035,7 @@ namespace bgfx { namespace d3d9 m_program[_handle.idx].destroy(); } - void* createTexture(TextureHandle _handle, const Memory* _mem, uint32_t _flags, uint8_t _skip) override + void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) override { m_textures[_handle.idx].create(_mem, _flags, _skip); return NULL; @@ -1145,11 +1145,11 @@ namespace bgfx { namespace d3d9 m_frameBuffers[_handle.idx].create(_num, _attachment); } - void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) override + void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override { uint16_t denseIdx = m_numWindows++; m_windows[denseIdx] = _handle; - m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); + m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat); } void destroyFrameBuffer(FrameBufferHandle _handle) override @@ -2894,7 +2894,7 @@ namespace bgfx { namespace d3d9 return surface; } - void TextureD3D9::create(const Memory* _mem, uint32_t _flags, uint8_t _skip) + void TextureD3D9::create(const Memory* _mem, uint64_t _flags, uint8_t _skip) { bimg::ImageContainer imageContainer; @@ -3107,9 +3107,9 @@ namespace bgfx { namespace d3d9 void TextureD3D9::commit(uint8_t _stage, uint32_t _flags, const float _palette[][4]) { - uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) + const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ? _flags - : m_flags + : uint32_t(m_flags) ; uint32_t index = (flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT; s_renderD3D9->setSamplerState(_stage, flags, _palette[index]); @@ -3235,7 +3235,7 @@ namespace bgfx { namespace d3d9 } } - void FrameBufferD3D9::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) + void FrameBufferD3D9::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { BX_UNUSED(_depthFormat); @@ -3246,6 +3246,7 @@ namespace bgfx { namespace d3d9 D3DPRESENT_PARAMETERS params; bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); + params.BackBufferFormat = TextureFormat::Count == _format ? params.BackBufferFormat : s_textureFormat[_format].m_fmt; params.BackBufferWidth = m_width; params.BackBufferHeight = m_height; diff --git a/src/renderer_d3d9.h b/src/renderer_d3d9.h index 3f4a6f248..29108e86a 100644 --- a/src/renderer_d3d9.h +++ b/src/renderer_d3d9.h @@ -314,7 +314,7 @@ namespace bgfx { namespace d3d9 void dirty(uint8_t _side, const Rect& _rect, uint16_t _z, uint16_t _depth); IDirect3DSurface9* getSurface(uint8_t _side = 0, uint8_t _mip = 0) const; - void create(const Memory* _mem, uint32_t _flags, uint8_t _skip); + void create(const Memory* _mem, uint64_t _flags, uint8_t _skip); void destroy(bool _resize = false) { @@ -371,7 +371,7 @@ namespace bgfx { namespace d3d9 IDirect3DCubeTexture9* m_stagingCube; }; - uint32_t m_flags; + uint64_t m_flags; uint32_t m_width; uint32_t m_height; uint32_t m_depth; @@ -395,7 +395,7 @@ namespace bgfx { namespace d3d9 } void create(uint8_t _num, const Attachment* _attachment); - void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat); + void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat); uint16_t destroy(); HRESULT present(); void resolve() const; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index f0e4dc704..8219b4ef5 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2723,7 +2723,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_program[_handle.idx].destroy(); } - void* createTexture(TextureHandle _handle, const Memory* _mem, uint32_t _flags, uint8_t _skip) override + void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) override { m_textures[_handle.idx].create(_mem, _flags, _skip); return NULL; @@ -2865,11 +2865,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_frameBuffers[_handle.idx].create(_num, _attachment); } - void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) override + void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override { uint16_t denseIdx = m_numWindows++; m_windows[denseIdx] = _handle; - m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); + m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat); } void destroyFrameBuffer(FrameBufferHandle _handle) override @@ -4535,7 +4535,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glDeleteBuffers(1, &m_id) ); } - bool TextureGL::init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint32_t _flags) + bool TextureGL::init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint64_t _flags) { m_target = _target; m_numMips = _numMips; @@ -4621,7 +4621,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } - setSamplerState(_flags, NULL); + setSamplerState(uint32_t(_flags), NULL); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) && TextureFormat::BGRA8 == m_requestedFormat @@ -4681,7 +4681,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); return true; } - void TextureGL::create(const Memory* _mem, uint32_t _flags, uint8_t _skip) + void TextureGL::create(const Memory* _mem, uint64_t _flags, uint8_t _skip) { bimg::ImageContainer imageContainer; @@ -5150,7 +5150,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ? _flags - : m_flags + : uint32_t(m_flags) ; const uint32_t index = (flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT; @@ -5988,9 +5988,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } - void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) + void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { - BX_UNUSED(_depthFormat); + BX_UNUSED(_format, _depthFormat); m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh); m_width = _width; m_height = _height; @@ -6514,7 +6514,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (Access::Read == bind.m_un.m_compute.m_access) { TextureGL& texture = m_textures[bind.m_idx]; - texture.commit(ii, texture.m_flags, _render->m_colorPalette); + texture.commit(ii, uint32_t(texture.m_flags), _render->m_colorPalette); } else { diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 7839eedb3..0c7849e72 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -1238,8 +1238,8 @@ namespace bgfx { namespace gl { } - bool init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint32_t _flags); - void create(const Memory* _mem, uint32_t _flags, uint8_t _skip); + bool init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint64_t _flags); + void create(const Memory* _mem, uint64_t _flags, uint8_t _skip); void destroy(); void overrideInternal(uintptr_t _ptr); void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem); @@ -1260,7 +1260,7 @@ namespace bgfx { namespace gl GLenum m_target; GLenum m_fmt; GLenum m_type; - uint32_t m_flags; + uint64_t m_flags; uint32_t m_currentSamplerHash; uint32_t m_width; uint32_t m_height; @@ -1299,7 +1299,7 @@ namespace bgfx { namespace gl } void create(uint8_t _num, const Attachment* _attachment); - void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat); + void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat); void postReset(); uint16_t destroy(); void resolve(); diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h index 4b23d983d..8825904db 100644 --- a/src/renderer_mtl.h +++ b/src/renderer_mtl.h @@ -849,7 +849,7 @@ namespace bgfx { namespace mtl { } - void create(const Memory* _mem, uint32_t _flags, uint8_t _skip); + void create(const Memory* _mem, uint64_t _flags, uint8_t _skip); void destroy() { @@ -878,7 +878,7 @@ namespace bgfx { namespace mtl Texture m_ptrMSAA; Texture m_ptrStencil; // for emulating packed depth/stencil formats - only for iOS8... SamplerState m_sampler; - uint32_t m_flags; + uint64_t m_flags; uint32_t m_width; uint32_t m_height; uint32_t m_depth; @@ -904,6 +904,7 @@ namespace bgfx { namespace mtl , void* _nwh , uint32_t _width , uint32_t _height + , TextureFormat::Enum _format , TextureFormat::Enum _depthFormat ); void postReset(); diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index b62fcceb9..cf1013502 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -831,7 +831,7 @@ namespace bgfx { namespace mtl m_program[_handle.idx].destroy(); } - void* createTexture(TextureHandle _handle, const Memory* _mem, uint32_t _flags, uint8_t _skip) override + void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) override { m_textures[_handle.idx].create(_mem, _flags, _skip); return NULL; @@ -921,11 +921,11 @@ namespace bgfx { namespace mtl m_frameBuffers[_handle.idx].create(_num, _attachment); } - void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) override + void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override { uint16_t denseIdx = m_numWindows++; m_windows[denseIdx] = _handle; - m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat); + m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat); } void destroyFrameBuffer(FrameBufferHandle _handle) override @@ -2551,9 +2551,9 @@ namespace bgfx { namespace mtl BufferMtl::create(_size, _data, _flags, stride, true); } - void TextureMtl::create(const Memory* _mem, uint32_t _flags, uint8_t _skip) + void TextureMtl::create(const Memory* _mem, uint64_t _flags, uint8_t _skip) { - m_sampler = s_renderMtl->getSamplerState(_flags); + m_sampler = s_renderMtl->getSamplerState(uint32_t(_flags) ); bimg::ImageContainer imageContainer; @@ -2950,9 +2950,9 @@ namespace bgfx { namespace mtl m_pixelFormatHash = murmur.end(); } - void FrameBufferMtl::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) + void FrameBufferMtl::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { - BX_UNUSED(_denseIdx, _nwh, _width, _height, _depthFormat); + BX_UNUSED(_denseIdx, _nwh, _width, _height, _format, _depthFormat); } void FrameBufferMtl::postReset() diff --git a/src/renderer_noop.cpp b/src/renderer_noop.cpp index 50208e32d..f5a9b088f 100644 --- a/src/renderer_noop.cpp +++ b/src/renderer_noop.cpp @@ -155,7 +155,7 @@ namespace bgfx { namespace noop { } - void* createTexture(TextureHandle /*_handle*/, const Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/) override + void* createTexture(TextureHandle /*_handle*/, const Memory* /*_mem*/, uint64_t /*_flags*/, uint8_t /*_skip*/) override { return NULL; } @@ -197,7 +197,7 @@ namespace bgfx { namespace noop { } - void createFrameBuffer(FrameBufferHandle /*_handle*/, void* /*_nwh*/, uint32_t /*_width*/, uint32_t /*_height*/, TextureFormat::Enum /*_depthFormat*/) override + void createFrameBuffer(FrameBufferHandle /*_handle*/, void* /*_nwh*/, uint32_t /*_width*/, uint32_t /*_height*/, TextureFormat::Enum /*_format*/, TextureFormat::Enum /*_depthFormat*/) override { } diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index b59db04a3..2973448e9 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -2060,7 +2060,7 @@ VK_IMPORT_DEVICE m_program[_handle.idx].destroy(); } - void* createTexture(TextureHandle /*_handle*/, const Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/) override + void* createTexture(TextureHandle /*_handle*/, const Memory* /*_mem*/, uint64_t /*_flags*/, uint8_t /*_skip*/) override { return NULL; } @@ -2102,7 +2102,7 @@ VK_IMPORT_DEVICE { } - void createFrameBuffer(FrameBufferHandle /*_handle*/, void* /*_nwh*/, uint32_t /*_width*/, uint32_t /*_height*/, TextureFormat::Enum /*_depthFormat*/) override + void createFrameBuffer(FrameBufferHandle /*_handle*/, void* /*_nwh*/, uint32_t /*_width*/, uint32_t /*_height*/, TextureFormat::Enum /*_format*/, TextureFormat::Enum /*_depthFormat*/) override { }