summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.h
blob: 14078f9db88bd8a84c02a10d987cfa27ed98f9fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// Blit11.cpp: Texture copy utility class.

#ifndef LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_
#define LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_

#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"

#include <map>

namespace rx
{
class Renderer11;

class Blit11 : angle::NonCopyable
{
  public:
    explicit Blit11(Renderer11 *renderer);
    ~Blit11();

    gl::Error swizzleTexture(const gl::Context *context,
                             const d3d11::SharedSRV &source,
                             const d3d11::RenderTargetView &dest,
                             const gl::Extents &size,
                             const gl::SwizzleState &swizzleTarget);

    gl::Error copyTexture(const gl::Context *context,
                          const d3d11::SharedSRV &source,
                          const gl::Box &sourceArea,
                          const gl::Extents &sourceSize,
                          GLenum sourceFormat,
                          const d3d11::RenderTargetView &dest,
                          const gl::Box &destArea,
                          const gl::Extents &destSize,
                          const gl::Rectangle *scissor,
                          GLenum destFormat,
                          GLenum filter,
                          bool maskOffAlpha,
                          bool unpackPremultiplyAlpha,
                          bool unpackUnmultiplyAlpha);

    gl::Error copyStencil(const gl::Context *context,
                          const TextureHelper11 &source,
                          unsigned int sourceSubresource,
                          const gl::Box &sourceArea,
                          const gl::Extents &sourceSize,
                          const TextureHelper11 &dest,
                          unsigned int destSubresource,
                          const gl::Box &destArea,
                          const gl::Extents &destSize,
                          const gl::Rectangle *scissor);

    gl::Error copyDepth(const gl::Context *context,
                        const d3d11::SharedSRV &source,
                        const gl::Box &sourceArea,
                        const gl::Extents &sourceSize,
                        const d3d11::DepthStencilView &dest,
                        const gl::Box &destArea,
                        const gl::Extents &destSize,
                        const gl::Rectangle *scissor);

    gl::Error copyDepthStencil(const TextureHelper11 &source,
                               unsigned int sourceSubresource,
                               const gl::Box &sourceArea,
                               const gl::Extents &sourceSize,
                               const TextureHelper11 &dest,
                               unsigned int destSubresource,
                               const gl::Box &destArea,
                               const gl::Extents &destSize,
                               const gl::Rectangle *scissor);

    gl::ErrorOrResult<TextureHelper11> resolveDepth(const gl::Context *context,
                                                    RenderTarget11 *depth);

    gl::ErrorOrResult<TextureHelper11> resolveStencil(const gl::Context *context,
                                                      RenderTarget11 *depthStencil,
                                                      bool alsoDepth);

    using BlitConvertFunction = void(const gl::Box &sourceArea,
                                     const gl::Box &destArea,
                                     const gl::Rectangle &clipRect,
                                     const gl::Extents &sourceSize,
                                     unsigned int sourceRowPitch,
                                     unsigned int destRowPitch,
                                     ptrdiff_t readOffset,
                                     ptrdiff_t writeOffset,
                                     size_t copySize,
                                     size_t srcPixelStride,
                                     size_t destPixelStride,
                                     const uint8_t *sourceData,
                                     uint8_t *destData);

  private:
    enum BlitShaderType
    {
        BLITSHADER_INVALID,

        // Passthrough shaders
        BLITSHADER_2D_RGBAF,
        BLITSHADER_2D_BGRAF,
        BLITSHADER_2D_RGBF,
        BLITSHADER_2D_RGF,
        BLITSHADER_2D_RF,
        BLITSHADER_2D_ALPHA,
        BLITSHADER_2D_LUMA,
        BLITSHADER_2D_LUMAALPHA,
        BLITSHADER_2D_RGBAUI,
        BLITSHADER_2D_RGBAI,
        BLITSHADER_2D_RGBUI,
        BLITSHADER_2D_RGBI,
        BLITSHADER_2D_RGUI,
        BLITSHADER_2D_RGI,
        BLITSHADER_2D_RUI,
        BLITSHADER_2D_RI,
        BLITSHADER_3D_RGBAF,
        BLITSHADER_3D_RGBAUI,
        BLITSHADER_3D_RGBAI,
        BLITSHADER_3D_BGRAF,
        BLITSHADER_3D_RGBF,
        BLITSHADER_3D_RGBUI,
        BLITSHADER_3D_RGBI,
        BLITSHADER_3D_RGF,
        BLITSHADER_3D_RGUI,
        BLITSHADER_3D_RGI,
        BLITSHADER_3D_RF,
        BLITSHADER_3D_RUI,
        BLITSHADER_3D_RI,
        BLITSHADER_3D_ALPHA,
        BLITSHADER_3D_LUMA,
        BLITSHADER_3D_LUMAALPHA,

