Diligent Engine API Reference
TextureD3D12Impl.h
1 /* Copyright 2015-2018 Egor Yusov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12  *
13  * In no event and under no legal theory, whether in tort (including negligence),
14  * contract, or otherwise, unless required by applicable law (such as deliberate
15  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16  * liable for any damages, including any direct, indirect, special, incidental,
17  * or consequential damages of any character arising as a result of this License or
18  * out of the use or inability to use the software (including but not limited to damages
19  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20  * all other commercial damages or losses), even if such Contributor has been advised
21  * of the possibility of such damages.
22  */
23 
24 #pragma once
25 
28 
29 #include "TextureD3D12.h"
30 #include "RenderDeviceD3D12.h"
31 #include "TextureBase.h"
32 #include "TextureViewD3D12Impl.h"
33 #include "D3D12ResourceBase.h"
34 
35 
36 namespace Diligent
37 {
38 
39 class FixedBlockMemoryAllocator;
40 
42 class TextureD3D12Impl : public TextureBase<ITextureD3D12, TextureViewD3D12Impl, FixedBlockMemoryAllocator>, public D3D12ResourceBase
43 {
44 public:
46 
47  // Creates a new D3D12 resource
48  TextureD3D12Impl(IReferenceCounters *pRefCounters,
49  FixedBlockMemoryAllocator &TexViewObjAllocator,
50  class RenderDeviceD3D12Impl *pDeviceD3D12,
51  const TextureDesc& TexDesc,
52  const TextureData &InitData = TextureData());
53  // Attaches to an existing D3D12 resource
54  TextureD3D12Impl(IReferenceCounters *pRefCounters,
55  FixedBlockMemoryAllocator &TexViewObjAllocator,
56  class RenderDeviceD3D12Impl *pDeviceD3D12,
57  const TextureDesc& TexDesc,
58  ID3D12Resource *pTexture);
60 
61  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
62 
63  virtual void UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData )override;
64 
65  //virtual void CopyData(CTexture *pSrcTexture, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size);
66  virtual void Map( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData )override;
67  virtual void Unmap( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags )override;
68 
69  virtual ID3D12Resource* GetD3D12Texture(){ return GetD3D12Resource(); }
70 
71  virtual void* GetNativeHandle()override final { return GetD3D12Texture(); }
72 
73  virtual void SetD3D12ResourceState(D3D12_RESOURCE_STATES state)override final{ SetState(state); }
74 
75  void CopyData(IDeviceContext *pContext,
76  ITexture *pSrcTexture,
77  Uint32 SrcMipLevel,
78  Uint32 SrcSlice,
79  const Box *pSrcBox,
80  Uint32 DstMipLevel,
81  Uint32 DstSlice,
82  Uint32 DstX,
83  Uint32 DstY,
84  Uint32 DstZ);
85 
86  D3D12_CPU_DESCRIPTOR_HANDLE GetMipLevelUAV(Uint32 Mip)
87  {
88  return m_MipUAVs.GetCpuHandle(Mip);
89  }
90 
91  D3D12_CPU_DESCRIPTOR_HANDLE GetTexArraySRV()
92  {
93  return m_TexArraySRV.GetCpuHandle();
94  }
95 
96 protected:
97  void CreateViewInternal( const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView )override;
98  //void PrepareD3D12InitData(const TextureData &InitData, Uint32 NumSubresources, std::vector<D3D12_SUBRESOURCE_DATA> &D3D12InitData);
99 
100  void CreateSRV( TextureViewDesc &SRVDesc, D3D12_CPU_DESCRIPTOR_HANDLE SRVHandle );
101  void CreateRTV( TextureViewDesc &RTVDesc, D3D12_CPU_DESCRIPTOR_HANDLE RTVHandle );
102  void CreateDSV( TextureViewDesc &DSVDesc, D3D12_CPU_DESCRIPTOR_HANDLE DSVHandle );
103  void CreateUAV( TextureViewDesc &UAVDesc, D3D12_CPU_DESCRIPTOR_HANDLE UAVHandle );
104 
105  // UAVs for every mip level to facilitate mipmap generation
106  DescriptorHeapAllocation m_MipUAVs;
107  // SRV as texture array (even for a non-array texture) required for mipmap generation
108  DescriptorHeapAllocation m_TexArraySRV;
109 
110  friend class RenderDeviceD3D12Impl;
111 };
112 
113 }
void CopyData(IDeviceContext *pContext, ITexture *pSrcTexture, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, Uint32 DstMipLevel, Uint32 DstSlice, Uint32 DstX, Uint32 DstY, Uint32 DstZ)
Base implementaiton of ITexture::CopyData(); validates input parameters.
Definition: TextureD3D12Impl.cpp:422
void CreateViewInternal(const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView) override
Pure virtual function that creates texture view for the specific engine implementation.
Definition: TextureD3D12Impl.cpp:326
Texture description.
Definition: Texture.h:82
virtual void * GetNativeHandle() override final
Returns native texture handle specific to the underlying graphics API.
Definition: TextureD3D12Impl.h:71
virtual void SetD3D12ResourceState(D3D12_RESOURCE_STATES state) override final
Sets the texture usage state.
Definition: TextureD3D12Impl.h:73
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Base implementation of a D3D12 resource.
Definition: D3D12ResourceBase.h:33
virtual void Unmap(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags) override
Base implementaiton of ITexture::Unmap()
Definition: TextureD3D12Impl.cpp:465
Describes data for one subresource.
Definition: Texture.h:193
virtual void UpdateData(IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData) override
Base implementaiton of ITexture::UpdateData(); validates input parameters.
Definition: TextureD3D12Impl.cpp:404
virtual void Map(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData) override
Base implementaiton of ITexture::Map()
Definition: TextureD3D12Impl.cpp:456
Describes the initial data to store in the texture.
Definition: Texture.h:243
Device context interface.
Definition: DeviceContext.h:443
Box.
Definition: GraphicsTypes.h:1005
virtual ID3D12Resource * GetD3D12Texture()
Returns a pointer to the ID3D12Resource interface of the internal Direct3D12 object.
Definition: TextureD3D12Impl.h:69
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.h:50
Base implementation of the Diligent::ITextureD3D12 interface.
Definition: TextureD3D12Impl.h:42
Base implementation of the ITexture interface.
Definition: TextureBase.h:52
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125
Texture inteface.
Definition: Texture.h:276
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface) override
Queries the specific interface, see IObject::QueryInterface() for details.
Implementation of the Diligent::IRenderDeviceD3D12 interface.
Definition: RenderDeviceD3D12Impl.h:43