summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-04-11 15:39:32 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-04-11 15:39:32 +0000
commit8ad6ca05f069b59af9544bc99bed7e5d1f785950 (patch)
tree0dd6d845177796fb24902f8baa88484922c99e37 /Graphics/GraphicsEngine
parentAdded render target format validation when creating a PSO (diff)
downloadDiligentCore-8ad6ca05f069b59af9544bc99bed7e5d1f785950.tar.gz
DiligentCore-8ad6ca05f069b59af9544bc99bed7e5d1f785950.zip
Reworked automatic mipmap generation in Vulkan backend to support sRGB textures, enable mipmap generation for partial texture views and optimize state transitions
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/DeviceContextBase.h5
-rw-r--r--Graphics/GraphicsEngine/include/TextureBase.h11
-rw-r--r--Graphics/GraphicsEngine/include/TextureViewBase.h4
-rw-r--r--Graphics/GraphicsEngine/interface/APIInfo.h2
-rw-r--r--Graphics/GraphicsEngine/interface/TextureView.h28
5 files changed, 42 insertions, 8 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h
index a742c912..74226452 100644
--- a/Graphics/GraphicsEngine/include/DeviceContextBase.h
+++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h
@@ -861,7 +861,10 @@ inline void DeviceContextBase<BaseInterface,ImplementationTraits> ::
VERIFY(pTexView != nullptr, "pTexView must not be null");
#ifdef DEVELOPMENT
const auto& ViewDesc = pTexView->GetDesc();
- DEV_CHECK_ERR( ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "GenerateMips() is allowed for shader resource views only, ", GetTexViewTypeLiteralName(ViewDesc.ViewType), " is not allowed." );
+ DEV_CHECK_ERR(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Shader resource view '", ViewDesc.Name,
+ "' can't be used to generate mipmaps because its type is ", GetTexViewTypeLiteralName(ViewDesc.ViewType), ". Required view type: TEXTURE_VIEW_SHADER_RESOURCE." );
+ DEV_CHECK_ERR((ViewDesc.Flags & TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION) != 0, "Shader resource view '", ViewDesc.Name,
+ "' was not created with TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION flag and can't be used to generate mipmaps.");
#endif
}
diff --git a/Graphics/GraphicsEngine/include/TextureBase.h b/Graphics/GraphicsEngine/include/TextureBase.h
index 0ebc5cf1..939c0e3a 100644
--- a/Graphics/GraphicsEngine/include/TextureBase.h
+++ b/Graphics/GraphicsEngine/include/TextureBase.h
@@ -392,6 +392,15 @@ void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObj
TEX_VIEW_VALIDATION_ERROR( "Texture view format (", GetTextureFormatAttribs(ViewDesc.Format).Name, ") cannot be typeless" );
}
+ if ((ViewDesc.Flags & TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION) != 0)
+ {
+ if ((this->m_Desc.MiscFlags & MISC_TEXTURE_FLAG_GENERATE_MIPS) == 0)
+ TEX_VIEW_VALIDATION_ERROR( "TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION flag can only set if the texture was created with MISC_TEXTURE_FLAG_GENERATE_MIPS flag" );
+
+ if (ViewDesc.ViewType != TEXTURE_VIEW_SHADER_RESOURCE)
+ TEX_VIEW_VALIDATION_ERROR( "TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION flag can only be used with TEXTURE_VIEW_SHADER_RESOURCE view type" );
+ }
+
#undef TEX_VIEW_VALIDATION_ERROR
if( ViewDesc.NumMipLevels == 0 || ViewDesc.NumMipLevels == TextureViewDesc::RemainingMipLevels )
@@ -444,6 +453,8 @@ void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObj
TextureViewDesc ViewDesc;
ViewDesc.ViewType = TEXTURE_VIEW_SHADER_RESOURCE;
ITextureView *pSRV = nullptr;
+ if ((this->m_Desc.MiscFlags & MISC_TEXTURE_FLAG_GENERATE_MIPS) != 0)
+ ViewDesc.Flags |= TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION;
CreateViewInternal( ViewDesc, &pSRV, true );
m_pDefaultSRV.reset( static_cast<TTextureViewImpl*>(pSRV) );
VERIFY( m_pDefaultSRV->GetDesc().ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Unexpected view type" );
diff --git a/Graphics/GraphicsEngine/include/TextureViewBase.h b/Graphics/GraphicsEngine/include/TextureViewBase.h
index f035e2e7..1c96a0fd 100644
--- a/Graphics/GraphicsEngine/include/TextureViewBase.h
+++ b/Graphics/GraphicsEngine/include/TextureViewBase.h
@@ -118,14 +118,14 @@ public:
protected:
/// Strong reference to the sampler
- Diligent::RefCntAutoPtr<ISampler> m_pSampler;
+ RefCntAutoPtr<ISampler> m_pSampler;
/// Raw pointer to the texture
ITexture* const m_pTexture;
/// Strong reference to the texture. Used for non-default views
/// to keep the texture alive
- Diligent::RefCntAutoPtr<ITexture> m_spTexture;
+ RefCntAutoPtr<ITexture> m_spTexture;
};
}
diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h
index bca337e7..f1c89e58 100644
--- a/Graphics/GraphicsEngine/interface/APIInfo.h
+++ b/Graphics/GraphicsEngine/interface/APIInfo.h
@@ -26,7 +26,7 @@
/// \file
/// Diligent API information
-#define DILIGENT_API_VERSION 240022
+#define DILIGENT_API_VERSION 240023
#include "../../../Primitives/interface/BasicTypes.h"
diff --git a/Graphics/GraphicsEngine/interface/TextureView.h b/Graphics/GraphicsEngine/interface/TextureView.h
index dc03314f..0f6a98b2 100644
--- a/Graphics/GraphicsEngine/interface/TextureView.h
+++ b/Graphics/GraphicsEngine/interface/TextureView.h
@@ -26,6 +26,7 @@
/// \file
/// Definition of the Diligent::ITextureView interface and related data structures
+#include "../../../Primitives/interface/FlagEnum.h"
#include "DeviceObject.h"
namespace Diligent
@@ -38,7 +39,7 @@ static constexpr INTERFACE_ID IID_TextureView =
{ 0x5b2ea04e, 0x8128, 0x45e4, { 0xaa, 0x4d, 0x6d, 0xc7, 0xe7, 0xd, 0xc4, 0x24 } };
/// Describes allowed unordered access view mode
-enum UAV_ACCESS_FLAG : Int32
+enum UAV_ACCESS_FLAG : Uint8
{
/// Access mode is unspecified
UAV_ACCESS_UNSPECIFIED = 0x00,
@@ -52,6 +53,20 @@ enum UAV_ACCESS_FLAG : Int32
/// Allow read and write operations on the UAV
UAV_ACCESS_FLAG_READ_WRITE = UAV_ACCESS_FLAG_READ | UAV_ACCESS_FLAG_WRITE
};
+DEFINE_FLAG_ENUM_OPERATORS(UAV_ACCESS_FLAG)
+
+/// Texture view flags
+enum TEXTURE_VIEW_FLAGS : Uint8
+{
+ /// No flags
+ TEXTURE_VIEW_FLAG_NONE = 0x00,
+
+ /// Allow automatic mipmap generation for this view.
+ /// This flag is only allowed for TEXTURE_VIEW_SHADER_RESOURCE view type.
+ /// The texture must be created with MISC_TEXTURE_FLAG_GENERATE_MIPS flag.
+ TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION = 0x01,
+};
+DEFINE_FLAG_ENUM_OPERATORS(TEXTURE_VIEW_FLAGS)
/// Texture view description
struct TextureViewDesc : DeviceObjectAttribs
@@ -105,7 +120,10 @@ struct TextureViewDesc : DeviceObjectAttribs
/// For an unordered access view, allowed access flags. See Diligent::UAV_ACCESS_FLAG
/// for details.
- Uint32 AccessFlags = 0;
+ UAV_ACCESS_FLAG AccessFlags = UAV_ACCESS_UNSPECIFIED;
+
+ /// Texture view flags, see Diligent::TEXTURE_VIEW_FLAGS.
+ TEXTURE_VIEW_FLAGS Flags = TEXTURE_VIEW_FLAG_NONE;
TextureViewDesc()noexcept{}
@@ -116,7 +134,8 @@ struct TextureViewDesc : DeviceObjectAttribs
Uint32 _NumMipLevels = TextureViewDesc{}.NumMipLevels,
Uint32 _FirstArrayOrDepthSlice = TextureViewDesc{}.FirstArraySlice,
Uint32 _NumArrayOrDepthSlices = TextureViewDesc{}.NumArraySlices,
- Uint32 _AccessFlags = TextureViewDesc{}.AccessFlags)noexcept :
+ UAV_ACCESS_FLAG _AccessFlags = TextureViewDesc{}.AccessFlags,
+ TEXTURE_VIEW_FLAGS _Flags = TextureViewDesc{}.Flags)noexcept :
ViewType (_ViewType),
TextureDim (_TextureDim),
Format (_Format),
@@ -124,7 +143,8 @@ struct TextureViewDesc : DeviceObjectAttribs
NumMipLevels (_NumMipLevels),
FirstArraySlice (_FirstArrayOrDepthSlice),
NumArraySlices (_NumArrayOrDepthSlices),
- AccessFlags (_AccessFlags)
+ AccessFlags (_AccessFlags),
+ Flags (_Flags)
{}
/// Tests if two structures are equivalent