        // Multiply alpha shaders
        BLITSHADER_2D_RGBAF_PREMULTIPLY,
        BLITSHADER_2D_RGBAF_UNMULTIPLY,

        BLITSHADER_2D_RGBF_PREMULTIPLY,
        BLITSHADER_2D_RGBF_UNMULTIPLY,

        BLITSHADER_2D_RGBAF_TOUI,
        BLITSHADER_2D_RGBAF_TOUI_PREMULTIPLY,
        BLITSHADER_2D_RGBAF_TOUI_UNMULTIPLY,

        BLITSHADER_2D_RGBF_TOUI,
        BLITSHADER_2D_RGBF_TOUI_PREMULTIPLY,
        BLITSHADER_2D_RGBF_TOUI_UNMULTIPLY,

        BLITSHADER_2D_LUMAF_PREMULTIPLY,
        BLITSHADER_2D_LUMAF_UNMULTIPLY,

        BLITSHADER_2D_LUMAALPHAF_PREMULTIPLY,
        BLITSHADER_2D_LUMAALPHAF_UNMULTIPLY
    };

    enum SwizzleShaderType
    {
        SWIZZLESHADER_INVALID,
        SWIZZLESHADER_2D_FLOAT,
        SWIZZLESHADER_2D_UINT,
        SWIZZLESHADER_2D_INT,
        SWIZZLESHADER_CUBE_FLOAT,
        SWIZZLESHADER_CUBE_UINT,
        SWIZZLESHADER_CUBE_INT,
        SWIZZLESHADER_3D_FLOAT,
        SWIZZLESHADER_3D_UINT,
        SWIZZLESHADER_3D_INT,
        SWIZZLESHADER_ARRAY_FLOAT,
        SWIZZLESHADER_ARRAY_UINT,
        SWIZZLESHADER_ARRAY_INT,
    };

    typedef void (*WriteVertexFunction)(const gl::Box &sourceArea,
                                        const gl::Extents &sourceSize,
                                        const gl::Box &destArea,
                                        const gl::Extents &destSize,
                                        void *outVertices,
                                        unsigned int *outStride,
                                        unsigned int *outVertexCount,
                                        D3D11_PRIMITIVE_TOPOLOGY *outTopology);

    enum ShaderDimension
    {
        SHADER_2D,
        SHADER_3D,
    };

    struct Shader
    {
        Shader();
        Shader(Shader &&other);
        ~Shader();
        Shader &operator=(Shader &&other);

        ShaderDimension dimension;
        d3d11::PixelShader pixelShader;
    };

    struct ShaderSupport
    {
        const d3d11::InputLayout *inputLayout;
        const d3d11::VertexShader *vertexShader;
        const d3d11::GeometryShader *geometryShader;
        WriteVertexFunction vertexWriteFunction;
    };

    gl::Error initResources();

    gl::Error getShaderSupport(const Shader &shader, ShaderSupport *supportOut);

    static BlitShaderType GetBlitShaderType(GLenum destinationFormat,
                                            GLenum sourceFormat,
                                            bool isSigned,
                                            bool unpackPremultiplyAlpha,
                                            bool unpackUnmultiplyAlpha,
                                            ShaderDimension dimension);
    static SwizzleShaderType GetSwizzleShaderType(GLenum type, D3D11_SRV_DIMENSION dimensionality);

    gl::Error copyDepthStencilImpl(const TextureHelper11 &source,
                                   unsigned int sourceSubresource,
                                   const gl::Box &sourceArea,
                                   const gl::Extents &sourceSize,
                                   const TextureHelper11 &dest,
                                   unsigned int destSubresource,
                                   const gl::Box &destArea,
                                   const gl::Extents &destSize,
                                   const gl::Rectangle *scissor,
                                   bool stencilOnly);

