diff --git a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.cpp b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.cpp index d4bbd4bfe..f74ff5316 100644 --- a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.cpp +++ b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.cpp @@ -14,7 +14,7 @@ namespace ashes::d3d11 { } - Buffer::~Buffer() + Buffer::~Buffer()noexcept { safeRelease( m_unorderedAccessView ); } @@ -47,7 +47,7 @@ namespace ashes::d3d11 , D3D11_BOX const & srcBox , UINT dstOffset )const { - VkDeviceSize size = srcBox.right - srcBox.left; + VkDeviceSize size = VkDeviceSize( srcBox.right ) - srcBox.left; get( m_memory )->updateData( get( src )->m_memory , VkDeviceSize( srcBox.left ) , VkDeviceSize( dstOffset ) diff --git a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.hpp b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.hpp index a1d7e3268..d40b907a1 100644 --- a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.hpp +++ b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11Buffer.hpp @@ -13,11 +13,12 @@ namespace ashes::d3d11 { class Buffer + : public NonCopyable { public: Buffer( VkDevice device , VkBufferCreateInfo createInfo ); - ~Buffer(); + ~Buffer()noexcept; VkResult bindMemory( VkDeviceMemory memory , VkDeviceSize memoryOffset ); @@ -28,54 +29,54 @@ namespace ashes::d3d11 , D3D11_BOX const & srcBox , UINT dstOffset )const; - inline void setDebugName( std::string name ) + void setDebugName( std::string name ) { m_debugName = std::move( name ); } - inline VkDeviceMemory getMemory()const + VkDeviceMemory getMemory()const { assert( m_memory != nullptr ); return m_memory; } - inline VkDeviceSize getMemoryOffset()const + VkDeviceSize getMemoryOffset()const { return m_memoryOffset; } - inline ObjectMemory const & getObjectMemory()const + ObjectMemory const & getObjectMemory()const { assert( m_objectMemory != nullptr ); return *m_objectMemory; } - inline ID3D11UnorderedAccessView * getUnorderedAccessView()const + ID3D11UnorderedAccessView * getUnorderedAccessView()const { return m_unorderedAccessView; } - inline ID3D11Resource * getResource()const + ID3D11Resource * getResource()const { return getObjectMemory().resource; } - inline ID3D11Buffer * getBuffer()const + ID3D11Buffer * getBuffer()const { return &static_cast< ID3D11Buffer & >( *getResource() ); } - inline VkBufferUsageFlags getUsage()const + VkBufferUsageFlags getUsage()const { return m_createInfo.usage; } - inline VkDeviceSize getSize()const + VkDeviceSize getSize()const { return m_createInfo.size; } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.cpp b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.cpp index a0d64d2d8..142f3d451 100644 --- a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.cpp +++ b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.cpp @@ -29,7 +29,7 @@ namespace ashes::d3d11 } } - BufferView::~BufferView() + BufferView::~BufferView()noexcept { safeRelease( m_view ); } diff --git a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.hpp b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.hpp index 3a79ae011..99bfbb76b 100644 --- a/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.hpp +++ b/source/ashes/renderer/D3D11Renderer/Buffer/D3D11BufferView.hpp @@ -13,18 +13,19 @@ namespace ashes::d3d11 { class BufferView + : public NonCopyable { public: BufferView( VkDevice device , VkBufferViewCreateInfo createInfo ); - ~BufferView(); + ~BufferView()noexcept; - inline ID3D11ShaderResourceView * getView()const + ID3D11ShaderResourceView * getView()const { return m_view; } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.cpp index 4f1cdb073..449d4ab7a 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.cpp @@ -12,8 +12,7 @@ namespace ashes::d3d11 { BeginQueryCommand::BeginQueryCommand( VkDevice device , VkQueryPool pool - , uint32_t query - , VkQueryControlFlags flags ) + , uint32_t query ) : CommandBase{ device } , m_query{ *( get( pool )->begin() + query ) } { diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.hpp index dc4c9d04d..02c1f49a2 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginQueryCommand.hpp @@ -18,8 +18,7 @@ namespace ashes::d3d11 public: BeginQueryCommand( VkDevice device , VkQueryPool pool - , uint32_t query - , VkQueryControlFlags flags ); + , uint32_t query ); void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.cpp index 2bc686303..d1d06bf54 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.cpp @@ -24,7 +24,7 @@ namespace ashes::d3d11 { auto rp = get( renderPass ); assert( clearValues.size() == rp->size() ); - for ( auto & attach : *rp ) + for ( auto const & attach : *rp ) { auto & clearValue = clearValues[attach.attachment]; @@ -45,7 +45,7 @@ namespace ashes::d3d11 auto & views = get( m_frameBuffer )->getAllViews(); uint32_t clearIndex = 0u; - for ( auto & reference : *get( m_renderPass ) ) + for ( auto const & reference : *get( m_renderPass ) ) { auto & attachDesc = get( m_renderPass )->getAttachment( reference ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.hpp index c86d890a8..9791e3e03 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginRenderPassCommand.hpp @@ -21,10 +21,10 @@ namespace ashes::d3d11 CommandPtr clone()const override; private: - VkRenderPass m_renderPass; - VkFramebuffer m_frameBuffer; - VkClearValueArray m_rtClearValues; - VkClearValue m_dsClearValue; - RECT m_scissor; + VkRenderPass m_renderPass{}; + VkFramebuffer m_frameBuffer{}; + VkClearValueArray m_rtClearValues{}; + VkClearValue m_dsClearValue{}; + RECT m_scissor{}; }; } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginSubpassCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginSubpassCommand.cpp index 9c1759144..bea73959c 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginSubpassCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BeginSubpassCommand.cpp @@ -26,9 +26,9 @@ namespace ashes::d3d11 auto attaches = makeArrayView( m_subpass.pColorAttachments , m_subpass.colorAttachmentCount ); - for ( auto & attach : attaches ) + for ( auto const & attach : attaches ) { - m_attaches.push_back( static_cast< ID3D11RenderTargetView * >( allViews[attach.attachment]->view ) ); + m_attaches.emplace_back( static_cast< ID3D11RenderTargetView * >( allViews[attach.attachment]->view ) ); } if ( m_subpass.pDepthStencilAttachment ) diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindDescriptorSetCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindDescriptorSetCommand.cpp index 204c1a432..2d1c71271 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindDescriptorSetCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindDescriptorSetCommand.cpp @@ -87,7 +87,7 @@ namespace ashes::d3d11 context->CSSetUnorderedAccessViews( bindingIndex, 1u, &view, nullptr ); } // Storage buffer/image - static void gather( UINT bindingIndex, ID3D11UnorderedAccessView * view, std::map< UINT, ID3D11UnorderedAccessView * > * uavs ) + static void gather( UINT, ID3D11UnorderedAccessView const *, std::map< UINT, ID3D11UnorderedAccessView * > const * ) { } }; @@ -277,7 +277,7 @@ namespace ashes::d3d11 context->CSSetShaderResources( bindingIndex, 1u, &image ); } // Uniform Buffer - static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT range ) + static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT ) { checkOffset( offset ); context->CSSetConstantBuffers( bindingIndex, 1u, &buffer ); @@ -288,7 +288,7 @@ namespace ashes::d3d11 context->CSSetUnorderedAccessViews( bindingIndex, 1u, &view, nullptr ); } // Storage buffer/image - static void gather( UINT bindingIndex, ID3D11UnorderedAccessView * view, std::map< UINT, ID3D11UnorderedAccessView * > * uavs ) + static void gather( UINT, ID3D11UnorderedAccessView const *, std::map< UINT, ID3D11UnorderedAccessView * > const * ) { } }; @@ -313,7 +313,7 @@ namespace ashes::d3d11 context->VSSetShaderResources( bindingIndex, 1u, &image ); } // Uniform Buffer - static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT range ) + static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT ) { checkOffset( offset ); context->VSSetConstantBuffers( bindingIndex, 1u, &buffer ); @@ -345,7 +345,7 @@ namespace ashes::d3d11 context->GSSetShaderResources( bindingIndex, 1u, &image ); } // Uniform Buffer - static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT range ) + static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT ) { checkOffset( offset ); context->GSSetConstantBuffers( bindingIndex, 1u, &buffer ); @@ -377,7 +377,7 @@ namespace ashes::d3d11 context->HSSetShaderResources( bindingIndex, 1u, &image ); } // Uniform Buffer - static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT range ) + static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT ) { checkOffset( offset ); context->HSSetConstantBuffers( bindingIndex, 1u, &buffer ); @@ -409,7 +409,7 @@ namespace ashes::d3d11 context->DSSetShaderResources( bindingIndex, 1u, &image ); } // Uniform Buffer - static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT range ) + static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT ) { checkOffset( offset ); context->DSSetConstantBuffers( bindingIndex, 1u, &buffer ); @@ -441,7 +441,7 @@ namespace ashes::d3d11 context->PSSetShaderResources( bindingIndex, 1u, &image ); } // Uniform Buffer - static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT range ) + static void bind( ID3D11DeviceContext * context, UINT bindingIndex, ID3D11Buffer * buffer, UINT offset, UINT ) { checkOffset( offset ); context->PSSetConstantBuffers( bindingIndex, 1u, &buffer ); @@ -613,7 +613,7 @@ namespace ashes::d3d11 , flags , buffer , UINT( write.pBufferInfo[i].offset ) / 16 - , UINT( ashes::getAlignedSize( range, 256ull ) / 16ull ) ); + , UINT( ashes::getAlignedSize( range, 256ULL ) / 16ULL ) ); } } } @@ -668,7 +668,7 @@ namespace ashes::d3d11 , flags , buffer , UINT( ( offset + write.pBufferInfo[i].offset ) / 16 ) - , UINT( ashes::getAlignedSize( range, 256ull ) / 16ull ) ); + , UINT( ashes::getAlignedSize( range, 256ULL ) / 16ULL ) ); } } } @@ -753,7 +753,7 @@ namespace ashes::d3d11 , LayoutBindingWrites const & writeBinding , ShaderBindingMap const & bindings , uint32_t setIndex - , uint32_t offset ) + , uint32_t /*offset*/ ) { for ( auto & write : writeBinding.writes ) { @@ -892,7 +892,7 @@ namespace ashes::d3d11 , ShaderBindingMap const & bindings , uint32_t setIndex , std::map< UINT, ID3D11UnorderedAccessView * > & uavs - , uint32_t offset ) + , uint32_t /*offset*/ ) { for ( auto & write : writeBinding.writes ) { @@ -921,7 +921,7 @@ namespace ashes::d3d11 { for ( auto i = 0u; i < offsets.size(); ++i ) { - auto & writeBinding = *writes[i]; + auto const & writeBinding = *writes[i]; switch ( writeBinding.binding.descriptorType ) { @@ -1062,7 +1062,7 @@ namespace ashes::d3d11 , flags , ( ID3D11Buffer * )nullptr , UINT( write.pBufferInfo[i].offset / 16 ) - , UINT( ashes::getAlignedSize( range, 256ull ) / 16ull ) ); + , UINT( ashes::getAlignedSize( range, 256ULL ) / 16ULL ) ); } } } @@ -1115,7 +1115,7 @@ namespace ashes::d3d11 , flags , ( ID3D11Buffer * )nullptr , UINT( ( offset + write.pBufferInfo[i].offset ) / 16 ) - , UINT( ashes::getAlignedSize( range, 256ull ) / 16ull ) ); + , UINT( ashes::getAlignedSize( range, 256ULL ) / 16ULL ) ); } } } @@ -1197,7 +1197,7 @@ namespace ashes::d3d11 , LayoutBindingWrites const & writeBinding , ShaderBindingMap const & bindings , uint32_t setIndex - , uint32_t offset ) + , uint32_t /*offset*/ ) { for ( auto & write : writeBinding.writes ) { @@ -1423,23 +1423,22 @@ namespace ashes::d3d11 bindAll< false >( context, m_layout, m_descriptorSet, m_dynamicOffsets ); } - auto newUavs = context.uavs; + std::map< UINT, ID3D11UnorderedAccessView * > newUavs = context.uavs; - for ( auto it : m_uavs ) + for ( auto const & [id, uav] : m_uavs ) { - newUavs[it.first] = it.second; + newUavs[id] = uav; } - bool dirtyUavs = context.uavs != newUavs; - - if ( dirtyUavs ) + if ( bool dirtyUavs = context.uavs != newUavs; + dirtyUavs ) { context.uavs = std::move( newUavs ); context.rawUavs.clear(); - for ( auto & uav : context.uavs ) + for ( auto const & [id, uav] : context.uavs ) { - context.rawUavs.push_back( uav.second ); + context.rawUavs.push_back( uav ); } if ( !context.rawUavs.empty() ) diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindPipelineCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindPipelineCommand.cpp index 7fa6fd299..ba1b705fc 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindPipelineCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindPipelineCommand.cpp @@ -139,7 +139,7 @@ namespace ashes::d3d11 } // Bind program - for ( auto & stage : get( m_pipeline )->getShaderStages() ) + for ( auto const & stage : get( m_pipeline )->getShaderStages() ) { switch ( stage.getStage() ) { @@ -332,7 +332,7 @@ namespace ashes::d3d11 SetDepthBoundsCommand::SetDepthBoundsCommand( VkDevice device , DepthBounds const & depthBounds ) : CommandBase{ device } - , m_physicalDevice{ get( m_device )->getPhysicalDevice() } + , m_physicalDevice{ get( getDevice() )->getPhysicalDevice() } , m_depthBounds{ depthBounds } { } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindVertexBuffersCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindVertexBuffersCommand.cpp index a9e381088..5e4068813 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindVertexBuffersCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BindVertexBuffersCommand.cpp @@ -16,9 +16,9 @@ namespace ashes::d3d11 { std::vector< ID3D11Buffer * > result; - for ( auto & vbo : vbos ) + for ( auto const & vbo : vbos ) { - result.push_back( get( vbo )->getBuffer() ); + result.emplace_back( get( vbo )->getBuffer() ); } return result; @@ -28,9 +28,9 @@ namespace ashes::d3d11 { std::vector< UINT > result; - for ( auto & v : array ) + for ( auto const & v : array ) { - result.push_back( UINT( v ) ); + result.emplace_back( UINT( v ) ); } return result; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.cpp index 2d52db669..5307864d7 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.cpp @@ -266,7 +266,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) VkPipeline doCreateBlitPipeline( Device const & device , VkPipelineLayout pipelineLayout - , VkShaderModule module ) + , VkShaderModule shaderModule ) { VkPipeline result; allocate( result @@ -283,7 +283,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) nullptr, 0u, VK_SHADER_STAGE_COMPUTE_BIT, - module, + shaderModule, "main", nullptr, }, @@ -475,9 +475,9 @@ void main( uint3 threadID : SV_DispatchThreadID ) , VkImageUsageFlags requiredUsage ) { VkImage result = image; - auto createInfo = get( image )->getCreateInfo(); - if ( !checkFlag( createInfo.usage, requiredUsage ) ) + if ( auto createInfo = get( image )->getCreateInfo(); + !checkFlag( createInfo.usage, requiredUsage ) ) { createInfo.usage = requiredUsage; allocate( result @@ -619,7 +619,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) { } - BlitPipeline::~BlitPipeline() + BlitPipeline::~BlitPipeline()noexcept { deallocate( pipeline, get( device )->getAllocationCallbacks() ); deallocate( shader, get( device )->getAllocationCallbacks() ); @@ -630,10 +630,9 @@ void main( uint3 threadID : SV_DispatchThreadID ) //********************************************************************************************* BlitImageCommand::Attachment::Attachment( VkDevice device - , VkImageSubresourceLayers & subresource + , VkImageSubresourceLayers const & subresource , VkImage image - , uint32_t layer - , bool dest ) + , uint32_t layer ) : device{ device } , image{ get( image )->getResource() } , subResourceIndex{ D3D11CalcSubresource( subresource.mipLevel @@ -656,7 +655,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) } ); } - BlitImageCommand::Attachment::~Attachment() + BlitImageCommand::Attachment::~Attachment()noexcept { deallocate( view, get( device )->getAllocationCallbacks() ); } @@ -670,7 +669,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) , VkDeviceSize offset , VkDeviceSize range , VkSampler sampler - , VkImageBlit blitRegion + , VkImageBlit const & blitRegion , VkImage srcImage , VkImage dstImage , uint32_t layer ) @@ -693,8 +692,8 @@ void main( uint3 threadID : SV_DispatchThreadID ) UINT( blitRegion.dstOffsets[0].y + blitRegion.dstOffsets[1].y ), UINT( blitRegion.dstOffsets[0].z + blitRegion.dstOffsets[1].z ) } - , src{ device, blitRegion.srcSubresource, srcImage, layer, false } - , dst{ device, blitRegion.dstSubresource, dstImage, layer, true } + , src{ device, blitRegion.srcSubresource, srcImage, layer } + , dst{ device, blitRegion.dstSubresource, dstImage, layer } , set{ doCreateDescriptorSet( device , pool , descriptorLayout @@ -770,11 +769,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) doCreateCommandBuffer( pool , pipeline.pipeline - , pipeline.pipelineLayout - , srcMinLevel - , srcMaxLevel - , dstMinLevel - , dstMaxLevel ); + , pipeline.pipelineLayout ); get( cb )->executeCommands( makeArrayView( const_cast< VkCommandBuffer const * >( &m_commandBuffer ), 1u ) ); } @@ -782,7 +777,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) , uint32_t count ) { VkDeviceSize range = 0u; - m_ubo = doCreateUbo( m_device, count, m_uboMemory, range ); + m_ubo = doCreateUbo( getDevice(), count, m_uboMemory, range ); ashes::VkDescriptorPoolSizeArray poolSizes { @@ -793,8 +788,8 @@ void main( uint3 threadID : SV_DispatchThreadID ) }; allocate( m_pool - , get( m_device )->getAllocationCallbacks() - , m_device + , get( getDevice() )->getAllocationCallbacks() + , getDevice() , VkDescriptorPoolCreateInfo { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, @@ -814,7 +809,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) { for ( uint32_t layer = 0u; layer < get( m_tmpSrcTexture )->getLayerCount(); ++layer ) { - m_layerStretches.emplace_back( std::make_shared< BlitImageCommand::LayerCopy >( m_device + m_layerStretches.emplace_back( std::make_shared< BlitImageCommand::LayerCopy >( getDevice() , m_pool , descriptorLayout , m_ubo @@ -849,8 +844,8 @@ void main( uint3 threadID : SV_DispatchThreadID ) { if ( count ) { - m_tmpSrcTexture = doGetSamplable( m_device, m_srcTexture, m_srcMemory ); - m_tmpDstTexture = doGetStorable( m_device, m_dstTexture, m_dstMemory ); + m_tmpSrcTexture = doGetSamplable( getDevice(), m_srcTexture, m_srcMemory ); + m_tmpDstTexture = doGetStorable( getDevice(), m_dstTexture, m_dstMemory ); doInitialiseStretchUbo( descriptorLayout, count ); } } @@ -865,9 +860,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) { // Copy source to staging get( m_commandBuffer )->copyImage( m_srcTexture - , VK_IMAGE_LAYOUT_UNDEFINED // don't care , m_tmpSrcTexture - , VK_IMAGE_LAYOUT_UNDEFINED // don't care , makeArrayView( const_cast< VkImageCopy const * >( m_layerBlitsToTmp.data() ) , m_layerBlitsToTmp.size() ) ); srcTexture = m_tmpSrcTexture; @@ -884,9 +877,7 @@ void main( uint3 threadID : SV_DispatchThreadID ) { // Copy staging to destination get( m_commandBuffer )->copyImage( m_tmpDstTexture - , VK_IMAGE_LAYOUT_UNDEFINED // don't care , m_dstTexture - , VK_IMAGE_LAYOUT_UNDEFINED // don't care , makeArrayView( const_cast< VkImageCopy const * >( m_layerBlitsFromTmp.data() ) , m_layerBlitsFromTmp.size() ) ); } @@ -897,29 +888,23 @@ void main( uint3 threadID : SV_DispatchThreadID ) if ( !m_layerBlits.empty() ) { get( m_commandBuffer )->copyImage( srcTexture - , VK_IMAGE_LAYOUT_UNDEFINED , m_dstTexture - , VK_IMAGE_LAYOUT_UNDEFINED , makeArrayView( const_cast< VkImageCopy const * >( m_layerBlits.data() ) , m_layerBlits.size() ) ); } } void BlitImageCommand::doAddStretches( VkPipeline pipeline - , VkPipelineLayout pipelineLayout - , uint32_t srcMinLevel - , uint32_t srcMaxLevel - , uint32_t dstMinLevel - , uint32_t dstMaxLevel ) + , VkPipelineLayout pipelineLayout ) { if ( !m_layerStretches.empty() ) { get( m_commandBuffer )->bindPipeline( pipeline, VK_PIPELINE_BIND_POINT_COMPUTE ); - for ( auto & copy : m_layerStretches ) + for ( auto const & copy : m_layerStretches ) { uint32_t srcWidth = copy->srcBox.right - copy->srcBox.left; - uint32_t srcHeight = uint32_t( std::abs( int( copy->srcBox.bottom ) - int( copy->srcBox.top ) ) ); + auto srcHeight = uint32_t( std::abs( int( copy->srcBox.bottom ) - int( copy->srcBox.top ) ) ); get( m_commandBuffer )->bindDescriptorSets( VK_PIPELINE_BIND_POINT_COMPUTE , pipelineLayout , 0u @@ -932,14 +917,10 @@ void main( uint3 threadID : SV_DispatchThreadID ) void BlitImageCommand::doCreateCommandBuffer( VkCommandPool pool , VkPipeline pipeline - , VkPipelineLayout pipelineLayout - , uint32_t srcMinLevel - , uint32_t srcMaxLevel - , uint32_t dstMinLevel - , uint32_t dstMaxLevel ) + , VkPipelineLayout pipelineLayout ) { allocateNA( m_commandBuffer - , m_device + , getDevice() , pool , true ); get( m_commandBuffer )->begin( VkCommandBufferBeginInfo @@ -952,32 +933,28 @@ void main( uint3 threadID : SV_DispatchThreadID ) VkImage image = doUpdateTmpSrc(); doAddBlits( image ); doAddStretches( pipeline - , pipelineLayout - , srcMinLevel - , srcMaxLevel - , dstMinLevel - , dstMaxLevel ); + , pipelineLayout ); doUpdateTmpDst(); get( m_commandBuffer )->end(); } - BlitImageCommand::~BlitImageCommand() + BlitImageCommand::~BlitImageCommand()noexcept { - deallocate( m_pool, get( m_device )->getAllocationCallbacks() ); - deallocate( m_uboMemory, get( m_device )->getAllocationCallbacks() ); - deallocate( m_ubo, get( m_device )->getAllocationCallbacks() ); - deallocate( m_sampler, get( m_device )->getAllocationCallbacks() ); + deallocate( m_pool, get( getDevice() )->getAllocationCallbacks() ); + deallocate( m_uboMemory, get( getDevice() )->getAllocationCallbacks() ); + deallocate( m_ubo, get( getDevice() )->getAllocationCallbacks() ); + deallocate( m_sampler, get( getDevice() )->getAllocationCallbacks() ); if ( m_tmpSrcTexture != m_srcTexture ) { - deallocate( m_dstMemory, get( m_device )->getAllocationCallbacks() ); - deallocate( m_tmpDstTexture, get( m_device )->getAllocationCallbacks() ); + deallocate( m_dstMemory, get( getDevice() )->getAllocationCallbacks() ); + deallocate( m_tmpDstTexture, get( getDevice() )->getAllocationCallbacks() ); } if ( m_tmpDstTexture != m_dstTexture ) { - deallocate( m_srcMemory, get( m_device )->getAllocationCallbacks() ); - deallocate( m_tmpDstTexture, get( m_device )->getAllocationCallbacks() ); + deallocate( m_srcMemory, get( getDevice() )->getAllocationCallbacks() ); + deallocate( m_tmpDstTexture, get( getDevice() )->getAllocationCallbacks() ); } } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.hpp index 86a11862d..47c23c772 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11BlitImageCommand.hpp @@ -12,17 +12,17 @@ namespace ashes::d3d11 { struct BlitPipeline { - VkDevice device; - VkDescriptorSetLayout descriptorLayout; - VkPipelineLayout pipelineLayout; - UInt32Array spirv; - VkShaderModule shader; - VkPipeline pipeline; + VkDevice device{}; + VkDescriptorSetLayout descriptorLayout{}; + VkPipelineLayout pipelineLayout{}; + UInt32Array spirv{}; + VkShaderModule shader{}; + VkPipeline pipeline{}; BlitPipeline( Device const & device , VkFormat src , VkFormat dst ); - ~BlitPipeline(); + ~BlitPipeline()noexcept; }; class BlitImageCommand @@ -32,16 +32,15 @@ namespace ashes::d3d11 struct Attachment { Attachment( VkDevice device - , VkImageSubresourceLayers & subresource + , VkImageSubresourceLayers const & subresource , VkImage image - , uint32_t layer - , bool dest ); - ~Attachment(); + , uint32_t layer ); + ~Attachment()noexcept; - VkDevice device; - VkImageView view; - ID3D11Resource * image; - UINT subResourceIndex; + VkDevice device{}; + VkImageView view{}; + ID3D11Resource * image{}; + UINT subResourceIndex{}; }; struct LayerCopy { @@ -52,24 +51,24 @@ namespace ashes::d3d11 , VkDeviceSize offset , VkDeviceSize range , VkSampler sampler - , VkImageBlit region + , VkImageBlit const & region , VkImage srcImage , VkImage dstImage , uint32_t layer ); - VkOffset3D dstOffset; - D3D11_BOX srcBox; - D3D11_BOX dstBox; + VkOffset3D dstOffset{}; + D3D11_BOX srcBox{}; + D3D11_BOX dstBox{}; Attachment src; Attachment dst; - VkDescriptorSet set; - uint8_t * buffer; + VkDescriptorSet set{}; + uint8_t * buffer{}; struct BlitBox { - std::array< float, 4u > srcBox; - std::array< float, 4u > dstBox; + std::array< float, 4u > srcBox{}; + std::array< float, 4u > dstBox{}; }; - BlitBox blitBox; + BlitBox blitBox{}; }; public: @@ -81,7 +80,7 @@ namespace ashes::d3d11 , VkImage dstImage , ArrayView< VkImageBlit const > const & regions , VkFilter filter ); - ~BlitImageCommand()override; + ~BlitImageCommand()noexcept override; void apply( Context const & context )const override; CommandPtr clone()const override; @@ -95,18 +94,10 @@ namespace ashes::d3d11 void doUpdateTmpDst(); void doAddBlits( VkImage srcTexture ); void doAddStretches( VkPipeline pipeline - , VkPipelineLayout pipelineLayout - , uint32_t srcMinLevel - , uint32_t srcMaxLevel - , uint32_t dstMinLevel - , uint32_t dstMaxLevel ); + , VkPipelineLayout pipelineLayout ); void doCreateCommandBuffer( VkCommandPool pool , VkPipeline pipeline - , VkPipelineLayout pipelineLayout - , uint32_t srcMinLevel - , uint32_t srcMaxLevel - , uint32_t dstMinLevel - , uint32_t dstMaxLevel ); + , VkPipelineLayout pipelineLayout ); private: VkImage m_srcTexture{}; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.cpp index 024d9516f..f0348fd8b 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.cpp @@ -41,7 +41,6 @@ namespace ashes::d3d11 } ClearAttachmentsCommand::ClearAttachmentsCommand( VkDevice device - , VkRenderPass renderPass , VkSubpassDescription const & subpass , VkFramebuffer framebuffer , ArrayView< VkClearAttachment const > const & clearAttaches @@ -54,11 +53,11 @@ namespace ashes::d3d11 if ( checkFlag( attach.aspectMask, VK_IMAGE_ASPECT_COLOR_BIT ) ) { auto ref = subpass.pColorAttachments[attach.colorAttachment]; - m_clearViews.push_back( { attach, get( framebuffer )->getAllViews()[ref.attachment]->view } ); + m_clearViews.emplace_back( attach, get( framebuffer )->getAllViews()[ref.attachment]->view ); } else if ( attach.aspectMask ) { - m_clearViews.push_back( { attach, get( framebuffer )->getDSView()->view } ); + m_clearViews.emplace_back( attach, get( framebuffer )->getDSView()->view ); } } } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.hpp index 2be73bfa7..1c9266494 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearAttachmentsCommand.hpp @@ -10,6 +10,13 @@ namespace ashes::d3d11 { struct ClearAttachmentView { + ClearAttachmentView( VkClearAttachment clear + , ID3D11View * view ) + : clear{ std::move( clear ) } + , view{ view } + { + } + VkClearAttachment clear; ID3D11View * view; }; @@ -21,7 +28,6 @@ namespace ashes::d3d11 { public: ClearAttachmentsCommand( VkDevice device - , VkRenderPass renderPass , VkSubpassDescription const & subpass , VkFramebuffer framebuffer , ArrayView< VkClearAttachment const > const & clearAttaches diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.cpp index 127c39d71..a238d989d 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.cpp @@ -51,30 +51,46 @@ namespace ashes::d3d11 , m_image{ image } , m_ranges{ ranges.begin(), ranges.end() } , m_colour{ colour } - , m_views{ createViews( m_device, m_image, m_ranges ) } + , m_views{ createViews( getDevice(), m_image, m_ranges ) } { } ClearColourCommand::ClearColourCommand( ClearColourCommand const & rhs ) - : CommandBase{ rhs.m_device } + : CommandBase{ rhs } , m_image{ rhs.m_image } , m_ranges{ rhs.m_ranges } , m_colour{ rhs.m_colour } - , m_views{ createViews( m_device, m_image, m_ranges ) } + , m_views{ createViews( getDevice(), m_image, m_ranges ) } { } - ClearColourCommand::~ClearColourCommand() + ClearColourCommand & ClearColourCommand::operator=( ClearColourCommand const & rhs ) { - for ( auto view : m_views ) + for ( auto const & view : m_views ) { - deallocate( view, get( m_device )->getAllocationCallbacks() ); + deallocate( view, get( getDevice() )->getAllocationCallbacks() ); + } + + CommandBase::operator=( rhs ); + m_image = rhs.m_image; + m_ranges = rhs.m_ranges; + m_colour = rhs.m_colour; + m_views = createViews( getDevice(), m_image, m_ranges ); + + return *this; + } + + ClearColourCommand::~ClearColourCommand()noexcept + { + for ( auto const & view : m_views ) + { + deallocate( view, get( getDevice() )->getAllocationCallbacks() ); } } void ClearColourCommand::apply( Context const & context )const { - for ( auto & view : m_views ) + for ( auto const & view : m_views ) { context.context->ClearRenderTargetView( get( view )->getRenderTargetView() , m_colour.float32 ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.hpp index 76dfd8ec8..e4a315a1c 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearColourCommand.hpp @@ -29,7 +29,10 @@ namespace ashes::d3d11 , ArrayView< VkImageSubresourceRange const > ranges , VkClearColorValue const & colour ); ClearColourCommand( ClearColourCommand const & rhs ); - ~ClearColourCommand()override; + ClearColourCommand & operator=( ClearColourCommand const & rhs ); + ClearColourCommand( ClearColourCommand && rhs )noexcept = default; + ClearColourCommand & operator=( ClearColourCommand && rhs )noexcept = default; + ~ClearColourCommand()noexcept override; void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.cpp index 95c39f5dc..055096044 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.cpp @@ -57,31 +57,48 @@ namespace ashes::d3d11 | ( isStencilFormat( get( image )->getFormat() ) ? D3D11_CLEAR_STENCIL : 0u ) } - , m_views{ createViews( m_device, m_image, m_ranges ) } + , m_views{ createViews( getDevice(), m_image, m_ranges ) } { } ClearDepthStencilCommand::ClearDepthStencilCommand( ClearDepthStencilCommand const & rhs ) - : CommandBase{ rhs.m_device } + : CommandBase{ rhs.getDevice() } , m_image{ rhs.m_image } , m_ranges{ rhs.m_ranges } , m_value{ rhs.m_value } , m_flags{ rhs.m_flags } - , m_views{ createViews( m_device, m_image, m_ranges ) } + , m_views{ createViews( getDevice(), m_image, m_ranges ) } { } - ClearDepthStencilCommand::~ClearDepthStencilCommand() + ClearDepthStencilCommand & ClearDepthStencilCommand::operator=( ClearDepthStencilCommand const & rhs ) { - for ( auto view : m_views ) + for ( auto const & view : m_views ) { - deallocate( view, get( m_device )->getAllocationCallbacks() ); + deallocate( view, get( getDevice() )->getAllocationCallbacks() ); + } + + CommandBase::operator=( rhs ); + m_image = rhs.m_image; + m_ranges = rhs.m_ranges; + m_value = rhs.m_value; + m_flags = rhs.m_flags; + m_views = createViews( getDevice(), m_image, m_ranges ); + + return *this; + } + + ClearDepthStencilCommand::~ClearDepthStencilCommand()noexcept + { + for ( auto const & view : m_views ) + { + deallocate( view, get( getDevice() )->getAllocationCallbacks() ); } } void ClearDepthStencilCommand::apply( Context const & context )const { - for ( auto & view : m_views ) + for ( auto const & view : m_views ) { context.context->ClearDepthStencilView( get( view )->getDepthStencilView() , m_flags diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.hpp index 765e0bca8..33d101e9a 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ClearDepthStencilCommand.hpp @@ -29,7 +29,10 @@ namespace ashes::d3d11 , ArrayView< VkImageSubresourceRange const > ranges , VkClearDepthStencilValue value ); ClearDepthStencilCommand( ClearDepthStencilCommand const & rhs ); - ~ClearDepthStencilCommand()override; + ClearDepthStencilCommand & operator=( ClearDepthStencilCommand const & rhs ); + ClearDepthStencilCommand( ClearDepthStencilCommand && rhs )noexcept = default; + ClearDepthStencilCommand & operator=( ClearDepthStencilCommand && rhs )noexcept = default; + ~ClearDepthStencilCommand()noexcept override; void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.cpp index 9e5ce8200..95ef11428 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.cpp @@ -24,9 +24,5 @@ namespace ashes::d3d11 { } - CommandBase::~CommandBase()noexcept - { - } - //************************************************************************* } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.hpp index 4a1cf5958..1446a4440 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CommandBase.hpp @@ -9,6 +9,7 @@ See LICENSE file in root folder namespace ashes::d3d11 { struct Context + : public NonCopyable { Context( D3D_FEATURE_LEVEL pfeatureLevel , VkDevice pdevice ) @@ -28,7 +29,7 @@ namespace ashes::d3d11 checkError( device, hr, "QueryInterface" ); } - ~Context() + ~Context()noexcept { safeRelease( context1 ); } @@ -48,19 +49,31 @@ namespace ashes::d3d11 class CommandBase { public: - CommandBase( VkDevice device ); - virtual ~CommandBase()noexcept; + CommandBase( CommandBase const & ) = default; + CommandBase( CommandBase && )noexcept = default; + CommandBase & operator=( CommandBase const & ) = default; + CommandBase & operator=( CommandBase && )noexcept = default; + + explicit CommandBase( VkDevice device ); + virtual ~CommandBase()noexcept = default; virtual void apply( Context const & context )const = 0; virtual void remove( Context const & context )const { } + virtual void fillContext( Context & context )const { } + virtual CommandPtr clone()const = 0; - protected: + VkDevice getDevice()const noexcept + { + return m_device; + } + + private: VkDevice m_device; }; } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.cpp index 5610840da..f8b608c36 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.cpp @@ -38,8 +38,7 @@ namespace ashes::d3d11 } VkDeviceSize doGetBufferSize( VkFormat format - , VkBufferImageCopy const & copyInfo - , uint32_t mipLevel ) + , VkBufferImageCopy const & copyInfo ) { VkExtent3D bufferPitch { @@ -55,7 +54,7 @@ namespace ashes::d3d11 , uint32_t slice ) { auto begin = copyInfo.bufferOffset; - auto end = begin + doGetBufferSize( format, copyInfo, 0u ); + auto end = begin + doGetBufferSize( format, copyInfo ); return { UINT( begin ), // left @@ -136,14 +135,14 @@ namespace ashes::d3d11 srcSlice += srcRowPitch; dstSlice += dstRowPitch; } + + srcLayer += srcDepthPitch; + dstLayer += dstDepthPitch; } - srcLayer += srcDepthPitch; - dstLayer += dstDepthPitch; + srcData += srcLayerPitch; + dstData += dstLayerPitch; } - - srcData += srcLayerPitch; - dstData += dstLayerPitch; } void doAdjustPitches( uint32_t bufferSize @@ -295,7 +294,6 @@ namespace ashes::d3d11 } VkBuffer getStagingBuffer( VkDevice device - , VkBuffer buffer , VkDeviceSize size , VkDeviceMemory & memory ) { @@ -341,7 +339,7 @@ namespace ashes::d3d11 for ( auto & copyInfo : copyInfos ) { - auto size = doGetBufferSize( format, copyInfo, 0u ); + auto size = doGetBufferSize( format, copyInfo ); minOffset = std::min( minOffset, copyInfo.bufferOffset ); maxSize = std::max( maxSize, copyInfo.bufferOffset + size ); } @@ -369,7 +367,6 @@ namespace ashes::d3d11 CopyToStagingProcess process; process.copyToStaging = copyToStaging; process.stagingSrc = getStagingBuffer( device - , src , process.copyToStaging.size , process.stagingSrcMemory ); @@ -427,7 +424,6 @@ namespace ashes::d3d11 MapCopyProcess getMapCopyProcess( VkDevice device , VkBuffer src , VkImage dst - , Optional< CopyToStagingProcess > const & copyToStaging , ArrayView< VkBufferImageCopy const > const & copyInfos , VkBufferImageCopy const & baseBufferImageCopy , bool dstMappable ) @@ -441,7 +437,7 @@ namespace ashes::d3d11 for ( auto & copy : copyInfos ) { - auto copyInfo = copy; + VkBufferImageCopy copyInfo = copy; // We process images array level per array level copyInfo.imageSubresource.layerCount = 1u; // We process images depth slice per depth slice @@ -503,15 +499,10 @@ namespace ashes::d3d11 auto mapCopy = getMapCopyProcess( device , src , dst - , copyToStaging , copyInfos , baseBufferImageCopy , dstMappable ); - return BufferToImageCopyProcess - { - copyToStaging, - mapCopy, - }; + return BufferToImageCopyProcess{ copyToStaging, mapCopy }; } } @@ -529,12 +520,12 @@ namespace ashes::d3d11 { } - CopyBufferToImageCommand::~CopyBufferToImageCommand() + CopyBufferToImageCommand::~CopyBufferToImageCommand()noexcept { if ( m_process.copyToStaging ) { - deallocate( m_process.copyToStaging->stagingSrcMemory, get( m_device )->getAllocationCallbacks() ); - deallocate( m_process.copyToStaging->stagingSrc, get( m_device )->getAllocationCallbacks() ); + deallocate( m_process.copyToStaging->stagingSrcMemory, get( getDevice() )->getAllocationCallbacks() ); + deallocate( m_process.copyToStaging->stagingSrc, get( getDevice() )->getAllocationCallbacks() ); } } @@ -551,7 +542,7 @@ namespace ashes::d3d11 void CopyBufferToImageCommand::apply( Context const & context , CopyToStagingProcess const & process )const { - CopyBufferCommand command{ m_device + CopyBufferCommand command{ getDevice() , process.copyToStaging , m_src , process.stagingSrc }; @@ -561,7 +552,7 @@ namespace ashes::d3d11 void CopyBufferToImageCommand::apply( Context const & context , CopyFromStagingProcess const & process )const { - CopyImageCommand command{ m_device + CopyImageCommand command{ getDevice() , process.copyFromStaging , process.stagingDst , m_dst }; @@ -572,26 +563,24 @@ namespace ashes::d3d11 , MapCopyProcess const & process )const { D3D11_MAPPED_SUBRESOURCE srcMapped{}; - auto & src = get( process.src )->getObjectMemory(); - if ( VK_SUCCESS == src.lock( *context.context - , 0u - , srcMapped ) ) + if ( auto & src = get( process.src )->getObjectMemory(); + VK_SUCCESS == src.lock( *context.context + , 0u + , srcMapped ) + && srcMapped.pData ) { - if ( srcMapped.pData ) + for ( auto & mapCopyImage : process.mapCopyImages ) { - for ( auto & mapCopyImage : process.mapCopyImages ) - { - doMapCopy( context - , mapCopyImage - , get( mapCopyImage.dst )->getFormat() - , srcMapped - , get( mapCopyImage.dst )->getObjectMemory() ); + doMapCopy( context + , mapCopyImage + , get( mapCopyImage.dst )->getFormat() + , srcMapped + , get( mapCopyImage.dst )->getObjectMemory() ); - if ( mapCopyImage.copyFromStaging ) - { - apply( context, *mapCopyImage.copyFromStaging ); - } + if ( mapCopyImage.copyFromStaging ) + { + apply( context, *mapCopyImage.copyFromStaging ); } } @@ -626,11 +615,10 @@ namespace ashes::d3d11 srcMapped.DepthPitch = UINT( imageSize ); } - D3D11_MAPPED_SUBRESOURCE dstMapped{}; - - if ( VK_SUCCESS == dst.lock( *context.context - , mapCopy.dstSubresource - , dstMapped ) + if ( D3D11_MAPPED_SUBRESOURCE dstMapped{}; + VK_SUCCESS == dst.lock( *context.context + , mapCopy.dstSubresource + , dstMapped ) && dstMapped.pData ) { doCopyMapped( format @@ -649,13 +637,8 @@ namespace ashes::d3d11 , VkBuffer src , VkBuffer staging )const { - CopyBufferCommand command{ m_device - , VkBufferCopy - { - srcOffset, - 0u, - size - } + CopyBufferCommand command{ getDevice() + , VkBufferCopy{ srcOffset, 0u, size } , src , staging }; command.apply( context ); @@ -669,15 +652,12 @@ namespace ashes::d3d11 VkImageSubresourceLayers stagingSurbresouce{ copyInfo.imageSubresource }; stagingSurbresouce.mipLevel = 0u; stagingSurbresouce.baseArrayLayer = 0u; - CopyImageCommand command{ m_device - , VkImageCopy - { - stagingSurbresouce, - VkOffset3D{}, - copyInfo.imageSubresource, - copyInfo.imageOffset, - copyInfo.imageExtent, - } + CopyImageCommand command{ getDevice() + , VkImageCopy{ stagingSurbresouce + , VkOffset3D{} + , copyInfo.imageSubresource + , copyInfo.imageOffset + , copyInfo.imageExtent } , staging , dst }; command.apply( context ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.hpp index 773ee6c9c..e21fc6e4f 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyBufferToImageCommand.hpp @@ -12,15 +12,15 @@ namespace ashes::d3d11 { VkBuffer stagingSrc{}; VkDeviceMemory stagingSrcMemory{}; - VkBufferCopy copyToStaging; + VkBufferCopy copyToStaging{}; }; struct CopyFromStagingProcess { VkImage stagingDst{}; VkDeviceMemory stagingDstMemory{}; - UINT stagingDstSubresource; - VkImageCopy copyFromStaging; + UINT stagingDstSubresource{}; + VkImageCopy copyFromStaging{}; }; struct MapCopyImage @@ -28,10 +28,10 @@ namespace ashes::d3d11 VkImage dst{}; VkDeviceMemory dstMemory{}; VkBufferImageCopy mapCopy; - D3D11_BOX srcBox; - UINT dstSubresource; - VkSubresourceLayout dstLayout; - Optional< CopyFromStagingProcess > copyFromStaging; + D3D11_BOX srcBox{}; + UINT dstSubresource{}; + VkSubresourceLayout dstLayout{}; + Optional< CopyFromStagingProcess > copyFromStaging{}; }; using MapCopyImageArray = std::vector< MapCopyImage >; @@ -39,13 +39,13 @@ namespace ashes::d3d11 { VkBuffer src{}; VkDeviceMemory srcMemory{}; - MapCopyImageArray mapCopyImages; + MapCopyImageArray mapCopyImages{}; }; struct BufferToImageCopyProcess { - Optional< CopyToStagingProcess > copyToStaging; - MapCopyProcess mapCopy; + Optional< CopyToStagingProcess > copyToStaging{}; + MapCopyProcess mapCopy{}; }; /** *\brief @@ -69,7 +69,7 @@ namespace ashes::d3d11 , ArrayView< VkBufferImageCopy const > const & copyInfo , VkBuffer src , VkImage dst ); - ~CopyBufferToImageCommand()override; + ~CopyBufferToImageCommand()noexcept override; void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyImageToBufferCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyImageToBufferCommand.cpp index b12b703ce..9565c1111 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyImageToBufferCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyImageToBufferCommand.cpp @@ -127,8 +127,7 @@ namespace ashes::d3d11 , VkBufferImageCopy const & copyInfo , uint8_t const * srcBuffer , VkSubresourceLayout const & srcLayout - , uint8_t * dstBuffer - , D3D11_BOX const & dstBox ) + , uint8_t * dstBuffer ) { auto extent = getTexelBlockExtent( format ); auto extentCombined = extent.width * extent.height * extent.depth; @@ -175,7 +174,6 @@ namespace ashes::d3d11 } VkBuffer getStagingBuffer( VkDevice device - , VkBuffer buffer , uint32_t size , VkDeviceMemory & memory ) { @@ -266,8 +264,8 @@ namespace ashes::d3d11 , VkImage src , VkBuffer dst ) : CommandBase{ device } - , m_src{ static_cast< VkImage >( src ) } - , m_dst{ static_cast< VkBuffer >( dst ) } + , m_src{ src } + , m_dst{ dst } , m_copyInfo{ copyInfo.begin(), copyInfo.end() } , m_format{ getSRVFormat( get( m_src )->getFormat() ) } , m_srcLayouts{ doGetSrcLayouts( device, m_src, copyInfo ) } @@ -302,7 +300,7 @@ namespace ashes::d3d11 if ( !m_srcMappable ) { - stagingSrc = getStagingTexture( m_device + stagingSrc = getStagingTexture( getDevice() , m_src , copyInfo.imageExtent , stagingSrcMemory ); @@ -315,8 +313,7 @@ namespace ashes::d3d11 if ( !m_dstMappable ) { - stagingDst = getStagingBuffer( m_device - , m_dst + stagingDst = getStagingBuffer( getDevice() , dstBox.right - dstBox.left , stagingDstMemory ); dst = &stagingDst; @@ -340,14 +337,14 @@ namespace ashes::d3d11 if ( stagingDst ) { - deallocate( stagingDstMemory, get( m_device )->getAllocationCallbacks() ); - deallocate( stagingDst, get( m_device )->getAllocationCallbacks() ); + deallocate( stagingDstMemory, get( getDevice() )->getAllocationCallbacks() ); + deallocate( stagingDst, get( getDevice() )->getAllocationCallbacks() ); } if ( stagingSrc ) { - deallocate( stagingSrcMemory, get( m_device )->getAllocationCallbacks() ); - deallocate( stagingSrc, get( m_device )->getAllocationCallbacks() ); + deallocate( stagingSrcMemory, get( getDevice() )->getAllocationCallbacks() ); + deallocate( stagingSrc, get( getDevice() )->getAllocationCallbacks() ); } } @@ -363,28 +360,25 @@ namespace ashes::d3d11 , VkDeviceMemory src , VkDeviceMemory dst )const { - uint8_t * srcBuffer; - - if ( VK_SUCCESS == get( src )->lock( srcLayout.offset - , srcLayout.size - , 0u - , reinterpret_cast< void ** >( &srcBuffer ) ) ) - { - uint8_t * dstBuffer; - - if ( VK_SUCCESS == get( dst )->lock( dstBox.left - , dstBox.right - dstBox.left + if ( uint8_t * srcBuffer{}; + VK_SUCCESS == get( src )->lock( srcLayout.offset + , srcLayout.size , 0u - , reinterpret_cast< void ** >( &dstBuffer ) ) ) + , reinterpret_cast< void ** >( &srcBuffer ) ) ) + { + if ( uint8_t * dstBuffer{}; + VK_SUCCESS == get( dst )->lock( dstBox.left + , VkDeviceSize( dstBox.right ) - dstBox.left + , 0u + , reinterpret_cast< void ** >( &dstBuffer ) ) ) { doCopyMapped( format , copyInfo , srcBuffer , srcLayout - , dstBuffer - , dstBox ); + , dstBuffer ); get( dst )->flush( dstBox.left - , dstBox.right - dstBox.left ); + , VkDeviceSize( dstBox.right ) - dstBox.left ); get( dst )->unlock(); } @@ -402,7 +396,7 @@ namespace ashes::d3d11 VkImageSubresourceLayers stagingSurbresouce{ copyInfo.imageSubresource }; stagingSurbresouce.mipLevel = 0u; stagingSurbresouce.baseArrayLayer = 0u; - CopyImageCommand command{ m_device + CopyImageCommand command{ getDevice() , VkImageCopy { copyInfo.imageSubresource, @@ -422,7 +416,7 @@ namespace ashes::d3d11 , VkBuffer dst , D3D11_BOX const & dstBox )const { - CopyBufferCommand command{ m_device + CopyBufferCommand command{ getDevice() , VkBufferCopy { 0u, diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyQueryPoolResultsCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyQueryPoolResultsCommand.cpp index b1f2ba9f7..475f53bee 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyQueryPoolResultsCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11CopyQueryPoolResultsCommand.cpp @@ -50,9 +50,8 @@ namespace ashes::d3d11 if ( m_mappable ) { - void * data; - - if ( get( m_dstMemory )->lock( m_dstOffset, m_data.size(), 0u, &data ) == VK_SUCCESS ) + if ( void * data; + get( m_dstMemory )->lock( m_dstOffset, m_data.size(), 0u, &data ) == VK_SUCCESS ) { std::memcpy( data, m_data.data(), m_data.size() ); get( m_dstMemory )->flush( m_dstOffset, m_data.size() ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawCommand.cpp index 639932d36..4552ee4ca 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawCommand.cpp @@ -27,7 +27,7 @@ namespace ashes::d3d11 { context.context->IASetPrimitiveTopology( m_mode ); - for ( auto & binding : m_vbos ) + for ( auto const & binding : m_vbos ) { context.context->IASetVertexBuffers( binding.startIndex , UINT( binding.d3dBuffers.size() ) diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedCommand.cpp index 6649de5a7..ab92bee3e 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedCommand.cpp @@ -49,7 +49,7 @@ namespace ashes::d3d11 { context.context->IASetPrimitiveTopology( m_mode ); - for ( auto & binding : m_vbos ) + for ( auto const & binding : m_vbos ) { context.context->IASetVertexBuffers( binding.startIndex , UINT( binding.d3dBuffers.size() ) diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedIndirectCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedIndirectCommand.cpp index 2d2380e8a..233a4d794 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedIndirectCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndexedIndirectCommand.cpp @@ -33,7 +33,7 @@ namespace ashes::d3d11 { context.context->IASetPrimitiveTopology( m_mode ); - for ( auto & binding : m_vbos ) + for ( auto const & binding : m_vbos ) { context.context->IASetVertexBuffers( binding.startIndex , UINT( binding.d3dBuffers.size() ) diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndirectCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndirectCommand.cpp index dbbcf4382..6760c6938 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndirectCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11DrawIndirectCommand.cpp @@ -31,7 +31,7 @@ namespace ashes::d3d11 { context.context->IASetPrimitiveTopology( m_mode ); - for ( auto & binding : m_vbos ) + for ( auto const & binding : m_vbos ) { context.context->IASetVertexBuffers( binding.startIndex , UINT( binding.d3dBuffers.size() ) diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11EndSubpassCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11EndSubpassCommand.cpp index 4ffcef37c..403907d7b 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11EndSubpassCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11EndSubpassCommand.cpp @@ -37,7 +37,8 @@ namespace ashes::d3d11 for ( auto & resolveAttach : makeArrayView( m_subpass.pResolveAttachments, m_subpass.colorAttachmentCount ) ) { - auto & srcAttach = get( m_frameBuffer )->getMsRTViews()[index++]; + auto & srcAttach = get( m_frameBuffer )->getMsRTViews()[index]; + ++index; auto & dstAttach = get( m_frameBuffer )->getAllViews()[resolveAttach.attachment]; context.context->ResolveSubresource( dstAttach->resource diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteActionsCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteActionsCommand.cpp index 41c8ca699..624a672a4 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteActionsCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteActionsCommand.cpp @@ -17,7 +17,7 @@ namespace ashes::d3d11 void ExecuteActionsCommand::apply( Context const & context )const { - for ( auto & action : m_actions ) + for ( auto const & action : m_actions ) { action( context ); } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.cpp index 7fa51ecb1..1b8e22246 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.cpp @@ -17,10 +17,6 @@ namespace ashes::d3d11 { } - ExecuteCommandsCommand::~ExecuteCommandsCommand() - { - } - void ExecuteCommandsCommand::apply( Context const & context )const { context.context->ExecuteCommandList( get( m_commandBuffer )->getCommandList() diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.hpp index bca304b4a..d9431fa18 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ExecuteCommandsCommand.hpp @@ -14,7 +14,6 @@ namespace ashes::d3d11 public: ExecuteCommandsCommand( VkDevice device , VkCommandBuffer commandBuffer ); - ~ExecuteCommandsCommand()override; void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.cpp index 8b27926ca..bdec19564 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.cpp @@ -14,7 +14,6 @@ namespace ashes::d3d11 { FillBufferCommand::FillBufferCommand( VkDevice device , VkBuffer buffer - , VkDeviceSize bufferOffset , VkDeviceSize size , uint32_t data ) : CommandBase{ device } @@ -27,9 +26,8 @@ namespace ashes::d3d11 void FillBufferCommand::apply( Context const & context )const { - uint32_t * data; - - if ( VK_SUCCESS == get( m_memory )->lock( m_memoryOffset, m_size, 0u, reinterpret_cast< void ** >( &data ) ) ) + if ( uint32_t * data{}; + VK_SUCCESS == get( m_memory )->lock( m_memoryOffset, m_size, 0u, reinterpret_cast< void ** >( &data ) ) ) { std::fill_n( data, m_size / sizeof( uint32_t ), m_data ); get( m_memory )->flush( m_memoryOffset, m_size ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.hpp index 67aaa1d1d..e9429dca9 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11FillBufferCommand.hpp @@ -14,7 +14,6 @@ namespace ashes::d3d11 public: FillBufferCommand( VkDevice device , VkBuffer buffer - , VkDeviceSize bufferOffset , VkDeviceSize size , uint32_t data ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11GenerateMipsCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11GenerateMipsCommand.cpp index 8d8561535..f6a054bf3 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11GenerateMipsCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11GenerateMipsCommand.cpp @@ -42,6 +42,6 @@ namespace ashes::d3d11 CommandPtr GenerateMipsCommand::clone()const { - return std::make_unique< GenerateMipsCommand >( *this ); + return std::make_unique< GenerateMipsCommand >( getDevice(), m_texture ); } } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.cpp index 034245d0d..82a34bdaa 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.cpp @@ -9,11 +9,7 @@ See LICENSE file in root folder. namespace ashes::d3d11 { MemoryBarrierCommand::MemoryBarrierCommand( VkDevice device - , VkPipelineStageFlags after - , VkPipelineStageFlags before - , ArrayView< VkMemoryBarrier const > const & memoryBarriers - , ArrayView< VkBufferMemoryBarrier const > const & bufferBarriers - , ArrayView< VkImageMemoryBarrier const > const & imageBarriers ) + , ArrayView< VkBufferMemoryBarrier const > const & bufferBarriers ) : CommandBase{ device } { for ( auto & barrier : bufferBarriers ) diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.hpp index 5943ac123..8c6f96b81 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11MemoryBarrierCommand.hpp @@ -21,11 +21,7 @@ namespace ashes::d3d11 * Constructeur. */ MemoryBarrierCommand( VkDevice device - , VkPipelineStageFlags after - , VkPipelineStageFlags before - , ArrayView< VkMemoryBarrier const > const & memoryBarriers - , ArrayView< VkBufferMemoryBarrier const > const & bufferBarriers - , ArrayView< VkImageMemoryBarrier const > const & imageBarriers ); + , ArrayView< VkBufferMemoryBarrier const > const & bufferBarriers ); void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.cpp index ec55776e5..166c49254 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.cpp @@ -9,8 +9,7 @@ See LICENSE file in root folder. namespace ashes::d3d11 { ResetEventCommand::ResetEventCommand( VkDevice device - , VkEvent event - , VkPipelineStageFlags stageFlags ) + , VkEvent event ) : CommandBase{ device } , m_event{ event } { diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.hpp index 474b2f473..798a0b790 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetEventCommand.hpp @@ -17,8 +17,7 @@ namespace ashes::d3d11 { public: ResetEventCommand( VkDevice device - , VkEvent event - , VkPipelineStageFlags stageFlags ); + , VkEvent event ); void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.cpp index 7f5316436..1f66e240a 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.cpp @@ -6,10 +6,7 @@ See LICENSE file in root folder. namespace ashes::d3d11 { - ResetQueryPoolCommand::ResetQueryPoolCommand( VkDevice device - , VkQueryPool pool - , uint32_t firstQuery - , uint32_t queryCount ) + ResetQueryPoolCommand::ResetQueryPoolCommand( VkDevice device ) : CommandBase{ device } { } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.hpp index 484299087..7fae8f83c 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResetQueryPoolCommand.hpp @@ -16,10 +16,7 @@ namespace ashes::d3d11 : public CommandBase { public: - ResetQueryPoolCommand( VkDevice device - , VkQueryPool pool - , uint32_t firstQuery - , uint32_t queryCount ); + ResetQueryPoolCommand( VkDevice device ); void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.cpp index abb01493d..838e730c8 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.cpp @@ -19,26 +19,23 @@ namespace ashes::d3d11 , m_srcResource{ get( srcImage )->getResource() } , m_dstResource{ get( dstImage )->getResource() } { - for ( auto & region : regions ) + for ( auto const & region : regions ) { for ( auto layer = 0u; layer < region.dstSubresource.layerCount; ++layer ) { - m_layers.push_back( - { - D3D11CalcSubresource( region.srcSubresource.mipLevel - , region.srcSubresource.baseArrayLayer + layer - , get( srcImage )->getMipmapLevels() ), - D3D11CalcSubresource( region.dstSubresource.mipLevel - , region.dstSubresource.baseArrayLayer + layer - , get( dstImage )->getMipmapLevels() ), - } ); + m_layers.emplace_back( D3D11CalcSubresource( region.srcSubresource.mipLevel + , region.srcSubresource.baseArrayLayer + layer + , get( srcImage )->getMipmapLevels() ) + , D3D11CalcSubresource( region.dstSubresource.mipLevel + , region.dstSubresource.baseArrayLayer + layer + , get( dstImage )->getMipmapLevels() ) ); } } } void ResolveImageCommand::apply( Context const & context )const { - for ( auto & layer : m_layers ) + for ( auto const & layer : m_layers ) { context.context->ResolveSubresource( m_dstResource , layer.dstSubresource diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.hpp index cc8e41543..6e51c63c3 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11ResolveImageCommand.hpp @@ -23,6 +23,13 @@ namespace ashes::d3d11 private: struct LayerResolve { + LayerResolve( UINT srcSubresource + , UINT dstSubresource ) + : srcSubresource{ srcSubresource } + , dstSubresource{ dstSubresource } + { + } + UINT srcSubresource; UINT dstSubresource; }; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.cpp index 4fe5e3ff5..9783f4eeb 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.cpp @@ -11,8 +11,7 @@ See LICENSE file in root folder. namespace ashes::d3d11 { SetEventCommand::SetEventCommand( VkDevice device - , VkEvent event - , VkPipelineStageFlags stageFlags ) + , VkEvent event ) : CommandBase{ device } , m_event{ event } { diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.hpp index 39629f997..4901cf083 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11SetEventCommand.hpp @@ -13,8 +13,7 @@ namespace ashes::d3d11 { public: SetEventCommand( VkDevice device - , VkEvent event - , VkPipelineStageFlags stageFlags ); + , VkEvent event ); void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11UpdateBufferCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11UpdateBufferCommand.cpp index 58d135017..de49b59d1 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11UpdateBufferCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11UpdateBufferCommand.cpp @@ -33,9 +33,8 @@ namespace ashes::d3d11 { if ( m_mappable ) { - void * data; - - if ( VK_SUCCESS == get( m_memory )->lock( m_memoryOffset, m_data.size(), 0u, &data ) ) + if ( void * data{}; + VK_SUCCESS == get( m_memory )->lock( m_memoryOffset, m_data.size(), 0u, &data ) ) { std::memcpy( data, m_data.data(), m_data.size() ); get( m_memory )->flush( m_memoryOffset, m_data.size() ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.cpp index f0c560855..55d1eee04 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.cpp @@ -19,11 +19,7 @@ See LICENSE file in root folder. namespace ashes::d3d11 { WaitEventsCommand::WaitEventsCommand( VkDevice device - , ArrayView< VkEvent const > const & events - , VkPipelineStageFlags srcStageMask - , VkPipelineStageFlags dstStageMask - , ArrayView< VkBufferMemoryBarrier const > const & bufferMemoryBarriers - , ArrayView< VkImageMemoryBarrier const > const & imageMemoryBarriers ) + , ArrayView< VkEvent const > const & events ) : CommandBase{ device } , m_events{ events.begin(), events.end() } { diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.hpp index 8a0947e51..d8e20d54a 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WaitEventsCommand.hpp @@ -13,11 +13,7 @@ namespace ashes::d3d11 { public: WaitEventsCommand( VkDevice device - , ArrayView< VkEvent const > const & events - , VkPipelineStageFlags srcStageMask - , VkPipelineStageFlags dstStageMask - , ArrayView< VkBufferMemoryBarrier const > const & bufferMemoryBarriers - , ArrayView< VkImageMemoryBarrier const > const & imageMemoryBarriers ); + , ArrayView< VkEvent const > const & events ); void apply( Context const & context )const override; CommandPtr clone()const override; diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.cpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.cpp index dc6a4460f..260d2f55e 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.cpp @@ -11,7 +11,6 @@ See LICENSE file in root folder. namespace ashes::d3d11 { WriteTimestampCommand::WriteTimestampCommand( VkDevice device - , VkPipelineStageFlagBits pipelineStage , VkQueryPool pool , uint32_t query ) : CommandBase{ device } diff --git a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.hpp b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.hpp index 2149f8f02..41dc08bff 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/Commands/D3D11WriteTimestampCommand.hpp @@ -17,7 +17,6 @@ namespace ashes::d3d11 { public: WriteTimestampCommand( VkDevice device - , VkPipelineStageFlagBits pipelineStage , VkQueryPool pool , uint32_t query ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.cpp b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.cpp index 9b88ec002..7685247af 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.cpp @@ -63,10 +63,10 @@ See LICENSE file in root folder. #include "ashesd3d11_api.hpp" -#define AshesD3D_UseCommandsList 0 - namespace ashes::d3d11 { + static bool constexpr UseCommandsList = false; + //********************************************************************************************* namespace @@ -88,39 +88,38 @@ namespace ashes::d3d11 , m_commandPool{ commandPool } { get( commandPool )->registerCommands( get( this ) ); -#if AshesD3D_UseCommandsList - if ( !primary ) + if constexpr ( UseCommandsList ) { - get( m_device )->getDevice()->CreateDeferredContext( 0u, &m_deferredContext ); + if ( !primary ) + { + get( m_device )->getDevice()->CreateDeferredContext( 0u, &m_deferredContext ); + } } - -#endif } - CommandBuffer::~CommandBuffer() + CommandBuffer::~CommandBuffer()noexcept { -#if AshesD3D_UseCommandsList - - safeRelease( m_commandList ); - safeRelease( m_deferredContext ); - -#endif + if constexpr ( UseCommandsList ) + { + safeRelease( m_commandList ); + safeRelease( m_deferredContext ); + } } void CommandBuffer::execute( Context & context )const { - for ( auto & command : m_commands ) + for ( auto const & command : m_commands ) { command->fillContext( context ); } - for ( auto & command : m_commands ) + for ( auto const & command : m_commands ) { command->apply( context ); } - for ( auto & action : m_afterSubmitActions ) + for ( auto const & action : m_afterSubmitActions ) { action( context ); } @@ -140,35 +139,34 @@ namespace ashes::d3d11 { m_state.pushConstantBuffers.clear(); -#if AshesD3D_UseCommandsList - - if ( m_deferredContext ) + if constexpr ( UseCommandsList ) { - safeRelease( m_commandList ); - Context context{ m_deferredContext }; - m_deferredContext->AddRef(); - execute( context ); - m_deferredContext->FinishCommandList( TRUE, &m_commandList ); + if ( m_deferredContext ) + { + safeRelease( m_commandList ); + Context context{ get( m_device )->getFeatureLevel(), m_device, DeviceContextLock{ m_deferredContext } }; + m_deferredContext->AddRef(); + execute( context ); + m_deferredContext->FinishCommandList( TRUE, &m_commandList ); + } } -#endif - return VK_SUCCESS; } - VkResult CommandBuffer::reset( VkCommandBufferResetFlags flags )const + VkResult CommandBuffer::reset()const { m_commands.clear(); return VK_SUCCESS; } - void CommandBuffer::beginRenderPass( VkRenderPassBeginInfo beginInfo - , VkSubpassContents contents )const + void CommandBuffer::beginRenderPass( VkRenderPassBeginInfo beginInfo )const { m_state.currentRenderPass = beginInfo.renderPass; m_state.currentFrameBuffer = beginInfo.framebuffer; m_state.currentSubpassIndex = 0u; - m_state.currentSubpass = &get( m_state.currentRenderPass )->getSubpasses()[m_state.currentSubpassIndex++]; + m_state.currentSubpass = &get( m_state.currentRenderPass )->getSubpasses()[m_state.currentSubpassIndex]; + ++m_state.currentSubpassIndex; m_state.vbos.clear(); m_commands.emplace_back( std::make_unique< BeginRenderPassCommand >( m_device , m_state.currentRenderPass @@ -180,12 +178,13 @@ namespace ashes::d3d11 , *m_state.currentSubpass ) ); } - void CommandBuffer::nextSubpass( VkSubpassContents contents )const + void CommandBuffer::nextSubpass()const { m_commands.emplace_back( std::make_unique< EndSubpassCommand >( m_device , m_state.currentFrameBuffer , *m_state.currentSubpass ) ); - m_state.currentSubpass = &get( m_state.currentRenderPass )->getSubpasses()[m_state.currentSubpassIndex++]; + m_state.currentSubpass = &get( m_state.currentRenderPass )->getSubpasses()[m_state.currentSubpassIndex]; + ++m_state.currentSubpassIndex; m_commands.emplace_back( std::make_unique< BeginSubpassCommand >( m_device , m_state.currentRenderPass , m_state.currentFrameBuffer @@ -206,34 +205,32 @@ namespace ashes::d3d11 void CommandBuffer::executeCommands( ArrayView< VkCommandBuffer const > commands )const { -#if AshesD3D_UseCommandsList - - for ( auto & commandBuffer : commands ) + if constexpr ( UseCommandsList ) { - m_commands.emplace_back( std::make_unique< ExecuteCommandsCommand >( m_device - , commandBuffer ) ); + for ( auto & commandBuffer : commands ) + { + m_commands.emplace_back( std::make_unique< ExecuteCommandsCommand >( m_device + , commandBuffer ) ); + } } - -#else - - for ( auto & commandBuffer : commands ) + else { - auto & dxCommandBuffer = *get( commandBuffer ); - - for ( auto & command : dxCommandBuffer.getCommands() ) + for ( auto & commandBuffer : commands ) { - m_commands.emplace_back( command->clone() ); - } + auto & dxCommandBuffer = *get( commandBuffer ); - m_commands.emplace_back( std::make_unique< ExecuteActionsCommand >( m_device - , dxCommandBuffer.m_afterSubmitActions ) ); - } + for ( auto & command : dxCommandBuffer.getCommands() ) + { + m_commands.emplace_back( command->clone() ); + } -#endif + m_commands.emplace_back( std::make_unique< ExecuteActionsCommand >( m_device + , dxCommandBuffer.m_afterSubmitActions ) ); + } + } } void CommandBuffer::clearColorImage( VkImage image - , VkImageLayout imageLayout , VkClearColorValue colour , ArrayView< VkImageSubresourceRange const > ranges )const { @@ -244,7 +241,6 @@ namespace ashes::d3d11 } void CommandBuffer::clearDepthStencilImage( VkImage image - , VkImageLayout imageLayout , VkClearDepthStencilValue value , ArrayView< VkImageSubresourceRange const > ranges )const { @@ -258,7 +254,6 @@ namespace ashes::d3d11 , ArrayView< VkClearRect const > clearRects ) { m_commands.emplace_back( std::make_unique< ClearAttachmentsCommand >( m_device - , m_state.currentRenderPass , *m_state.currentSubpass , m_state.currentFrameBuffer , clearAttachments @@ -288,10 +283,10 @@ namespace ashes::d3d11 , bindingPoint ) ); doAddAfterSubmitAction(); - for ( auto & pcb : m_state.pushConstantBuffers ) + for ( auto const & [layout, desc] : m_state.pushConstantBuffers ) { m_commands.emplace_back( std::make_unique< PushConstantsCommand >( m_device - , get( m_state.currentPipeline )->findPushConstantBuffer( pcb.second ) ) ); + , get( m_state.currentPipeline )->findPushConstantBuffer( desc ) ) ); doAddAfterSubmitAction(); } @@ -305,10 +300,10 @@ namespace ashes::d3d11 , bindingPoint ) ); doAddAfterSubmitAction(); - for ( auto & pcb : m_state.pushConstantBuffers ) + for ( auto const & [layout, desc] : m_state.pushConstantBuffers ) { m_commands.emplace_back( std::make_unique< PushConstantsCommand >( m_device - , get( m_state.currentPipeline )->findPushConstantBuffer( pcb.second ) ) ); + , get( m_state.currentPipeline )->findPushConstantBuffer( desc ) ) ); doAddAfterSubmitAction(); } @@ -357,7 +352,7 @@ namespace ashes::d3d11 , VkIndexType indexType )const { m_commands.emplace_back( std::make_unique< BindIndexBufferCommand >( m_device - , static_cast< VkBuffer >( buffer ) + , buffer , offset , indexType ) ); doAddAfterSubmitAction(); @@ -371,7 +366,7 @@ namespace ashes::d3d11 , ArrayView< VkDescriptorSet const > descriptorSets , ArrayView< uint32_t const > dynamicOffsets )const { - for ( auto & descriptorSet : descriptorSets ) + for ( auto & descriptorSet : ashes::makeArrayView( std::next( descriptorSets.begin(), firstSet ), descriptorSets.end() ) ) { m_state.boundDescriptors.push_back( descriptorSet ); doProcessMappedBoundDescriptorResourcesIn( descriptorSet ); @@ -507,20 +502,16 @@ namespace ashes::d3d11 void CommandBuffer::copyToImage( VkBuffer src , VkImage dst - , VkImageLayout dstLayout , ArrayView< VkBufferImageCopy const > copyInfos )const { - if ( !get( m_device )->onCopyToImageCommand( get( this ), copyInfos, src, dst ) ) - { - m_commands.emplace_back( std::make_unique< CopyBufferToImageCommand >( m_device - , std::move( copyInfos ) - , src - , dst ) ); - } + get( m_device )->onCopyToImageCommand( get( this ), copyInfos, src, dst ); + m_commands.emplace_back( std::make_unique< CopyBufferToImageCommand >( m_device + , std::move( copyInfos ) + , src + , dst ) ); } void CommandBuffer::copyToBuffer( VkImage src - , VkImageLayout srcLayout , VkBuffer dst , ArrayView< VkBufferImageCopy const > copyInfos )const { @@ -541,13 +532,12 @@ namespace ashes::d3d11 } void CommandBuffer::fillBuffer( VkBuffer dstBuffer - , VkDeviceSize dstOffset + , [[maybe_unused]] VkDeviceSize dstOffset , VkDeviceSize size , uint32_t data ) { m_commands.emplace_back( std::make_unique< FillBufferCommand >( m_device , dstBuffer - , dstOffset , size , data ) ); } @@ -556,19 +546,17 @@ namespace ashes::d3d11 , VkBuffer dst , ArrayView< VkBufferCopy const > copyInfos )const { - for ( auto & copyInfo : copyInfos ) + for ( auto const & copyInfo : copyInfos ) { m_commands.emplace_back( std::make_unique< CopyBufferCommand >( m_device - , std::move( copyInfo ) + , copyInfo , src , dst ) ); } } void CommandBuffer::copyImage( VkImage src - , VkImageLayout srcLayout , VkImage dst - , VkImageLayout dstLayout , ArrayView< VkImageCopy const > copyInfos )const { for ( auto & copyInfo : copyInfos ) @@ -581,9 +569,7 @@ namespace ashes::d3d11 } void CommandBuffer::blitImage( VkImage srcImage - , VkImageLayout srcLayout , VkImage dstImage - , VkImageLayout dstLayout , ArrayView< VkImageBlit const > regions , VkFilter filter )const { @@ -600,9 +586,7 @@ namespace ashes::d3d11 } void CommandBuffer::resolveImage( VkImage srcImage - , VkImageLayout srcLayout , VkImage dstImage - , VkImageLayout dstLayout , ArrayView< VkImageResolve const > regions )const { m_commands.emplace_back( std::make_unique< ResolveImageCommand >( m_device @@ -611,24 +595,20 @@ namespace ashes::d3d11 , regions ) ); } - void CommandBuffer::resetQueryPool( VkQueryPool pool - , uint32_t firstQuery - , uint32_t queryCount )const + void CommandBuffer::resetQueryPool( [[maybe_unused]] VkQueryPool pool + , [[maybe_unused]] uint32_t firstQuery + , [[maybe_unused]] uint32_t queryCount )const { - m_commands.emplace_back( std::make_unique< ResetQueryPoolCommand >( m_device - , pool - , firstQuery - , queryCount ) ); + m_commands.emplace_back( std::make_unique< ResetQueryPoolCommand >( m_device ) ); } void CommandBuffer::beginQuery( VkQueryPool pool , uint32_t query - , VkQueryControlFlags flags )const + , [[maybe_unused]] VkQueryControlFlags flags )const { m_commands.emplace_back( std::make_unique< BeginQueryCommand >( m_device , pool - , query - , flags ) ); + , query ) ); } void CommandBuffer::endQuery( VkQueryPool pool @@ -639,12 +619,11 @@ namespace ashes::d3d11 , query ) ); } - void CommandBuffer::writeTimestamp( VkPipelineStageFlagBits pipelineStage + void CommandBuffer::writeTimestamp( [[maybe_unused]] VkPipelineStageFlagBits pipelineStage , VkQueryPool pool , uint32_t query )const { m_commands.emplace_back( std::make_unique< WriteTimestampCommand >( m_device - , pipelineStage , pool , query ) ); } @@ -799,49 +778,37 @@ namespace ashes::d3d11 } void CommandBuffer::setEvent( VkEvent event - , VkPipelineStageFlags stageMask )const + , [[maybe_unused]] VkPipelineStageFlags stageMask )const { m_commands.emplace_back( std::make_unique< SetEventCommand >( m_device - , event - , stageMask ) ); + , event ) ); } void CommandBuffer::resetEvent( VkEvent event - , VkPipelineStageFlags stageMask )const + , [[maybe_unused]] VkPipelineStageFlags stageMask )const { m_commands.emplace_back( std::make_unique< ResetEventCommand >( m_device - , event - , stageMask ) ); + , event ) ); } void CommandBuffer::waitEvents( ArrayView< VkEvent const > events - , VkPipelineStageFlags srcStageMask - , VkPipelineStageFlags dstStageMask - , ArrayView< VkMemoryBarrier const > memoryBarriers - , ArrayView< VkBufferMemoryBarrier const > bufferMemoryBarriers - , ArrayView< VkImageMemoryBarrier const > imageMemoryBarriers )const + , [[maybe_unused]] VkPipelineStageFlags srcStageMask + , [[maybe_unused]] VkPipelineStageFlags dstStageMask + , [[maybe_unused]] ArrayView< VkBufferMemoryBarrier const > bufferMemoryBarriers + , [[maybe_unused]] ArrayView< VkImageMemoryBarrier const > imageMemoryBarriers )const { m_commands.emplace_back( std::make_unique< WaitEventsCommand >( m_device - , events - , srcStageMask - , dstStageMask - , bufferMemoryBarriers - , imageMemoryBarriers ) ); + , events ) ); } - void CommandBuffer::pipelineBarrier( VkPipelineStageFlags after - , VkPipelineStageFlags before - , VkDependencyFlags dependencyFlags - , ArrayView< VkMemoryBarrier const > memoryBarriers + void CommandBuffer::pipelineBarrier( [[maybe_unused]] VkPipelineStageFlags after + , [[maybe_unused]] VkPipelineStageFlags before + , [[maybe_unused]] ArrayView< VkMemoryBarrier const > memoryBarriers , ArrayView< VkBufferMemoryBarrier const > bufferMemoryBarriers - , ArrayView< VkImageMemoryBarrier const > imageMemoryBarriers )const + , [[maybe_unused]] ArrayView< VkImageMemoryBarrier const > imageMemoryBarriers )const { m_commands.emplace_back( std::make_unique< MemoryBarrierCommand >( m_device - , after - , before - , memoryBarriers - , bufferMemoryBarriers - , imageMemoryBarriers ) ); + , bufferMemoryBarriers ) ); } void CommandBuffer::generateMipmaps( VkImage texture )const @@ -921,14 +888,13 @@ namespace ashes::d3d11 for ( auto i = 0u; i < binding.buffers.size(); ++i ) { - auto it = std::find_if( state.pVertexBindingDescriptions - , bindingsEnd - , [startIndex]( ::VkVertexInputBindingDescription const & desc ) - { - return desc.binding == startIndex; - } ); - - if ( it != bindingsEnd ) + if ( auto it = std::find_if( state.pVertexBindingDescriptions + , bindingsEnd + , [startIndex]( ::VkVertexInputBindingDescription const & desc ) + { + return desc.binding == startIndex; + } ); + it != bindingsEnd ) { binding.strides.push_back( it->stride ); } @@ -940,8 +906,8 @@ namespace ashes::d3d11 void CommandBuffer::doAddAfterSubmitAction()const { - auto & command = *m_commands.back(); - m_afterSubmitActions.insert( m_afterSubmitActions.begin() + auto const & command = *m_commands.back(); + m_afterSubmitActions.emplace( m_afterSubmitActions.begin() , [&command]( Context const & context ) { command.remove( context ); @@ -952,7 +918,7 @@ namespace ashes::d3d11 { for ( auto & writes : get( descriptor )->getDynamicBuffers() ) { - for ( auto & write : writes->writes ) + for ( auto const & write : writes->writes ) { for ( auto & info : makeArrayView( write.pBufferInfo, write.descriptorCount ) ) { @@ -963,7 +929,7 @@ namespace ashes::d3d11 for ( auto & writes : get( descriptor )->getStorageBuffers() ) { - for ( auto & write : writes->writes ) + for ( auto const & write : writes->writes ) { for ( auto & info : makeArrayView( write.pBufferInfo, write.descriptorCount ) ) { @@ -974,7 +940,7 @@ namespace ashes::d3d11 for ( auto & writes : get( descriptor )->getStorageTextures() ) { - for ( auto & write : writes->writes ) + for ( auto const & write : writes->writes ) { for ( auto & info : makeArrayView( write.pImageInfo, write.descriptorCount ) ) { @@ -985,7 +951,7 @@ namespace ashes::d3d11 for ( auto & writes : get( descriptor )->getUniformBuffers() ) { - for ( auto & write : writes->writes ) + for ( auto const & write : writes->writes ) { for ( auto & info : makeArrayView( write.pBufferInfo, write.descriptorCount ) ) { @@ -1001,7 +967,7 @@ namespace ashes::d3d11 { for ( auto & writes : get( descriptor )->getDynamicStorageBuffers() ) { - for ( auto & write : writes->writes ) + for ( auto const & write : writes->writes ) { for ( auto & info : makeArrayView( write.pBufferInfo, write.descriptorCount ) ) { @@ -1012,7 +978,7 @@ namespace ashes::d3d11 for ( auto & writes : get( descriptor )->getStorageBuffers() ) { - for ( auto & write : writes->writes ) + for ( auto const & write : writes->writes ) { for ( auto & info : makeArrayView( write.pBufferInfo, write.descriptorCount ) ) { @@ -1023,7 +989,7 @@ namespace ashes::d3d11 for ( auto & writes : get( descriptor )->getStorageTextures() ) { - for ( auto & write : writes->writes ) + for ( auto const & write : writes->writes ) { for ( auto & info : makeArrayView( write.pImageInfo, write.descriptorCount ) ) { @@ -1036,7 +1002,7 @@ namespace ashes::d3d11 void CommandBuffer::doProcessMappedBoundVaoBuffersIn()const { - for ( auto & vbo : m_state.vbos ) + for ( auto const & vbo : m_state.vbos ) { for ( auto & buffer : vbo.buffers ) { @@ -1066,31 +1032,27 @@ namespace ashes::d3d11 void CommandBuffer::doProcessMappedBoundResourceIn( VkImageView image )const { auto img = get( get( image )->getImage() ); - - //if ( get( img->getMemory() )->isMapped() ) + auto & range = get( image )->getSubResourceRange(); + auto layerSize = getLevelsSize( img->getDimensions() + , img->getFormat() + , 0u + , img->getMipmapLevels() + , uint32_t( img->getMemoryAlignment() ) ); + auto size = getLevelsSize( img->getDimensions() + , img->getFormat() + , range.baseMipLevel + , range.levelCount + , uint32_t( img->getMemoryAlignment() ) ); + auto offset = img->getMemoryOffset(); + + for ( auto layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer ) { - auto & range = get( image )->getSubResourceRange(); - auto layerSize = getLevelsSize( img->getDimensions() - , img->getFormat() - , 0u - , img->getMipmapLevels() - , uint32_t( img->getMemoryAlignment() ) ); - auto size = getLevelsSize( img->getDimensions() - , img->getFormat() - , range.baseMipLevel - , range.levelCount - , uint32_t( img->getMemoryAlignment() ) ); - auto offset = img->getMemoryOffset(); - - for ( auto layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer ) - { - doAddMappedResource( &img->getObjectMemory() - , offset - , size - , get( image )->getSubresource( layer ) - , true ); - offset += layerSize; - } + doAddMappedResource( &img->getObjectMemory() + , offset + , size + , get( image )->getSubresource( layer ) + , true ); + offset += layerSize; } } @@ -1113,31 +1075,27 @@ namespace ashes::d3d11 void CommandBuffer::doProcessMappedBoundResourceOut( VkImageView image )const { auto img = get( get( image )->getImage() ); - - //if ( get( img->getMemory() )->isMapped() ) + auto & range = get( image )->getSubResourceRange(); + auto layerSize = getLevelsSize( img->getDimensions() + , img->getFormat() + , 0u + , img->getMipmapLevels() + , uint32_t( img->getMemoryAlignment() ) ); + auto size = getLevelsSize( img->getDimensions() + , img->getFormat() + , range.baseMipLevel + , range.levelCount + , uint32_t( img->getMemoryAlignment() ) ); + auto offset = img->getMemoryOffset(); + + for ( auto layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer ) { - auto & range = get( image )->getSubResourceRange(); - auto layerSize = getLevelsSize( img->getDimensions() - , img->getFormat() - , 0u - , img->getMipmapLevels() - , uint32_t( img->getMemoryAlignment() ) ); - auto size = getLevelsSize( img->getDimensions() - , img->getFormat() - , range.baseMipLevel - , range.levelCount - , uint32_t( img->getMemoryAlignment() ) ); - auto offset = img->getMemoryOffset(); - - for ( auto layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer ) - { - doAddMappedResource( &img->getObjectMemory() - , offset - , size - , get( image )->getSubresource( layer ) - , false ); - offset += layerSize; - } + doAddMappedResource( &img->getObjectMemory() + , offset + , size + , get( image )->getSubresource( layer ) + , false ); + offset += layerSize; } } @@ -1182,7 +1140,7 @@ namespace ashes::d3d11 { result = &m_mappedResources.emplace_back( memory , m_commands.size() - 1u - , get( memory->deviceMemory )->onDestroy.connect( [this, memory]( VkDeviceMemory deviceMemory ) + , get( memory->deviceMemory )->onDestroy.connect( [this, memory]( VkDeviceMemory ) { doRemoveMappedResource( memory ); } ) ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.hpp b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.hpp index 0351ee09d..6328c4917 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandBuffer.hpp @@ -17,24 +17,21 @@ namespace ashes::d3d11 CommandBuffer( VkDevice device , VkCommandPool commandPool , bool primary ); - ~CommandBuffer(); + ~CommandBuffer()noexcept; void execute( Context & context )const; VkResult begin( VkCommandBufferBeginInfo info )const; VkResult end()const; - VkResult reset( VkCommandBufferResetFlags flags )const; - void beginRenderPass( VkRenderPassBeginInfo beginInfo - , VkSubpassContents contents )const; - void nextSubpass( VkSubpassContents contents )const; + VkResult reset()const; + void beginRenderPass( VkRenderPassBeginInfo beginInfo )const; + void nextSubpass()const; void endRenderPass()const; void executeCommands( ArrayView< VkCommandBuffer const > commands )const; void clearColorImage( VkImage image - , VkImageLayout imageLayout , VkClearColorValue colour , ArrayView < VkImageSubresourceRange const > ranges )const; void clearDepthStencilImage( VkImage image - , VkImageLayout imageLayout , VkClearDepthStencilValue value , ArrayView< VkImageSubresourceRange const > ranges )const; void clearAttachments( ArrayView< VkClearAttachment const > clearAttachments @@ -75,10 +72,8 @@ namespace ashes::d3d11 , uint32_t stride )const; void copyToImage( VkBuffer src , VkImage dst - , VkImageLayout dstLayout , ArrayView< VkBufferImageCopy const > copyInfos )const; void copyToBuffer( VkImage src - , VkImageLayout srcLayout , VkBuffer dst , ArrayView< VkBufferImageCopy const > copyInfos )const; void updateBuffer( VkBuffer dstBuffer @@ -92,20 +87,14 @@ namespace ashes::d3d11 , VkBuffer dst , ArrayView< VkBufferCopy const > copyInfos )const; void copyImage( VkImage src - , VkImageLayout srcLayout , VkImage dst - , VkImageLayout dstLayout , ArrayView< VkImageCopy const > copyInfos )const; void blitImage( VkImage srcImage - , VkImageLayout srcLayout , VkImage dstImage - , VkImageLayout dstLayout , ArrayView< VkImageBlit const > regions , VkFilter filter )const; void resolveImage( VkImage srcImage - , VkImageLayout srcLayout , VkImage dstImage - , VkImageLayout dstLayout , ArrayView< VkImageResolve const > regions )const; void resetQueryPool( VkQueryPool pool , uint32_t firstQuery @@ -155,12 +144,10 @@ namespace ashes::d3d11 void waitEvents( ArrayView< VkEvent const > events , VkPipelineStageFlags srcStageMask , VkPipelineStageFlags dstStageMask - , ArrayView< VkMemoryBarrier const > memoryBarriers , ArrayView< VkBufferMemoryBarrier const > bufferMemoryBarriers , ArrayView< VkImageMemoryBarrier const > imageMemoryBarriers )const; void pipelineBarrier( VkPipelineStageFlags after , VkPipelineStageFlags before - , VkDependencyFlags dependencyFlags , ArrayView< VkMemoryBarrier const > memoryBarriers , ArrayView< VkBufferMemoryBarrier const > bufferMemoryBarriers , ArrayView< VkImageMemoryBarrier const > imageMemoryBarriers )const; @@ -241,22 +228,22 @@ namespace ashes::d3d11 mutable std::vector< ResourceIndex > m_mappedResources; struct State { - VkCommandBufferBeginInfo beginInfo; + VkCommandBufferBeginInfo beginInfo{}; VkPipeline currentPipeline{}; std::vector< std::pair < VkPipelineLayout, PushConstantsDesc > > pushConstantBuffers; VkPipeline currentComputePipeline{}; VkSubpassDescription const * currentSubpass{}; VkRenderPass currentRenderPass{}; VkFramebuffer currentFrameBuffer{}; - uint32_t currentSubpassIndex{ 0u }; + uint32_t currentSubpassIndex{}; mutable VbosBindingArray vbos; - VkIndexType indexType; + VkIndexType indexType{}; VkDescriptorSetArray boundDescriptors; VkBuffer newlyBoundIbo{}; - Optional< float > lineWidth; - Optional< DepthBias > depthBias; - Optional< std::array< float, 4u > > blendConstants; - Optional< DepthBounds > depthBounds; + Optional< float > lineWidth{}; + Optional< DepthBias > depthBias{}; + Optional< std::array< float, 4u > > blendConstants{}; + Optional< DepthBounds > depthBounds{}; std::array< Optional< uint32_t >, 2u > stencilCompareMask; std::array< Optional< uint32_t >, 2u > stencilWriteMask; std::array< Optional< uint32_t >, 2u > stencilReference; diff --git a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.cpp b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.cpp index 0e2d154e7..62f5213ff 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.cpp @@ -18,7 +18,7 @@ namespace ashes::d3d11 { } - CommandPool::~CommandPool() + CommandPool::~CommandPool()noexcept { for ( auto & command : m_commands ) { @@ -31,7 +31,7 @@ namespace ashes::d3d11 m_commands.push_back( commands ); } - VkResult CommandPool::reset( VkCommandPoolResetFlags flags ) + VkResult CommandPool::reset() { for ( auto & command : m_commands ) { @@ -42,15 +42,14 @@ namespace ashes::d3d11 return VK_SUCCESS; } - VkResult CommandPool::free( ArrayView< VkCommandBuffer const > commands ) + VkResult CommandPool::freeCommands( ArrayView< VkCommandBuffer const > commands )noexcept { for ( auto & command : commands ) { - auto it = std::find( m_commands.begin() - , m_commands.end() - , command ); - - if ( it != m_commands.end() ) + if ( auto it = std::find( m_commands.begin() + , m_commands.end() + , command ); + it != m_commands.end() ) { deallocateNA( command ); m_commands.erase( it ); diff --git a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.hpp b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.hpp index ea5f73627..0c898ff28 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/D3D11CommandPool.hpp @@ -9,15 +9,16 @@ See LICENSE file in root folder namespace ashes::d3d11 { class CommandPool + : public NonCopyable { public: CommandPool( VkDevice device , VkCommandPoolCreateInfo createInfo ); - ~CommandPool(); + ~CommandPool()noexcept; void registerCommands( VkCommandBuffer commands ); - VkResult reset( VkCommandPoolResetFlags flags ); - VkResult free( ArrayView< VkCommandBuffer const > sets ); + VkResult reset(); + VkResult freeCommands( ArrayView< VkCommandBuffer const > sets )noexcept; VkDevice getDevice()const { diff --git a/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.cpp b/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.cpp index ad5ed5f7c..896102386 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.cpp +++ b/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.cpp @@ -27,28 +27,22 @@ namespace ashes::d3d11 get( m_device )->getDevice()->CreateQuery( &desc, &m_waitIdleQuery ); } - Queue::~Queue() + Queue::~Queue()noexcept { safeRelease( m_waitIdleQuery ); } - VkResult Queue::submit( ArrayView< VkSubmitInfo const > const & infos - , VkFence fence )const + VkResult Queue::submit( ArrayView< VkSubmitInfo const > const & infos )const { for ( auto & info : infos ) { - doSubmit( makeArrayView( info.pCommandBuffers, info.commandBufferCount ) - , makeArrayView( info.pWaitSemaphores, info.waitSemaphoreCount ) - , makeArrayView( info.pWaitDstStageMask, info.waitSemaphoreCount ) - , makeArrayView( info.pSignalSemaphores, info.signalSemaphoreCount ) - , fence ); + doSubmit( makeArrayView( info.pCommandBuffers, info.commandBufferCount ) ); } return VK_SUCCESS; } - VkResult Queue::bindSparse( ArrayView< VkBindSparseInfo const > values - , VkFence fence )const + VkResult Queue::bindSparse()const { return VK_ERROR_FEATURE_NOT_PRESENT; } @@ -63,7 +57,7 @@ namespace ashes::d3d11 for ( auto & swapChain : makeArrayView( presentInfo.pSwapchains, presentInfo.swapchainCount ) ) { - *itResult = get( swapChain )->present( *itIndices ); + *itResult = get( swapChain )->present(); ++itResult; ++itIndices; } @@ -72,7 +66,7 @@ namespace ashes::d3d11 { for ( auto & swapChain : makeArrayView( presentInfo.pSwapchains, presentInfo.swapchainCount ) ) { - get( swapChain )->present( *itIndices ); + get( swapChain )->present(); ++itIndices; } } @@ -93,7 +87,7 @@ namespace ashes::d3d11 , 0u ) ) && !data ) { - std::this_thread::sleep_for( std::chrono::microseconds{ 1ull } ); + std::this_thread::sleep_for( std::chrono::microseconds{ 1ULL } ); } return data @@ -154,17 +148,13 @@ namespace ashes::d3d11 #endif - VkResult Queue::doSubmit( ArrayView< VkCommandBuffer const > const & commandBuffers - , ArrayView< VkSemaphore const > const & semaphoresToWait - , ArrayView< VkPipelineStageFlags const > const & semaphoresStage - , ArrayView< VkSemaphore const > const & semaphoresToSignal - , VkFence fence )const + VkResult Queue::doSubmit( ArrayView< VkCommandBuffer const > const & commandBuffers )const { Context context{ get( m_device )->getFeatureLevel(), m_device }; - for ( auto & commandBuffer : commandBuffers ) + for ( auto const & commandBuffer : commandBuffers ) { - auto & dxCommandBuffer = *get( commandBuffer ); + auto const & dxCommandBuffer = *get( commandBuffer ); dxCommandBuffer.execute( context ); context.uavs.clear(); } diff --git a/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.hpp b/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.hpp index 2285a7af3..852c9897b 100644 --- a/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.hpp +++ b/source/ashes/renderer/D3D11Renderer/Command/D3D11Queue.hpp @@ -12,16 +12,15 @@ namespace ashes::d3d11 { class Queue : public ashes::IcdObject + , public NonCopyable { public: Queue( VkDevice device , VkDeviceQueueCreateInfo createInfo , uint32_t index ); - ~Queue(); - VkResult submit( ArrayView< VkSubmitInfo const > const & infos - , VkFence fence )const; - VkResult bindSparse( ArrayView< VkBindSparseInfo const > values - , VkFence fence )const; + ~Queue()noexcept; + VkResult submit( ArrayView< VkSubmitInfo const > const & infos )const; + VkResult bindSparse()const; VkResult present( VkPresentInfoKHR const & presentInfo )const; VkResult waitIdle()const; #if VK_EXT_debug_utils @@ -41,11 +40,7 @@ namespace ashes::d3d11 } private: - VkResult doSubmit( ArrayView< VkCommandBuffer const > const & commandBuffers - , ArrayView< VkSemaphore const > const & semaphoresToWait - , ArrayView< VkPipelineStageFlags const > const & semaphoresStage - , ArrayView< VkSemaphore const > const & semaphoresToSignal - , VkFence fence )const; + VkResult doSubmit( ArrayView< VkCommandBuffer const > const & commandBuffers )const; private: VkDevice m_device; diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.cpp index 4f4ffc1f8..033b0d9bf 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.cpp @@ -46,12 +46,12 @@ namespace ashes::d3d11 , typename DataT , typename LayerT , typename CallbackT > - bool checkValid( CallbackT & callback - , LayerT const & layer - , VkBufferImageCopy const & copyInfo - , VkImage image - , DataT & data - , CheckFuncT check ) + bool checkValid( CallbackT & callback + , LayerT const & layer + , VkBufferImageCopy const & copyInfo + , VkImage image + , DataT & data + , CheckFuncT check ) { auto format = get( image )->getFormat(); VkExtent3D texelBlockExtent{ 1u, 1u, 1u }; @@ -83,28 +83,23 @@ namespace ashes::d3d11 auto texelBlockDepth = texelBlockSize / ( texelBlockExtent.width * texelBlockExtent.height ); auto result = VK_SUCCESS == check( callback - , layer , data , 0u == ( copyInfo.bufferOffset % texelBlockSize ) , "bufferOffset must be a multiple of the format's texel block size" ); result = result && VK_SUCCESS == check( callback - , layer , data , ( copyInfo.bufferOffset == 0u || 0u == ( copyInfo.bufferOffset % 4u ) ) , "bufferOffset must be a multiple of 4" ); result = result && VK_SUCCESS == check( callback - , layer , data , ( copyInfo.bufferRowLength == 0 ) || ( copyInfo.bufferRowLength >= copyInfo.imageExtent.width ) , "bufferRowLength must be 0, or greater than or equal to the width member of imageExtent" ); result = result && VK_SUCCESS == check( callback - , layer , data , ( copyInfo.bufferImageHeight == 0 ) || ( copyInfo.bufferImageHeight >= copyInfo.imageExtent.height ) , "bufferImageHeight must be 0, or greater than or equal to the height member of imageExtent" ); auto subresourceWidth = texelBlockWidth * get( image )->getDimensions().width >> copyInfo.imageSubresource.mipLevel; result = result && VK_SUCCESS == check( callback - , layer , data , ( copyInfo.imageOffset.x >= 0 && copyInfo.imageOffset.x <= int32_t( subresourceWidth ) ) && ( copyInfo.imageExtent.width + copyInfo.imageOffset.x >= 0 @@ -112,7 +107,6 @@ namespace ashes::d3d11 , "imageOffset.x and (imageExtent.width + imageOffset.x) must both be greater than or equal to 0 and less than or equal to the image subresource width" ); auto subresourceHeight = texelBlockHeight * get( image )->getDimensions().height >> copyInfo.imageSubresource.mipLevel; result = result && VK_SUCCESS == check( callback - , layer , data , ( copyInfo.imageOffset.y >= 0 && copyInfo.imageOffset.y <= int32_t( subresourceHeight ) ) && ( copyInfo.imageExtent.height + copyInfo.imageOffset.y >= 0 @@ -120,7 +114,6 @@ namespace ashes::d3d11 , "imageOffset.y and (imageExtent.height + imageOffset.y) must both be greater than or equal to 0 and less than or equal to the image subresource height" ); auto subresourceDepth = texelBlockDepth * get( image )->getDimensions().depth; result = result && VK_SUCCESS == check( callback - , layer , data , ( copyInfo.imageOffset.z >= 0 && copyInfo.imageOffset.z <= int32_t( subresourceDepth ) ) && ( copyInfo.imageExtent.depth + copyInfo.imageOffset.z >= 0 @@ -128,40 +121,34 @@ namespace ashes::d3d11 , "imageOffset.z and (imageExtent.depth + imageOffset.z) must both be greater than or equal to 0 and less than or equal to the image subresource depth" ); auto imageType = get( image )->getType(); result = result && VK_SUCCESS == check( callback - , layer , data , ( imageType != VK_IMAGE_TYPE_1D || ( copyInfo.imageOffset.y == 0 && copyInfo.imageExtent.height == 1u ) ) , "if the calling command's VkImage parameter is of type VK_IMAGE_TYPE_1D, then imageOffset.y must be 0 and imageExtent.height must be 1." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( imageType != VK_IMAGE_TYPE_1D && imageType != VK_IMAGE_TYPE_2D ) || ( copyInfo.imageOffset.z == 0 && copyInfo.imageExtent.depth == 1u ) ) , "if the calling command's VkImage parameter is of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D, then imageOffset.z must be 0 and imageExtent.depth must be 1." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( imageType != VK_IMAGE_TYPE_3D || ( copyInfo.imageSubresource.baseArrayLayer == 0 && copyInfo.imageSubresource.layerCount == 1u ) ) , "if the calling command's VkImage parameter is of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D, then imageOffset.z must be 0 and imageExtent.depth must be 1." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( !ashes::isCompressedFormat( format ) ) || ( ( copyInfo.bufferRowLength % texelBlockExtent.width ) == 0 ) ) , "If the calling command's VkImage parameter is a compressed image, or a single-plane, _422 image format, bufferRowLength must be a multiple of the compressed texel block width." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( !ashes::isCompressedFormat( format ) ) || ( ( copyInfo.bufferImageHeight % texelBlockExtent.height ) == 0 ) ) , "If the calling command's VkImage parameter is a compressed image, or a single-plane, _422 image format, bufferImageHeight must be a multiple of the compressed texel block height." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( !ashes::isCompressedFormat( format ) ) || ( ( copyInfo.imageOffset.x % texelBlockExtent.width ) == 0 @@ -169,39 +156,33 @@ namespace ashes::d3d11 && ( copyInfo.imageOffset.z % 1u ) == 0 ) ) , "If the calling command's VkImage parameter is a compressed image, or a single-plane, _422 image format, all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( !ashes::isCompressedFormat( format ) ) || ( ( copyInfo.bufferOffset % texelBlockSize ) == 0 ) ) , "If the calling command's VkImage parameter is a compressed image, or a single-plane, _422 image format, bufferOffset must be a multiple of the compressed texel block size in bytes." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( !ashes::isCompressedFormat( format ) ) || ( copyInfo.imageExtent.width % texelBlockExtent.width ) == 0 || ( copyInfo.imageExtent.width + copyInfo.imageOffset.x ) == subresourceWidth ) , "If the calling command's VkImage parameter is a compressed image, or a single-plane, _422 image format, imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x) must equal the image subresource width." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( !ashes::isCompressedFormat( format ) ) || ( copyInfo.imageExtent.height % texelBlockExtent.height ) == 0 || ( copyInfo.imageExtent.height + copyInfo.imageOffset.y ) == subresourceHeight ) , "If the calling command's VkImage parameter is a compressed image, or a single-plane, _422 image format, imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y) must equal the image subresource height." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( ( !ashes::isCompressedFormat( format ) ) || ( copyInfo.imageExtent.depth % texelBlockExtent.depth ) == 0 || ( copyInfo.imageExtent.depth + copyInfo.imageOffset.z ) == subresourceDepth ) , "If the calling command's VkImage parameter is a compressed image, or a single-plane, _422 image format, imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z) must equal the image subresource depth." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( checkFlag( copyInfo.imageSubresource.aspectMask, ashes::getAspectMask( format ) ) != 0u ) , "The aspectMask member of imageSubresource must specify aspects present in the calling command's VkImage parameter." ); result = result && VK_SUCCESS == check( callback - , layer , data , ( isOneBitSet( copyInfo.imageSubresource.aspectMask ) ) , "The aspectMask member of imageSubresource must specify aspects present in the calling command's VkImage parameter." ); @@ -215,54 +196,54 @@ namespace ashes::d3d11 }; using ErrorsMap = std::map< HRESULT, Error >; - - ErrorsMap const & getErrors() - { #if !defined( DXGI_ERROR_INVALID_CALL ) # define DXGI_ERROR_INVALID_CALL D3DERR_INVALIDCALL #endif #if !defined( DXGI_ERROR_WAS_STILL_DRAWING ) # define DXGI_ERROR_WAS_STILL_DRAWING D3DERR_WASSTILLDRAWING #endif - static ErrorsMap Errors - { - { D3D11_ERROR_FILE_NOT_FOUND, { "The file was not found.", VK_ERROR_INITIALIZATION_FAILED } }, - { D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS, { "There are too many unique instances of a particular type of state object.", VK_ERROR_INITIALIZATION_FAILED } }, - { D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS, { "There are too many unique instances of a particular type of view object.", VK_ERROR_INITIALIZATION_FAILED } }, - { D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, { "The first call to ID3D11DeviceContext::Map after either ID3D11Device::CreateDeferredContext or ID3D11DeviceContext::FinishCommandList per Resource was not D3D11_MAP_WRITE_DISCARD.", VK_ERROR_INITIALIZATION_FAILED } }, - { E_FAIL, { "Attempted to create a device with the debug layer enabled and the layer is not installed.", VK_ERROR_INITIALIZATION_FAILED } }, - { E_INVALIDARG, { "An invalid parameter was passed to the returning function.", VK_ERROR_INITIALIZATION_FAILED } }, - { E_OUTOFMEMORY, { "Direct3D could not allocate sufficient memory to complete the call.", VK_ERROR_OUT_OF_DEVICE_MEMORY } }, - { E_NOTIMPL, { "The method call isn't implemented with the passed parameter combination.", VK_ERROR_INITIALIZATION_FAILED } }, - { S_FALSE, { "Alternate success value, indicating a successful but nonstandard completion( the precise meaning depends on context ).", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_INVALID_CALL, { "The method call is invalid.For example, a method's parameter may not be a valid pointer.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_ACCESS_DENIED, { "You tried to use a resource to which you did not have the required access privileges.This error is most typically caused when you write to a shared resource with read - only access.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_ACCESS_LOST, { "The desktop duplication interface is invalid.The desktop duplication interface typically becomes invalid when a different type of image is displayed on the desktop.", VK_ERROR_INITIALIZATION_FAILED } }, + inline ErrorsMap const Errors + { + { D3D11_ERROR_FILE_NOT_FOUND, { "The file was not found.", VK_ERROR_INITIALIZATION_FAILED } }, + { D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS, { "There are too many unique instances of a particular type of state object.", VK_ERROR_INITIALIZATION_FAILED } }, + { D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS, { "There are too many unique instances of a particular type of view object.", VK_ERROR_INITIALIZATION_FAILED } }, + { D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, { "The first call to ID3D11DeviceContext::Map after either ID3D11Device::CreateDeferredContext or ID3D11DeviceContext::FinishCommandList per Resource was not D3D11_MAP_WRITE_DISCARD.", VK_ERROR_INITIALIZATION_FAILED } }, + { E_FAIL, { "Attempted to create a device with the debug layer enabled and the layer is not installed.", VK_ERROR_INITIALIZATION_FAILED } }, + { E_INVALIDARG, { "An invalid parameter was passed to the returning function.", VK_ERROR_INITIALIZATION_FAILED } }, + { E_OUTOFMEMORY, { "Direct3D could not allocate sufficient memory to complete the call.", VK_ERROR_OUT_OF_DEVICE_MEMORY } }, + { E_NOTIMPL, { "The method call isn't implemented with the passed parameter combination.", VK_ERROR_INITIALIZATION_FAILED } }, + { S_FALSE, { "Alternate success value, indicating a successful but nonstandard completion( the precise meaning depends on context ).", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_INVALID_CALL, { "The method call is invalid.For example, a method's parameter may not be a valid pointer.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_ACCESS_DENIED, { "You tried to use a resource to which you did not have the required access privileges.This error is most typically caused when you write to a shared resource with read - only access.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_ACCESS_LOST, { "The desktop duplication interface is invalid.The desktop duplication interface typically becomes invalid when a different type of image is displayed on the desktop.", VK_ERROR_INITIALIZATION_FAILED } }, #if defined( DXGI_ERROR_ALREADY_EXISTS ) - { DXGI_ERROR_ALREADY_EXISTS, { "The desired element already exists.This is returned by DXGIDeclareAdapterRemovalSupport if it is not the first time that the function is called.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_ALREADY_EXISTS, { "The desired element already exists.This is returned by DXGIDeclareAdapterRemovalSupport if it is not the first time that the function is called.", VK_ERROR_INITIALIZATION_FAILED } }, #endif - { DXGI_ERROR_CANNOT_PROTECT_CONTENT, { "DXGI can't provide content protection on the swap chain. This error is typically caused by an older driver, or when you use a swap chain that is incompatible with content protection.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_DEVICE_HUNG, { "The application's device failed due to badly formed commands sent by the application. This is an design-time issue that should be investigated and fixed.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_DEVICE_REMOVED, { "The video card has been physically removed from the system, or a driver upgrade for the video card has occurred.The application should destroy and recreate the device.For help debugging the problem, call ID3D10Device::GetDeviceRemovedReason.", VK_ERROR_DEVICE_LOST } }, - { DXGI_ERROR_DEVICE_RESET, { "The device failed due to a badly formed command.This is a run - time issue; The application should destroy and recreate the device.", VK_ERROR_DEVICE_LOST } }, - { DXGI_ERROR_DRIVER_INTERNAL_ERROR, { "The driver encountered a problem and was put into the device removed state.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_FRAME_STATISTICS_DISJOINT, { "An event( for example, a power cycle ) interrupted the gathering of presentation statistics.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE, { "The application attempted to acquire exclusive ownership of an output, but failed because some other application( or device within the application ) already acquired ownership.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_MORE_DATA, { "The buffer supplied by the application is not big enough to hold the requested data.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_NAME_ALREADY_EXISTS, { "The supplied name of a resource in a call to IDXGIResource1::CreateSharedHandle is already associated with some other resource.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_NONEXCLUSIVE, { "A global counter resource is in use, and the Direct3D device can't currently use the counter resource.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_NOT_CURRENTLY_AVAILABLE, { "The resource or request is not currently available, but it might become available later.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_NOT_FOUND, { "When calling IDXGIObject::GetPrivateData, the GUID passed in is not recognized as one previously passed to IDXGIObject::SetPrivateData or IDXGIObject::SetPrivateDataInterface.When calling IDXGIFactory::EnumAdapters or IDXGIAdapter::EnumOutputs, the enumerated ordinal is out of range.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED, { "Reserved", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_REMOTE_OUTOFMEMORY, { "Reserved", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_RESTRICT_TO_OUTPUT_STALE, { "The DXGI output( monitor ) to which the swap chain content was restricted is now disconnected or changed.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_SDK_COMPONENT_MISSING, { "The operation depends on an SDK component that is missing or mismatched.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_SESSION_DISCONNECTED, { "The Remote Desktop Services session is currently disconnected.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_UNSUPPORTED, { "The requested functionality is not supported by the device or the driver.", VK_ERROR_INITIALIZATION_FAILED } }, - { DXGI_ERROR_WAIT_TIMEOUT, { "The time - out interval elapsed before the next desktop frame was available.", VK_TIMEOUT } }, - { DXGI_ERROR_WAS_STILL_DRAWING, { "The GPU was busy at the moment when a call was made to perform an operation, and did not execute or schedule the operation.", VK_ERROR_INITIALIZATION_FAILED } }, - { S_OK, { "No error occurred.", VK_SUCCESS } }, - }; + { DXGI_ERROR_CANNOT_PROTECT_CONTENT, { "DXGI can't provide content protection on the swap chain. This error is typically caused by an older driver, or when you use a swap chain that is incompatible with content protection.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_DEVICE_HUNG, { "The application's device failed due to badly formed commands sent by the application. This is an design-time issue that should be investigated and fixed.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_DEVICE_REMOVED, { "The video card has been physically removed from the system, or a driver upgrade for the video card has occurred.The application should destroy and recreate the device.For help debugging the problem, call ID3D10Device::GetDeviceRemovedReason.", VK_ERROR_DEVICE_LOST } }, + { DXGI_ERROR_DEVICE_RESET, { "The device failed due to a badly formed command.This is a run - time issue; The application should destroy and recreate the device.", VK_ERROR_DEVICE_LOST } }, + { DXGI_ERROR_DRIVER_INTERNAL_ERROR, { "The driver encountered a problem and was put into the device removed state.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_FRAME_STATISTICS_DISJOINT, { "An event( for example, a power cycle ) interrupted the gathering of presentation statistics.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE, { "The application attempted to acquire exclusive ownership of an output, but failed because some other application( or device within the application ) already acquired ownership.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_MORE_DATA, { "The buffer supplied by the application is not big enough to hold the requested data.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_NAME_ALREADY_EXISTS, { "The supplied name of a resource in a call to IDXGIResource1::CreateSharedHandle is already associated with some other resource.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_NONEXCLUSIVE, { "A global counter resource is in use, and the Direct3D device can't currently use the counter resource.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_NOT_CURRENTLY_AVAILABLE, { "The resource or request is not currently available, but it might become available later.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_NOT_FOUND, { "When calling IDXGIObject::GetPrivateData, the GUID passed in is not recognized as one previously passed to IDXGIObject::SetPrivateData or IDXGIObject::SetPrivateDataInterface.When calling IDXGIFactory::EnumAdapters or IDXGIAdapter::EnumOutputs, the enumerated ordinal is out of range.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED, { "Reserved", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_REMOTE_OUTOFMEMORY, { "Reserved", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_RESTRICT_TO_OUTPUT_STALE, { "The DXGI output( monitor ) to which the swap chain content was restricted is now disconnected or changed.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_SDK_COMPONENT_MISSING, { "The operation depends on an SDK component that is missing or mismatched.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_SESSION_DISCONNECTED, { "The Remote Desktop Services session is currently disconnected.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_UNSUPPORTED, { "The requested functionality is not supported by the device or the driver.", VK_ERROR_INITIALIZATION_FAILED } }, + { DXGI_ERROR_WAIT_TIMEOUT, { "The time - out interval elapsed before the next desktop frame was available.", VK_TIMEOUT } }, + { DXGI_ERROR_WAS_STILL_DRAWING, { "The GPU was busy at the moment when a call was made to perform an operation, and did not execute or schedule the operation.", VK_ERROR_INITIALIZATION_FAILED } }, + { S_OK, { "No error occurred.", VK_SUCCESS } }, + }; + + ErrorsMap const & getErrors() + { return Errors; } } @@ -326,10 +307,9 @@ namespace ashes::d3d11 namespace du { VkResult check( DebugUtilsMessengerEXT & callback - , DebugUtilsLayer const & layer , MessageData report , bool condition - , std::string message ) + , std::string const & message ) { if ( !condition ) { @@ -403,7 +383,7 @@ namespace ashes::d3d11 } bool DebugUtilsLayer::onCheckHResultCommand( HRESULT hresult - , std::string message )const + , std::string const & message )const { static MessageData const baseMessage { @@ -426,19 +406,16 @@ namespace ashes::d3d11 std::stringstream stream; stream.imbue( std::locale{ "C" } ); stream << "Error calling [" << message << "]: " << std::hex << hresult; - auto it = getErrors().find( hresult ); - VkResult ret{ VK_ERROR_INITIALIZATION_FAILED }; - if ( it != getErrors().end() ) + if ( auto it = getErrors().find( hresult ); + it != getErrors().end() ) { stream << "\n Direct3D: " << it->second.name; - ret = it->second.result; } stream << "\n Windows: " << getLastErrorText(); messageData.callbackData.messageIdNumber = hresult; du::check( m_callback - , *this , std::move( messageData ) , false , stream.str() ); @@ -512,12 +489,12 @@ namespace ashes::d3d11 get( m_instance )->registerLayer( &m_layer ); } - DebugUtilsMessengerEXT::~DebugUtilsMessengerEXT() + DebugUtilsMessengerEXT::~DebugUtilsMessengerEXT()noexcept { get( m_instance )->unregisterLayer( &m_layer ); } - bool DebugUtilsMessengerEXT::report( MessageData report ) + bool DebugUtilsMessengerEXT::report( MessageData const & report )noexcept { if ( report.messageTypes & m_createInfo.messageType && m_createInfo.messageSeverity & report.messageSeverity ) @@ -541,10 +518,9 @@ namespace ashes::d3d11 namespace dr { VkResult check( DebugReportCallbackEXT & callback - , DebugReportLayer const & layer , ReportData report , bool condition - , std::string message ) + , std::string const & message ) { if ( !condition ) { @@ -609,7 +585,7 @@ namespace ashes::d3d11 } bool DebugReportLayer::onCheckHResultCommand( HRESULT hresult - , std::string message )const + , std::string const & message )const { static ReportData const baseReport { @@ -628,19 +604,16 @@ namespace ashes::d3d11 std::stringstream stream; stream.imbue( std::locale{ "C" } ); stream << "Error calling [" << message << "]: " << std::hex << hresult; - auto it = getErrors().find( hresult ); - VkResult ret{ VK_ERROR_INITIALIZATION_FAILED }; - if ( it != getErrors().end() ) + if ( auto it = getErrors().find( hresult ); + it != getErrors().end() ) { stream << "\n Direct3D: " << it->second.name; - ret = it->second.result; } stream << "\n Windows: " << getLastErrorText(); report.messageCode = hresult; dr::check( m_callback - , *this , std::move( report ) , false , stream.str() ); @@ -704,12 +677,12 @@ namespace ashes::d3d11 get( m_instance )->registerLayer( &m_layer ); } - DebugReportCallbackEXT::~DebugReportCallbackEXT() + DebugReportCallbackEXT::~DebugReportCallbackEXT()noexcept { get( m_instance )->unregisterLayer( &m_layer ); } - bool DebugReportCallbackEXT::report( ReportData report ) + bool DebugReportCallbackEXT::report( ReportData report )noexcept { if ( report.flags & m_createInfo.flags ) { diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.hpp index ce209b47c..fac80a0a3 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11DebugReportCallback.hpp @@ -14,6 +14,8 @@ namespace ashes::d3d11 struct MessageData { + ~MessageData()noexcept = default; + MessageData( MessageData const & rhs ) : messageSeverity{ rhs.messageSeverity } , messageTypes{ rhs.messageTypes } @@ -106,7 +108,7 @@ namespace ashes::d3d11 : public Layer { public: - DebugUtilsLayer( DebugUtilsMessengerEXT & callback ); + explicit DebugUtilsLayer( DebugUtilsMessengerEXT & callback ); bool onBufferImageCommand( VkCommandBuffer cmd , VkBufferImageCopy const & copyInfo , VkBuffer buffer @@ -116,7 +118,7 @@ namespace ashes::d3d11 , VkBuffer src , VkImage dst )const override; bool onCheckHResultCommand( HRESULT hresult - , std::string message )const override; + , std::string const & message )const override; # if VK_EXT_debug_report void onReportMessage( VkDebugReportFlagsEXT flags , VkDebugReportObjectTypeEXT objectType @@ -135,20 +137,21 @@ namespace ashes::d3d11 }; class DebugUtilsMessengerEXT + : public NonCopyable { public: DebugUtilsMessengerEXT( VkInstance instance , VkDebugUtilsMessengerCreateInfoEXT createInfo ); - ~DebugUtilsMessengerEXT(); + ~DebugUtilsMessengerEXT()noexcept; - bool report( MessageData report ); + bool report( MessageData const & report )noexcept; - inline DebugUtilsLayer const & getLayer()const + inline DebugUtilsLayer const & getLayer()const noexcept { return m_layer; } - VkInstance getInstance()const + VkInstance getInstance()const noexcept { return m_instance; } @@ -179,7 +182,7 @@ namespace ashes::d3d11 : public Layer { public: - DebugReportLayer( DebugReportCallbackEXT & callback ); + explicit DebugReportLayer( DebugReportCallbackEXT & callback ); bool onBufferImageCommand( VkCommandBuffer cmd , VkBufferImageCopy const & copyInfo , VkBuffer buffer @@ -189,7 +192,7 @@ namespace ashes::d3d11 , VkBuffer src , VkImage dst )const override; bool onCheckHResultCommand( HRESULT hresult - , std::string message )const override; + , std::string const & message )const override; void onReportMessage( VkDebugReportFlagsEXT flags , VkDebugReportObjectTypeEXT objectType , uint64_t object @@ -208,20 +211,21 @@ namespace ashes::d3d11 }; class DebugReportCallbackEXT + : public NonCopyable { public: DebugReportCallbackEXT( VkInstance instance , VkDebugReportCallbackCreateInfoEXT createInfo ); - ~DebugReportCallbackEXT(); + ~DebugReportCallbackEXT()noexcept; - bool report( ReportData report ); + bool report( ReportData report )noexcept; - inline DebugReportLayer const & getLayer()const + inline DebugReportLayer const & getLayer()const noexcept { return m_layer; } - VkInstance getInstance()const + VkInstance getInstance()const noexcept { return m_instance; } diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.cpp index 672e1cf2a..7b9af7c76 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.cpp @@ -94,9 +94,9 @@ namespace ashes::d3d11 void doCheckEnabledExtensions( VkPhysicalDevice physicalDevice , ashes::ArrayView< char const * const > const & extensions ) { - auto available = get( physicalDevice )->enumerateExtensionProperties( nullptr ); + auto const & available = get( physicalDevice )->enumerateExtensionProperties(); - for ( auto & extension : extensions ) + for ( auto extension : extensions ) { if ( available.end() == std::find_if( available.begin() , available.end() @@ -165,29 +165,35 @@ namespace ashes::d3d11 } ); } - Device::~Device() + Device::~Device()noexcept { - for ( auto creates : m_queues ) + for ( auto const & [_, creates] : m_queues ) { - for ( auto queue : creates.second.queues ) + for ( auto queue : creates.queues ) { deallocateNA( queue ); } } - for ( auto & it : m_stagingTextures ) + for ( auto & [_, staging] : m_stagingTextures ) { - deallocate( it.second.first, getAllocationCallbacks() ); - deallocate( it.second.second, getAllocationCallbacks() ); + deallocate( staging.first, getAllocationCallbacks() ); + deallocate( staging.second, getAllocationCallbacks() ); } deallocate( m_sampler, getAllocationCallbacks() ); deallocate( m_dummyIndexed.memory, getAllocationCallbacks() ); deallocate( m_dummyIndexed.buffer, getAllocationCallbacks() ); - m_mtxDeviceContext.lock(); - safeRelease( m_deviceContext ); - m_mtxDeviceContext.unlock(); + try + { + lock_type lock{ m_mtxDeviceContext }; + safeRelease( m_deviceContext ); + } + catch ( ... ) + { + // What to do here ? + } safeRelease( m_waitIdleQuery ); safeRelease( m_d3dDevice ); @@ -211,7 +217,7 @@ namespace ashes::d3d11 return m_deviceContext; } - void Device::unlockImmediateContext()const + void Device::unlockImmediateContext()const noexcept { m_mtxDeviceContext.unlock(); } @@ -276,7 +282,7 @@ namespace ashes::d3d11 deduced } ); get( result )->bindMemory( resMem, 0u ); - it = m_stagingTextures.emplace( key, std::make_pair( result, resMem ) ).first; + it = m_stagingTextures.try_emplace( key, result, resMem ).first; } memory = it->second.second; @@ -291,8 +297,8 @@ namespace ashes::d3d11 auto byteSize = getTexelBlockByteSize( extent, get( image )->getFormat() ); auto mipWidth = getSubresourceValue( get( image )->getDimensions().width, subresource.mipLevel ); auto mipHeight = getSubresourceValue( get( image )->getDimensions().height, subresource.mipLevel ); - layout.rowPitch = byteSize * mipWidth / ( extent.width * extent.height * extent.depth ); - layout.arrayPitch = layout.rowPitch * mipHeight * extent.height / ( extent.width * extent.depth ); + layout.rowPitch = VkDeviceSize( byteSize ) * mipWidth / ( VkDeviceSize( extent.width ) * extent.height * extent.depth ); + layout.arrayPitch = layout.rowPitch * mipHeight * extent.height / ( VkDeviceSize( extent.width ) * extent.depth ); layout.depthPitch = layout.arrayPitch; layout.offset = subresource.arrayLayer * layout.arrayPitch; layout.size = layout.arrayPitch * get( image )->getDimensions().depth; @@ -302,7 +308,7 @@ namespace ashes::d3d11 VkResult Device::setDebugUtilsObjectName( VkDebugUtilsObjectNameInfoEXT const & nameInfo )const { - HRESULT hr = S_OK; + auto hr = S_OK; switch ( nameInfo.objectType ) { @@ -346,7 +352,7 @@ namespace ashes::d3d11 : VK_ERROR_INVALID_DEVICE_ADDRESS_EXT; } - VkResult Device::setDebugUtilsObjectTag( VkDebugUtilsObjectTagInfoEXT const & tagInfo )const + VkResult Device::setDebugUtilsObjectTag( VkDebugUtilsObjectTagInfoEXT const & )const { return VK_SUCCESS; } @@ -372,14 +378,14 @@ namespace ashes::d3d11 #endif #if VK_EXT_debug_marker - VkResult Device::debugMarkerSetObjectTag( VkDebugMarkerObjectTagInfoEXT const & tagInfo )const + VkResult Device::debugMarkerSetObjectTag( VkDebugMarkerObjectTagInfoEXT const & )const { return VK_SUCCESS; } VkResult Device::debugMarkerSetObjectName( VkDebugMarkerObjectNameInfoEXT const & nameInfo )const { - HRESULT hr = S_OK; + auto hr = S_OK; switch ( nameInfo.objectType ) { @@ -432,7 +438,7 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ) + , const char * pMessage )const noexcept { get( m_instance )->reportMessage( flags , objectType @@ -449,7 +455,7 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ) + , const char * pMessage )const noexcept { get( m_instance )->onReportMessage( flags , objectType @@ -507,7 +513,7 @@ namespace ashes::d3d11 , 0u ) ) && !data ) { - std::this_thread::sleep_for( std::chrono::microseconds{ 1ull } ); + std::this_thread::sleep_for( std::chrono::microseconds{ 1ULL } ); } return data @@ -515,7 +521,7 @@ namespace ashes::d3d11 : VK_TIMEOUT; } - bool Device::onCopyToImageCommand( VkCommandBuffer cmd + void Device::onCopyToImageCommand( VkCommandBuffer cmd , ArrayView< VkBufferImageCopy const > const & copyInfo , VkBuffer src , VkImage dst )const @@ -523,10 +529,10 @@ namespace ashes::d3d11 return get( m_instance )->onCopyToImageCommand( cmd, copyInfo, src, dst ); } - bool Device::onCheckHResultCommand( HRESULT hresult - , std::string message )const + void Device::onCheckHResultCommand( HRESULT hresult + , std::string const & message )const { - return get( m_instance )->onCheckHResultCommand( hresult, std::move( message ) ); + return get( m_instance )->onCheckHResultCommand( hresult, message ); } void Device::doCreateD3D11Device() @@ -541,7 +547,6 @@ namespace ashes::d3d11 D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1, }; - HRESULT hr; UINT flags = 0; #if !defined( NDEBUG ) @@ -550,8 +555,8 @@ namespace ashes::d3d11 D3D_FEATURE_LEVEL supportedFeatureLevel = get( m_physicalDevice )->getFeatureLevel(); { - std::unique_lock< std::mutex > lock{ m_mtxDeviceContext }; - hr = D3D11CreateDevice( nullptr + lock_type lock{ m_mtxDeviceContext }; + D3D11CreateDevice( nullptr , D3D_DRIVER_TYPE_HARDWARE , nullptr , flags @@ -611,7 +616,7 @@ namespace ashes::d3d11 deduced } ); get( m_dummyIndexed.buffer )->bindMemory( m_dummyIndexed.memory, 0u ); - uint32_t * buffer; + uint32_t * buffer{}; if ( VK_SUCCESS == get( m_dummyIndexed.memory )->lock( 0u , size @@ -628,17 +633,16 @@ namespace ashes::d3d11 { for ( auto & queueCreateInfo : makeArrayView( m_createInfos.pQueueCreateInfos, m_createInfos.queueCreateInfoCount ) ) { - auto it = m_queues.emplace( queueCreateInfo.queueFamilyIndex - , QueueCreates{ queueCreateInfo, {} } ).first; + auto & queueCreates = m_queues.try_emplace( queueCreateInfo.queueFamilyIndex, queueCreateInfo ).first->second; for ( auto i = 0u; i < queueCreateInfo.queueCount; ++i ) { VkQueue queue; allocateNA( queue , get( this ) - , it->second.createInfo - , uint32_t( it->second.queues.size() ) ); - it->second.queues.emplace_back( queue ); + , queueCreates.createInfo + , uint32_t( queueCreates.queues.size() ) ); + queueCreates.queues.emplace_back( queue ); } } } diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.hpp index 7abcd53c0..9963fe6e6 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Device.hpp @@ -27,12 +27,14 @@ namespace ashes::d3d11 class Device : public ashes::IcdObject { + using lock_type = std::unique_lock< std::mutex >; + public: Device( VkInstance instance , VkPhysicalDevice physicalDevice , VkAllocationCallbacks const * callbacks , VkDeviceCreateInfo createInfos ); - ~Device(); + ~Device()noexcept; DeviceContextLock getImmediateContext()const; @@ -64,14 +66,14 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ); + , const char * pMessage )const noexcept; void onReportMessage( VkDebugReportFlagsEXT flags , VkDebugReportObjectTypeEXT objectType , uint64_t object , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ); + , const char * pMessage )const noexcept; #endif VkQueue getQueue( uint32_t familyIndex , uint32_t index )const; @@ -81,12 +83,12 @@ namespace ashes::d3d11 * Layers delegation. */ /**@{*/ - bool onCopyToImageCommand( VkCommandBuffer cmd + void onCopyToImageCommand( VkCommandBuffer cmd , ArrayView< VkBufferImageCopy const > const & copyInfo , VkBuffer src , VkImage dst )const; - bool onCheckHResultCommand( HRESULT hresult - , std::string message )const; + void onCheckHResultCommand( HRESULT hresult + , std::string const & message )const; /**@}*/ /** *name @@ -145,11 +147,18 @@ namespace ashes::d3d11 friend class DeviceContextLock; ID3D11DeviceContext * lockImmediateContext()const; - void unlockImmediateContext()const; + void unlockImmediateContext()const noexcept; private: struct QueueCreates { + QueueCreates( VkDeviceQueueCreateInfo createInfo + , std::vector< VkQueue > queues = {} ) + : createInfo{ std::move( createInfo ) } + , queues{ std::move( queues ) } + { + } + VkDeviceQueueCreateInfo createInfo; std::vector< VkQueue > queues; }; diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.cpp index 8cf2b1c3c..6c8f739b1 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.cpp @@ -16,7 +16,12 @@ namespace ashes::d3d11 { } - DeviceContextLock::DeviceContextLock( DeviceContextLock && rhs ) + DeviceContextLock::DeviceContextLock( ID3D11DeviceContext * context )noexcept + : m_context{ context } + { + } + + DeviceContextLock::DeviceContextLock( DeviceContextLock && rhs )noexcept : m_device{ rhs.m_device } , m_context{ rhs.m_context } { @@ -24,7 +29,7 @@ namespace ashes::d3d11 rhs.m_context = nullptr; } - DeviceContextLock & DeviceContextLock::operator=( DeviceContextLock && rhs ) + DeviceContextLock & DeviceContextLock::operator=( DeviceContextLock && rhs )noexcept { m_device = rhs.m_device; m_context = rhs.m_context; @@ -35,7 +40,7 @@ namespace ashes::d3d11 return *this; } - DeviceContextLock::~DeviceContextLock() + DeviceContextLock::~DeviceContextLock()noexcept { if ( m_device ) { diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.hpp index 77e3663a9..b127d42c0 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11DeviceContextLock.hpp @@ -13,10 +13,11 @@ namespace ashes::d3d11 public: DeviceContextLock( DeviceContextLock const & ) = delete; DeviceContextLock & operator=( DeviceContextLock const & ) = delete; - DeviceContextLock( DeviceContextLock && rhs ); - DeviceContextLock & operator=( DeviceContextLock && rhs ); - DeviceContextLock( Device const * device ); - ~DeviceContextLock(); + DeviceContextLock( DeviceContextLock && rhs )noexcept; + DeviceContextLock & operator=( DeviceContextLock && rhs )noexcept; + explicit DeviceContextLock( Device const * device ); + explicit DeviceContextLock( ID3D11DeviceContext * context )noexcept; + ~DeviceContextLock()noexcept; ID3D11DeviceContext * operator->()const { @@ -29,7 +30,7 @@ namespace ashes::d3d11 } private: - Device const * m_device; - ID3D11DeviceContext * m_context; + Device const * m_device{}; + ID3D11DeviceContext * m_context{}; }; } diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.cpp index 4fdddd2fd..5589fa1e7 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.cpp @@ -19,7 +19,7 @@ namespace ashes::d3d11 , m_format{ format } , m_descs{ descs } { - for ( auto & desc : m_descs ) + for ( auto const & desc : m_descs ) { VkDisplayModeParametersKHR parameters { @@ -49,7 +49,7 @@ namespace ashes::d3d11 } } - DisplayKHR::~DisplayKHR() + DisplayKHR::~DisplayKHR()noexcept { for ( auto & displayMode : m_displayModes ) { diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.hpp index b5b7e37eb..e618da790 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Display.hpp @@ -9,13 +9,14 @@ See LICENSE file in root folder namespace ashes::d3d11 { class DisplayKHR + : public NonCopyable { public: DisplayKHR( VkPhysicalDevice physicalDevice , VkExtent2D const & extent , VkFormat format , std::vector< DXGI_MODE_DESC > const & desc ); - ~DisplayKHR(); + ~DisplayKHR()noexcept; std::vector< VkDisplayModePropertiesKHR > const & getDisplayModeProperties()const; DXGI_MODE_DESC const & getDesc( VkDisplayModeParametersKHR const & parameters )const; diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.cpp index e0a593b35..6ba241dda 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.cpp @@ -10,17 +10,13 @@ See LICENSE file in root folder. namespace ashes::d3d11 { DisplayModeKHR::DisplayModeKHR( VkDisplayKHR display - , VkDisplayModeCreateInfoKHR createInfo ) + , VkDisplayModeCreateInfoKHR const & createInfo ) : m_display{ display } , m_desc{ get( m_display )->getDesc( createInfo.parameters ) } { } - DisplayModeKHR::~DisplayModeKHR() - { - } - - VkDisplayPlaneCapabilitiesKHR DisplayModeKHR::getDisplayPlaneCapabilities( uint32_t planeIndex ) + VkDisplayPlaneCapabilitiesKHR DisplayModeKHR::getDisplayPlaneCapabilities() { VkExtent2D defaultExt{ get( m_display )->getExtent() }; VkOffset2D defaultMinPos{}; diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.hpp index 77ead8e90..0ad84434f 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11DisplayMode.hpp @@ -12,10 +12,9 @@ namespace ashes::d3d11 { public: DisplayModeKHR( VkDisplayKHR display - , VkDisplayModeCreateInfoKHR createInfo ); - ~DisplayModeKHR(); + , VkDisplayModeCreateInfoKHR const & createInfo ); - VkDisplayPlaneCapabilitiesKHR getDisplayPlaneCapabilities( uint32_t planeIndex ); + VkDisplayPlaneCapabilitiesKHR getDisplayPlaneCapabilities(); DXGI_MODE_DESC const & getDesc()const { diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.cpp index 9398347ae..60fb3653e 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.cpp @@ -24,13 +24,36 @@ namespace ashes::d3d11 { namespace { + inline VkPhysicalDeviceMemoryProperties const MemoryProperties = []() + { + VkPhysicalDeviceMemoryProperties result{}; + // Emulate one device local heap + result.memoryHeaps[result.memoryHeapCount++] = { ~0ULL, VK_MEMORY_HEAP_DEVICE_LOCAL_BIT }; + // and one host visible heap + result.memoryHeaps[result.memoryHeapCount++] = { ~0ULL, 0u }; + + // Emulate all combinations of device local memory types + // and all combinations of host visible memory types + result.memoryTypes[result.memoryTypeCount++] = { VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0u }; + result.memoryTypes[result.memoryTypeCount++] = { VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1u }; + result.memoryTypes[result.memoryTypeCount++] = { VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, 1u }; + + return result; + }(); + + inline VkPhysicalDeviceMemoryProperties2KHR const MemoryProperties2 = []() + { + VkPhysicalDeviceMemoryProperties2KHR result{}; + result.memoryProperties = Instance::getMemoryProperties(); + return result; + }(); + IDXGIFactory * createDXGIFactory() { - IDXGIFactory * result; - HRESULT hr = CreateDXGIFactory( __uuidof( IDXGIFactory ) - , reinterpret_cast< void ** >( &result ) ); + IDXGIFactory * result{}; - if ( hr != S_OK ) + if ( CreateDXGIFactory( __uuidof( IDXGIFactory ) + , reinterpret_cast< void ** >( &result ) ) != S_OK ) { throw ashes::BaseException{ "Can't create Factory object" }; } @@ -38,8 +61,7 @@ namespace ashes::d3d11 return result; } - D3D_FEATURE_LEVEL getSupportedFeatureLevel( IDXGIFactory * factory - , IDXGIAdapter * adapter ) + D3D_FEATURE_LEVEL getSupportedFeatureLevel( IDXGIAdapter * adapter ) { static std::vector< D3D_FEATURE_LEVEL > const requestedFeatureLevels { @@ -51,19 +73,19 @@ namespace ashes::d3d11 D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1, }; - D3D_FEATURE_LEVEL result; - auto hr = D3D11CreateDevice( adapter - , D3D_DRIVER_TYPE_UNKNOWN - , nullptr - , 0u - , requestedFeatureLevels.data() - , UINT( requestedFeatureLevels.size() ) - , D3D11_SDK_VERSION - , nullptr - , &result - , nullptr ); - - if ( !SUCCEEDED( hr ) ) + D3D_FEATURE_LEVEL result{}; + + if ( auto hr = D3D11CreateDevice( adapter + , D3D_DRIVER_TYPE_UNKNOWN + , nullptr + , 0u + , requestedFeatureLevels.data() + , UINT( requestedFeatureLevels.size() ) + , D3D11_SDK_VERSION + , nullptr + , &result + , nullptr ); + !SUCCEEDED( hr ) ) { throw ashes::Exception{ VK_ERROR_INCOMPATIBLE_DRIVER, "Feature level retrieval" }; } @@ -92,7 +114,7 @@ namespace ashes::d3d11 ( void )adapter->EnumOutputs( 0, &info.output ); - info.featureLevel = getSupportedFeatureLevel( factory, adapter ); + info.featureLevel = getSupportedFeatureLevel( adapter ); result.push_back( info ); ++index; @@ -105,21 +127,65 @@ namespace ashes::d3d11 { auto result = D3D_FEATURE_LEVEL_9_1; - for ( auto adapter : adapters ) + for ( auto const & adapter : adapters ) { result = std::max( adapter.featureLevel, result ); } return result; } + + void checkEnabledExtensions( ashes::ArrayView< char const * const > const & extensions ) + { + auto & available = getSupportedInstanceExtensions( nullptr ); + + for ( auto const & extension : extensions ) + { + if ( available.end() == std::find_if( available.begin() + , available.end() + , [&extension]( VkExtensionProperties const & lookup ) + { + return lookup.extensionName == std::string{ extension }; + } ) ) + { + throw ExtensionNotPresentException{ extension }; + } + } + } + + bool hasEnabledExtensions( ashes::ArrayView< char const * const > const & extensions ) + { + try + { + checkEnabledExtensions( extensions ); + return true; + } + catch ( ExtensionNotPresentException & ) + { + return false; + } + } + + VkApplicationInfo getDefaultApplicationInfo() + { + return + { + VK_STRUCTURE_TYPE_APPLICATION_INFO, + nullptr, + nullptr, + ashes::makeVersion( 1, 0, 0 ), + nullptr, + ashes::makeVersion( 1, 0, 0 ), + ashes::makeVersion( 1, 0, 0 ), + }; + } } D3D_FEATURE_LEVEL getSupportedFeatureLevel() { D3D_FEATURE_LEVEL result = D3D_FEATURE_LEVEL_9_1; - auto factory = createDXGIFactory(); - if ( factory ) + if ( auto factory = createDXGIFactory() ) { auto adapters = listAdapters( factory ); result = getMaxFeatureLevel( adapters ); @@ -138,54 +204,9 @@ namespace ashes::d3d11 return result; } - void doCheckEnabledExtensions( ashes::ArrayView< char const * const > const & extensions ) - { - auto & available = getSupportedInstanceExtensions( nullptr ); - - for ( auto & extension : extensions ) - { - if ( available.end() == std::find_if( available.begin() - , available.end() - , [&extension]( VkExtensionProperties const & lookup ) - { - return lookup.extensionName == std::string{ extension }; - } ) ) - { - throw ExtensionNotPresentException{ extension }; - } - } - } - - bool doHasEnabledExtensions( ashes::ArrayView< char const * const > const & extensions ) - { - try - { - doCheckEnabledExtensions( extensions ); - return true; - } - catch ( ExtensionNotPresentException & ) - { - return false; - } - } - - VkApplicationInfo doGetDefaultApplicationInfo() - { - return - { - VK_STRUCTURE_TYPE_APPLICATION_INFO, - nullptr, - nullptr, - ashes::makeVersion( 1, 0, 0 ), - nullptr, - ashes::makeVersion( 1, 0, 0 ), - ashes::makeVersion( 1, 0, 0 ), - }; - } - - Instance::Instance( VkInstanceCreateInfo createInfo ) + Instance::Instance( VkInstanceCreateInfo const & createInfo ) : m_flags{ createInfo.flags } - , m_applicationInfo{ createInfo.pApplicationInfo ? *createInfo.pApplicationInfo : doGetDefaultApplicationInfo() } + , m_applicationInfo{ createInfo.pApplicationInfo ? *createInfo.pApplicationInfo : getDefaultApplicationInfo() } , m_enabledLayerNames{ ashes::convert( CharPtrArray{ createInfo.ppEnabledLayerNames, createInfo.ppEnabledLayerNames + createInfo.enabledLayerCount } ) } , m_enabledExtensions{ ashes::convert( CharPtrArray{ createInfo.ppEnabledExtensionNames, createInfo.ppEnabledExtensionNames + createInfo.enabledExtensionCount } ) } , m_factory{ createDXGIFactory() } @@ -201,10 +222,10 @@ namespace ashes::d3d11 m_features.hasStorageBuffers = m_maxFeatureLevel >= D3D_FEATURE_LEVEL_11_0; m_features.supportsPersistentMapping = false; - doCheckEnabledExtensions( ashes::makeArrayView( createInfo.ppEnabledExtensionNames, createInfo.enabledExtensionCount ) ); + checkEnabledExtensions( ashes::makeArrayView( createInfo.ppEnabledExtensionNames, createInfo.enabledExtensionCount ) ); } - Instance::~Instance() + Instance::~Instance()noexcept { for ( auto & physicalDevice : m_physicalDevices ) { @@ -230,7 +251,7 @@ namespace ashes::d3d11 bool Instance::hasExtension( std::string_view extension )const { char const * const version = extension.data(); - return doHasEnabledExtensions( ashes::makeArrayView( &version, 1u ) ); + return hasEnabledExtensions( ashes::makeArrayView( &version, 1u ) ); } VkPhysicalDeviceArray Instance::enumeratePhysicalDevices()const @@ -298,7 +319,7 @@ namespace ashes::d3d11 m_layers.push_back( layer ); } - void Instance::unregisterLayer( Layer * layer )const + void Instance::unregisterLayer( Layer * layer )const noexcept { auto it = std::find( m_layers.begin(), m_layers.end(), layer ); @@ -308,55 +329,35 @@ namespace ashes::d3d11 } } - bool Instance::onCopyToImageCommand( VkCommandBuffer cmd + void Instance::onCopyToImageCommand( VkCommandBuffer cmd , ArrayView< VkBufferImageCopy const > const & copyInfo , VkBuffer src - , VkImage dst )const + , VkImage dst )const noexcept { - try + for ( auto & layer : m_layers ) { - for ( auto & layer : m_layers ) - { - layer->copyToImageCommand( cmd - , copyInfo - , src - , dst ); - } - } - catch ( LayerException & exc ) - { - std::cerr << exc.what() << std::endl; - return true; + layer->copyToImageCommand( cmd + , copyInfo + , src + , dst ); } - - return false; } - bool Instance::onCheckHResultCommand( HRESULT hresult - , std::string message )const + void Instance::onCheckHResultCommand( HRESULT hresult + , std::string const & message )const noexcept { - try + for ( auto & layer : m_layers ) { - for ( auto & layer : m_layers ) - { - layer->checkHResultCommand( hresult - , message ); - } - } - catch ( LayerException & exc ) - { - std::cerr << exc.what() << std::endl; - return true; + layer->checkHResultCommand( hresult + , message ); } - - return false; } #if VK_EXT_debug_utils void Instance::submitDebugUtilsMessenger( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity , VkDebugUtilsMessageTypeFlagsEXT messageTypes - , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const + , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const noexcept { onSubmitDebugUtilsMessenger( messageSeverity , messageTypes @@ -365,20 +366,13 @@ namespace ashes::d3d11 void Instance::onSubmitDebugUtilsMessenger( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity , VkDebugUtilsMessageTypeFlagsEXT messageTypes - , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const + , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const noexcept { - try - { - for ( auto & layer : m_layers ) - { - layer->submitDebugUtilsMessenger( messageSeverity - , messageTypes - , callbackData ); - } - } - catch ( LayerException & exc ) + for ( auto & layer : m_layers ) { - std::cerr << exc.what() << std::endl; + layer->submitDebugUtilsMessenger( messageSeverity + , messageTypes + , callbackData ); } } @@ -391,7 +385,7 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ) + , const char * pMessage )const noexcept { onReportMessage( flags , objectType @@ -408,24 +402,17 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ) + , const char * pMessage )const noexcept { - try - { - for ( auto & layer : m_layers ) - { - layer->reportMessage( flags - , objectType - , object - , location - , messageCode - , pLayerPrefix - , pMessage ); - } - } - catch ( LayerException & exc ) + for ( auto & layer : m_layers ) { - std::cerr << exc.what() << std::endl; + layer->reportMessage( flags + , objectType + , object + , location + , messageCode + , pLayerPrefix + , pMessage ); } } @@ -442,44 +429,22 @@ namespace ashes::d3d11 m_physicalDevices.resize( m_adapters.size() ); uint32_t index = 0u; - for ( auto adapter : m_adapters ) + for ( auto const & adapter : m_adapters ) { allocateNA( m_physicalDevices[index] , get( this ) - , std::move( adapter ) ); + , adapter ); ++index; } } - VkPhysicalDeviceMemoryProperties const & Instance::getMemoryProperties() + VkPhysicalDeviceMemoryProperties const & Instance::getMemoryProperties()noexcept { - static VkPhysicalDeviceMemoryProperties const memoryProperties = []() - { - VkPhysicalDeviceMemoryProperties result{}; - // Emulate one device local heap - result.memoryHeaps[result.memoryHeapCount++] = { ~( 0ull ), VK_MEMORY_HEAP_DEVICE_LOCAL_BIT }; - // and one host visible heap - result.memoryHeaps[result.memoryHeapCount++] = { ~( 0ull ), 0u }; - - // Emulate all combinations of device local memory types - // and all combinations of host visible memory types - result.memoryTypes[result.memoryTypeCount++] = { VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0u }; - result.memoryTypes[result.memoryTypeCount++] = { VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1u }; - result.memoryTypes[result.memoryTypeCount++] = { VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, 1u }; - - return result; - }( ); - return memoryProperties; + return MemoryProperties; } - VkPhysicalDeviceMemoryProperties2KHR const & Instance::getMemoryProperties2() + VkPhysicalDeviceMemoryProperties2KHR const & Instance::getMemoryProperties2()noexcept { - static VkPhysicalDeviceMemoryProperties2KHR const memoryProperties2 = []() - { - VkPhysicalDeviceMemoryProperties2KHR result{}; - result.memoryProperties = Instance::getMemoryProperties(); - return result; - }( ); - return memoryProperties2; + return MemoryProperties2; } } diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.hpp index abc670a21..f73d23e54 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Instance.hpp @@ -18,10 +18,11 @@ namespace ashes::d3d11 class Instance : public ashes::IcdObject + , public NonCopyable { public: - Instance( VkInstanceCreateInfo createInfo ); - ~Instance(); + explicit Instance( VkInstanceCreateInfo const & createInfo ); + ~Instance()noexcept; uint32_t getApiVersion()const; bool hasExtension( std::string_view extension )const; @@ -48,20 +49,20 @@ namespace ashes::d3d11 */ /**@{*/ void registerLayer( Layer * layer )const; - void unregisterLayer( Layer * layer )const; - bool onCopyToImageCommand( VkCommandBuffer cmd + void unregisterLayer( Layer * layer )const noexcept; + void onCopyToImageCommand( VkCommandBuffer cmd , ArrayView< VkBufferImageCopy const > const & copyInfo , VkBuffer src - , VkImage dst )const; - bool onCheckHResultCommand( HRESULT hresult - , std::string message )const; + , VkImage dst )const noexcept; + void onCheckHResultCommand( HRESULT hresult + , std::string const & message )const noexcept; #if VK_EXT_debug_utils void onSubmitDebugUtilsMessenger( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity , VkDebugUtilsMessageTypeFlagsEXT messageTypes - , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const; + , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const noexcept; void submitDebugUtilsMessenger( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity , VkDebugUtilsMessageTypeFlagsEXT messageTypes - , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const; + , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const noexcept; #endif #if VK_EXT_debug_report void reportMessage( VkDebugReportFlagsEXT flags @@ -70,20 +71,20 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ); + , const char * pMessage )const noexcept; void onReportMessage( VkDebugReportFlagsEXT flags , VkDebugReportObjectTypeEXT objectType , uint64_t object , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage ); + , const char * pMessage )const noexcept; #endif /**@}*/ - static VkPhysicalDeviceMemoryProperties const & getMemoryProperties(); + static VkPhysicalDeviceMemoryProperties const & getMemoryProperties()noexcept; #ifdef VK_KHR_get_physical_device_properties2 - static VkPhysicalDeviceMemoryProperties2KHR const & getMemoryProperties2(); + static VkPhysicalDeviceMemoryProperties2KHR const & getMemoryProperties2()noexcept; #endif inline IDXGIFactory * getDXGIFactory()const diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.cpp index 1de4008d7..5d4ef1278 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.cpp @@ -14,97 +14,110 @@ namespace ashes::d3d11 bool Layer::bufferImageCommand( VkCommandBuffer cmd , VkBufferImageCopy const & copyInfo , VkBuffer buffer - , VkImage image )const try - { - return onBufferImageCommand( cmd - , copyInfo - , buffer - , image ); - } - catch ( LayerException & exc ) - { - std::cerr << "Layer Exception " << exc.what() << std::endl; - return false; - } - catch ( std::exception & exc ) - { - std::cerr << "Std Exception " << exc.what() << std::endl; - return false; - } - catch ( ... ) - { - std::cerr << "Unknown Exception" << std::endl; - return false; + , VkImage image )const noexcept + { + try + { + return onBufferImageCommand( cmd + , copyInfo + , buffer + , image ); + } + catch ( LayerException & exc ) + { + std::cerr << "Layer Exception " << exc.what() << std::endl; + return false; + } + catch ( std::exception & exc ) + { + std::cerr << "Std Exception " << exc.what() << std::endl; + return false; + } + catch ( ... ) + { + std::cerr << "Unknown Exception" << std::endl; + return false; + } } bool Layer::copyToImageCommand( VkCommandBuffer cmd , ArrayView< VkBufferImageCopy const > const & copyInfo , VkBuffer src - , VkImage dst )const try - { - return onCopyToImageCommand( cmd - , copyInfo - , src - , dst ); - } - catch ( LayerException & exc ) - { - std::cerr << "Layer Exception " << exc.what() << std::endl; - return false; - } - catch ( std::exception & exc ) - { - std::cerr << "Std Exception " << exc.what() << std::endl; - return false; - } - catch ( ... ) - { - std::cerr << "Unknown Exception" << std::endl; - return false; + , VkImage dst )const noexcept + { + try + { + return onCopyToImageCommand( cmd + , copyInfo + , src + , dst ); + } + catch ( LayerException & exc ) + { + std::cerr << "Layer Exception " << exc.what() << std::endl; + return false; + } + catch ( std::exception & exc ) + { + std::cerr << "Std Exception " << exc.what() << std::endl; + return false; + } + catch ( ... ) + { + std::cerr << "Unknown Exception" << std::endl; + return false; + } } bool Layer::checkHResultCommand( HRESULT hresult - , std::string message )const try - { - return onCheckHResultCommand( hresult - , message ); - } - catch ( LayerException & /*exc*/ ) - { - throw; - } - catch ( std::exception & exc ) - { - std::cerr << "Std Exception " << exc.what() << std::endl; - return false; - } - catch ( ... ) - { - std::cerr << "Unknown Exception" << std::endl; - return false; + , std::string const & message )const noexcept + { + try + { + return onCheckHResultCommand( hresult + , message ); + } + catch ( LayerException & exc ) + { + std::cerr << "Layer Exception " << exc.what() << std::endl; + return false; + } + catch ( std::exception & exc ) + { + std::cerr << "Std Exception " << exc.what() << std::endl; + return false; + } + catch ( ... ) + { + std::cerr << "Unknown Exception" << std::endl; + return false; + } } #if VK_EXT_debug_utils void Layer::submitDebugUtilsMessenger( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity , VkDebugUtilsMessageTypeFlagsEXT messageTypes - , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const try - { - onSubmitDebugUtilsMessenger( messageSeverity - , messageTypes - , callbackData ); - } - catch ( LayerException & exc ) - { - std::cerr << "Layer Exception " << exc.what() << std::endl; - } - catch ( std::exception & exc ) - { - std::cerr << "Std Exception " << exc.what() << std::endl; - } - catch ( ... ) - { - std::cerr << "Unknown Exception" << std::endl; + , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const noexcept + { + try + { + onSubmitDebugUtilsMessenger( messageSeverity + , messageTypes + , callbackData ); + } + catch ( LayerException & exc ) + { + std::cerr << "Layer Exception " << exc.what() << std::endl; + } + catch ( std::exception & exc ) + { + std::cerr << "Std Exception " << exc.what() << std::endl; + } + catch ( ... ) + { + std::cerr << "Unknown Exception" << std::endl; + } } #endif @@ -116,27 +129,30 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage )const try - { - return onReportMessage( flags - , objectType - , object - , location - , messageCode - , pLayerPrefix - , pMessage ); - } - catch ( LayerException & exc ) - { - std::cerr << "Layer Exception " << exc.what() << std::endl; - } - catch ( std::exception & exc ) - { - std::cerr << "Std Exception " << exc.what() << std::endl; - } - catch ( ... ) - { - std::cerr << "Unknown Exception" << std::endl; + , const char * pMessage )const noexcept + { + try + { + return onReportMessage( flags + , objectType + , object + , location + , messageCode + , pLayerPrefix + , pMessage ); + } + catch ( LayerException & exc ) + { + std::cerr << "Layer Exception " << exc.what() << std::endl; + } + catch ( std::exception & exc ) + { + std::cerr << "Std Exception " << exc.what() << std::endl; + } + catch ( ... ) + { + std::cerr << "Unknown Exception" << std::endl; + } } #endif diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.hpp index 389ed7c28..486743e58 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Layer.hpp @@ -11,21 +11,21 @@ namespace ashes::d3d11 class Layer { public: - virtual ~Layer() = default; + virtual ~Layer()noexcept = default; bool bufferImageCommand( VkCommandBuffer cmd , VkBufferImageCopy const & copyInfo , VkBuffer buffer - , VkImage image )const; + , VkImage image )const noexcept; bool copyToImageCommand( VkCommandBuffer cmd , ArrayView< VkBufferImageCopy const > const & copyInfo , VkBuffer src - , VkImage dst )const; + , VkImage dst )const noexcept; bool checkHResultCommand( HRESULT hresult - , std::string message )const; + , std::string const & message )const noexcept; #if VK_EXT_debug_utils void submitDebugUtilsMessenger( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity , VkDebugUtilsMessageTypeFlagsEXT messageTypes - , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const; + , VkDebugUtilsMessengerCallbackDataEXT const & callbackData )const noexcept; #endif #if VK_EXT_debug_report void reportMessage( VkDebugReportFlagsEXT flags @@ -34,7 +34,7 @@ namespace ashes::d3d11 , size_t location , int32_t messageCode , const char * pLayerPrefix - , const char * pMessage )const; + , const char * pMessage )const noexcept; #endif private: @@ -55,7 +55,7 @@ namespace ashes::d3d11 } virtual bool onCheckHResultCommand( HRESULT hresult - , std::string message )const + , std::string const & message )const { return true; } diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.cpp index d12c2266c..0d0aef9ba 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.cpp @@ -29,9 +29,39 @@ namespace ashes::d3d11 { namespace { + inline VkLayerPropertiesArray const LayersProperties{}; + + inline VkExtensionPropertiesArray const ExtensionsProperties + { +#if VK_KHR_swapchain + VkExtensionProperties{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION }, +#endif +#if VK_EXT_debug_report + VkExtensionProperties{ VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION }, +#endif +#if VK_EXT_debug_marker + VkExtensionProperties{ VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION }, +#endif +#if VK_EXT_debug_utils + VkExtensionProperties{ VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION }, +#endif +#if VK_EXT_inline_uniform_block + VkExtensionProperties{ VK_EXT_INLINE_UNIFORM_BLOCK_EXTENSION_NAME, VK_EXT_INLINE_UNIFORM_BLOCK_SPEC_VERSION }, +#endif +#if VK_KHR_maintenance1 + VkExtensionProperties{ VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_MAINTENANCE1_SPEC_VERSION }, +#endif +#if VK_KHR_get_physical_device_properties2 + VkExtensionProperties{ VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION }, +#endif +#if VK_KHR_portability_subset + VkExtensionProperties{ VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION }, +#endif + }; + int getBitSize( uint64_t value ) { - static constexpr int bitPatternToLog2[128] + static constexpr std::array< int, 128u > bitPatternToLog2 { 0, // change to 0 if you want bitSize(0) = 0 48, -1, -1, 31, -1, 15, 51, -1, 63, 5, -1, -1, -1, 19, -1, @@ -43,7 +73,7 @@ namespace ashes::d3d11 41, -1, 25, 37, -1, 47, -1, 30, 14, -1, -1, -1, -1, 22, -1, -1, 35, 12, -1, -1, -1, 59, 42, -1, -1, 61, 3, 26, 38, 44, -1, 56 }; - static uint64_t constexpr multiplicator = 0x6c04f118e9966f6bull; + static uint64_t constexpr multiplicator = 0x6C04F118E9966F6BULL; value |= value >> 1; value |= value >> 2; value |= value >> 4; @@ -147,7 +177,7 @@ namespace ashes::d3d11 #endif } - PhysicalDevice::~PhysicalDevice() + PhysicalDevice::~PhysicalDevice()noexcept { #if defined( ASHES_D3D11_USE_AMD_AGS ) if ( isAMD() ) @@ -171,7 +201,7 @@ namespace ashes::d3d11 uint32_t PhysicalDevice::getMemoryTypeBits( VkMemoryPropertyFlags properties )const { uint32_t result{}; - auto memoryProperties = getMemoryProperties(); + auto const & memoryProperties = getMemoryProperties(); for ( auto i = 0u; i < memoryProperties.memoryTypeCount; ++i ) { @@ -192,47 +222,19 @@ namespace ashes::d3d11 return result; } - VkBool32 PhysicalDevice::getPresentationSupport( uint32_t queueFamilyIndex )const + VkBool32 PhysicalDevice::getPresentationSupport()const { return getOutput() != nullptr; } - VkLayerPropertiesArray PhysicalDevice::enumerateLayerProperties()const + VkLayerPropertiesArray const & PhysicalDevice::enumerateLayerProperties()const { - VkLayerPropertiesArray result; - return result; + return LayersProperties; } - VkExtensionPropertiesArray PhysicalDevice::enumerateExtensionProperties( const char * layerName )const + VkExtensionPropertiesArray const & PhysicalDevice::enumerateExtensionProperties()const { - static VkExtensionPropertiesArray const extensions - { -#if VK_KHR_swapchain - VkExtensionProperties{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION }, -#endif -#if VK_EXT_debug_report - VkExtensionProperties{ VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION }, -#endif -#if VK_EXT_debug_marker - VkExtensionProperties{ VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION }, -#endif -#if VK_EXT_debug_utils - VkExtensionProperties{ VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION }, -#endif -#if VK_EXT_inline_uniform_block - VkExtensionProperties{ VK_EXT_INLINE_UNIFORM_BLOCK_EXTENSION_NAME, VK_EXT_INLINE_UNIFORM_BLOCK_SPEC_VERSION }, -#endif -#if VK_KHR_maintenance1 - VkExtensionProperties{ VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_MAINTENANCE1_SPEC_VERSION }, -#endif -#if VK_KHR_get_physical_device_properties2 - VkExtensionProperties{ VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION }, -#endif -#if VK_KHR_portability_subset - VkExtensionProperties{ VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION }, -#endif - }; - return extensions; + return ExtensionsProperties; } VkPhysicalDeviceProperties const & PhysicalDevice::getProperties()const @@ -240,22 +242,22 @@ namespace ashes::d3d11 return m_properties; } - VkPhysicalDeviceMemoryProperties PhysicalDevice::getMemoryProperties()const + VkPhysicalDeviceMemoryProperties const & PhysicalDevice::getMemoryProperties()const { return Instance::getMemoryProperties(); } - VkPhysicalDeviceFeatures PhysicalDevice::getFeatures()const + VkPhysicalDeviceFeatures const & PhysicalDevice::getFeatures()const { return m_features; } - VkQueueFamilyPropertiesArray PhysicalDevice::getQueueFamilyProperties()const + VkQueueFamilyPropertiesArray const & PhysicalDevice::getQueueFamilyProperties()const { return m_queueProperties; } - VkFormatProperties PhysicalDevice::getFormatProperties( VkFormat fmt )const + VkFormatProperties const & PhysicalDevice::getFormatProperties( VkFormat fmt )const { return m_formatProperties[fmt]; } @@ -267,7 +269,7 @@ namespace ashes::d3d11 , VkImageCreateFlags flags , VkImageFormatProperties & imageProperties )const { - auto & formatProperties = m_formatProperties[format]; + auto const & formatProperties = m_formatProperties[format]; if ( formatProperties.linearTilingFeatures == 0u ) { @@ -308,8 +310,6 @@ namespace ashes::d3d11 if ( tiling != VK_IMAGE_TILING_LINEAR && type == VK_IMAGE_TYPE_2D && !checkFlag( flags, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT ) - //&& !checkFlag( formatProperties.optimalTilingFeatures, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT ) - //&& !checkFlag( formatProperties.optimalTilingFeatures, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT ) && !checkFlag( usage, VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV ) && !checkFlag( usage, VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT ) && !isYCBCRFormat( format ) ) @@ -374,12 +374,12 @@ namespace ashes::d3d11 return VK_SUCCESS; } - VkResult PhysicalDevice::getSparseImageFormatProperties( VkFormat format - , VkImageType type - , VkSampleCountFlagBits samples - , VkImageUsageFlags usage - , VkImageTiling tiling - , std::vector< VkSparseImageFormatProperties > & sparseImageFormatProperties )const + VkResult PhysicalDevice::getSparseImageFormatProperties( [[maybe_unused]] VkFormat format + , [[maybe_unused]] VkImageType type + , [[maybe_unused]] VkSampleCountFlagBits samples + , [[maybe_unused]] VkImageUsageFlags usage + , [[maybe_unused]] VkImageTiling tiling + , [[maybe_unused]] std::vector< VkSparseImageFormatProperties > & sparseImageFormatProperties )const { return VK_ERROR_FORMAT_NOT_SUPPORTED; } @@ -437,14 +437,11 @@ namespace ashes::d3d11 if ( result != VK_ERROR_FORMAT_NOT_SUPPORTED ) { - for ( auto & prop : props ) + for ( auto const & prop : props ) { - sparseImageFormatProperties.push_back( - { - VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2, - nullptr, - prop, - } ); + sparseImageFormatProperties.push_back( { VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2 + , nullptr + , prop } ); } } @@ -568,25 +565,19 @@ namespace ashes::d3d11 m_properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; m_properties2.properties = m_properties; - for ( auto & queueProperty : m_queueProperties ) + for ( auto const & queueProperty : m_queueProperties ) { - m_queueProperties2.push_back( - { - VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2, - nullptr, - queueProperty, - } ); + m_queueProperties2.push_back( { VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2 + , nullptr + , queueProperty } ); } - for ( auto & formatProperty : m_formatProperties ) + for ( auto const & [format, properties] : m_formatProperties ) { - m_formatProperties2.emplace( formatProperty.first - , VkFormatProperties2 - { - VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, - nullptr, - formatProperty.second, - } ); + m_formatProperties2.try_emplace( format + , VkFormatProperties2{ VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2 + , nullptr + , properties } ); } #elif VK_KHR_get_physical_device_properties2 @@ -605,23 +596,17 @@ namespace ashes::d3d11 for ( auto & queueProperty : m_queueProperties ) { - m_queueProperties2.push_back( - { - VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR, - nullptr, - queueProperty, - } ); + m_queueProperties2.push_back( { VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR + , nullptr + , queueProperty } ); } - for ( auto & formatProperty : m_formatProperties ) + for ( auto const & [format, properties] : m_formatProperties ) { - m_formatProperties2.emplace( formatProperty.first - , VkFormatProperties2 - { - VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR, - nullptr, - formatProperty.second, - } ); + m_formatProperties2.try_emplace( format + , VkFormatProperties2{ VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR + , nullptr + , properties } ); } #endif @@ -629,10 +614,8 @@ namespace ashes::d3d11 void PhysicalDevice::doInitialiseProperties() { - DXGI_ADAPTER_DESC2 adapterDesc; - - if ( m_adapterInfo.adapter2 - && SUCCEEDED( m_adapterInfo.adapter2->GetDesc2( &adapterDesc ) ) ) + if ( DXGI_ADAPTER_DESC2 adapterDesc{}; + m_adapterInfo.adapter2 && SUCCEEDED( m_adapterInfo.adapter2->GetDesc2( &adapterDesc ) ) ) { strncpy( m_properties.deviceName , toString( adapterDesc.Description ).c_str() @@ -712,7 +695,7 @@ namespace ashes::d3d11 m_properties.limits.subPixelPrecisionBits = 8u; m_properties.limits.subTexelPrecisionBits = 8u; m_properties.limits.mipmapPrecisionBits = 8u; - m_properties.limits.maxDrawIndexedIndexValue = ( 1ull << D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP ) - 1u; + m_properties.limits.maxDrawIndexedIndexValue = ( 1ULL << D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP ) - 1u; m_properties.limits.maxDrawIndirectCount = 4294967295u; m_properties.limits.maxSamplerLodBias = 15.0f; m_properties.limits.maxSamplerAnisotropy = D3D11_REQ_MAXANISOTROPY - 0.01f; @@ -778,8 +761,8 @@ namespace ashes::d3d11 m_features.fullDrawIndexUint32 = true; m_features.imageCubeArray = true; m_features.independentBlend = true; - m_features.geometryShader = false;// m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_10_0; - m_features.tessellationShader = false;// m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_11_0; + m_features.geometryShader = false;//! m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_10_0; + m_features.tessellationShader = false;//! m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_11_0; m_features.sampleRateShading = true; m_features.dualSrcBlend = true; m_features.logicOp = true; @@ -801,7 +784,7 @@ namespace ashes::d3d11 m_features.pipelineStatisticsQuery = true; m_features.vertexPipelineStoresAndAtomics = true; m_features.fragmentStoresAndAtomics = true; - m_features.shaderTessellationAndGeometryPointSize = false;// m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_11_0; + m_features.shaderTessellationAndGeometryPointSize = false;//! m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_11_0; m_features.shaderImageGatherExtended = m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_11_0; m_features.shaderStorageImageExtendedFormats = m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_11_0; m_features.shaderStorageImageMultisample = m_adapterInfo.featureLevel >= D3D_FEATURE_LEVEL_11_0; @@ -860,7 +843,6 @@ namespace ashes::d3d11 D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1, }; - HRESULT hr; UINT flags = 0; #if !defined( NDEBUG ) @@ -870,7 +852,7 @@ namespace ashes::d3d11 D3D_FEATURE_LEVEL supportedFeatureLevel = getFeatureLevel(); D3D_FEATURE_LEVEL featureLevel; ID3D11Device * d3dDevice; - hr = D3D11CreateDevice( nullptr + D3D11CreateDevice( nullptr , D3D_DRIVER_TYPE_HARDWARE , nullptr , flags @@ -885,7 +867,7 @@ namespace ashes::d3d11 { auto fillProps = [&d3dDevice]( VkFormat fmt , VkFormatProperties & props - , DXGI_FORMAT( *convertFmt )( VkFormat const & ) ) + , auto convertFmt ) { auto dxgi = convertFmt( fmt ); @@ -963,21 +945,21 @@ namespace ashes::d3d11 m_portabilityFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_KHR , nullptr - , VK_FALSE /* constantAlphaColorBlendFactors; */ - , VK_FALSE /* events; */ - , VK_TRUE /* imageViewFormatReinterpretation; */ - , VK_TRUE /* imageViewFormatSwizzle; */ - , VK_FALSE /* imageView2DOn3DImage; */ - , VK_FALSE /* multisampleArrayImage; */ - , VK_TRUE /* mutableComparisonSamplers; */ - , VK_TRUE /* pointPolygons; */ - , VK_TRUE /* samplerMipLodBias; */ - , VK_FALSE /* separateStencilMaskRef; */ - , m_features.sampleRateShading /* shaderSampleRateInterpolationFunctions; */ - , m_features.tessellationShader /* tessellationIsolines; */ - , m_features.tessellationShader /* tessellationPointMode; */ - , VK_TRUE /* triangleFans; */ - , VK_FALSE /* vertexAttributeAccessBeyondStride; */ }; + , VK_FALSE /* constantAlphaColorBlendFactors */ + , VK_FALSE /* events */ + , VK_TRUE /* imageViewFormatReinterpretation */ + , VK_TRUE /* imageViewFormatSwizzle */ + , VK_FALSE /* imageView2DOn3DImage */ + , VK_FALSE /* multisampleArrayImage */ + , VK_TRUE /* mutableComparisonSamplers */ + , VK_TRUE /* pointPolygons */ + , VK_TRUE /* samplerMipLodBias */ + , VK_FALSE /* separateStencilMaskRef */ + , m_features.sampleRateShading /* shaderSampleRateInterpolationFunctions */ + , m_features.tessellationShader /* tessellationIsolines */ + , m_features.tessellationShader /* tessellationPointMode */ + , VK_TRUE /* triangleFans */ + , VK_FALSE /* vertexAttributeAccessBeyondStride */ }; # endif } @@ -986,8 +968,8 @@ namespace ashes::d3d11 struct ExtentFormat { - VkExtent2D extent; - VkFormat format; + VkExtent2D extent{}; + VkFormat format{}; }; size_t makeKey( VkFormat format @@ -1018,27 +1000,27 @@ namespace ashes::d3d11 std::vector< DXGI_MODE_DESC > displayModes = getDisplayModesList( m_instance, output ); std::map< ExtentFormat, std::vector< DXGI_MODE_DESC >, ExtentFormatComp > grouped; - for ( auto & displayMode : displayModes ) + for ( auto const & displayMode : displayModes ) { ExtentFormat key{ VkExtent2D{ displayMode.Width, displayMode.Height } , getVkFormat( displayMode.Format ) }; - auto it = grouped.insert( { key, {} } ).first; - it->second.push_back( displayMode ); + auto & modes = grouped.try_emplace( key ).first->second; + modes.emplace_back( displayMode ); } - for ( auto & pair : grouped ) + for ( auto & [extent, descs] : grouped ) { VkDisplayKHR display{}; allocate( display , nullptr , get( this ) - , pair.first.extent - , pair.first.format - , pair.second ); + , extent.extent + , extent.format + , descs ); m_displays.push_back( { display , "coin" - , pair.first.extent - , pair.first.extent + , extent.extent + , extent.extent , VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR , VK_FALSE , VK_TRUE } ); diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.hpp index a266c5397..0af13f905 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11PhysicalDevice.hpp @@ -19,23 +19,24 @@ namespace ashes::d3d11 class PhysicalDevice : public ashes::IcdObject + , public NonCopyable { public: PhysicalDevice( VkInstance instance , AdapterInfo adapterInfo ); - ~PhysicalDevice(); + ~PhysicalDevice()noexcept; uint32_t getMemoryTypeBits( VkMemoryPropertyFlags properties )const; uint32_t getMemoryTypeBits( VkMemoryPropertyFlags properties1 , VkMemoryPropertyFlags properties2 )const; - VkBool32 getPresentationSupport( uint32_t queueFamilyIndex )const; - VkLayerPropertiesArray enumerateLayerProperties()const; - VkExtensionPropertiesArray enumerateExtensionProperties( const char * layerName )const; + VkBool32 getPresentationSupport()const; + VkLayerPropertiesArray const & enumerateLayerProperties()const; + VkExtensionPropertiesArray const & enumerateExtensionProperties()const; VkPhysicalDeviceProperties const & getProperties()const; - VkPhysicalDeviceMemoryProperties getMemoryProperties()const; - VkPhysicalDeviceFeatures getFeatures()const; - VkQueueFamilyPropertiesArray getQueueFamilyProperties()const; - VkFormatProperties getFormatProperties( VkFormat fmt )const; + VkPhysicalDeviceMemoryProperties const & getMemoryProperties()const; + VkPhysicalDeviceFeatures const & getFeatures()const; + VkQueueFamilyPropertiesArray const & getQueueFamilyProperties()const; + VkFormatProperties const & getFormatProperties( VkFormat fmt )const; VkResult getImageFormatProperties( VkFormat format , VkImageType type , VkImageTiling tiling diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.cpp index d0d472371..88d284f6e 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.cpp @@ -14,22 +14,23 @@ namespace ashes::d3d11 { namespace { - std::vector< VkFormat > const & getFormatsList() + inline std::vector< VkFormat > const FormatsList = []() { - static std::vector< VkFormat > const list = []() + std::vector< VkFormat > result; + + for ( auto i = uint32_t( VK_FORMAT_R4G4_UNORM_PACK8 ); + i <= uint32_t( VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 ); + ++i ) { - std::vector< VkFormat > result; + result.push_back( VkFormat( i ) ); + } - for ( uint32_t i = uint32_t( VK_FORMAT_R4G4_UNORM_PACK8 ); - i <= uint32_t( VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 ); - ++i ) - { - result.push_back( VkFormat( i ) ); - } + return result; + }(); - return result; - }( ); - return list; + std::vector< VkFormat > const & getFormatsList() + { + return FormatsList; } void updateSurfaceCapabilities( std::vector< DXGI_MODE_DESC > const & displayModeList @@ -40,9 +41,9 @@ namespace ashes::d3d11 { capabilities.minImageCount = 1u; capabilities.maxImageCount = 1u; - capabilities.currentExtent.width = ~( 0u ); - capabilities.currentExtent.height = ~( 0u ); - capabilities.minImageExtent = { ~( 0u ), ~( 0u ) }; + capabilities.currentExtent.width = ~0u; + capabilities.currentExtent.height = ~0u; + capabilities.minImageExtent = { ~0u, ~0u }; capabilities.maxImageExtent = { 0u, 0u }; capabilities.maxImageArrayLayers = 1u; capabilities.supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; @@ -77,8 +78,8 @@ namespace ashes::d3d11 && displayMode.Height == height ) { matchingDisplayModes.push_back( displayMode ); - auto it = descs.emplace( getVkFormat( displayMode.Format ), std::vector< DXGI_MODE_DESC >{} ).first; - it->second.emplace_back( displayMode ); + auto & modes = descs.try_emplace( getVkFormat( displayMode.Format ) ).first->second; + modes.emplace_back( displayMode ); } } @@ -106,8 +107,8 @@ namespace ashes::d3d11 && displayMode.Height == size.height ) { matchingDisplayModes.push_back( displayMode ); - auto it = descs.emplace( getVkFormat( displayMode.Format ), std::vector< DXGI_MODE_DESC >{} ).first; - it->second.emplace_back( displayMode ); + auto & datas = descs.try_emplace( getVkFormat( displayMode.Format ) ).first->second; + datas.emplace_back( displayMode ); } } } @@ -136,15 +137,15 @@ namespace ashes::d3d11 { // Choose the display mode with highest width. matchingDisplayModes.push_back( maxWidth ); - auto it = descs.emplace( getVkFormat( maxWidth.Format ), std::vector< DXGI_MODE_DESC >{} ).first; - it->second.emplace_back( maxWidth ); + auto & datas = descs.try_emplace( getVkFormat( maxWidth.Format ) ).first->second; + datas.emplace_back( maxWidth ); } else { // Choose the display mode with highest height. matchingDisplayModes.push_back( maxHeight ); - auto it = descs.emplace( getVkFormat( maxHeight.Format ), std::vector< DXGI_MODE_DESC >{} ).first; - it->second.emplace_back( maxHeight ); + auto & datas = descs.try_emplace( getVkFormat( maxHeight.Format ) ).first->second; + datas.emplace_back( maxHeight ); } } @@ -163,9 +164,9 @@ namespace ashes::d3d11 capabilities.currentExtent.height = height; } - for ( auto & desc : descs ) + for ( auto const & [format, desc] : descs ) { - matchingDescs.emplace( desc.first, desc.second.front() ); + matchingDescs.try_emplace( format, desc.front() ); } } @@ -200,7 +201,7 @@ namespace ashes::d3d11 if ( dxgiFormat != DXGI_FORMAT_UNKNOWN ) { - UINT numModes; + UINT numModes{}; // Get the number of modes that fit the display format for the adapter output. auto hr = adapterOutput->GetDisplayModeList( dxgiFormat , DXGI_ENUM_MODES_INTERLACED @@ -266,10 +267,6 @@ namespace ashes::d3d11 m_presentModes.push_back( VK_PRESENT_MODE_FIFO_KHR ); } - SurfaceKHR::~SurfaceKHR() - { - } - inline VkFlags & mergeFlags( VkFlags & value , VkFlags const & flag )noexcept { @@ -314,9 +311,9 @@ namespace ashes::d3d11 m_surfaceCapabilities.supportedUsageFlags = VK_IMAGE_TYPE_MAX_ENUM; - for ( auto surfaceFormat : m_surfaceFormats ) + for ( auto const & surfaceFormat : m_surfaceFormats ) { - auto props = get( m_currentPhysicalDevice )->getFormatProperties( surfaceFormat.format ); + auto const & props = get( m_currentPhysicalDevice )->getFormatProperties( surfaceFormat.format ); mergeFlags( m_surfaceCapabilities.supportedUsageFlags , getUsageFlags( props.linearTilingFeatures ) ); } @@ -324,8 +321,7 @@ namespace ashes::d3d11 } } - VkBool32 SurfaceKHR::getSupport( VkPhysicalDevice physicalDevice - , uint32_t queueFamilyIndex )const + VkBool32 SurfaceKHR::getSupport( VkPhysicalDevice physicalDevice )const { m_currentPhysicalDevice = nullptr; doUpdate( physicalDevice ); diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.hpp index e468d662d..20d0472c3 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11Surface.hpp @@ -18,10 +18,8 @@ namespace ashes::d3d11 , VkWin32SurfaceCreateInfoKHR createInfo ); SurfaceKHR( VkInstance instance , VkDisplaySurfaceCreateInfoKHR createInfo ); - ~SurfaceKHR(); - VkBool32 getSupport( VkPhysicalDevice physicalDevice - , uint32_t queueFamilyIndex )const; + VkBool32 getSupport( VkPhysicalDevice physicalDevice )const; HWND getHwnd()const; DXGI_MODE_DESC const & getDisplayMode()const; @@ -49,22 +47,22 @@ namespace ashes::d3d11 return m_instance; } - inline std::vector< DXGI_MODE_DESC > const & getDescs( VkFormat format )const + std::vector< DXGI_MODE_DESC > const & getDescs( VkFormat format )const { return m_descs[format]; } - inline DXGI_MODE_DESC const & getMatchingDesc( VkFormat format )const + DXGI_MODE_DESC const & getMatchingDesc( VkFormat format )const { return m_matchingDescs[format]; } - inline bool isWin32()const + bool isWin32()const { return m_win32CreateInfo.sType != 0; } - inline bool isDisplay()const + bool isDisplay()const { return m_displayCreateInfo.sType != 0; } @@ -73,16 +71,16 @@ namespace ashes::d3d11 void doUpdate( VkPhysicalDevice physicalDevice )const; private: - VkInstance m_instance; + VkInstance m_instance{}; VkWin32SurfaceCreateInfoKHR m_win32CreateInfo{}; VkDisplaySurfaceCreateInfoKHR m_displayCreateInfo{}; std::string m_type; - mutable VkSurfaceFormatArrayKHR m_surfaceFormats; - mutable VkSurfaceCapabilitiesKHR m_surfaceCapabilities; - mutable VkPresentModeArrayKHR m_presentModes; + mutable VkSurfaceFormatArrayKHR m_surfaceFormats{}; + mutable VkSurfaceCapabilitiesKHR m_surfaceCapabilities{}; + mutable VkPresentModeArrayKHR m_presentModes{}; mutable VkPhysicalDevice m_currentPhysicalDevice{}; - mutable std::vector< DXGI_MODE_DESC > m_displayModes; - mutable std::map< VkFormat, std::vector< DXGI_MODE_DESC > > m_descs; - mutable std::map< VkFormat, DXGI_MODE_DESC > m_matchingDescs; + mutable std::vector< DXGI_MODE_DESC > m_displayModes{}; + mutable std::map< VkFormat, std::vector< DXGI_MODE_DESC > > m_descs{}; + mutable std::map< VkFormat, DXGI_MODE_DESC > m_matchingDescs{}; }; } diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.cpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.cpp index 2abdb81e6..ae0f93438 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.cpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.cpp @@ -99,7 +99,7 @@ namespace ashes::d3d11 if ( !checkError( m_device, hr, "ResizeTarget" ) ) { - hr = m_swapChain->SetFullscreenState( FALSE, get( get( device )->getPhysicalDevice() )->getOutput() ); + m_swapChain->SetFullscreenState( FALSE, get( get( device )->getPhysicalDevice() )->getOutput() ); throw ashes::BaseException{ "Could not resize the swapchain" }; } } @@ -154,7 +154,7 @@ namespace ashes::d3d11 } } - SwapchainKHR::~SwapchainKHR() + SwapchainKHR::~SwapchainKHR()noexcept { deallocate( m_view, get( m_device )->getAllocationCallbacks() ); deallocate( m_image, get( m_device )->getAllocationCallbacks() ); @@ -174,7 +174,7 @@ namespace ashes::d3d11 return result; } - VkResult SwapchainKHR::present( uint32_t imageIndex )const + VkResult SwapchainKHR::present()const { auto context{ get( m_device )->getImmediateContext() }; D3D11_BOX srcBox{}; @@ -194,10 +194,7 @@ namespace ashes::d3d11 : VK_ERROR_SURFACE_LOST_KHR; } - VkResult SwapchainKHR::acquireNextImage( uint64_t timeout - , VkSemaphore semaphore - , VkFence fence - , uint32_t & imageIndex )const + VkResult SwapchainKHR::acquireNextImage( uint32_t & imageIndex )const { imageIndex = 0u; return VK_SUCCESS; diff --git a/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.hpp b/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.hpp index e0d6b8019..28898c56e 100644 --- a/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.hpp +++ b/source/ashes/renderer/D3D11Renderer/Core/D3D11SwapChain.hpp @@ -11,19 +11,17 @@ namespace ashes::d3d11 { class SwapchainKHR + : public NonCopyable { public: SwapchainKHR( VkDevice device , VkSwapchainCreateInfoKHR createInfo ); - ~SwapchainKHR(); + ~SwapchainKHR()noexcept; uint32_t getImageCount()const; VkImageArray getImages()const; - VkResult acquireNextImage( uint64_t timeout - , VkSemaphore semaphore - , VkFence fence - , uint32_t & imageIndex )const; - VkResult present( uint32_t imageIndex )const; + VkResult acquireNextImage( uint32_t & imageIndex )const; + VkResult present()const; inline IDXGISwapChain * getSwapChain()const { @@ -38,7 +36,7 @@ namespace ashes::d3d11 private: void doInitPresentParameters(); - protected: + private: VkDevice m_device; VkSwapchainCreateInfoKHR m_createInfo; DXGI_SWAP_CHAIN_DESC m_presentDesc; diff --git a/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.cpp b/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.cpp index 64b4b2381..4fefdf950 100644 --- a/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.cpp +++ b/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.cpp @@ -76,7 +76,8 @@ namespace ashes::d3d11 bool checkError( VkDevice device, HRESULT hResult, char const * const text ) { - return !get( device )->onCheckHResultCommand( hResult, text ); + get( device )->onCheckHResultCommand( hResult, text ); + return SUCCEEDED( hResult ); } std::string toString( std::wstring const & text ) diff --git a/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.hpp b/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.hpp index 90061ff00..cf1d53a2d 100644 --- a/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.hpp +++ b/source/ashes/renderer/D3D11Renderer/D3D11RendererPrerequisites.hpp @@ -216,6 +216,19 @@ DECLARE_GUID( IID_IDXGIFactory, 0x7b7166ec, 0x21c7, 0x44ae, 0xb2, 0x1a, 0xc9, 0x namespace ashes::d3d11 { + class NonCopyable + { + private: + NonCopyable( NonCopyable const & ) = delete; + NonCopyable( NonCopyable && )noexcept = delete; + NonCopyable & operator=( NonCopyable const & ) = delete; + NonCopyable & operator=( NonCopyable && )noexcept = delete; + + protected: + NonCopyable()noexcept = default; + ~NonCopyable()noexcept = default; + }; + struct AdapterInfo { IDXGIAdapter * adapter{ nullptr }; @@ -346,7 +359,7 @@ namespace ashes::d3d11 using CommandArray = std::vector< CommandPtr >; template< typename T > - void safeRelease( T *& toRelease ) + void safeRelease( T *& toRelease )noexcept { if ( toRelease ) { diff --git a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.cpp b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.cpp index bf5a92f33..b7b8d169d 100644 --- a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.cpp +++ b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.cpp @@ -17,7 +17,7 @@ namespace ashes::d3d11 m_createInfos.pPoolSizes = m_poolSizes.data(); } - DescriptorPool::~DescriptorPool() + DescriptorPool::~DescriptorPool()noexcept { for ( auto & set : m_sets ) { @@ -35,7 +35,7 @@ namespace ashes::d3d11 m_allSets.push_back( set ); } - VkResult DescriptorPool::reset( VkDescriptorPoolResetFlags flags ) + VkResult DescriptorPool::reset() { for ( auto & set : m_allSets ) { @@ -47,7 +47,7 @@ namespace ashes::d3d11 return VK_SUCCESS; } - VkResult DescriptorPool::free( ArrayView< VkDescriptorSet const > sets ) + VkResult DescriptorPool::freeDescriptors( ArrayView< VkDescriptorSet const > sets ) { if ( checkFlag( m_createInfos.flags, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT ) ) { diff --git a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.hpp b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.hpp index 78fcb7dad..5e3c45728 100644 --- a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.hpp +++ b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorPool.hpp @@ -15,15 +15,16 @@ namespace ashes::d3d11 { class DescriptorPool + : public NonCopyable { public: DescriptorPool( VkDevice device , VkDescriptorPoolCreateInfo createInfos ); - ~DescriptorPool(); + ~DescriptorPool()noexcept; void registerSet( VkDescriptorSet set ); - VkResult reset( VkDescriptorPoolResetFlags flags ); - VkResult free( ArrayView< VkDescriptorSet const > sets ); + VkResult reset(); + VkResult freeDescriptors( ArrayView< VkDescriptorSet const > sets ); inline VkDevice getDevice()const { diff --git a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.cpp b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.cpp index 6bd9b6246..c30259af5 100644 --- a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.cpp +++ b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.cpp @@ -29,51 +29,51 @@ namespace ashes::d3d11 binding, {}, }; - m_writes.insert( { binding.binding, bindingWrites } ); + m_writes.try_emplace( binding.binding, bindingWrites ); } - for ( auto & write : m_writes ) + for ( auto & [_, write] : m_writes ) { - switch ( write.second.binding.descriptorType ) + switch ( write.binding.descriptorType ) { case VK_DESCRIPTOR_TYPE_SAMPLER: - m_samplers.push_back( &write.second ); + m_samplers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: - m_combinedTextureSamplers.push_back( &write.second ); + m_combinedTextureSamplers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: - m_sampledTextures.push_back( &write.second ); + m_sampledTextures.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: - m_storageTextures.push_back( &write.second ); + m_storageTextures.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: - m_uniformTexelBuffers.push_back( &write.second ); + m_uniformTexelBuffers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: - m_storageTexelBuffers.push_back( &write.second ); + m_storageTexelBuffers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: - m_uniformBuffers.push_back( &write.second ); + m_uniformBuffers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: - m_storageBuffers.push_back( &write.second ); + m_storageBuffers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: - m_dynamicUniformBuffers.push_back( &write.second ); - m_dynamicBuffers.push_back( &write.second ); + m_dynamicUniformBuffers.push_back( &write ); + m_dynamicBuffers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: - m_dynamicStorageBuffers.push_back( &write.second ); - m_dynamicBuffers.push_back( &write.second ); + m_dynamicStorageBuffers.push_back( &write ); + m_dynamicBuffers.push_back( &write ); break; case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: - m_inputAttachments.push_back( &write.second ); + m_inputAttachments.push_back( &write ); break; #if VK_EXT_inline_uniform_block case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: - m_inlineUniforms.push_back( &write.second ); + m_inlineUniforms.push_back( &write ); break; #endif default: @@ -91,9 +91,9 @@ namespace ashes::d3d11 } ); } - DescriptorSet::~DescriptorSet() + DescriptorSet::~DescriptorSet()noexcept { - for ( auto & inlineUbo : m_inlineUbos ) + for ( auto const & inlineUbo : m_inlineUbos ) { deallocate( inlineUbo->buffer, get( get( m_pool )->getDevice() )->getAllocationCallbacks() ); deallocate( inlineUbo->memory, get( get( m_pool )->getDevice() )->getAllocationCallbacks() ); @@ -107,15 +107,13 @@ namespace ashes::d3d11 if ( myWrite.pImageInfo ) { - m_imagesInfos.emplace_back( std::vector< VkDescriptorImageInfo >{ myWrite.pImageInfo, myWrite.pImageInfo + myWrite.descriptorCount } ); + m_imagesInfos.emplace_back( myWrite.pImageInfo, myWrite.pImageInfo + myWrite.descriptorCount ); myWrite.pImageInfo = m_imagesInfos.back().data(); } #if VK_EXT_inline_uniform_block - auto inlineUniform = tryGet< VkWriteDescriptorSetInlineUniformBlockEXT >( myWrite.pNext ); - - if ( inlineUniform ) + if ( auto inlineUniform = tryGet< VkWriteDescriptorSetInlineUniformBlockEXT >( myWrite.pNext ) ) { myWrite.descriptorCount /= inlineUniform->dataSize; auto device = get( m_pool )->getDevice(); @@ -137,7 +135,7 @@ namespace ashes::d3d11 if ( myWrite.pBufferInfo ) { - m_buffersInfos.emplace_back( std::vector< VkDescriptorBufferInfo >{ myWrite.pBufferInfo, myWrite.pBufferInfo + myWrite.descriptorCount } ); + m_buffersInfos.emplace_back( myWrite.pBufferInfo, myWrite.pBufferInfo + myWrite.descriptorCount ); myWrite.pBufferInfo = m_buffersInfos.back().data(); } } @@ -152,7 +150,7 @@ namespace ashes::d3d11 mergeWrites( it->second, write ); } - void DescriptorSet::update( VkCopyDescriptorSet const & copy ) + void DescriptorSet::update() { reportUnsupported( get( m_pool )->getDevice(), "VkCopyDescriptorSet" ); } diff --git a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.hpp b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.hpp index 0c134612f..3050b6771 100644 --- a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.hpp +++ b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSet.hpp @@ -22,10 +22,10 @@ namespace ashes::d3d11 DescriptorSet( VkDevice device , VkDescriptorPool pool , VkDescriptorSetLayout layout ); - ~DescriptorSet(); + ~DescriptorSet()noexcept; void update( VkWriteDescriptorSet const & write ); - void update( VkCopyDescriptorSet const & write ); + void update(); VkDescriptorSetLayout getLayout()const { diff --git a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.cpp b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.cpp index a7d85aa25..b2e7269b2 100644 --- a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.cpp +++ b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.cpp @@ -15,10 +15,6 @@ namespace ashes::d3d11 m_createInfo.pBindings = m_bindings.data(); } - DescriptorSetLayout::~DescriptorSetLayout() - { - } - VkDescriptorSetLayoutBinding const & DescriptorSetLayout::getBinding( uint32_t bindingPoint , uint32_t index )const { diff --git a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.hpp b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.hpp index 79928b049..63a9218ca 100644 --- a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.hpp +++ b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11DescriptorSetLayout.hpp @@ -17,7 +17,6 @@ namespace ashes::d3d11 public: DescriptorSetLayout( VkDevice device , VkDescriptorSetLayoutCreateInfo createInfo ); - ~DescriptorSetLayout(); VkDescriptorSetLayoutBinding const & getBinding( uint32_t bindingPoint , uint32_t index )const; @@ -32,7 +31,7 @@ namespace ashes::d3d11 return m_bindings.end(); } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11WriteDescriptorSet.cpp b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11WriteDescriptorSet.cpp index 39103500b..56c33dce5 100644 --- a/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11WriteDescriptorSet.cpp +++ b/source/ashes/renderer/D3D11Renderer/Descriptor/D3D11WriteDescriptorSet.cpp @@ -1,5 +1 @@ #include "D3D11RendererPrerequisites.hpp" - -namespace ashes::d3d11 -{ -} diff --git a/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.cpp b/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.cpp index de396c45c..2daf84f8b 100644 --- a/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.cpp +++ b/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.cpp @@ -2,7 +2,7 @@ namespace ashes::d3d11 { - bool isRenderTarget( VkImageUsageFlags const & flags ) + bool isRenderTarget( VkImageUsageFlags const & flags )noexcept { return checkFlag( flags, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ) || checkFlag( flags, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ) @@ -10,12 +10,12 @@ namespace ashes::d3d11 || checkFlag( flags, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT ); } - bool isStorage( VkImageUsageFlags const & flags ) + bool isStorage( VkImageUsageFlags const & flags )noexcept { return checkFlag( flags, VK_IMAGE_USAGE_STORAGE_BIT ); } - bool isSampled( VkImageUsageFlags const & flags ) + bool isSampled( VkImageUsageFlags const & flags )noexcept { return checkFlag( flags, VK_IMAGE_USAGE_SAMPLED_BIT ) || checkFlag( flags, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT ) @@ -24,7 +24,7 @@ namespace ashes::d3d11 bool isRenderable( VkImageUsageFlags const & flags , VkFormat format - , uint32_t mipLevels ) + , uint32_t mipLevels )noexcept { return isRenderTarget( flags ) || ( mipLevels > 1 && !isCompressedFormat( format ) ); @@ -32,7 +32,7 @@ namespace ashes::d3d11 bool isMipmapped( VkImageUsageFlags const & flags , VkFormat format - , uint32_t mipLevels ) + , uint32_t mipLevels )noexcept { return isRenderable( flags, format, mipLevels ) && isSampled( flags ) diff --git a/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.hpp b/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.hpp index 07866df48..dcc075326 100644 --- a/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.hpp +++ b/source/ashes/renderer/D3D11Renderer/Enum/D3D11ImageUsageFlag.hpp @@ -6,13 +6,13 @@ See LICENSE file in root folder. namespace ashes::d3d11 { - bool isRenderTarget( VkImageUsageFlags const & flags ); - bool isStorage( VkImageUsageFlags const & flags ); - bool isSampled( VkImageUsageFlags const & flags ); + bool isRenderTarget( VkImageUsageFlags const & flags )noexcept; + bool isStorage( VkImageUsageFlags const & flags )noexcept; + bool isSampled( VkImageUsageFlags const & flags )noexcept; bool isRenderable( VkImageUsageFlags const & flags , VkFormat format - , uint32_t mipLevels ); + , uint32_t mipLevels )noexcept; bool isMipmapped( VkImageUsageFlags const & flags , VkFormat format - , uint32_t mipLevels ); + , uint32_t mipLevels )noexcept; } diff --git a/source/ashes/renderer/D3D11Renderer/Enum/D3D11MemoryPropertyFlag.cpp b/source/ashes/renderer/D3D11Renderer/Enum/D3D11MemoryPropertyFlag.cpp index 5cf62c2b3..8ac96c69a 100644 --- a/source/ashes/renderer/D3D11Renderer/Enum/D3D11MemoryPropertyFlag.cpp +++ b/source/ashes/renderer/D3D11Renderer/Enum/D3D11MemoryPropertyFlag.cpp @@ -20,10 +20,6 @@ namespace ashes::d3d11 { result = D3D11_USAGE_DYNAMIC; } - else if ( checkFlag( targets, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT ) - || checkFlag( targets, VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT ) ) - { - } else if ( checkFlag( targets, VK_BUFFER_USAGE_TRANSFER_SRC_BIT ) || checkFlag( targets, VK_BUFFER_USAGE_TRANSFER_DST_BIT ) ) { @@ -68,19 +64,17 @@ namespace ashes::d3d11 { D3D11_USAGE result{ D3D11_USAGE_DEFAULT }; - if ( isHostVisible( flags ) ) + if ( isHostVisible( flags ) + && !isRenderTarget( usage ) ) { - if ( !isRenderTarget( usage ) ) + if ( checkFlag( usage, VK_IMAGE_USAGE_TRANSFER_SRC_BIT ) + || checkFlag( usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT ) ) { - if ( checkFlag( usage, VK_IMAGE_USAGE_TRANSFER_SRC_BIT ) - || checkFlag( usage, VK_IMAGE_USAGE_TRANSFER_DST_BIT ) ) - { - result = D3D11_USAGE_STAGING; - } - else - { - result = D3D11_USAGE_DYNAMIC; - } + result = D3D11_USAGE_STAGING; + } + else + { + result = D3D11_USAGE_DYNAMIC; } } diff --git a/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.cpp b/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.cpp index eaac3c543..454157712 100644 --- a/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.cpp +++ b/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.cpp @@ -13,7 +13,7 @@ namespace ashes::d3d11 { - Image::Image( Image && rhs ) + Image::Image( Image && rhs )noexcept : m_device{ rhs.m_device } , m_createInfo{ std::move( rhs.m_createInfo ) } , m_image{ rhs.m_image } @@ -22,7 +22,7 @@ namespace ashes::d3d11 rhs.m_image.tex1D = nullptr; } - Image & Image::operator=( Image && rhs ) + Image & Image::operator=( Image && rhs )noexcept { m_image = rhs.m_image; m_memoryRequirements = rhs.m_memoryRequirements; @@ -72,8 +72,7 @@ namespace ashes::d3d11 , VkFormat format , VkExtent2D const & dimensions , VkImageUsageFlags usageFlags - , VkImageTiling tiling - , VkMemoryPropertyFlags memoryFlags ) + , VkImageTiling tiling ) : Image{ device , { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, @@ -96,10 +95,6 @@ namespace ashes::d3d11 doInitialiseMemoryRequirements(); } - Image::~Image() - { - } - VkMemoryRequirements Image::getMemoryRequirements()const { return m_memoryRequirements; diff --git a/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.hpp b/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.hpp index 78fc59378..57ce08d1e 100644 --- a/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.hpp +++ b/source/ashes/renderer/D3D11Renderer/Image/D3D11Image.hpp @@ -17,8 +17,8 @@ namespace ashes::d3d11 public: Image( VkImage ) = delete; Image & operator=( VkImage ) = delete; - Image( Image && rhs ); - Image & operator=( Image && rhs ); + Image( Image && rhs )noexcept; + Image & operator=( Image && rhs )noexcept; Image( VkDevice device , VkImageCreateInfo createInfo ); @@ -30,9 +30,8 @@ namespace ashes::d3d11 , VkFormat format , VkExtent2D const & dimensions , VkImageUsageFlags usageFlags - , VkImageTiling tiling - , VkMemoryPropertyFlags memoryFlags ); - ~Image(); + , VkImageTiling tiling ); + ~Image()noexcept = default; VkMemoryRequirements getMemoryRequirements()const; std::vector< VkSparseImageMemoryRequirements > getSparseImageMemoryRequirements()const; @@ -41,114 +40,114 @@ namespace ashes::d3d11 , VkDeviceSize memoryOffset ); bool isMapped()const; - inline ID3D11Resource * getResource()const + ID3D11Resource * getResource()const noexcept { return m_image.resource; } - inline ID3D11Texture1D * getTexture1D()const + ID3D11Texture1D * getTexture1D()const noexcept { assert( getType() == VK_IMAGE_TYPE_1D ); return m_image.tex1D; } - inline ID3D11Texture2D * getTexture2D()const + ID3D11Texture2D * getTexture2D()const noexcept { assert( getType() == VK_IMAGE_TYPE_2D ); return m_image.tex2D; } - inline ID3D11Texture3D * getTexture3D()const + ID3D11Texture3D * getTexture3D()const noexcept { assert( getType() == VK_IMAGE_TYPE_3D ); return m_image.tex3D; } - inline bool isRenderTarget()const + bool isRenderTarget()const noexcept { return ashes::d3d11::isRenderTarget( m_createInfo.usage ); } - inline uint32_t getMipmapLevels()const + uint32_t getMipmapLevels()const noexcept { return m_createInfo.mipLevels; } - inline uint32_t getLayerCount()const + uint32_t getLayerCount()const noexcept { return m_createInfo.arrayLayers; } - inline bool isSamplable()const + bool isSamplable()const noexcept { return checkFlag( m_createInfo.usage, VK_IMAGE_USAGE_SAMPLED_BIT ) || checkFlag( m_createInfo.usage, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT ); } - inline bool isStorage()const + bool isStorage()const noexcept { return checkFlag( m_createInfo.usage, VK_IMAGE_USAGE_STORAGE_BIT ); } - inline VkDeviceMemory getMemory()const + VkDeviceMemory getMemory()const noexcept { assert( m_memory != nullptr ); return m_memory; } - inline VkDeviceSize getMemoryAlignment()const + VkDeviceSize getMemoryAlignment()const noexcept { return m_memoryRequirements.alignment; } - inline VkDeviceSize getMemoryOffset()const + VkDeviceSize getMemoryOffset()const noexcept { return m_memoryOffset; } - inline VkImageCreateInfo const & getCreateInfo()const + VkImageCreateInfo const & getCreateInfo()const noexcept { return m_createInfo; } - inline VkExtent3D const & getDimensions()const + VkExtent3D const & getDimensions()const noexcept { return m_createInfo.extent; } - inline VkImageUsageFlags getUsage()const noexcept + VkImageUsageFlags getUsage()const noexcept { return m_createInfo.usage; } - inline VkFormat getFormat()const + VkFormat getFormat()const noexcept { return m_createInfo.format; } - inline VkSampleCountFlagBits getSamplesCount()const + VkSampleCountFlagBits getSamplesCount()const noexcept { return m_createInfo.samples; } - inline VkImageType getType()const + VkImageType getType()const noexcept { return m_createInfo.imageType; } - inline VkDevice getDevice()const + VkDevice getDevice()const noexcept { return m_device; } - inline ObjectMemory const & getObjectMemory()const + ObjectMemory const & getObjectMemory()const noexcept { assert( m_objectMemory != nullptr ); return *m_objectMemory; } - inline void setDebugName( std::string name ) + void setDebugName( std::string name )noexcept { m_debugName = std::move( name ); } @@ -165,12 +164,12 @@ namespace ashes::d3d11 ID3D11Texture1D * tex1D; ID3D11Texture2D * tex2D; ID3D11Texture3D * tex3D; - } m_image; + } m_image{}; VkDeviceMemory m_memory{}; VkDeviceSize m_memoryOffset{ 0u }; ObjectMemory * m_objectMemory{ nullptr }; std::string m_debugName; - VkMemoryRequirements m_memoryRequirements; + VkMemoryRequirements m_memoryRequirements{}; }; } diff --git a/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.cpp b/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.cpp index 4a3f698a4..594ae1168 100644 --- a/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.cpp +++ b/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.cpp @@ -81,7 +81,7 @@ namespace ashes::d3d11 } } - ImageView::~ImageView() + ImageView::~ImageView()noexcept { safeRelease( m_renderTargetView ); safeRelease( m_depthStencilView ); diff --git a/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.hpp b/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.hpp index 195d83b8e..03a13282f 100644 --- a/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.hpp +++ b/source/ashes/renderer/D3D11Renderer/Image/D3D11ImageView.hpp @@ -13,15 +13,16 @@ namespace ashes::d3d11 { class ImageView + : public NonCopyable { public: ImageView( VkDevice device , VkImageViewCreateInfo createInfo ); - ~ImageView(); + ~ImageView()noexcept; UINT getSubresource( uint32_t layer )const; - inline ID3D11View * getView()const + ID3D11View * getView()const { using ViewPtr = ID3D11View*; return m_renderTargetView @@ -35,37 +36,37 @@ namespace ashes::d3d11 : nullptr ) ) ); } - inline ID3D11RenderTargetView * getRenderTargetView()const + ID3D11RenderTargetView * getRenderTargetView()const { return m_renderTargetView; } - inline ID3D11DepthStencilView * getDepthStencilView()const + ID3D11DepthStencilView * getDepthStencilView()const { return m_depthStencilView; } - inline ID3D11UnorderedAccessView * getUnorderedAccessView()const + ID3D11UnorderedAccessView * getUnorderedAccessView()const { return m_unorderedAccessView; } - inline ID3D11ShaderResourceView * getShaderView()const + ID3D11ShaderResourceView * getShaderView()const { return m_shaderView; } - inline VkFormat getFormat()const + VkFormat getFormat()const { return m_createInfo.format; } - inline VkImage getImage()const + VkImage getImage()const { return m_createInfo.image; } - inline VkImageSubresourceRange const & getSubResourceRange()const + VkImageSubresourceRange const & getSubResourceRange()const { return m_createInfo.subresourceRange; } diff --git a/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.cpp b/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.cpp index 30a94fdbe..2b72bf473 100644 --- a/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.cpp +++ b/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.cpp @@ -6,120 +6,123 @@ namespace ashes::d3d11 { - D3D11_TEXTURE_ADDRESS_MODE convert( VkSamplerAddressMode mode ) + namespace spl { - switch ( mode ) + D3D11_TEXTURE_ADDRESS_MODE convert( VkSamplerAddressMode mode ) { - case VK_SAMPLER_ADDRESS_MODE_REPEAT: - return D3D11_TEXTURE_ADDRESS_WRAP; + switch ( mode ) + { + case VK_SAMPLER_ADDRESS_MODE_REPEAT: + return D3D11_TEXTURE_ADDRESS_WRAP; - case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: - return D3D11_TEXTURE_ADDRESS_MIRROR; + case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: + return D3D11_TEXTURE_ADDRESS_MIRROR; - case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: - return D3D11_TEXTURE_ADDRESS_CLAMP; + case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: + return D3D11_TEXTURE_ADDRESS_CLAMP; - case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER: - return D3D11_TEXTURE_ADDRESS_BORDER; + case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER: + return D3D11_TEXTURE_ADDRESS_BORDER; - case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE: - return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE; + case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE: + return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE; - default: - assert( false && "Unsupported VkSamplerAddressMode" ); - return D3D11_TEXTURE_ADDRESS_WRAP; + default: + assert( false && "Unsupported VkSamplerAddressMode" ); + return D3D11_TEXTURE_ADDRESS_WRAP; + } } - } - void convert( VkBorderColor colour - , float output[4] ) - { - switch ( colour ) + void convert( VkBorderColor colour + , float output[4] ) { - case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK: - case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK: - output[0] = 0.0; - output[1] = 0.0; - output[2] = 0.0; - output[3] = 0.0; - break; - case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK: - case VK_BORDER_COLOR_INT_OPAQUE_BLACK: - output[0] = 0.0; - output[1] = 0.0; - output[2] = 0.0; - output[3] = 1.0; - break; - case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE: - case VK_BORDER_COLOR_INT_OPAQUE_WHITE: - output[0] = 1.0; - output[1] = 1.0; - output[2] = 1.0; - output[3] = 1.0; - break; - default: - break; + switch ( colour ) + { + case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK: + case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK: + output[0] = 0.0; + output[1] = 0.0; + output[2] = 0.0; + output[3] = 0.0; + break; + case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK: + case VK_BORDER_COLOR_INT_OPAQUE_BLACK: + output[0] = 0.0; + output[1] = 0.0; + output[2] = 0.0; + output[3] = 1.0; + break; + case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE: + case VK_BORDER_COLOR_INT_OPAQUE_WHITE: + output[0] = 1.0; + output[1] = 1.0; + output[2] = 1.0; + output[3] = 1.0; + break; + default: + break; + } } - } - D3D11_FILTER convert( VkFilter min - , VkFilter mag - , VkSamplerMipmapMode mip - , float maxAnisotropy ) - { - if ( maxAnisotropy > 1.0 ) + D3D11_FILTER convert( VkFilter min + , VkFilter mag + , VkSamplerMipmapMode mip + , float maxAnisotropy ) { - return D3D11_FILTER_ANISOTROPIC; - } + if ( maxAnisotropy > 1.0 ) + { + return D3D11_FILTER_ANISOTROPIC; + } - if ( min == VK_FILTER_NEAREST ) - { - if ( mag == VK_FILTER_NEAREST ) + if ( min == VK_FILTER_NEAREST ) { + if ( mag == VK_FILTER_NEAREST ) + { + switch ( mip ) + { + case VK_SAMPLER_MIPMAP_MODE_NEAREST: + return D3D11_FILTER_MIN_MAG_MIP_POINT; + case VK_SAMPLER_MIPMAP_MODE_LINEAR: + return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; + default: + return D3D11_FILTER_MIN_MAG_MIP_POINT; + } + } + switch ( mip ) { case VK_SAMPLER_MIPMAP_MODE_NEAREST: - return D3D11_FILTER_MIN_MAG_MIP_POINT; + return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; case VK_SAMPLER_MIPMAP_MODE_LINEAR: - return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; + return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; default: - return D3D11_FILTER_MIN_MAG_MIP_POINT; + return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; } } - switch ( mip ) + if ( mag == VK_FILTER_NEAREST ) { - case VK_SAMPLER_MIPMAP_MODE_NEAREST: - return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; - case VK_SAMPLER_MIPMAP_MODE_LINEAR: - return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; - default: - return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; + switch ( mip ) + { + case VK_SAMPLER_MIPMAP_MODE_NEAREST: + return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; + case VK_SAMPLER_MIPMAP_MODE_LINEAR: + return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + default: + return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; + } } - } - if ( mag == VK_FILTER_NEAREST ) - { switch ( mip ) { case VK_SAMPLER_MIPMAP_MODE_NEAREST: - return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; + return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; case VK_SAMPLER_MIPMAP_MODE_LINEAR: - return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + return D3D11_FILTER_MIN_MAG_MIP_LINEAR; default: - return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; + return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; } } - - switch ( mip ) - { - case VK_SAMPLER_MIPMAP_MODE_NEAREST: - return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - case VK_SAMPLER_MIPMAP_MODE_LINEAR: - return D3D11_FILTER_MIN_MAG_MIP_LINEAR; - default: - return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - } } Sampler::Sampler( VkDevice device @@ -129,12 +132,12 @@ namespace ashes::d3d11 { auto d3ddevice = get( device )->getDevice(); D3D11_SAMPLER_DESC desc{}; - desc.AddressU = convert( createInfo.addressModeU ); - desc.AddressV = convert( createInfo.addressModeV ); - desc.AddressW = convert( createInfo.addressModeW ); - convert( createInfo.borderColor, desc.BorderColor ); + desc.AddressU = spl::convert( createInfo.addressModeU ); + desc.AddressV = spl::convert( createInfo.addressModeV ); + desc.AddressW = spl::convert( createInfo.addressModeW ); + spl::convert( createInfo.borderColor, desc.BorderColor ); desc.ComparisonFunc = getComparisonFunc( createInfo.compareOp ); - desc.Filter = convert( createInfo.minFilter + desc.Filter = spl::convert( createInfo.minFilter , createInfo.magFilter , createInfo.mipmapMode , createInfo.maxAnisotropy ); @@ -150,7 +153,7 @@ namespace ashes::d3d11 } } - Sampler::~Sampler() + Sampler::~Sampler()noexcept { safeRelease( m_sampler ); } diff --git a/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.hpp b/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.hpp index 117a63c00..ddcb94860 100644 --- a/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.hpp +++ b/source/ashes/renderer/D3D11Renderer/Image/D3D11Sampler.hpp @@ -13,18 +13,19 @@ namespace ashes::d3d11 { class Sampler + : public NonCopyable { public: Sampler( VkDevice device , VkSamplerCreateInfo createInfo ); - ~Sampler(); + ~Sampler()noexcept; - inline ID3D11SamplerState * getSampler()const + ID3D11SamplerState * getSampler()const { return m_sampler; } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.cpp b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.cpp index cfb00efff..6153ab9a1 100644 --- a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.cpp +++ b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.cpp @@ -23,40 +23,40 @@ namespace ashes::d3d11 { //********************************************************************************************* - VkMemoryPropertyFlags getMemoryProperties( uint32_t memoryTypeIndex ) + namespace mem { - assert( memoryTypeIndex < Instance::getMemoryProperties().memoryTypeCount - && "Wrong deduced memory type" ); - return Instance::getMemoryProperties().memoryTypes[memoryTypeIndex].propertyFlags; - } + static VkMemoryPropertyFlags getMemoryProperties( uint32_t memoryTypeIndex ) + { + assert( memoryTypeIndex < Instance::getMemoryProperties().memoryTypeCount + && "Wrong deduced memory type" ); + return Instance::getMemoryProperties().memoryTypes[memoryTypeIndex].propertyFlags; + } - UINT getBindFlags( VkImageCreateInfo const & createInfo - , VkMemoryPropertyFlags propertyFlags ) - { - return ( ( isSampled( createInfo.usage ) - ? D3D11_BIND_SHADER_RESOURCE - : 0u ) - | ( isRenderable( createInfo.usage, createInfo.format, createInfo.mipLevels ) - ? ( isHostVisible( propertyFlags ) - ? 0u - : ( isDepthOrStencilFormat( createInfo.format ) - ? D3D11_BIND_DEPTH_STENCIL - : D3D11_BIND_RENDER_TARGET ) ) - : 0u ) - | ( isStorage( createInfo.usage ) - ? D3D11_BIND_UNORDERED_ACCESS - : 0 ) ); - } + static UINT getBindFlags( VkImageCreateInfo const & createInfo + , VkMemoryPropertyFlags propertyFlags ) + { + return ( ( isSampled( createInfo.usage ) + ? D3D11_BIND_SHADER_RESOURCE + : 0u ) + | ( isRenderable( createInfo.usage, createInfo.format, createInfo.mipLevels ) + ? ( isHostVisible( propertyFlags ) + ? 0u + : ( isDepthOrStencilFormat( createInfo.format ) + ? D3D11_BIND_DEPTH_STENCIL + : D3D11_BIND_RENDER_TARGET ) ) + : 0u ) + | ( isStorage( createInfo.usage ) + ? D3D11_BIND_UNORDERED_ACCESS + : 0 ) ); + } - UINT getMiscFlags( VkImageCreateInfo const & createInfo ) - { - return 0u - //| ( isMipmapped( createInfo.usage, createInfo.format, createInfo.mipLevels ) - // ? D3D11_RESOURCE_MISC_GENERATE_MIPS - // : 0 ) - | ( checkFlag( createInfo.flags, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT ) - ? D3D11_RESOURCE_MISC_TEXTURECUBE - : 0u ); + static UINT getMiscFlags( VkImageCreateInfo const & createInfo ) + { + return 0u + | ( checkFlag( createInfo.flags, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT ) + ? D3D11_RESOURCE_MISC_TEXTURECUBE + : 0u ); + } } //********************************************************************************************* @@ -120,13 +120,12 @@ namespace ashes::d3d11 , UINT subresource , D3D11_MAPPED_SUBRESOURCE & data )const { - HRESULT hr = context->Map( resource - , subresource - , mapFlags - , 0 - , &data ); - - if ( !checkError( device, hr, "LockMemory" ) ) + if ( HRESULT hr = context->Map( resource + , subresource + , mapFlags + , 0 + , &data ); + !checkError( device, hr, "LockMemory" ) ) { return VK_ERROR_MEMORY_MAP_FAILED; } @@ -166,13 +165,15 @@ namespace ashes::d3d11 if ( lock( *context, subresource, mapped ) == VK_SUCCESS ) { + assert( mapped.pData != nullptr ); + auto dstData = static_cast< uint8_t * >( mapped.pData ) + objectOffset; + assert( dstData != nullptr ); + if ( mapped.DepthPitch == subresourceLayout.SysMemSlicePitch || mapped.RowPitch == subresourceLayout.SysMemPitch ) { copySize = std::min( copySize, VkDeviceSize( mapped.DepthPitch ) ); - std::memcpy( static_cast< uint8_t * >( mapped.pData ) + objectOffset - , data + maxOffset - , copySize ); + std::memcpy( dstData, data + maxOffset, copySize ); } else { @@ -181,7 +182,7 @@ namespace ashes::d3d11 auto rowSize = std::min( mapped.RowPitch, subresourceLayout.SysMemPitch ); assert( mappedSteps == systemSteps ); auto src = data + maxOffset; - auto dst = static_cast< uint8_t * >( mapped.pData ) + objectOffset; + auto dst = dstData; for ( UINT step = 0u; step < std::min( mappedSteps, systemSteps ); ++step ) { @@ -222,13 +223,17 @@ namespace ashes::d3d11 if ( lock( *context, subresource, mapped ) == VK_SUCCESS ) { + assert( mapped.pData != nullptr ); + auto srcData = static_cast< uint8_t const * >( mapped.pData ) + objectOffset; + assert( srcData != nullptr ); + if ( mapped.RowPitch != subresourceLayout.SysMemPitch ) { auto mappedSteps = mapped.DepthPitch / mapped.RowPitch; auto systemSteps = subresourceLayout.SysMemSlicePitch / subresourceLayout.SysMemPitch; auto rowSize = std::min( mapped.RowPitch, subresourceLayout.SysMemPitch ); assert( mappedSteps == systemSteps ); - auto src = static_cast< uint8_t const * >( mapped.pData ) + objectOffset; + auto src = srcData; auto dst = data + maxOffset; for ( UINT step = 0u; step < std::min( mappedSteps, systemSteps ); ++step ) @@ -241,9 +246,7 @@ namespace ashes::d3d11 else { copySize = std::min( copySize, VkDeviceSize( mapped.DepthPitch ) ); - std::memcpy( data + maxOffset - , static_cast< uint8_t * >( mapped.pData ) + objectOffset - , copySize ); + std::memcpy( data + maxOffset, srcData, copySize ); } unlock( *context, subresource ); @@ -261,17 +264,13 @@ namespace ashes::d3d11 , VkMemoryAllocateInfo allocateInfo , VkBufferUsageFlags targets ) : m_bufferTargets{ targets } - , m_propertyFlags{ getMemoryProperties( allocateInfo.memoryTypeIndex ) } + , m_propertyFlags{ mem::getMemoryProperties( allocateInfo.memoryTypeIndex ) } , m_buffer{ doCreateBuffer( device, allocateInfo ) } , memory{ device, parent, m_buffer, offset, std::move( allocateInfo ), getBufferMapFlags( m_propertyFlags, m_bufferTargets ) } { memory.subresources.push_back( { nullptr, UINT( memory.allocateInfo.allocationSize ), UINT( memory.allocateInfo.allocationSize ) } ); } - ~BufferDeviceMemory()noexcept - { - } - inline ID3D11Buffer * getBuffer()const { return m_buffer; @@ -283,9 +282,9 @@ namespace ashes::d3d11 { ID3D11Buffer * result{ nullptr }; auto d3ddevice = get( device )->getDevice(); - UINT size = UINT( allocateInfo.allocationSize ); - if ( size > 0 ) + if ( auto size = UINT( allocateInfo.allocationSize ); + size > 0 ) { D3D11_BUFFER_DESC desc{}; desc.ByteWidth = size; @@ -328,13 +327,13 @@ namespace ashes::d3d11 , VkMemoryAllocateInfo allocateInfo , VkImageCreateInfo const & createInfo ) : m_usage{ createInfo.usage } - , m_propertyFlags{ getMemoryProperties( allocateInfo.memoryTypeIndex ) } + , m_propertyFlags{ mem::getMemoryProperties( allocateInfo.memoryTypeIndex ) } , m_texture{ doCreateTexture( device, createInfo ) } , memory{ device, parent, m_texture, offset, std::move( allocateInfo ), getImageMapFlags( m_propertyFlags, m_usage ) } { auto extent = getTexelBlockExtent( createInfo.format ); auto byteSize = getTexelBlockByteSize( extent, createInfo.format ); - memory.subresources.resize( createInfo.arrayLayers * createInfo.mipLevels ); + memory.subresources.resize( size_t( createInfo.arrayLayers ) * createInfo.mipLevels ); for ( uint32_t layer = 0u; layer < createInfo.arrayLayers; ++layer ) { @@ -349,10 +348,6 @@ namespace ashes::d3d11 } } - ~Texture1DDeviceMemory()noexcept - { - } - inline ID3D11Texture1D * getImage()const { return m_texture; @@ -362,16 +357,16 @@ namespace ashes::d3d11 ID3D11Texture1D * doCreateTexture( VkDevice device , VkImageCreateInfo const & createInfo )const { - ID3D11Texture1D * result; + ID3D11Texture1D * result{}; getImageMapFlags( m_propertyFlags, m_usage ); auto d3ddevice = get( device )->getDevice(); D3D11_TEXTURE1D_DESC desc{}; doInitTexDesc( device, createInfo, desc ); - HRESULT hr = d3ddevice->CreateTexture1D( &desc - , nullptr - , &result ); - if ( checkError( device, hr, "CreateTexture1D" ) ) + if ( HRESULT hr = d3ddevice->CreateTexture1D( &desc + , nullptr + , &result ); + checkError( device, hr, "CreateTexture1D" ) ) { dxDebugName( result, Texture1D ); } @@ -389,12 +384,12 @@ namespace ashes::d3d11 desc.Usage = getImageUsage( m_propertyFlags, m_usage ); desc.CPUAccessFlags = getCpuImageAccessFlags( m_propertyFlags, m_usage ); desc.MipLevels = createInfo.mipLevels; - desc.BindFlags = getBindFlags( createInfo, m_propertyFlags ); - desc.MiscFlags = getMiscFlags( createInfo ); + desc.BindFlags = mem::getBindFlags( createInfo, m_propertyFlags ); + desc.MiscFlags = mem::getMiscFlags( createInfo ); if ( get( device )->getFeatureLevel() < D3D_FEATURE_LEVEL_11_0 ) { - desc.BindFlags &= ~( D3D11_BIND_UNORDERED_ACCESS ); + desc.BindFlags &= ~D3D11_BIND_UNORDERED_ACCESS; } } @@ -418,13 +413,13 @@ namespace ashes::d3d11 , VkMemoryAllocateInfo allocateInfo , VkImageCreateInfo const & createInfo ) : m_usage{ createInfo.usage } - , m_propertyFlags{ getMemoryProperties( allocateInfo.memoryTypeIndex ) } + , m_propertyFlags{ mem::getMemoryProperties( allocateInfo.memoryTypeIndex ) } , m_texture{ doCreateTexture( device, createInfo ) } , memory{ device, parent, m_texture, offset, std::move( allocateInfo ), getImageMapFlags( m_propertyFlags, m_usage ) } { auto extent = getTexelBlockExtent( createInfo.format ); auto byteSize = getTexelBlockByteSize( extent, createInfo.format ); - memory.subresources.resize( createInfo.arrayLayers * createInfo.mipLevels ); + memory.subresources.resize( size_t( createInfo.arrayLayers ) * createInfo.mipLevels ); for ( uint32_t layer = 0u; layer < createInfo.arrayLayers; ++layer ) { @@ -439,10 +434,6 @@ namespace ashes::d3d11 } } - ~Texture2DDeviceMemory()noexcept - { - } - inline ID3D11Texture2D * getImage()const { return m_texture; @@ -452,15 +443,15 @@ namespace ashes::d3d11 ID3D11Texture2D * doCreateTexture( VkDevice device , VkImageCreateInfo const & createInfo )const { - ID3D11Texture2D * result; + ID3D11Texture2D * result{}; auto d3ddevice = get( device )->getDevice(); D3D11_TEXTURE2D_DESC desc{}; doInitTexDesc( device, createInfo, desc ); - HRESULT hr = d3ddevice->CreateTexture2D( &desc - , nullptr - , &result ); - if ( checkError( device, hr, "CreateTexture2D" ) ) + if ( HRESULT hr = d3ddevice->CreateTexture2D( &desc + , nullptr + , &result ); + checkError( device, hr, "CreateTexture2D" ) ) { dxDebugName( result, Texture2D ); } @@ -482,8 +473,8 @@ namespace ashes::d3d11 desc.MipLevels = createInfo.mipLevels; desc.SampleDesc.Count = UINT( createInfo.samples ); desc.SampleDesc.Quality = 0; - desc.BindFlags = getBindFlags( createInfo, m_propertyFlags ); - desc.MiscFlags = getMiscFlags( createInfo ); + desc.BindFlags = mem::getBindFlags( createInfo, m_propertyFlags ); + desc.MiscFlags = mem::getMiscFlags( createInfo ); if ( desc.SampleDesc.Count > 1 ) { @@ -499,7 +490,7 @@ namespace ashes::d3d11 if ( get( device )->getFeatureLevel() < D3D_FEATURE_LEVEL_11_0 ) { - desc.BindFlags &= ~( D3D11_BIND_UNORDERED_ACCESS ); + desc.BindFlags &= ~D3D11_BIND_UNORDERED_ACCESS; } } @@ -523,13 +514,13 @@ namespace ashes::d3d11 , VkMemoryAllocateInfo allocateInfo , VkImageCreateInfo const & createInfo ) : m_usage{ createInfo.usage } - , m_propertyFlags{ getMemoryProperties( allocateInfo.memoryTypeIndex ) } + , m_propertyFlags{ mem::getMemoryProperties( allocateInfo.memoryTypeIndex ) } , m_texture{ doCreateTexture( device, createInfo ) } , memory{ device, parent, m_texture, offset, std::move( allocateInfo ), getImageMapFlags( m_propertyFlags, m_usage ) } { auto extent = getTexelBlockExtent( createInfo.format ); auto byteSize = getTexelBlockByteSize( extent, createInfo.format ); - memory.subresources.resize( createInfo.arrayLayers * createInfo.mipLevels ); + memory.subresources.resize( size_t( createInfo.arrayLayers ) * createInfo.mipLevels ); for ( uint32_t layer = 0u; layer < createInfo.arrayLayers; ++layer ) { @@ -544,10 +535,6 @@ namespace ashes::d3d11 } } - ~Texture3DDeviceMemory()noexcept - { - } - inline ID3D11Texture3D * getImage()const { return m_texture; @@ -557,15 +544,15 @@ namespace ashes::d3d11 ID3D11Texture3D * doCreateTexture( VkDevice device , VkImageCreateInfo const & createInfo )const { - ID3D11Texture3D * result; + ID3D11Texture3D * result{}; auto d3ddevice = get( device )->getDevice(); D3D11_TEXTURE3D_DESC desc{}; doInitTexDesc( device, createInfo, desc ); - HRESULT hr = d3ddevice->CreateTexture3D( &desc - , nullptr - , &result ); - if ( checkError( device, hr, "CreateTexture3D" ) ) + if ( HRESULT hr = d3ddevice->CreateTexture3D( &desc + , nullptr + , &result ); + checkError( device, hr, "CreateTexture3D" ) ) { dxDebugName( result, Texture3D ); } @@ -584,12 +571,12 @@ namespace ashes::d3d11 desc.Usage = getImageUsage( m_propertyFlags, m_usage ); desc.CPUAccessFlags = getCpuImageAccessFlags( m_propertyFlags, m_usage ); desc.MipLevels = createInfo.mipLevels; - desc.BindFlags = getBindFlags( createInfo, m_propertyFlags ); - desc.MiscFlags = getMiscFlags( createInfo ); + desc.BindFlags = mem::getBindFlags( createInfo, m_propertyFlags ); + desc.MiscFlags = mem::getMiscFlags( createInfo ); if ( get( device )->getFeatureLevel() < D3D_FEATURE_LEVEL_11_0 ) { - desc.BindFlags &= ~( D3D11_BIND_UNORDERED_ACCESS ); + desc.BindFlags &= ~D3D11_BIND_UNORDERED_ACCESS; } } @@ -608,17 +595,18 @@ namespace ashes::d3d11 , VkMemoryAllocateInfo allocateInfo ) : m_device{ device } , m_allocateInfo{ std::move( allocateInfo ) } - , m_propertyFlags{ getMemoryProperties( m_allocateInfo.memoryTypeIndex ) } + , m_propertyFlags{ mem::getMemoryProperties( m_allocateInfo.memoryTypeIndex ) } { thread_local uint8_t defaultInitValue = 10u; if ( ashes::checkFlag( m_propertyFlags, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ) ) { - m_data.resize( allocateInfo.allocationSize, defaultInitValue++ ); + m_data.resize( allocateInfo.allocationSize, defaultInitValue ); + ++defaultInitValue; } } - DeviceMemory::~DeviceMemory() + DeviceMemory::~DeviceMemory()noexcept { if ( !m_objects.empty() ) { @@ -644,7 +632,7 @@ namespace ashes::d3d11 }; m_objects.emplace_back( std::make_unique< ObjectMemory >( std::move( impl.memory ) ) ); objectMemory = m_objects.back().get(); - updateUpload( *objectMemory, 0ull, WholeSize, 0u ); + updateUpload( *objectMemory, 0ULL, WholeSize, 0u ); result = VK_SUCCESS; } catch ( Exception & exc ) @@ -682,7 +670,7 @@ namespace ashes::d3d11 }; m_objects.emplace_back( std::make_unique< ObjectMemory >( std::move( impl.memory ) ) ); objectMemory = m_objects.back().get(); - updateUpload( *objectMemory, 0ull, WholeSize, 0u ); + updateUpload( *objectMemory, 0ULL, WholeSize, 0u ); result = VK_SUCCESS; } catch ( Exception & exc ) @@ -720,7 +708,7 @@ namespace ashes::d3d11 }; m_objects.emplace_back( std::make_unique< ObjectMemory >( std::move( impl.memory ) ) ); objectMemory = m_objects.back().get(); - updateUpload( *objectMemory, 0ull, WholeSize, 0u ); + updateUpload( *objectMemory, 0ULL, WholeSize, 0u ); result = VK_SUCCESS; } catch ( Exception & exc ) @@ -758,7 +746,7 @@ namespace ashes::d3d11 }; m_objects.emplace_back( std::make_unique< ObjectMemory >( std::move( impl.memory ) ) ); objectMemory = m_objects.back().get(); - updateUpload( *objectMemory, 0ull, WholeSize, 0u ); + updateUpload( *objectMemory, 0ULL, WholeSize, 0u ); result = VK_SUCCESS; } catch ( Exception & exc ) diff --git a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.hpp b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.hpp index d3a601b53..859bf72d3 100644 --- a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.hpp +++ b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11DeviceMemory.hpp @@ -44,14 +44,14 @@ namespace ashes::d3d11 , VkDeviceSize size )const; public: - VkDevice device; - VkDeviceMemory deviceMemory; - ID3D11Resource * resource; - VkDeviceSize offset; - VkDeviceSize size; - VkMemoryAllocateInfo allocateInfo; - D3D11_MAP mapFlags; - std::vector< D3D11_SUBRESOURCE_DATA > subresources; + VkDevice device{}; + VkDeviceMemory deviceMemory{}; + ID3D11Resource * resource{}; + VkDeviceSize offset{}; + VkDeviceSize size{}; + VkMemoryAllocateInfo allocateInfo{}; + D3D11_MAP mapFlags{}; + std::vector< D3D11_SUBRESOURCE_DATA > subresources{}; }; using ObjectMemoryPtr = std::unique_ptr< ObjectMemory >; /** @@ -63,7 +63,7 @@ namespace ashes::d3d11 public: DeviceMemory( VkDevice device , VkMemoryAllocateInfo allocateInfo ); - ~DeviceMemory(); + ~DeviceMemory()noexcept; VkResult bindToBuffer( VkBuffer buffer , VkDeviceSize memoryOffset , ObjectMemory *& objectMemory ); @@ -106,27 +106,27 @@ namespace ashes::d3d11 , VkDeviceSize size )const; void unlock()const; - inline bool isMapped()const + bool isMapped()const { return m_mapped; } - inline void upload()const + void upload()const { upload( m_mappedOffset, m_mappedSize ); } - inline void download()const + void download()const { download( m_mappedOffset, m_mappedSize ); } - inline VkMemoryPropertyFlags getMemoryPropertyFlags()const + VkMemoryPropertyFlags getMemoryPropertyFlags()const { return m_propertyFlags; } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } @@ -155,11 +155,11 @@ namespace ashes::d3d11 } private: - VkDevice m_device; - VkMemoryAllocateInfo m_allocateInfo; - VkMemoryPropertyFlags m_propertyFlags; - VkMemoryRequirements m_requirements; - std::vector< ObjectMemoryPtr > m_objects; + VkDevice m_device{}; + VkMemoryAllocateInfo m_allocateInfo{}; + VkMemoryPropertyFlags m_propertyFlags{}; + VkMemoryRequirements m_requirements{}; + std::vector< ObjectMemoryPtr > m_objects{}; mutable bool m_dirty{ true }; mutable bool m_mapped{ false }; mutable VkDeviceSize m_mappedOffset{ 0u }; diff --git a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.cpp b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.cpp index d04673695..b0471a2ea 100644 --- a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.cpp +++ b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.cpp @@ -14,13 +14,10 @@ namespace ashes::d3d11 { case VK_QUERY_TYPE_OCCLUSION: return D3D11_QUERY_OCCLUSION; - case VK_QUERY_TYPE_PIPELINE_STATISTICS: return D3D11_QUERY_PIPELINE_STATISTICS; - case VK_QUERY_TYPE_TIMESTAMP: return D3D11_QUERY_TIMESTAMP; - default: assert( false ); return D3D11_QUERY_TIMESTAMP; @@ -54,14 +51,13 @@ namespace ashes::d3d11 return stats.DSInvocations; case 10: return stats.CSInvocations; + default: + return 0ULL; } - - return 0ull; } uint32_t adjustQueryCount( uint32_t count - , VkQueryType type - , VkQueryPipelineStatisticFlags pipelineStatistics ) + , VkQueryType type ) { if ( type != VK_QUERY_TYPE_PIPELINE_STATISTICS ) { @@ -77,16 +73,15 @@ namespace ashes::d3d11 : m_device{ device } , m_createInfo{ std::move( createInfo ) } { - D3D11_QUERY_DESC desc; + D3D11_QUERY_DESC desc{}; desc.MiscFlags = 0u; desc.Query = convert( m_createInfo.queryType ); - m_queries.resize( adjustQueryCount( m_createInfo.queryCount, m_createInfo.queryType, m_createInfo.pipelineStatistics ) ); + m_queries.resize( adjustQueryCount( m_createInfo.queryCount, m_createInfo.queryType ) ); for ( auto & query : m_queries ) { - auto hr = get( m_device )->getDevice()->CreateQuery( &desc, &query ); - - if ( checkError( m_device, hr, "CreateQuery" ) ) + if ( auto hr = get( m_device )->getDevice()->CreateQuery( &desc, &query ); + checkError( m_device, hr, "CreateQuery" ) ) { dxDebugName( query, Query ); } @@ -96,11 +91,11 @@ namespace ashes::d3d11 { case VK_QUERY_TYPE_OCCLUSION: m_data.resize( sizeof( uint64_t ) ); - getUint32 = [this]( uint32_t index ) + getUint32 = [this]( uint32_t ) { return uint32_t( *reinterpret_cast< uint64_t * >( m_data.data() ) ); }; - getUint64 = [this]( uint32_t index ) + getUint64 = [this]( uint32_t ) { return *reinterpret_cast< uint64_t * >( m_data.data() ); }; @@ -122,11 +117,11 @@ namespace ashes::d3d11 case VK_QUERY_TYPE_TIMESTAMP: m_data.resize( sizeof( uint64_t ) ); - getUint32 = [this]( uint32_t index ) + getUint32 = [this]( uint32_t ) { return uint32_t( *reinterpret_cast< uint64_t * >( m_data.data() ) ); }; - getUint64 = [this]( uint32_t index ) + getUint64 = [this]( uint32_t ) { return *reinterpret_cast< uint64_t * >( m_data.data() ); }; @@ -137,7 +132,7 @@ namespace ashes::d3d11 } } - QueryPool::~QueryPool() + QueryPool::~QueryPool()noexcept { for ( auto & query : m_queries ) { @@ -166,7 +161,6 @@ namespace ashes::d3d11 , queryCount , stride , flags - , dataSize , data ); } @@ -246,7 +240,6 @@ namespace ashes::d3d11 , uint32_t queryCount , VkDeviceSize stride , VkQueryResultFlags flags - , VkDeviceSize dataSize , void * data )const { auto max = firstQuery + queryCount; diff --git a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.hpp b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.hpp index 1ed06656d..143aedbed 100644 --- a/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.hpp +++ b/source/ashes/renderer/D3D11Renderer/Miscellaneous/D3D11QueryPool.hpp @@ -9,11 +9,12 @@ See LICENSE file in root folder namespace ashes::d3d11 { class QueryPool + : public NonCopyable { public: QueryPool( VkDevice device , VkQueryPoolCreateInfo createInfo ); - ~QueryPool(); + ~QueryPool()noexcept; VkResult getResults( uint32_t firstQuery , uint32_t queryCount @@ -22,17 +23,17 @@ namespace ashes::d3d11 , VkDeviceSize dataSize , void * data )const; - inline auto begin()const + auto begin()const noexcept { return m_queries.begin(); } - inline auto end()const + auto end()const noexcept { return m_queries.end(); } - inline VkDevice getDevice()const + VkDevice getDevice()const noexcept { return m_device; } @@ -48,7 +49,6 @@ namespace ashes::d3d11 , uint32_t queryCount , VkDeviceSize stride , VkQueryResultFlags flags - , VkDeviceSize dataSize , void * data )const; private: diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.cpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.cpp index a83d9b600..109beaa70 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.cpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.cpp @@ -23,8 +23,7 @@ namespace ashes::d3d11 } } - DynamicStates::DynamicStates( VkDevice device - , VkPipelineDynamicStateCreateInfo const * createInfo ) + DynamicStates::DynamicStates( VkPipelineDynamicStateCreateInfo const * createInfo ) : m_dynamicStates{ getStates( createInfo ) } , m_dynamicState{ getState( createInfo ) } { @@ -80,10 +79,6 @@ namespace ashes::d3d11 } } - DynamicStates::~DynamicStates() - { - } - void DynamicStates::setLineWidth( Optional< float > const & lineWidth ) { if ( lineWidth.has_value() diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.hpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.hpp index d9545ebe4..217337e30 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.hpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11DynamicStates.hpp @@ -15,9 +15,7 @@ namespace ashes::d3d11 class DynamicStates { public: - DynamicStates( VkDevice device - , VkPipelineDynamicStateCreateInfo const * createInfo ); - ~DynamicStates(); + DynamicStates( VkPipelineDynamicStateCreateInfo const * createInfo ); void setLineWidth( Optional< float > const & lineWidth ); void setDepthBias( Optional< DepthBias > const & depthBias ); diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.cpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.cpp index 995ae7770..2b304ba0f 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.cpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.cpp @@ -87,7 +87,7 @@ namespace ashes::d3d11 , m_colorBlendState{ ( createInfo.pColorBlendState ? deepCopy( *createInfo.pColorBlendState, m_colorBlendStateAttachments ) : VkPipelineColorBlendStateCreateInfo{} ) } - , m_dynamicStates{ device, createInfo.pDynamicState } + , m_dynamicStates{ createInfo.pDynamicState } , m_scissors{ makeScissors( m_stateScissors.begin(), m_stateScissors.end() ) } , m_viewports{ makeViewports( m_stateViewports.begin(), m_stateViewports.end() ) } , m_vertexInputStateHash{ doHash( m_vertexInputState ) } @@ -116,14 +116,14 @@ namespace ashes::d3d11 , VkComputePipelineCreateInfo createInfo ) : m_device{ device } , m_layout{ createInfo.layout } - , m_dynamicStates{ device, nullptr } + , m_dynamicStates{ nullptr } { doCompileProgram( device, { createInfo.stage }, createInfo.flags ); get( m_layout )->addPipeline( get( this ) ); } - Pipeline::~Pipeline() + Pipeline::~Pipeline()noexcept { if ( m_layout ) { @@ -265,9 +265,9 @@ namespace ashes::d3d11 { auto d3ddevice = get( device )->getDevice(); auto blendDesc = convert( m_colorBlendState ); - HRESULT hr = d3ddevice->CreateBlendState( &blendDesc, &m_bdState ); - if ( !checkError( device, hr, "CreateBlendState" ) ) + if ( HRESULT hr = d3ddevice->CreateBlendState( &blendDesc, &m_bdState ); + !checkError( device, hr, "CreateBlendState" ) ) { get( device )->onReportMessage( VK_DEBUG_REPORT_ERROR_BIT_EXT , VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT @@ -287,9 +287,9 @@ namespace ashes::d3d11 auto d3ddevice = get( device )->getDevice(); auto rasterizerDesc = convert( m_rasterizationState , m_multisampleState ); - auto hr = d3ddevice->CreateRasterizerState( &rasterizerDesc, &m_rsState ); - if ( !checkError( device, hr, "CreateRasterizerState" ) ) + if ( auto hr = d3ddevice->CreateRasterizerState( &rasterizerDesc, &m_rsState ); + !checkError( device, hr, "CreateRasterizerState" ) ) { get( device )->onReportMessage( VK_DEBUG_REPORT_ERROR_BIT_EXT , VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT @@ -310,9 +310,9 @@ namespace ashes::d3d11 { auto d3ddevice = get( device )->getDevice(); auto depthStencilDesc = convert( *m_depthStencilState ); - auto hr = d3ddevice->CreateDepthStencilState( &depthStencilDesc, &m_dsState ); - if ( !checkError( device, hr, "CreateDepthStencilState" ) ) + if ( auto hr = d3ddevice->CreateDepthStencilState( &depthStencilDesc, &m_dsState ); + !checkError( device, hr, "CreateDepthStencilState" ) ) { get( device )->onReportMessage( VK_DEBUG_REPORT_ERROR_BIT_EXT , VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT @@ -332,23 +332,23 @@ namespace ashes::d3d11 , VkPipelineShaderStageCreateInfoArray const & stages , VkPipelineCreateFlags createFlags ) { - for ( auto & state : stages ) + for ( auto const & state : stages ) { - auto module = get( state.module ); - m_programModules.push_back( module->compile( state, m_layout, createFlags ) ); - m_programLayout.emplace( state.stage, m_programModules.back().getLayout() ); + auto shaderModule = get( state.module ); + m_programModules.emplace_back( shaderModule->compile( state, m_layout, createFlags ) ); + m_programLayout.try_emplace( state.stage, m_programModules.back().getLayout() ); } - for ( auto & shaderLayoutIt : m_programLayout ) + for ( auto const & [stage, desc] : m_programLayout ) { - for ( auto & blockLayout : shaderLayoutIt.second.interfaceBlockLayout ) + for ( auto const & blockLayout : desc.interfaceBlockLayout ) { PushConstantsBuffer pcb { nullptr, blockLayout.binding, { - VkShaderStageFlags( shaderLayoutIt.first ), + VkShaderStageFlags( stage ), 0u, blockLayout.size }, @@ -395,20 +395,19 @@ namespace ashes::d3d11 if ( it != m_programLayout.end() ) { - auto compiled = it->second.module->getCompiled(); - auto & inputLayout = it->second.inputLayout; + auto compiled = it->second.shaderModule->getCompiled(); + auto const & inputLayout = it->second.inputLayout; auto d3ddevice = get( device )->getDevice(); auto inputDesc = convert( m_vertexInputState, inputLayout ); if ( !inputDesc.empty() ) { - auto hr = d3ddevice->CreateInputLayout( inputDesc.data() - , UINT( inputDesc.size() ) - , compiled->GetBufferPointer() - , compiled->GetBufferSize() - , &m_iaState ); - - if ( !checkError( device, hr, "CreateInputLayout" ) ) + if ( auto hr = d3ddevice->CreateInputLayout( inputDesc.data() + , UINT( inputDesc.size() ) + , compiled->GetBufferPointer() + , compiled->GetBufferSize() + , &m_iaState ); + !checkError( device, hr, "CreateInputLayout" ) ) { get( device )->onReportMessage( VK_DEBUG_REPORT_ERROR_BIT_EXT , VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.hpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.hpp index dd910fb7b..de0ee1f18 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.hpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11Pipeline.hpp @@ -15,6 +15,7 @@ namespace ashes::d3d11 { class Pipeline + : public NonCopyable { friend class PipelineLayout; @@ -23,129 +24,129 @@ namespace ashes::d3d11 , VkGraphicsPipelineCreateInfo createInfo ); Pipeline( VkDevice device , VkComputePipelineCreateInfo createInfo ); - ~Pipeline(); + ~Pipeline()noexcept; PushConstantsBuffer findPushConstantBuffer( PushConstantsDesc const & pushConstants )const; VkDescriptorSetLayoutArray const & getDescriptorsLayouts()const; void update(); - inline VkPipelineInputAssemblyStateCreateInfo const & getInputAssemblyState()const + VkPipelineInputAssemblyStateCreateInfo const & getInputAssemblyState()const { return m_inputAssemblyState; } - inline bool hasVertexLayout()const + bool hasVertexLayout()const { return !m_vertexAttributeDescriptions.empty() && !m_vertexBindingDescriptions.empty(); } - inline std::vector< PushConstantsBuffer > const & getConstantsPcbs()const + std::vector< PushConstantsBuffer > const & getConstantsPcbs()const { return m_constantsPcbs; } - inline ID3D11DepthStencilState * getDSState()const + ID3D11DepthStencilState * getDSState()const { return m_dsState; } - inline ID3D11RasterizerState * getRSState()const + ID3D11RasterizerState * getRSState()const { return m_rsState; } - inline ID3D11InputLayout * getIAState()const + ID3D11InputLayout * getIAState()const { return m_iaState; } - inline ID3D11BlendState * getBDState()const + ID3D11BlendState * getBDState()const { return m_bdState; } - inline VkPipelineVertexInputStateCreateInfo const & getVertexInputState()const + VkPipelineVertexInputStateCreateInfo const & getVertexInputState()const { return m_vertexInputState; } - inline bool hasViewport()const + bool hasViewport()const { return !m_viewports.empty(); } - inline bool hasScissor()const + bool hasScissor()const { return !m_scissors.empty(); } - inline float const * getBlendFactor()const + float const * getBlendFactor()const { return m_colorBlendState.blendConstants; } - inline UINT getSampleMask()const + UINT getSampleMask()const { return m_colorBlendState.attachmentCount == 0u ? 0u : m_colorBlendState.pAttachments->colorWriteMask; } - inline UINT getStencilRef()const + UINT getStencilRef()const { return bool( m_depthStencilState ) ? m_depthStencilState->front.reference : 0u; } - inline std::vector < D3D11_VIEWPORT > const & getViewports()const + std::vector < D3D11_VIEWPORT > const & getViewports()const { assert( !m_viewports.empty() ); return m_viewports; } - inline std::vector< RECT > const & getScissors()const + std::vector< RECT > const & getScissors()const { assert( !m_scissors.empty() ); return m_scissors; } - inline std::list< CompiledShaderModule > const & getShaderStages()const + std::list< CompiledShaderModule > const & getShaderStages()const { return m_programModules; } - inline CompiledShaderModule const & getShaderStage()const + CompiledShaderModule const & getShaderStage()const { return m_programModules.front(); } - inline ProgramLayout const & getProgramLayout()const + ProgramLayout const & getProgramLayout()const { return m_programLayout; } - inline VkPipelineLayout getLayout()const + VkPipelineLayout getLayout()const { return m_layout; } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } - inline size_t getVertexInputStateHash()const + size_t getVertexInputStateHash()const { return m_vertexInputStateHash; } - inline DynamicStates & getDynamicStates() + DynamicStates & getDynamicStates() { return m_dynamicStates; } - inline bool hasDynamicStateEnable( VkDynamicState state )const + bool hasDynamicStateEnable( VkDynamicState state )const { return m_dynamicStates.hasDynamicStateEnable( state ); } diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.cpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.cpp index 284ce168a..6ca5fd140 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.cpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.cpp @@ -5,11 +5,11 @@ namespace ashes::d3d11 PipelineCache::PipelineCache( VkDevice device , VkPipelineCacheCreateInfo createInfo ) : m_device{ device } - , m_createInfo{ createInfo } + , m_createInfo{ std::move( createInfo ) } { } - VkResult PipelineCache::merge( ArrayView< VkPipelineCache const > pipelines ) + VkResult PipelineCache::merge()const { return VK_SUCCESS; } diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.hpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.hpp index 51c4e2bd5..3bb8dca2d 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.hpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineCache.hpp @@ -28,14 +28,14 @@ namespace ashes::d3d11 , VkPipelineCacheCreateInfo createInfo ); /**@}*/ - VkResult merge( ArrayView< VkPipelineCache const > pipelines ); + VkResult merge()const; - inline ByteArray const & getData()const + ByteArray const & getData()const { return m_data; } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.cpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.cpp index e182838be..1d1792d02 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.cpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.cpp @@ -30,7 +30,7 @@ namespace ashes::d3d11 } } - PipelineLayout::~PipelineLayout() + PipelineLayout::~PipelineLayout()noexcept { for ( auto & pipeline : m_pipelines ) { diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.hpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.hpp index 058f7e093..28a07a46c 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.hpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11PipelineLayout.hpp @@ -13,23 +13,24 @@ See LICENSE file in root folder namespace ashes::d3d11 { class PipelineLayout + : public NonCopyable { friend class Pipeline; public: PipelineLayout( VkDevice device , VkPipelineLayoutCreateInfo createInfo ); - ~PipelineLayout(); + ~PipelineLayout()noexcept; ShaderBindings const & getShaderBindings()const; uint32_t getDescriptorSetIndex( VkDescriptorSet set )const; - inline VkDescriptorSetLayoutArray const & getDescriptorsLayouts()const + VkDescriptorSetLayoutArray const & getDescriptorsLayouts()const { return m_setLayouts; } - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.cpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.cpp index fcc10fc1c..06e2d06cd 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.cpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.cpp @@ -5,41 +5,3 @@ See LICENSE file in root folder. #include "Core/D3D11Device.hpp" #include - -namespace ashes::d3d11 -{ - //ashes::PushConstantArray convert( VkShaderStageFlagBits stage - // , ashes::SpecialisationMapEntryArray::const_iterator const & begin - // , ashes::SpecialisationMapEntryArray::const_iterator const & end ) - //{ - // ashes::PushConstantArray result; - - // //for ( auto it = begin; it != end; ++it ) - // //{ - // // result.push_back( { - // // it->constantID, - // // it->offset, - // // it->format, - // // it->arraySize - // // } ); - // //} - - // return result; - //} - - //ashes::PushConstantsBufferPtr convert( ashes::VkDevice device - // , uint32_t location - // , VkShaderStageFlagBits stage - // , ashes::SpecialisationInfoBase const & specialisationInfo ) - //{ - // return ashes::PushConstantsBufferPtr{}; - // //auto result = device.createPushConstantsBuffer( location - // // , stage - // // , convert( stage, specialisationInfo.begin(), specialisationInfo.end() ) ); - // //assert( result->getSize() == specialisationInfo.getSize() ); - // //std::memcpy( result->getData() - // // , specialisationInfo.getData() - // // , specialisationInfo.getSize() ); - // //return std::move( result ); - //} -} diff --git a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.hpp b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.hpp index 9812cdf0a..625eb66df 100644 --- a/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.hpp +++ b/source/ashes/renderer/D3D11Renderer/Pipeline/D3D11SpecialisationInfo.hpp @@ -3,13 +3,3 @@ This file belongs to Ashes. See LICENSE file in root folder. */ #pragma once - -namespace ashes::d3d11 -{ - //ashes::PushConstantArray convert( VkShaderStageFlagBits stage - // , std::vector< VkSpecialisationMapEntry > const & entries ); - //ashes::PushConstantsBufferPtr convert( VkDevice device - // , uint32_t location - // , VkShaderStageFlagBits stage - // , ashes::SpecialisationInfoBase const & specialisationInfo ); -} diff --git a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.cpp b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.cpp index 90f7ae917..868fa75be 100644 --- a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.cpp +++ b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.cpp @@ -95,9 +95,8 @@ namespace ashes::d3d11 , bool msaa ) { FboAttach * result{ nullptr }; - auto attach = doGetDepthStencilAttach( attaches, msaa ); - if ( attach ) + if ( auto attach = doGetDepthStencilAttach( attaches, msaa ) ) { auto view = get( attach->imageView ); auto multisampled = get( view->getImage() )->getSamplesCount() > VK_SAMPLE_COUNT_1_BIT; @@ -155,8 +154,4 @@ namespace ashes::d3d11 , m_multisampled{ ( !m_msRtViews.empty() ) || ( m_msDsView != nullptr ) } { } - - Framebuffer::~Framebuffer() - { - } } diff --git a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.hpp b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.hpp index fb06164f5..f500d8463 100644 --- a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.hpp +++ b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11FrameBuffer.hpp @@ -21,10 +21,10 @@ namespace ashes::d3d11 { } - VkImageView imageView; - ID3D11View * view; - ID3D11Resource * resource; - UINT subresource; + VkImageView imageView{}; + ID3D11View * view{}; + ID3D11Resource * resource{}; + UINT subresource{}; }; using FboAttachPtr = std::unique_ptr< FboAttach >; @@ -33,49 +33,48 @@ namespace ashes::d3d11 public: Framebuffer( VkDevice device , VkFramebufferCreateInfo createInfo ); - ~Framebuffer(); - inline VkExtent2D const & getDimensions()const noexcept + VkExtent2D const & getDimensions()const noexcept { return m_dimensions; } - inline std::vector< FboAttachPtr > const & getAllViews()const + std::vector< FboAttachPtr > const & getAllViews()const noexcept { return m_allViews; } - inline std::vector< FboAttach * > const & getRTViews()const + std::vector< FboAttach * > const & getRTViews()const noexcept { return m_rtViews; } - inline std::vector< FboAttach * > const & getMsRTViews()const + std::vector< FboAttach * > const & getMsRTViews()const noexcept { return m_msRtViews; } - inline FboAttach * getDSView()const + FboAttach * getDSView()const noexcept { return m_dsView; } - inline FboAttach * getMsDSView()const + FboAttach * getMsDSView()const noexcept { return m_msDsView; } - inline UINT getDSViewFlags()const + UINT getDSViewFlags()const noexcept { return m_dsViewFlags; } - bool isMultisampled()const + bool isMultisampled()const noexcept { return m_multisampled; } - VkDevice getDevice()const + VkDevice getDevice()const noexcept { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.cpp b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.cpp index 7bbe7d34f..05b4b1bb9 100644 --- a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.cpp +++ b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.cpp @@ -54,10 +54,6 @@ namespace ashes::d3d11 } } - RenderPass::~RenderPass() - { - } - VkAttachmentDescription const * RenderPass::findAttachment( uint32_t referenceIndex )const { if ( referenceIndex >= m_referencedAttachments.size() ) @@ -99,7 +95,7 @@ namespace ashes::d3d11 void RenderPass::referenceAttaches( VkAttachmentReferenceArray const & values ) { - for ( auto & value : values ) + for ( auto const & value : values ) { referenceAttaches( value ); } diff --git a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.hpp b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.hpp index e2c93ae78..e7c7e3a95 100644 --- a/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.hpp +++ b/source/ashes/renderer/D3D11Renderer/RenderPass/D3D11RenderPass.hpp @@ -13,47 +13,46 @@ namespace ashes::d3d11 public: RenderPass( VkDevice device , VkRenderPassCreateInfo createInfo ); - ~RenderPass(); VkAttachmentDescription const * findAttachment( uint32_t referenceIndex )const; VkAttachmentDescription const & getAttachment( VkAttachmentReference const & reference )const; - inline VkSubpassDescriptionArray const & getSubpasses()const + VkSubpassDescriptionArray const & getSubpasses()const { return m_subpasses; } - inline VkExtent2D getRenderAreaGranularity()const + VkExtent2D getRenderAreaGranularity()const { return VkExtent2D{ 1u, 1u }; } - inline auto empty()const + auto empty()const { return m_referencedAttachments.empty(); } - inline auto size()const + auto size()const { return m_referencedAttachments.size(); } - inline auto begin() + auto begin() { return m_referencedAttachments.begin(); } - inline auto end() + auto end() { return m_referencedAttachments.end(); } - inline auto begin()const + auto begin()const { return m_referencedAttachments.begin(); } - inline auto end()const + auto end()const { return m_referencedAttachments.end(); } diff --git a/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderDesc.hpp b/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderDesc.hpp index 5f396f616..c513d2d23 100644 --- a/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderDesc.hpp +++ b/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderDesc.hpp @@ -11,27 +11,27 @@ namespace ashes::d3d11 struct InputElementDesc { std::string SemanticName; - UINT SemanticIndex; - UINT BaseSemanticIndex; - DXGI_FORMAT Format; - UINT InputSlot; - UINT AlignedByteOffset; - D3D11_INPUT_CLASSIFICATION InputSlotClass; - UINT InstanceDataStepRate; + UINT SemanticIndex{}; + UINT BaseSemanticIndex{}; + DXGI_FORMAT Format{}; + UINT InputSlot{}; + UINT AlignedByteOffset{}; + D3D11_INPUT_CLASSIFICATION InputSlotClass{}; + UINT InstanceDataStepRate{}; }; struct ConstantDesc { std::string name; - UINT offset; - UINT size; + UINT offset{}; + UINT size{}; }; struct ConstantBufferDesc { std::string name; - UINT binding; - UINT size; + UINT binding{}; + UINT size{}; std::vector< ConstantDesc > constants; }; @@ -42,7 +42,7 @@ namespace ashes::d3d11 struct ShaderDesc { - CompiledShaderModule * module{ nullptr }; + CompiledShaderModule * shaderModule{ nullptr }; InputLayout inputLayout; InterfaceBlockLayout interfaceBlockLayout; }; diff --git a/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.cpp b/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.cpp index c8c656e6e..c801e54ce 100644 --- a/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.cpp +++ b/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.cpp @@ -38,9 +38,10 @@ namespace ashes::d3d11 namespace { - static uint32_t constexpr OpCodeSPIRV = 0x07230203; + inline uint32_t constexpr OpCodeSPIRV = 0x07230203; struct BlockLocale + : public NonCopyable { BlockLocale() { @@ -160,7 +161,7 @@ namespace ashes::d3d11 auto model = getExecutionModel( stage ); std::string entryPoint; - for ( auto & e : compiler.get_entry_points_and_stages() ) + for ( auto const & e : compiler.get_entry_points_and_stages() ) { if ( entryPoint.empty() && e.execution_model == model ) { @@ -176,10 +177,9 @@ namespace ashes::d3d11 compiler.set_entry_point( entryPoint, model ); } - void doSetupOptions( VkDevice device - , spirv_cross::CompilerHLSL & compiler ) + void doSetupOptions( spirv_cross::CompilerHLSL & compiler ) { - auto options = compiler.get_common_options(); + spirv_cross::CompilerGLSL::Options options = compiler.get_common_options(); options.es = false; options.separate_shader_objects = true; options.enable_420pack_extension = true; @@ -189,18 +189,16 @@ namespace ashes::d3d11 compiler.set_common_options( options ); } - void doSetupHlslOptions( VkDevice device - , spirv_cross::CompilerHLSL & compiler ) + void doSetupHlslOptions( spirv_cross::CompilerHLSL & compiler ) { - auto hlslOptions = compiler.get_hlsl_options(); + spirv_cross::CompilerHLSL::Options hlslOptions = compiler.get_hlsl_options(); hlslOptions.shader_model = 50; hlslOptions.point_coord_compat = true; hlslOptions.point_size_compat = true; compiler.set_hlsl_options( hlslOptions ); } - void reportMissingBinding( VkDevice device - , VkShaderModule module + void reportMissingBinding( VkShaderModule shaderModule , std::string const & typeName , uint32_t binding , uint32_t set ) @@ -209,22 +207,21 @@ namespace ashes::d3d11 std::stringstream stream; stream.imbue( std::locale{ "C" } ); stream << typeName << ", binding=" << binding << ", set=" << set; - reportError( module + reportError( shaderModule , VK_ERROR_VALIDATION_FAILED_EXT , "Missing binding" , stream.str() ); } - void doReworkBindings( VkDevice device - , VkShaderModule module + void doReworkBindings( VkShaderModule shaderModule , std::string const & typeName , spirv_cross::CompilerGLSL & compiler - , spirv_cross::SmallVector< spirv_cross::Resource > & resources + , spirv_cross::SmallVector< spirv_cross::Resource > const & resources , ShaderBindingMap const & bindings , bool failOnError , ShaderBindingMap const * fallback = nullptr ) { - for ( auto & obj : resources ) + for ( auto const & obj : resources ) { auto binding = compiler.get_decoration( obj.id, spv::DecorationBinding ); auto set = compiler.get_decoration( obj.id, spv::DecorationDescriptorSet ); @@ -245,27 +242,26 @@ namespace ashes::d3d11 } else if ( failOnError ) { - reportMissingBinding( device, module, typeName, binding, set ); + reportMissingBinding( shaderModule, typeName, binding, set ); } } else if ( failOnError ) { - reportMissingBinding( device, module, typeName, binding, set ); + reportMissingBinding( shaderModule, typeName, binding, set ); } } } - void doReworkUavBindings( VkDevice device - , VkShaderModule module + void doReworkUavBindings( VkShaderModule shaderModule , std::string const & typeName , spirv_cross::CompilerGLSL & compiler - , spirv_cross::SmallVector< spirv_cross::Resource > & resources + , spirv_cross::SmallVector< spirv_cross::Resource > const & resources , ShaderBindingMap const & bindings , uint32_t uavStart , bool failOnError , ShaderBindingMap const * fallback = nullptr ) { - for ( auto & obj : resources ) + for ( auto const & obj : resources ) { auto binding = compiler.get_decoration( obj.id, spv::DecorationBinding ); auto set = compiler.get_decoration( obj.id, spv::DecorationDescriptorSet ); @@ -291,24 +287,21 @@ namespace ashes::d3d11 } else if ( failOnError ) { - reportMissingBinding( device, module, typeName, binding, set ); + reportMissingBinding( shaderModule, typeName, binding, set ); } } else if ( failOnError ) { - reportMissingBinding( device, module, typeName, binding, set ); + reportMissingBinding( shaderModule, typeName, binding, set ); } } } - void doReworkOutputs( VkDevice device - , VkShaderModule module - , std::string const & typeName - , spirv_cross::CompilerGLSL & compiler - , spirv_cross::SmallVector< spirv_cross::Resource > & resources + void doReworkOutputs( spirv_cross::CompilerGLSL const & compiler + , spirv_cross::SmallVector< spirv_cross::Resource > const & resources , uint32_t & index ) { - for ( auto & obj : resources ) + for ( auto const & obj : resources ) { auto location = compiler.get_decoration( obj.id, spv::DecorationLocation ); index = std::max( index, location ); @@ -317,39 +310,37 @@ namespace ashes::d3d11 void doReworkBindings( VkPipelineLayout pipelineLayout , VkPipelineCreateFlags createFlags - , VkShaderModule module + , VkShaderModule shaderModule , VkShaderStageFlagBits stage , spirv_cross::CompilerGLSL & compiler ) { spirv_cross::ShaderResources resources = compiler.get_shader_resources(); auto & bindings = get( pipelineLayout )->getShaderBindings(); - auto device = get( pipelineLayout )->getDevice(); auto failOnError = !( checkFlag( createFlags, VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT ) || checkFlag( createFlags, VK_PIPELINE_CREATE_DERIVATIVE_BIT ) ); - doReworkBindings( device, module, "UniformBuffer", compiler, resources.uniform_buffers, bindings.ubo, failOnError ); - doReworkBindings( device, module, "CombinedSamplerImage", compiler, resources.sampled_images, bindings.tex, failOnError, &bindings.tbo ); - doReworkBindings( device, module, "SampledImage", compiler, resources.separate_images, bindings.tex, failOnError ); - doReworkBindings( device, module, "Sampler", compiler, resources.separate_samplers, bindings.tex, failOnError ); - doReworkBindings( device, module, "SubpassInput", compiler, resources.subpass_inputs, bindings.tex, failOnError ); + doReworkBindings( shaderModule, "UniformBuffer", compiler, resources.uniform_buffers, bindings.ubo, failOnError ); + doReworkBindings( shaderModule, "CombinedSamplerImage", compiler, resources.sampled_images, bindings.tex, failOnError, &bindings.tbo ); + doReworkBindings( shaderModule, "SampledImage", compiler, resources.separate_images, bindings.tex, failOnError ); + doReworkBindings( shaderModule, "Sampler", compiler, resources.separate_samplers, bindings.tex, failOnError ); + doReworkBindings( shaderModule, "SubpassInput", compiler, resources.subpass_inputs, bindings.tex, failOnError ); uint32_t uav{}; if ( stage == VK_SHADER_STAGE_FRAGMENT_BIT ) { // Tightly pack outputs indices. - doReworkOutputs( device, module, "FragmentOutputs", compiler, resources.stage_outputs, uav ); + doReworkOutputs( compiler, resources.stage_outputs, uav ); } - doReworkUavBindings( device, module, "StorageBuffer", compiler, resources.storage_buffers, bindings.uav, uav, failOnError ); - doReworkUavBindings( device, module, "StorageImage", compiler, resources.storage_images, bindings.uav, uav, failOnError, &bindings.ibo ); + doReworkUavBindings( shaderModule, "StorageBuffer", compiler, resources.storage_buffers, bindings.uav, uav, failOnError ); + doReworkUavBindings( shaderModule, "StorageImage", compiler, resources.storage_images, bindings.uav, uav, failOnError, &bindings.ibo ); } #endif - std::string compileSpvToHlsl( VkDevice device - , VkPipelineLayout pipelineLayout + std::string compileSpvToHlsl( VkPipelineLayout pipelineLayout , VkPipelineCreateFlags createFlags - , VkShaderModule module + , VkShaderModule shaderModule , UInt32Array const & shader , VkShaderStageFlagBits stage , VkPipelineShaderStageCreateInfo const & state ) @@ -364,9 +355,9 @@ namespace ashes::d3d11 spirv_cross::CompilerHLSL compiler{ shader }; doProcessSpecializationConstants( state, compiler ); doSetEntryPoint( stage, compiler ); - doSetupOptions( device, compiler ); - doSetupHlslOptions( device, compiler ); - doReworkBindings( pipelineLayout, createFlags, module, stage, compiler ); + doSetupOptions( compiler ); + doSetupHlslOptions( compiler ); + doReworkBindings( pipelineLayout, createFlags, shaderModule, stage, compiler ); return compiler.compile(); } catch ( std::exception & exc ) @@ -387,13 +378,13 @@ namespace ashes::d3d11 return std::string( hlslCode.data(), hlslCode.data() + strnlen( hlslCode.data(), hlslCode.size() ) ); } - uint32_t extractLocation( InputElementDesc & desc ) + uint32_t extractLocation( InputElementDesc const & desc ) { uint32_t result{ 0u }; if ( desc.InputSlotClass == D3D11_INPUT_PER_INSTANCE_DATA ) { - auto name = desc.SemanticName; + std::string name = desc.SemanticName; name = name.substr( 0u, name.size() - 1u ); auto index = name.find_last_not_of( "0123456789" ); name = name.substr( index + 1 ); @@ -421,10 +412,10 @@ namespace ashes::d3d11 , m_compiled{ std::move( rhs.m_compiled ) } , m_layout{ std::move( rhs.m_layout ) } { - m_layout.module = this; + m_layout.shaderModule = this; rhs.m_shader.compute = nullptr; rhs.m_compiled = nullptr; - rhs.m_layout.module = nullptr; + rhs.m_layout.shaderModule = nullptr; } CompiledShaderModule & CompiledShaderModule::operator=( CompiledShaderModule && rhs )noexcept @@ -436,10 +427,10 @@ namespace ashes::d3d11 m_source = std::move( rhs.m_source ); m_compiled = std::move( rhs.m_compiled ); m_layout = std::move( rhs.m_layout ); - m_layout.module = this; + m_layout.shaderModule = this; rhs.m_shader.compute = nullptr; rhs.m_compiled = nullptr; - rhs.m_layout.module = nullptr; + rhs.m_layout.shaderModule = nullptr; } return *this; @@ -448,11 +439,10 @@ namespace ashes::d3d11 CompiledShaderModule::CompiledShaderModule( VkDevice device , VkPipelineLayout pipelineLayout , VkPipelineCreateFlags createFlags - , VkShaderModule module + , VkShaderModule shaderModule , UInt32Array const & spv , VkPipelineShaderStageCreateInfo const & state ) - : m_shader{ nullptr } - , m_stage{ state.stage } + : m_stage{ state.stage } { static std::map< D3D_FEATURE_LEVEL, std::map< VkShaderStageFlagBits, std::string > > Profiles { @@ -516,10 +506,9 @@ namespace ashes::d3d11 } }; - m_source = compileSpvToHlsl( device - , pipelineLayout + m_source = compileSpvToHlsl( pipelineLayout , createFlags - , module + , shaderModule , spv , m_stage , state ); @@ -554,7 +543,7 @@ namespace ashes::d3d11 std::stringstream stream; stream << reinterpret_cast< char * >( errors->GetBufferPointer() ) << std::endl; stream << m_source << std::endl; - reportWarning( module + reportWarning( shaderModule , VK_ERROR_VALIDATION_FAILED_EXT , "Shader compilation succeeded with messages" , stream.str() ); @@ -565,14 +554,14 @@ namespace ashes::d3d11 std::stringstream stream; stream << reinterpret_cast< char * >( errors->GetBufferPointer() ) << std::endl; stream << m_source << std::endl; - reportError( module + reportError( shaderModule , VK_ERROR_VALIDATION_FAILED_EXT , "Shader compilation failed" , stream.str() ); } } - CompiledShaderModule::~CompiledShaderModule() + CompiledShaderModule::~CompiledShaderModule()noexcept { safeRelease( m_compiled ); @@ -684,7 +673,7 @@ namespace ashes::d3d11 } InputLayout CompiledShaderModule::doRetrieveInputLayout( ID3D11ShaderReflection * reflection - , UINT inputParameters ) + , UINT inputParameters )const { InputLayout result; @@ -740,7 +729,7 @@ namespace ashes::d3d11 } InterfaceBlockLayout CompiledShaderModule::doRetrieveInterfaceBlockLayout( ID3D11ShaderReflection * reflection - , UINT constantBuffers ) + , UINT constantBuffers )const { InterfaceBlockLayout result; @@ -795,10 +784,6 @@ namespace ashes::d3d11 m_createInfo.pCode = m_code.data(); } - ShaderModule::~ShaderModule()noexcept - { - } - CompiledShaderModule ShaderModule::compile( VkPipelineShaderStageCreateInfo const & state , VkPipelineLayout pipelineLayout , VkPipelineCreateFlags createFlags )const diff --git a/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.hpp b/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.hpp index 80ac21179..400a0b544 100644 --- a/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.hpp +++ b/source/ashes/renderer/D3D11Renderer/Shader/D3D11ShaderModule.hpp @@ -22,52 +22,52 @@ namespace ashes::d3d11 CompiledShaderModule( VkDevice device , VkPipelineLayout pipelineLayout , VkPipelineCreateFlags createFlags - , VkShaderModule module + , VkShaderModule shaderModule , UInt32Array const & spv , VkPipelineShaderStageCreateInfo const & state ); ~CompiledShaderModule()noexcept; - inline ID3D11ComputeShader * getCSShader()const + ID3D11ComputeShader * getCSShader()const { return m_shader.compute; } - inline ID3D11VertexShader * getVSShader()const + ID3D11VertexShader * getVSShader()const { return m_shader.vertex; } - inline ID3D11GeometryShader * getGSShader()const + ID3D11GeometryShader * getGSShader()const { return m_shader.geometry; } - inline ID3D11HullShader * getHSShader()const + ID3D11HullShader * getHSShader()const { return m_shader.hull; } - inline ID3D11DomainShader * getDSShader()const + ID3D11DomainShader * getDSShader()const { return m_shader.domain; } - inline ID3D11PixelShader * getPSShader()const + ID3D11PixelShader * getPSShader()const { return m_shader.pixel; } - inline ID3DBlob * getCompiled()const + ID3DBlob * getCompiled()const { return m_compiled; } - inline VkShaderStageFlagBits getStage()const + VkShaderStageFlagBits getStage()const { return m_stage; } - inline ShaderDesc const & getLayout()const + ShaderDesc const & getLayout()const { return m_layout; } @@ -76,9 +76,9 @@ namespace ashes::d3d11 void doRetrieveShader( VkDevice device ); ShaderDesc doRetrieveShaderDesc( VkDevice device ); InputLayout doRetrieveInputLayout( ID3D11ShaderReflection * reflection - , UINT inputParameters ); + , UINT inputParameters )const; InterfaceBlockLayout doRetrieveInterfaceBlockLayout( ID3D11ShaderReflection * reflection - , UINT constantBuffers ); + , UINT constantBuffers )const; private: union @@ -89,7 +89,7 @@ namespace ashes::d3d11 ID3D11HullShader * hull; ID3D11DomainShader * domain; ID3D11PixelShader * pixel; - } m_shader; + } m_shader{}; VkShaderStageFlagBits m_stage; std::string m_source; ID3DBlob * m_compiled{ nullptr }; @@ -101,13 +101,12 @@ namespace ashes::d3d11 public: ShaderModule( VkDevice device , VkShaderModuleCreateInfo createInfo ); - ~ShaderModule(); CompiledShaderModule compile( VkPipelineShaderStageCreateInfo const & state , VkPipelineLayout pipelineLayout , VkPipelineCreateFlags createFlags )const; - inline VkDevice getDevice()const + VkDevice getDevice()const { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.cpp b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.cpp index 3177922d3..04c1b3837 100644 --- a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.cpp +++ b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.cpp @@ -8,27 +8,23 @@ See LICENSE file in root folder. namespace ashes::d3d11 { - Event::Event( VkDevice device ) + Event::Event( VkDevice device )noexcept : m_device{ device } { } - Event::~Event() - { - } - - VkResult Event::getStatus()const + VkResult Event::getStatus()const noexcept { return m_status; } - VkResult Event::set()const + VkResult Event::set()const noexcept { m_status = VK_EVENT_SET; return VK_SUCCESS; } - VkResult Event::reset()const + VkResult Event::reset()const noexcept { m_status = VK_EVENT_RESET; return VK_SUCCESS; diff --git a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.hpp b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.hpp index ec183c48b..d06566188 100644 --- a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.hpp +++ b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Event.hpp @@ -9,24 +9,24 @@ See LICENSE file in root folder namespace ashes::d3d11 { class Event + : public NonCopyable { public: - Event( VkDevice device ); - ~Event(); + explicit Event( VkDevice device )noexcept; /** *\copydoc ashes::Event::getStatus */ - VkResult getStatus()const; + VkResult getStatus()const noexcept; /** *\copydoc ashes::Event::getStatus */ - VkResult set()const; + VkResult set()const noexcept; /** *\copydoc ashes::Event::getStatus */ - VkResult reset()const; + VkResult reset()const noexcept; - inline VkDevice getDevice()const + VkDevice getDevice()const noexcept { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.cpp b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.cpp index 6134bfe74..316717c70 100644 --- a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.cpp +++ b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.cpp @@ -6,26 +6,21 @@ See LICENSE file in root folder. namespace ashes::d3d11 { - Fence::Fence( VkDevice device - , VkFenceCreateFlags flags ) + Fence::Fence( VkDevice device )noexcept : m_device{ device } { } - Fence::~Fence() - { - } - - VkResult Fence::wait( uint64_t timeout )const + VkResult Fence::wait()const noexcept { return VK_SUCCESS; } - void Fence::reset()const + void Fence::reset()const noexcept { } - VkResult Fence::getStatus()const + VkResult Fence::getStatus()const noexcept { return VK_SUCCESS; } diff --git a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.hpp b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.hpp index 5683c36d5..71fc69b35 100644 --- a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.hpp +++ b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Fence.hpp @@ -9,17 +9,16 @@ See LICENSE file in root folder namespace ashes::d3d11 { class Fence + : public NonCopyable { public: - Fence( VkDevice device - , VkFenceCreateFlags flags = 0 ); - ~Fence(); + explicit Fence( VkDevice device )noexcept; - VkResult wait( uint64_t timeout )const; - void reset()const; - VkResult getStatus()const; + VkResult wait()const noexcept; + void reset()const noexcept; + VkResult getStatus()const noexcept; - inline VkDevice getDevice()const + VkDevice getDevice()const noexcept { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.cpp b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.cpp index a37964d4e..51365cc2d 100644 --- a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.cpp +++ b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.cpp @@ -6,12 +6,8 @@ See LICENSE file in root folder. namespace ashes::d3d11 { - Semaphore::Semaphore( VkDevice device ) + Semaphore::Semaphore( VkDevice device )noexcept : m_device{ device } { } - - Semaphore::~Semaphore() - { - } } diff --git a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.hpp b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.hpp index e9755985c..90886b9d0 100644 --- a/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.hpp +++ b/source/ashes/renderer/D3D11Renderer/Sync/D3D11Semaphore.hpp @@ -9,12 +9,12 @@ See LICENSE file in root folder. namespace ashes::d3d11 { class Semaphore + : public NonCopyable { public: - explicit Semaphore( VkDevice device ); - ~Semaphore(); + explicit Semaphore( VkDevice device )noexcept; - inline VkDevice getDevice()const + VkDevice getDevice()const noexcept { return m_device; } diff --git a/source/ashes/renderer/D3D11Renderer/ash_direct3d11.cpp b/source/ashes/renderer/D3D11Renderer/ash_direct3d11.cpp index 621f8e628..c012398a2 100644 --- a/source/ashes/renderer/D3D11Renderer/ash_direct3d11.cpp +++ b/source/ashes/renderer/D3D11Renderer/ash_direct3d11.cpp @@ -198,7 +198,7 @@ namespace ashes::d3d11 uint32_t * pPropertyCount, VkExtensionProperties * pProperties ) { - auto props = get( physicalDevice )->enumerateExtensionProperties( pLayerName ); + auto props = get( physicalDevice )->enumerateExtensionProperties(); *pPropertyCount = uint32_t( props.size() ); if ( pProperties ) @@ -269,8 +269,7 @@ namespace ashes::d3d11 const VkSubmitInfo * pSubmits, VkFence fence ) { - return get( queue )->submit( makeArrayView( pSubmits, submitCount ) - , fence ); + return get( queue )->submit( makeArrayView( pSubmits, submitCount ) ); } VkResult VKAPI_CALL vkQueueWaitIdle( @@ -443,7 +442,7 @@ namespace ashes::d3d11 if ( pProperties ) { - for ( auto & prop : props ) + for ( auto const & prop : props ) { *pProperties = prop; ++pProperties; @@ -457,8 +456,7 @@ namespace ashes::d3d11 const VkBindSparseInfo * pBindInfo, VkFence fence ) { - return get( queue )->bindSparse( makeArrayView( pBindInfo, bindInfoCount ) - , fence ); + return get( queue )->bindSparse(); } VkResult VKAPI_CALL vkCreateFence( @@ -470,8 +468,7 @@ namespace ashes::d3d11 assert( pFence ); return allocate( *pFence , pAllocator - , device - , pCreateInfo->flags ); + , device ); } void VKAPI_CALL vkDestroyFence( @@ -511,7 +508,7 @@ namespace ashes::d3d11 { for ( uint32_t i = 0u; i < fenceCount; ++i ) { - get( *pFences )->wait( timeout ); + get( *pFences )->wait(); } return VK_SUCCESS; @@ -777,7 +774,7 @@ namespace ashes::d3d11 uint32_t srcCacheCount, const VkPipelineCache * pSrcCaches ) { - return get( dstCache )->merge( makeArrayView( pSrcCaches, srcCacheCount ) ); + return get( dstCache )->merge(); } VkResult VKAPI_CALL vkCreateGraphicsPipelines( @@ -933,7 +930,7 @@ namespace ashes::d3d11 VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags ) { - return get( descriptorPool )->reset( flags ); + return get( descriptorPool )->reset(); } VkResult VKAPI_CALL vkAllocateDescriptorSets( @@ -966,7 +963,7 @@ namespace ashes::d3d11 uint32_t descriptorSetCount, const VkDescriptorSet * pDescriptorSets ) { - return get( descriptorPool )->free( makeArrayView( pDescriptorSets, descriptorSetCount ) ); + return get( descriptorPool )->freeDescriptors( makeArrayView( pDescriptorSets, descriptorSetCount ) ); } void VKAPI_CALL vkUpdateDescriptorSets( @@ -983,7 +980,7 @@ namespace ashes::d3d11 for ( auto & copy : makeArrayView( pDescriptorCopies, descriptorCopyCount ) ) { - get( copy.dstSet )->update( copy ); + get( copy.dstSet )->update(); } } @@ -1063,7 +1060,7 @@ namespace ashes::d3d11 VkCommandPool commandPool, VkCommandPoolResetFlags flags ) { - return get( commandPool )->reset( flags ); + return get( commandPool )->reset(); } VkResult VKAPI_CALL vkAllocateCommandBuffers( @@ -1097,7 +1094,7 @@ namespace ashes::d3d11 uint32_t commandBufferCount, const VkCommandBuffer * pCommandBuffers ) { - get( commandPool )->free( makeArrayView( pCommandBuffers, commandBufferCount ) ); + get( commandPool )->freeCommands( makeArrayView( pCommandBuffers, commandBufferCount ) ); } VkResult VKAPI_CALL vkBeginCommandBuffer( @@ -1117,7 +1114,7 @@ namespace ashes::d3d11 VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags ) { - return get( commandBuffer )->reset( flags ); + return get( commandBuffer )->reset(); } void VKAPI_CALL vkCmdBindPipeline( @@ -1342,9 +1339,7 @@ namespace ashes::d3d11 const VkImageCopy * pRegions ) { get( commandBuffer )->copyImage( srcImage - , srcImageLayout , dstImage - , dstImageLayout , makeArrayView( pRegions, regionCount ) ); } @@ -1359,9 +1354,7 @@ namespace ashes::d3d11 VkFilter filter ) { get( commandBuffer )->blitImage( srcImage - , srcImageLayout , dstImage - , dstImageLayout , makeArrayView( pRegions, regionCount ) , filter ); } @@ -1376,7 +1369,6 @@ namespace ashes::d3d11 { get( commandBuffer )->copyToImage( srcBuffer , dstImage - , dstImageLayout , makeArrayView( pRegions, regionCount ) ); } @@ -1389,7 +1381,6 @@ namespace ashes::d3d11 const VkBufferImageCopy * pRegions ) { get( commandBuffer )->copyToBuffer( srcImage - , srcImageLayout , dstBuffer , makeArrayView( pRegions, regionCount ) ); } @@ -1428,7 +1419,6 @@ namespace ashes::d3d11 const VkImageSubresourceRange * pRanges ) { get( commandBuffer )->clearColorImage( image - , imageLayout , *pColor , makeArrayView( pRanges, rangeCount ) ); } @@ -1442,7 +1432,6 @@ namespace ashes::d3d11 const VkImageSubresourceRange * pRanges ) { get( commandBuffer )->clearDepthStencilImage( image - , imageLayout , *pDepthStencil , makeArrayView( pRanges, rangeCount ) ); } @@ -1468,9 +1457,7 @@ namespace ashes::d3d11 const VkImageResolve * pRegions ) { get( commandBuffer )->resolveImage( srcImage - , srcImageLayout , dstImage - , dstImageLayout , makeArrayView( pRegions, regionCount ) ); } @@ -1506,7 +1493,6 @@ namespace ashes::d3d11 get( commandBuffer )->waitEvents( { pEvents, pEvents + eventCount } , srcStageMask , dstStageMask - , makeArrayView( pMemoryBarriers, memoryBarrierCount ) , makeArrayView( pBufferMemoryBarriers, bufferMemoryBarrierCount ) , makeArrayView( pImageMemoryBarriers, imageMemoryBarrierCount ) ); } @@ -1525,7 +1511,6 @@ namespace ashes::d3d11 { get( commandBuffer )->pipelineBarrier( srcStageMask , dstStageMask - , dependencyFlags , makeArrayView( pMemoryBarriers, memoryBarrierCount ) , makeArrayView( pBufferMemoryBarriers, bufferMemoryBarrierCount ) , makeArrayView( pImageMemoryBarriers, imageMemoryBarrierCount ) ); @@ -1612,14 +1597,14 @@ namespace ashes::d3d11 const VkRenderPassBeginInfo * pRenderPassBegin, VkSubpassContents contents ) { - get( commandBuffer )->beginRenderPass( *pRenderPassBegin, contents ); + get( commandBuffer )->beginRenderPass( *pRenderPassBegin ); } void VKAPI_CALL vkCmdNextSubpass( VkCommandBuffer commandBuffer, VkSubpassContents contents ) { - get( commandBuffer )->nextSubpass( contents ); + get( commandBuffer )->nextSubpass(); } void VKAPI_CALL vkCmdEndRenderPass( @@ -2106,7 +2091,7 @@ namespace ashes::d3d11 VkSurfaceKHR surface, VkBool32 * pSupported ) { - *pSupported = get( surface )->getSupport( physicalDevice, queueFamilyIndex ); + *pSupported = get( surface )->getSupport( physicalDevice ); return VK_SUCCESS; } @@ -2216,10 +2201,7 @@ namespace ashes::d3d11 VkFence fence, uint32_t * pImageIndex ) { - return get( swapchain )->acquireNextImage( timeout - , semaphore - , fence - , *pImageIndex ); + return get( swapchain )->acquireNextImage( *pImageIndex ); } VkResult VKAPI_CALL vkQueuePresentKHR( @@ -2372,7 +2354,7 @@ namespace ashes::d3d11 uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR * pCapabilities ) { - *pCapabilities = get( mode )->getDisplayPlaneCapabilities( planeIndex ); + *pCapabilities = get( mode )->getDisplayPlaneCapabilities(); return VK_SUCCESS; } @@ -4363,7 +4345,7 @@ namespace ashes::d3d11 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex ) { - return get( physicalDevice )->getPresentationSupport( queueFamilyIndex ); + return get( physicalDevice )->getPresentationSupport(); } # endif @@ -4397,45 +4379,46 @@ namespace ashes::d3d11 namespace ashes::d3d11 { - std::vector< VkExtensionProperties > const & getSupportedInstanceExtensions( const char * pLayerName ) + static std::vector< VkExtensionProperties > const SupportedInstanceExtensions { - static std::vector< VkExtensionProperties > const extensions - { #if VK_KHR_surface - VkExtensionProperties{ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_SPEC_VERSION }, + VkExtensionProperties{ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_SPEC_VERSION }, #endif #if VK_KHR_swapchain - VkExtensionProperties{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION }, + VkExtensionProperties{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION }, #endif #if VK_KHR_win32_surface - VkExtensionProperties{ VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_SPEC_VERSION }, + VkExtensionProperties{ VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_SPEC_VERSION }, #endif #if VK_EXT_debug_report - VkExtensionProperties{ VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION }, + VkExtensionProperties{ VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION }, #endif #if VK_EXT_debug_marker - VkExtensionProperties{ VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION }, + VkExtensionProperties{ VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION }, #endif #if VK_EXT_debug_utils - VkExtensionProperties{ VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION }, + VkExtensionProperties{ VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION }, #endif #if VK_KHR_get_physical_device_properties2 - VkExtensionProperties{ VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION }, + VkExtensionProperties{ VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION }, #endif #if VK_KHR_display - VkExtensionProperties{ VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_DISPLAY_SPEC_VERSION }, + VkExtensionProperties{ VK_KHR_DISPLAY_EXTENSION_NAME, VK_KHR_DISPLAY_SPEC_VERSION }, #endif #if VK_KHR_portability_subset - VkExtensionProperties{ VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION }, + VkExtensionProperties{ VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION }, #endif - }; - return extensions; + }; + static std::vector< VkLayerProperties > const InstanceLayerProperties{}; + + std::vector< VkExtensionProperties > const & getSupportedInstanceExtensions( const char * pLayerName ) + { + return SupportedInstanceExtensions; } std::vector< VkLayerProperties > const & getInstanceLayerProperties() { - static std::vector< VkLayerProperties > result; - return result; + return InstanceLayerProperties; } struct Library @@ -4529,7 +4512,7 @@ namespace ashes::d3d11 && get( device )->hasExtension( extension.data() ); } - using InstanceFunctions = std::map< std::string, PFN_vkVoidFunction >; + using InstanceFunctions = std::map< std::string, PFN_vkVoidFunction, std::less<> >; #pragma warning( push ) #pragma warning( disable: 4191 ) @@ -4537,13 +4520,13 @@ namespace ashes::d3d11 InstanceFunctions const & getFunctions( VkInstance instance ) { static std::map< VkInstance, InstanceFunctions > functions; - auto it = functions.insert( { instance, {} } ); + auto [it, res] = functions.try_emplace( instance ); - if ( it.second ) + if ( res ) { if ( instance != nullptr ) { - it.first->second = + it->second = { #define VK_LIB_GLOBAL_FUNCTION( v, x )\ { "vk"#x, checkVersion( instance, v ) ? PFN_vkVoidFunction( vk##x ) : PFN_vkVoidFunction( nullptr ) }, @@ -4562,7 +4545,7 @@ namespace ashes::d3d11 } else { - it.first->second = + it->second = { #define VK_LIB_GLOBAL_FUNCTION( v, x )\ { "vk"#x, PFN_vkVoidFunction( vk##x ) }, @@ -4578,7 +4561,7 @@ namespace ashes::d3d11 } } - return it.first->second; + return it->second; } PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr( @@ -4587,9 +4570,9 @@ namespace ashes::d3d11 { PFN_vkVoidFunction result{ nullptr }; auto & functions = getFunctions( instance ); - auto it = functions.find( pName ); - if ( it != functions.end() ) + if ( auto it = functions.find( pName ); + it != functions.end() ) { result = it->second; } @@ -4602,7 +4585,7 @@ namespace ashes::d3d11 const char* pName ) { PFN_vkVoidFunction result{ nullptr }; - static std::map< std::string, PFN_vkVoidFunction > functions + static std::map< std::string, PFN_vkVoidFunction, std::less<> > functions { { "vkGetDeviceProcAddr", PFN_vkVoidFunction( vkGetDeviceProcAddr ) }, #define VK_LIB_DEVICE_FUNCTION( v, x )\ @@ -4612,9 +4595,8 @@ namespace ashes::d3d11 #include }; - auto it = functions.find( pName ); - - if ( it != functions.end() ) + if ( auto it = functions.find( pName ); + it != functions.end() ) { result = it->second; } @@ -4808,7 +4790,6 @@ extern "C" } # endif -// #endif #pragma endregion #pragma region VK_KHR_wayland_surface # ifdef __linux__ diff --git a/source/ashes/renderer/D3D11Renderer/ashesd3d11_api.hpp b/source/ashes/renderer/D3D11Renderer/ashesd3d11_api.hpp index 5d6d63a09..d1086408b 100644 --- a/source/ashes/renderer/D3D11Renderer/ashesd3d11_api.hpp +++ b/source/ashes/renderer/D3D11Renderer/ashesd3d11_api.hpp @@ -427,7 +427,7 @@ namespace ashes::d3d11 { using Type = typename VkDxTypeTraits< VkType >::Type; - vkValue = VkType( new Type{ std::forward< Params && >( params )... } ); + vkValue = VkType( new Type{ std::forward< Params >( params )... } ); result = VK_SUCCESS; } catch ( Exception & exc ) @@ -468,7 +468,7 @@ namespace ashes::d3d11 if ( mem ) { - vkValue = VkType( new( mem )Type{ std::forward< Params && >( params )... } ); + vkValue = VkType( new( mem )Type{ std::forward< Params >( params )... } ); result = VK_SUCCESS; } else @@ -478,7 +478,7 @@ namespace ashes::d3d11 } else { - vkValue = VkType( new Type{ std::forward< Params && >( params )... } ); + vkValue = VkType( new Type{ std::forward< Params >( params )... } ); result = VK_SUCCESS; } } @@ -500,7 +500,7 @@ namespace ashes::d3d11 } template< typename VkType > - VkResult deallocateNA( VkType & vkValue ) + VkResult deallocateNA( VkType & vkValue )noexcept { if ( vkValue ) { @@ -513,7 +513,7 @@ namespace ashes::d3d11 } template< typename VkType > - VkResult deallocateNA( VkType const & vkValue ) + VkResult deallocateNA( VkType const & vkValue )noexcept { if ( vkValue ) { @@ -525,7 +525,7 @@ namespace ashes::d3d11 } template< typename VkType > - VkResult deallocate( VkType & vkValue, const VkAllocationCallbacks * allocInfo ) + VkResult deallocate( VkType & vkValue, const VkAllocationCallbacks * allocInfo )noexcept { if ( vkValue ) { @@ -550,7 +550,7 @@ namespace ashes::d3d11 } template< typename VkType > - VkResult deallocate( VkType const & vkValue, const VkAllocationCallbacks * allocInfo ) + VkResult deallocate( VkType const & vkValue, const VkAllocationCallbacks * allocInfo )noexcept { if ( vkValue ) {