• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // Blit11.cpp: Texture copy utility class.
8 
9 #ifndef LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_
10 #define LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_
11 
12 #include "common/angleutils.h"
13 #include "libANGLE/Error.h"
14 #include "libANGLE/angletypes.h"
15 #include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h"
16 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
17 
18 #include <map>
19 
20 namespace rx
21 {
22 class Renderer11;
23 
24 class Blit11 : angle::NonCopyable
25 {
26   public:
27     explicit Blit11(Renderer11 *renderer);
28     ~Blit11();
29 
30     angle::Result swizzleTexture(const gl::Context *context,
31                                  const d3d11::SharedSRV &source,
32                                  const d3d11::RenderTargetView &dest,
33                                  const gl::Extents &size,
34                                  const gl::SwizzleState &swizzleTarget);
35 
36     // Set destTypeForDownsampling to GL_NONE to skip downsampling
37     angle::Result copyTexture(const gl::Context *context,
38                               const d3d11::SharedSRV &source,
39                               const gl::Box &sourceArea,
40                               const gl::Extents &sourceSize,
41                               GLenum sourceFormat,
42                               const d3d11::RenderTargetView &dest,
43                               const gl::Box &destArea,
44                               const gl::Extents &destSize,
45                               const gl::Rectangle *scissor,
46                               GLenum destFormat,
47                               GLenum destTypeForDownsampling,
48                               GLenum filter,
49                               bool maskOffAlpha,
50                               bool unpackPremultiplyAlpha,
51                               bool unpackUnmultiplyAlpha);
52 
53     angle::Result copyStencil(const gl::Context *context,
54                               const TextureHelper11 &source,
55                               unsigned int sourceSubresource,
56                               const gl::Box &sourceArea,
57                               const gl::Extents &sourceSize,
58                               const TextureHelper11 &dest,
59                               unsigned int destSubresource,
60                               const gl::Box &destArea,
61                               const gl::Extents &destSize,
62                               const gl::Rectangle *scissor);
63 
64     angle::Result copyDepth(const gl::Context *context,
65                             const d3d11::SharedSRV &source,
66                             const gl::Box &sourceArea,
67                             const gl::Extents &sourceSize,
68                             const d3d11::DepthStencilView &dest,
69                             const gl::Box &destArea,
70                             const gl::Extents &destSize,
71                             const gl::Rectangle *scissor);
72 
73     angle::Result copyDepthStencil(const gl::Context *context,
74                                    const TextureHelper11 &source,
75                                    unsigned int sourceSubresource,
76                                    const gl::Box &sourceArea,
77                                    const gl::Extents &sourceSize,
78                                    const TextureHelper11 &dest,
79                                    unsigned int destSubresource,
80                                    const gl::Box &destArea,
81                                    const gl::Extents &destSize,
82                                    const gl::Rectangle *scissor);
83 
84     angle::Result resolveDepth(const gl::Context *context,
85                                RenderTarget11 *depth,
86                                TextureHelper11 *textureOut);
87 
88     angle::Result resolveStencil(const gl::Context *context,
89                                  RenderTarget11 *depthStencil,
90                                  bool alsoDepth,
91                                  TextureHelper11 *textureOut);
92 
93     using BlitConvertFunction = void(const gl::Box &sourceArea,
94                                      const gl::Box &destArea,
95                                      const gl::Rectangle &clipRect,
96                                      const gl::Extents &sourceSize,
97                                      unsigned int sourceRowPitch,
98                                      unsigned int destRowPitch,
99                                      ptrdiff_t readOffset,
100                                      ptrdiff_t writeOffset,
101                                      size_t copySize,
102                                      size_t srcPixelStride,
103                                      size_t destPixelStride,
104                                      const uint8_t *sourceData,
105                                      uint8_t *destData);
106 
107   private:
108     enum BlitShaderOperation : unsigned int;
109     enum BlitShaderType : unsigned int;
110     enum SwizzleShaderType
111     {
112         SWIZZLESHADER_INVALID,
113         SWIZZLESHADER_2D_FLOAT,
114         SWIZZLESHADER_2D_UINT,
115         SWIZZLESHADER_2D_INT,
116         SWIZZLESHADER_CUBE_FLOAT,
117         SWIZZLESHADER_CUBE_UINT,
118         SWIZZLESHADER_CUBE_INT,
119         SWIZZLESHADER_3D_FLOAT,
120         SWIZZLESHADER_3D_UINT,
121         SWIZZLESHADER_3D_INT,
122         SWIZZLESHADER_ARRAY_FLOAT,
123         SWIZZLESHADER_ARRAY_UINT,
124         SWIZZLESHADER_ARRAY_INT,
125     };
126 
127     typedef void (*WriteVertexFunction)(const gl::Box &sourceArea,
128                                         const gl::Extents &sourceSize,
129                                         const gl::Box &destArea,
130                                         const gl::Extents &destSize,
131                                         void *outVertices,
132                                         unsigned int *outStride,
133                                         unsigned int *outVertexCount,
134                                         D3D11_PRIMITIVE_TOPOLOGY *outTopology);
135 
136     enum ShaderDimension
137     {
138         SHADER_INVALID,
139         SHADER_2D,
140         SHADER_3D,
141         SHADER_2DARRAY
142     };
143 
144     struct Shader
145     {
146         Shader();
147         Shader(Shader &&other);
148         ~Shader();
149         Shader &operator=(Shader &&other);
150 
151         ShaderDimension dimension;
152         d3d11::PixelShader pixelShader;
153     };
154 
155     struct ShaderSupport
156     {
157         const d3d11::InputLayout *inputLayout;
158         const d3d11::VertexShader *vertexShader;
159         const d3d11::GeometryShader *geometryShader;
160         WriteVertexFunction vertexWriteFunction;
161     };
162 
163     angle::Result initResources(const gl::Context *context);
164 
165     angle::Result getShaderSupport(const gl::Context *context,
166                                    const Shader &shader,
167                                    ShaderSupport *supportOut);
168 
169     static BlitShaderOperation getBlitShaderOperation(GLenum destinationFormat,
170                                                       GLenum sourceFormat,
171                                                       bool isSrcSigned,
172                                                       bool isDestSigned,
173                                                       bool unpackPremultiplyAlpha,
174                                                       bool unpackUnmultiplyAlpha,
175                                                       GLenum destTypeForDownsampling);
176 
177     static BlitShaderType getBlitShaderType(BlitShaderOperation operation,
178                                             ShaderDimension dimension);
179 
180     static SwizzleShaderType GetSwizzleShaderType(GLenum type, D3D11_SRV_DIMENSION dimensionality);
181 
182     angle::Result copyDepthStencilImpl(const gl::Context *context,
183                                        const TextureHelper11 &source,
184                                        unsigned int sourceSubresource,
185                                        const gl::Box &sourceArea,
186                                        const gl::Extents &sourceSize,
187                                        const TextureHelper11 &dest,
188                                        unsigned int destSubresource,
189                                        const gl::Box &destArea,
190                                        const gl::Extents &destSize,
191                                        const gl::Rectangle *scissor,
192                                        bool stencilOnly);
193 
194     angle::Result copyAndConvertImpl(const gl::Context *context,
195                                      const TextureHelper11 &source,
196                                      unsigned int sourceSubresource,
197                                      const gl::Box &sourceArea,
198                                      const gl::Extents &sourceSize,
199                                      const TextureHelper11 &destStaging,
200                                      const gl::Box &destArea,
201                                      const gl::Extents &destSize,
202                                      const gl::Rectangle *scissor,
203                                      size_t readOffset,
204                                      size_t writeOffset,
205                                      size_t copySize,
206                                      size_t srcPixelStride,
207                                      size_t destPixelStride,
208                                      BlitConvertFunction *convertFunction);
209 
210     angle::Result copyAndConvert(const gl::Context *context,
211                                  const TextureHelper11 &source,
212                                  unsigned int sourceSubresource,
213                                  const gl::Box &sourceArea,
214                                  const gl::Extents &sourceSize,
215                                  const TextureHelper11 &dest,
216                                  unsigned int destSubresource,
217                                  const gl::Box &destArea,
218                                  const gl::Extents &destSize,
219                                  const gl::Rectangle *scissor,
220                                  size_t readOffset,
221                                  size_t writeOffset,
222                                  size_t copySize,
223                                  size_t srcPixelStride,
224                                  size_t destPixelStride,
225                                  BlitConvertFunction *convertFunction);
226 
227     angle::Result mapBlitShader(const gl::Context *context, BlitShaderType blitShaderType);
228     angle::Result addBlitShaderToMap(const gl::Context *context,
229                                      BlitShaderType blitShaderType,
230                                      ShaderDimension dimension,
231                                      const ShaderData &shaderData,
232                                      const char *name);
233 
234     angle::Result getBlitShader(const gl::Context *context,
235                                 GLenum destFormat,
236                                 GLenum sourceFormat,
237                                 bool isSrcSigned,
238                                 bool isDestSigned,
239                                 bool unpackPremultiplyAlpha,
240                                 bool unpackUnmultiplyAlpha,
241                                 GLenum destTypeForDownsampling,
242                                 ShaderDimension dimension,
243                                 const Shader **shaderOut);
244     angle::Result getSwizzleShader(const gl::Context *context,
245                                    GLenum type,
246                                    D3D11_SRV_DIMENSION viewDimension,
247                                    const Shader **shaderOut);
248 
249     angle::Result addSwizzleShaderToMap(const gl::Context *context,
250                                         SwizzleShaderType swizzleShaderType,
251                                         ShaderDimension dimension,
252                                         const ShaderData &shaderData,
253                                         const char *name);
254 
255     void clearShaderMap();
256     void releaseResolveDepthStencilResources();
257     angle::Result initResolveDepthOnly(const gl::Context *context,
258                                        const d3d11::Format &format,
259                                        const gl::Extents &extents);
260     angle::Result initResolveDepthStencil(const gl::Context *context, const gl::Extents &extents);
261 
262     Renderer11 *mRenderer;
263 
264     std::map<BlitShaderType, Shader> mBlitShaderMap;
265     std::map<SwizzleShaderType, Shader> mSwizzleShaderMap;
266 
267     bool mResourcesInitialized;
268     d3d11::Buffer mVertexBuffer;
269     d3d11::SamplerState mPointSampler;
270     d3d11::SamplerState mLinearSampler;
271     d3d11::RasterizerState mScissorEnabledRasterizerState;
272     d3d11::RasterizerState mScissorDisabledRasterizerState;
273     d3d11::DepthStencilState mDepthStencilState;
274 
275     d3d11::LazyInputLayout mQuad2DIL;
276     d3d11::LazyShader<ID3D11VertexShader> mQuad2DVS;
277     d3d11::LazyShader<ID3D11PixelShader> mDepthPS;
278 
279     d3d11::LazyInputLayout mQuad3DIL;
280     d3d11::LazyShader<ID3D11VertexShader> mQuad3DVS;
281     d3d11::LazyShader<ID3D11GeometryShader> mQuad3DGS;
282 
283     d3d11::LazyBlendState mAlphaMaskBlendState;
284 
285     d3d11::Buffer mSwizzleCB;
286 
287     d3d11::LazyShader<ID3D11VertexShader> mResolveDepthStencilVS;
288     d3d11::LazyShader<ID3D11PixelShader> mResolveDepthPS;
289     d3d11::LazyShader<ID3D11PixelShader> mResolveDepthStencilPS;
290     d3d11::LazyShader<ID3D11PixelShader> mResolveStencilPS;
291     d3d11::ShaderResourceView mStencilSRV;
292     TextureHelper11 mResolvedDepthStencil;
293     d3d11::RenderTargetView mResolvedDepthStencilRTView;
294     TextureHelper11 mResolvedDepth;
295     d3d11::DepthStencilView mResolvedDepthDSView;
296 };
297 
298 }  // namespace rx
299 
300 #endif  // LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_
301