    gl::Error copyAndConvertImpl(const TextureHelper11 &source,
                                 unsigned int sourceSubresource,
                                 const gl::Box &sourceArea,
                                 const gl::Extents &sourceSize,
                                 const TextureHelper11 &destStaging,
                                 const gl::Box &destArea,
                                 const gl::Extents &destSize,
                                 const gl::Rectangle *scissor,
                                 size_t readOffset,
                                 size_t writeOffset,
                                 size_t copySize,
                                 size_t srcPixelStride,
                                 size_t destPixelStride,
                                 BlitConvertFunction *convertFunction);

    gl::Error copyAndConvert(const TextureHelper11 &source,
                             unsigned int sourceSubresource,
                             const gl::Box &sourceArea,
                             const gl::Extents &sourceSize,
                             const TextureHelper11 &dest,
                             unsigned int destSubresource,
                             const gl::Box &destArea,
                             const gl::Extents &destSize,
                             const gl::Rectangle *scissor,
                             size_t readOffset,
                             size_t writeOffset,
                             size_t copySize,
                             size_t srcPixelStride,
                             size_t destPixelStride,
                             BlitConvertFunction *convertFunction);

    gl::Error addBlitShaderToMap(BlitShaderType blitShaderType,
                                 ShaderDimension dimension,
                                 const ShaderData &shaderData,
                                 const char *name);

    gl::Error getBlitShader(GLenum destFormat,
                            GLenum sourceFormat,
                            bool isSigned,
                            bool unpackPremultiplyAlpha,
                            bool unpackUnmultiplyAlpha,
                            ShaderDimension dimension,
                            const Shader **shaderOut);
    gl::Error getSwizzleShader(GLenum type,
                               D3D11_SRV_DIMENSION viewDimension,
                               const Shader **shaderOut);

    gl::Error addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType,
                                    ShaderDimension dimension,
                                    const ShaderData &shaderData,
                                    const char *name);

    void clearShaderMap();
    void releaseResolveDepthStencilResources();
    gl::Error initResolveDepthOnly(const d3d11::Format &format, const gl::Extents &extents);
    gl::Error initResolveDepthStencil(const gl::Extents &extents);

    Renderer11 *mRenderer;

    std::map<BlitShaderType, Shader> mBlitShaderMap;
    std::map<SwizzleShaderType, Shader> mSwizzleShaderMap;

    bool mResourcesInitialized;
    d3d11::Buffer mVertexBuffer;
    d3d11::SamplerState mPointSampler;
    d3d11::SamplerState mLinearSampler;
    d3d11::RasterizerState mScissorEnabledRasterizerState;
    d3d11::RasterizerState mScissorDisabledRasterizerState;
    d3d11::DepthStencilState mDepthStencilState;

    d3d11::LazyInputLayout mQuad2DIL;
    d3d11::LazyShader<ID3D11VertexShader> mQuad2DVS;
    d3d11::LazyShader<ID3D11PixelShader> mDepthPS;

    d3d11::LazyInputLayout mQuad3DIL;
    d3d11::LazyShader<ID3D11VertexShader> mQuad3DVS;
    d3d11::LazyShader<ID3D11GeometryShader> mQuad3DGS;

    d3d11::LazyBlendState mAlphaMaskBlendState;

    d3d11::Buffer mSwizzleCB;

    d3d11::LazyShader<ID3D11VertexShader> mResolveDepthStencilVS;
    d3d11::LazyShader<ID3D11PixelShader> mResolveDepthPS;
    d3d11::LazyShader<ID3D11PixelShader> mResolveDepthStencilPS;
    d3d11::LazyShader<ID3D11PixelShader> mResolveStencilPS;
    d3d11::ShaderResourceView mStencilSRV;
    TextureHelper11 mResolvedDepthStencil;
    d3d11::RenderTargetView mResolvedDepthStencilRTView;
    TextureHelper11 mResolvedDepth;
    d3d11::DepthStencilView mResolvedDepthDSView;
};

}  // namespace rx

#endif  // LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_