• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 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 // StateManager11.h: Defines a class for caching D3D11 state
8 
9 #ifndef LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_
10 #define LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_
11 
12 #include <array>
13 
14 #include "libANGLE/State.h"
15 #include "libANGLE/angletypes.h"
16 #include "libANGLE/renderer/d3d/IndexDataManager.h"
17 #include "libANGLE/renderer/d3d/RendererD3D.h"
18 #include "libANGLE/renderer/d3d/d3d11/InputLayoutCache.h"
19 #include "libANGLE/renderer/d3d/d3d11/Query11.h"
20 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
21 
22 namespace rx
23 {
24 class Buffer11;
25 class DisplayD3D;
26 class Framebuffer11;
27 struct RenderTargetDesc;
28 struct Renderer11DeviceCaps;
29 class VertexArray11;
30 
31 class ShaderConstants11 : angle::NonCopyable
32 {
33   public:
34     ShaderConstants11();
35     ~ShaderConstants11();
36 
37     void init(const gl::Caps &caps);
38     size_t getRequiredBufferSize(gl::ShaderType shaderType) const;
39     void markDirty();
40 
41     void setComputeWorkGroups(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ);
42     void setMultiviewWriteToViewportIndex(GLfloat index);
43     void onViewportChange(const gl::Rectangle &glViewport,
44                           const D3D11_VIEWPORT &dxViewport,
45                           bool is9_3,
46                           bool presentPathFast);
47     bool onFirstVertexChange(GLint firstVertex);
48     void onImageLayerChange(gl::ShaderType shaderType, unsigned int imageIndex, int layer);
49     void onSamplerChange(gl::ShaderType shaderType,
50                          unsigned int samplerIndex,
51                          const gl::Texture &texture,
52                          const gl::SamplerState &samplerState);
53     void onImageChange(gl::ShaderType shaderType,
54                        unsigned int imageIndex,
55                        const gl::ImageUnit &imageUnit);
56     void onClipControlChange(bool lowerLeft, bool zeroToOne);
57 
58     angle::Result updateBuffer(const gl::Context *context,
59                                Renderer11 *renderer,
60                                gl::ShaderType shaderType,
61                                const ProgramD3D &programD3D,
62                                const d3d11::Buffer &driverConstantBuffer);
63 
64   private:
65     struct Vertex
66     {
VertexVertex67         Vertex()
68             : depthRange{.0f},
69               viewAdjust{.0f},
70               viewCoords{.0f},
71               viewScale{.0f},
72               multiviewWriteToViewportIndex{.0f},
73               clipControlOrigin{-1.0f},
74               clipControlZeroToOne{.0f},
75               firstVertex{0},
76               padding{.0f, .0f}
77         {}
78 
79         float depthRange[4];
80         float viewAdjust[4];
81         float viewCoords[4];
82         float viewScale[2];
83         // multiviewWriteToViewportIndex is used to select either the side-by-side or layered
84         // code-path in the GS. It's value, if set, is either 0.0f or 1.0f. The value is updated
85         // whenever a multi-view draw framebuffer is made active.
86         float multiviewWriteToViewportIndex;
87 
88         // EXT_clip_control
89         // Multiplied with Y coordinate: -1.0 for GL_LOWER_LEFT_EXT, 1.0f for GL_UPPER_LEFT_EXT
90         float clipControlOrigin;
91         // 0.0 for GL_NEGATIVE_ONE_TO_ONE_EXT, 1.0 for GL_ZERO_TO_ONE_EXT
92         float clipControlZeroToOne;
93 
94         uint32_t firstVertex;
95 
96         // Added here to manually pad the struct to 16 byte boundary
97         float padding[2];
98     };
99     static_assert(sizeof(Vertex) % 16u == 0,
100                   "D3D11 constant buffers must be multiples of 16 bytes");
101 
102     struct Pixel
103     {
PixelPixel104         Pixel()
105             : depthRange{.0f},
106               viewCoords{.0f},
107               depthFront{.0f},
108               viewScale{.0f},
109               multiviewWriteToViewportIndex{.0f},
110               padding{.0f}
111         {}
112 
113         float depthRange[4];
114         float viewCoords[4];
115         float depthFront[4];
116         float viewScale[2];
117         // multiviewWriteToViewportIndex is used to select either the side-by-side or layered
118         // code-path in the GS. It's value, if set, is either 0.0f or 1.0f. The value is updated
119         // whenever a multi-view draw framebuffer is made active.
120         float multiviewWriteToViewportIndex;
121 
122         // Added here to manually pad the struct.
123         float padding;
124     };
125     static_assert(sizeof(Pixel) % 16u == 0, "D3D11 constant buffers must be multiples of 16 bytes");
126 
127     struct Compute
128     {
ComputeCompute129         Compute() : numWorkGroups{0u}, padding(0u) {}
130         unsigned int numWorkGroups[3];
131         unsigned int padding;  // This just pads the struct to 16 bytes
132     };
133 
134     struct SamplerMetadata
135     {
SamplerMetadataSamplerMetadata136         SamplerMetadata()
137             : baseLevel(0), internalFormatBits(0), wrapModes(0), padding(0), intBorderColor{0}
138         {}
139 
140         int baseLevel;
141         int internalFormatBits;
142         int wrapModes;
143         int padding;  // This just pads the struct to 32 bytes
144         int intBorderColor[4];
145     };
146 
147     static_assert(sizeof(SamplerMetadata) == 32u,
148                   "Sampler metadata struct must be two 4-vec --> 32 bytes.");
149 
150     struct ImageMetadata
151     {
ImageMetadataImageMetadata152         ImageMetadata() : layer(0), level(0), padding{0} {}
153 
154         int layer;
155         unsigned int level;
156         int padding[2];  // This just pads the struct to 16 bytes
157     };
158     static_assert(sizeof(ImageMetadata) == 16u,
159                   "Image metadata struct must be one 4-vec --> 16 bytes.");
160 
161     static size_t GetShaderConstantsStructSize(gl::ShaderType shaderType);
162 
163     // Return true if dirty.
164     bool updateSamplerMetadata(SamplerMetadata *data,
165                                const gl::Texture &texture,
166                                const gl::SamplerState &samplerState);
167 
168     // Return true if dirty.
169     bool updateImageMetadata(ImageMetadata *data, const gl::ImageUnit &imageUnit);
170 
171     Vertex mVertex;
172     Pixel mPixel;
173     Compute mCompute;
174     gl::ShaderBitSet mShaderConstantsDirty;
175 
176     gl::ShaderMap<std::vector<SamplerMetadata>> mShaderSamplerMetadata;
177     gl::ShaderMap<int> mNumActiveShaderSamplers;
178     gl::ShaderMap<std::vector<ImageMetadata>> mShaderReadonlyImageMetadata;
179     gl::ShaderMap<int> mNumActiveShaderReadonlyImages;
180     gl::ShaderMap<std::vector<ImageMetadata>> mShaderImageMetadata;
181     gl::ShaderMap<int> mNumActiveShaderImages;
182 };
183 
184 class StateManager11 final : angle::NonCopyable
185 {
186   public:
187     StateManager11(Renderer11 *renderer);
188     ~StateManager11();
189 
190     void deinitialize();
191 
192     void syncState(const gl::Context *context,
193                    const gl::State::DirtyBits &dirtyBits,
194                    gl::Command command);
195 
196     angle::Result updateStateForCompute(const gl::Context *context,
197                                         GLuint numGroupsX,
198                                         GLuint numGroupsY,
199                                         GLuint numGroupsZ);
200 
201     void updateStencilSizeIfChanged(bool depthStencilInitialized, unsigned int stencilSize);
202 
203     // These invalidations methods are called externally.
204 
205     // Called from TextureStorage11.
206     void invalidateBoundViews();
207 
208     // Called from VertexArray11::updateVertexAttribStorage.
209     void invalidateCurrentValueAttrib(size_t attribIndex);
210 
211     // Checks are done on a framebuffer state change to trigger other state changes.
212     // The Context is allowed to be nullptr for these methods, when called in EGL init code.
213     void invalidateRenderTarget();
214 
215     // Called by instanced point sprite emulation.
216     void invalidateVertexBuffer();
217 
218     // Called by Framebuffer11::syncState for the default sized viewport.
219     void invalidateViewport(const gl::Context *context);
220 
221     // Called by TextureStorage11::markLevelDirty.
222     void invalidateSwizzles();
223 
224     // Called by the Framebuffer11 and VertexArray11.
225     void invalidateShaders();
226 
227     // Called by the Program on Uniform Buffer change. Also called internally.
228     void invalidateProgramUniformBuffers();
229 
230     // Called by TransformFeedback11.
231     void invalidateTransformFeedback();
232 
233     // Called by VertexArray11.
234     void invalidateInputLayout();
235 
236     // Called by VertexArray11 element array buffer sync.
237     void invalidateIndexBuffer();
238 
239     // Called by TextureStorage11. Also called internally.
240     void invalidateTexturesAndSamplers();
241 
242     void setRenderTarget(ID3D11RenderTargetView *rtv, ID3D11DepthStencilView *dsv);
243     void setRenderTargets(ID3D11RenderTargetView **rtvs, UINT numRtvs, ID3D11DepthStencilView *dsv);
244 
245     void onBeginQuery(Query11 *query);
246     void onDeleteQueryObject(Query11 *query);
247     angle::Result onMakeCurrent(const gl::Context *context);
248 
249     void setInputLayout(const d3d11::InputLayout *inputLayout);
250 
251     void setSingleVertexBuffer(const d3d11::Buffer *buffer, UINT stride, UINT offset);
252 
253     angle::Result updateState(const gl::Context *context,
254                               gl::PrimitiveMode mode,
255                               GLint firstVertex,
256                               GLsizei vertexOrIndexCount,
257                               gl::DrawElementsType indexTypeOrInvalid,
258                               const void *indices,
259                               GLsizei instanceCount,
260                               GLint baseVertex,
261                               GLuint baseInstance,
262                               bool promoteDynamic);
263 
264     void setShaderResourceShared(gl::ShaderType shaderType,
265                                  UINT resourceSlot,
266                                  const d3d11::SharedSRV *srv);
267     void setShaderResource(gl::ShaderType shaderType,
268                            UINT resourceSlot,
269                            const d3d11::ShaderResourceView *srv);
270     void setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY primitiveTopology);
271 
272     void setDrawShaders(const d3d11::VertexShader *vertexShader,
273                         const d3d11::GeometryShader *geometryShader,
274                         const d3d11::PixelShader *pixelShader);
275     void setVertexShader(const d3d11::VertexShader *shader);
276     void setGeometryShader(const d3d11::GeometryShader *shader);
277     void setPixelShader(const d3d11::PixelShader *shader);
278     void setComputeShader(const d3d11::ComputeShader *shader);
279     void setVertexConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer);
280     void setPixelConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer);
281     void setDepthStencilState(const d3d11::DepthStencilState *depthStencilState, UINT stencilRef);
282     void setSimpleBlendState(const d3d11::BlendState *blendState);
283     void setRasterizerState(const d3d11::RasterizerState *rasterizerState);
284     void setSimpleViewport(const gl::Extents &viewportExtents);
285     void setSimpleViewport(int width, int height);
286     void setSimplePixelTextureAndSampler(const d3d11::SharedSRV &srv,
287                                          const d3d11::SamplerState &samplerState);
288     void setSimpleScissorRect(const gl::Rectangle &glRect);
289     void setScissorRectD3D(const D3D11_RECT &d3dRect);
290 
291     void setIndexBuffer(ID3D11Buffer *buffer, DXGI_FORMAT indexFormat, unsigned int offset);
292 
293     angle::Result updateVertexOffsetsForPointSpritesEmulation(const gl::Context *context,
294                                                               GLint startVertex,
295                                                               GLsizei emulatedInstanceId);
296 
297     // TODO(jmadill): Should be private.
298     angle::Result applyComputeUniforms(const gl::Context *context, ProgramD3D *programD3D);
299 
300     // Only used in testing.
getInputLayoutCache()301     InputLayoutCache *getInputLayoutCache() { return &mInputLayoutCache; }
302 
getCullEverything()303     bool getCullEverything() const { return mCullEverything; }
getVertexDataManager()304     VertexDataManager *getVertexDataManager() { return &mVertexDataManager; }
305 
getProgramD3D()306     ProgramD3D *getProgramD3D() const { return mProgramD3D; }
307 
308   private:
309     angle::Result ensureInitialized(const gl::Context *context);
310 
311     template <typename SRVType>
312     void setShaderResourceInternal(gl::ShaderType shaderType,
313                                    UINT resourceSlot,
314                                    const SRVType *srv);
315     template <typename UAVType>
316     void setUnorderedAccessViewInternal(gl::ShaderType shaderType,
317                                         UINT resourceSlot,
318                                         const UAVType *uav);
319 
320     void unsetConflictingView(gl::PipelineType pipeline, ID3D11View *view, bool isRenderTarget);
321     void unsetConflictingSRVs(gl::PipelineType pipeline,
322                               gl::ShaderType shaderType,
323                               uintptr_t resource,
324                               const gl::ImageIndex *index,
325                               bool isRenderTarget);
326     void unsetConflictingUAVs(gl::PipelineType pipeline,
327                               gl::ShaderType shaderType,
328                               uintptr_t resource,
329                               const gl::ImageIndex *index);
330     void unsetConflictingRTVs(uintptr_t resource);
331 
332     void unsetConflictingAttachmentResources(const gl::FramebufferAttachment &attachment,
333                                              ID3D11Resource *resource);
334 
335     angle::Result syncBlendState(const gl::Context *context,
336                                  const gl::BlendStateExt &blendStateExt,
337                                  const gl::ColorF &blendColor,
338                                  unsigned int sampleMask,
339                                  bool sampleAlphaToCoverage,
340                                  bool emulateConstantAlpha);
341 
342     angle::Result syncDepthStencilState(const gl::Context *context);
343 
344     angle::Result syncRasterizerState(const gl::Context *context, gl::PrimitiveMode mode);
345 
346     void syncScissorRectangle(const gl::Context *context);
347 
348     void syncViewport(const gl::Context *context);
349 
350     void checkPresentPath(const gl::Context *context);
351 
352     angle::Result syncFramebuffer(const gl::Context *context);
353     angle::Result syncProgram(const gl::Context *context, gl::PrimitiveMode drawMode);
354     angle::Result syncProgramForCompute(const gl::Context *context);
355 
356     angle::Result syncTextures(const gl::Context *context);
357     angle::Result applyTexturesForSRVs(const gl::Context *context, gl::ShaderType shaderType);
358     angle::Result applyTexturesForUAVs(const gl::Context *context, gl::ShaderType shaderType);
359     angle::Result syncTexturesForCompute(const gl::Context *context);
360 
361     angle::Result setSamplerState(const gl::Context *context,
362                                   gl::ShaderType type,
363                                   int index,
364                                   gl::Texture *texture,
365                                   const gl::SamplerState &sampler);
366     angle::Result setTextureForSampler(const gl::Context *context,
367                                        gl::ShaderType type,
368                                        int index,
369                                        gl::Texture *texture,
370                                        const gl::SamplerState &sampler);
371     angle::Result setImageState(const gl::Context *context,
372                                 gl::ShaderType type,
373                                 int index,
374                                 const gl::ImageUnit &imageUnit);
375     angle::Result setTextureForImage(const gl::Context *context,
376                                      gl::ShaderType type,
377                                      int index,
378                                      bool readonly,
379                                      const gl::ImageUnit &imageUnit);
380 
381     void handleMultiviewDrawFramebufferChange(const gl::Context *context);
382 
383     angle::Result syncCurrentValueAttribs(
384         const gl::Context *context,
385         const std::vector<gl::VertexAttribCurrentValueData> &currentValues);
386 
387     angle::Result generateSwizzle(const gl::Context *context, gl::Texture *texture);
388     angle::Result generateSwizzlesForShader(const gl::Context *context, gl::ShaderType type);
389     angle::Result generateSwizzles(const gl::Context *context);
390 
391     angle::Result applyDriverUniforms(const gl::Context *context);
392     angle::Result applyDriverUniformsForShader(const gl::Context *context,
393                                                gl::ShaderType shaderType);
394     angle::Result applyUniforms(const gl::Context *context);
395     angle::Result applyUniformsForShader(const gl::Context *context, gl::ShaderType shaderType);
396 
397     angle::Result syncShaderStorageBuffersForShader(const gl::Context *context,
398                                                     gl::ShaderType shaderType);
399 
400     angle::Result syncUniformBuffers(const gl::Context *context);
401     angle::Result syncUniformBuffersForShader(const gl::Context *context,
402                                               gl::ShaderType shaderType);
403     angle::Result syncAtomicCounterBuffers(const gl::Context *context);
404     angle::Result syncAtomicCounterBuffersForShader(const gl::Context *context,
405                                                     gl::ShaderType shaderType);
406     angle::Result syncShaderStorageBuffers(const gl::Context *context);
407     angle::Result syncTransformFeedbackBuffers(const gl::Context *context);
408 
409     // These are currently only called internally.
410     void invalidateDriverUniforms();
411     void invalidateProgramUniforms();
412     void invalidateConstantBuffer(unsigned int slot);
413     void invalidateProgramAtomicCounterBuffers();
414     void invalidateProgramShaderStorageBuffers();
415 
416     // Called by the Framebuffer11 directly.
417     void processFramebufferInvalidation(const gl::Context *context);
418 
419     bool syncIndexBuffer(ID3D11Buffer *buffer, DXGI_FORMAT indexFormat, unsigned int offset);
420     angle::Result syncVertexBuffersAndInputLayout(const gl::Context *context,
421                                                   gl::PrimitiveMode mode,
422                                                   GLint firstVertex,
423                                                   GLsizei vertexOrIndexCount,
424                                                   gl::DrawElementsType indexTypeOrInvalid,
425                                                   GLsizei instanceCount);
426 
427     bool setInputLayoutInternal(const d3d11::InputLayout *inputLayout);
428 
429     angle::Result applyVertexBuffers(const gl::Context *context,
430                                      gl::PrimitiveMode mode,
431                                      gl::DrawElementsType indexTypeOrInvalid,
432                                      GLint firstVertex);
433     // TODO(jmadill): Migrate to d3d11::Buffer.
434     bool queueVertexBufferChange(size_t bufferIndex,
435                                  ID3D11Buffer *buffer,
436                                  UINT stride,
437                                  UINT offset);
438     void applyVertexBufferChanges();
439     bool setPrimitiveTopologyInternal(D3D11_PRIMITIVE_TOPOLOGY primitiveTopology);
440     void syncPrimitiveTopology(const gl::State &glState, gl::PrimitiveMode currentDrawMode);
441 
442     // Not handled by an internal dirty bit because it isn't synced on drawArrays calls.
443     angle::Result applyIndexBuffer(const gl::Context *context,
444                                    GLsizei indexCount,
445                                    gl::DrawElementsType indexType,
446                                    const void *indices);
447 
448     enum DirtyBitType
449     {
450         DIRTY_BIT_RENDER_TARGET,
451         DIRTY_BIT_VIEWPORT_STATE,
452         DIRTY_BIT_SCISSOR_STATE,
453         DIRTY_BIT_RASTERIZER_STATE,
454         DIRTY_BIT_BLEND_STATE,
455         DIRTY_BIT_DEPTH_STENCIL_STATE,
456         // DIRTY_BIT_SHADERS and DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE should be dealt before
457         // DIRTY_BIT_PROGRAM_UNIFORM_BUFFERS for update image layers.
458         DIRTY_BIT_SHADERS,
459         // DIRTY_BIT_GRAPHICS_SRVUAV_STATE and DIRTY_BIT_COMPUTE_SRVUAV_STATE should be lower
460         // bits than DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE.
461         DIRTY_BIT_GRAPHICS_SRVUAV_STATE,
462         DIRTY_BIT_COMPUTE_SRVUAV_STATE,
463         DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE,
464         DIRTY_BIT_PROGRAM_UNIFORMS,
465         DIRTY_BIT_DRIVER_UNIFORMS,
466         DIRTY_BIT_PROGRAM_UNIFORM_BUFFERS,
467         DIRTY_BIT_PROGRAM_ATOMIC_COUNTER_BUFFERS,
468         DIRTY_BIT_PROGRAM_SHADER_STORAGE_BUFFERS,
469         DIRTY_BIT_CURRENT_VALUE_ATTRIBS,
470         DIRTY_BIT_TRANSFORM_FEEDBACK,
471         DIRTY_BIT_VERTEX_BUFFERS_AND_INPUT_LAYOUT,
472         DIRTY_BIT_PRIMITIVE_TOPOLOGY,
473         DIRTY_BIT_INVALID,
474         DIRTY_BIT_MAX = DIRTY_BIT_INVALID,
475     };
476 
477     using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
478 
479     Renderer11 *mRenderer;
480 
481     // Internal dirty bits.
482     DirtyBits mInternalDirtyBits;
483     DirtyBits mGraphicsDirtyBitsMask;
484     DirtyBits mComputeDirtyBitsMask;
485 
486     bool mCurSampleAlphaToCoverage;
487 
488     // Blend State
489     gl::BlendStateExt mCurBlendStateExt;
490     gl::ColorF mCurBlendColor;
491     unsigned int mCurSampleMask;
492 
493     // Currently applied depth stencil state
494     gl::DepthStencilState mCurDepthStencilState;
495     int mCurStencilRef;
496     int mCurStencilBackRef;
497     unsigned int mCurStencilSize;
498     Optional<bool> mCurDisableDepth;
499     Optional<bool> mCurDisableStencil;
500 
501     // Currently applied rasterizer state
502     gl::RasterizerState mCurRasterState;
503 
504     // Currently applied scissor rectangle state
505     bool mCurScissorEnabled;
506     gl::Rectangle mCurScissorRect;
507 
508     // Currently applied viewport state
509     gl::Rectangle mCurViewport;
510     float mCurNear;
511     float mCurFar;
512 
513     // Currently applied offset to viewport and scissor
514     gl::Offset mCurViewportOffset;
515     gl::Offset mCurScissorOffset;
516 
517     // Things needed in viewport state
518     ShaderConstants11 mShaderConstants;
519 
520     // Render target variables
521     gl::Extents mViewportBounds;
522     bool mRenderTargetIsDirty;
523 
524     // EGL_ANGLE_experimental_present_path variables
525     bool mCurPresentPathFastEnabled;
526     int mCurPresentPathFastColorBufferHeight;
527 
528     // Queries that are currently active in this state
529     std::set<Query11 *> mCurrentQueries;
530 
531     // Currently applied textures
532     template <typename DescType>
533     struct ViewRecord
534     {
535         uintptr_t view;
536         uintptr_t resource;
537         DescType desc;
538     };
539 
540     // A cache of current Views that also tracks the highest 'used' (non-NULL) View.
541     // We might want to investigate a more robust approach that is also fast when there's
542     // a large gap between used Views (e.g. if View 0 and 7 are non-NULL, this approach will
543     // waste time on Views 1-6.)
544     template <typename ViewType, typename DescType>
545     class ViewCache : angle::NonCopyable
546     {
547       public:
548         ViewCache();
549         ~ViewCache();
550 
initialize(size_t size)551         void initialize(size_t size) { mCurrentViews.resize(size); }
552 
size()553         size_t size() const { return mCurrentViews.size(); }
highestUsed()554         size_t highestUsed() const { return mHighestUsedView; }
555 
556         const ViewRecord<DescType> &operator[](size_t index) const { return mCurrentViews[index]; }
557         void clear();
558         void update(size_t resourceIndex, ViewType *view);
559 
560       private:
561         std::vector<ViewRecord<DescType>> mCurrentViews;
562         size_t mHighestUsedView;
563     };
564 
565     using SRVCache = ViewCache<ID3D11ShaderResourceView, D3D11_SHADER_RESOURCE_VIEW_DESC>;
566     using UAVCache = ViewCache<ID3D11UnorderedAccessView, D3D11_UNORDERED_ACCESS_VIEW_DESC>;
567     using RTVCache = ViewCache<ID3D11RenderTargetView, D3D11_RENDER_TARGET_VIEW_DESC>;
568     gl::ShaderMap<SRVCache> mCurShaderSRVs;
569     UAVCache mCurComputeUAVs;
570     RTVCache mCurRTVs;
571 
572     SRVCache *getSRVCache(gl::ShaderType shaderType);
573 
574     // A block of NULL pointers, cached so we don't re-allocate every draw call
575     std::vector<ID3D11ShaderResourceView *> mNullSRVs;
576     std::vector<ID3D11UnorderedAccessView *> mNullUAVs;
577 
578     // Current translations of "Current-Value" data - owned by Context, not VertexArray.
579     gl::AttributesMask mDirtyCurrentValueAttribs;
580     std::vector<TranslatedAttribute> mCurrentValueAttribs;
581 
582     // Current applied input layout.
583     ResourceSerial mCurrentInputLayout;
584 
585     // Current applied vertex states.
586     // TODO(jmadill): Figure out how to use ResourceSerial here.
587     gl::AttribArray<ID3D11Buffer *> mCurrentVertexBuffers;
588     gl::AttribArray<UINT> mCurrentVertexStrides;
589     gl::AttribArray<UINT> mCurrentVertexOffsets;
590     gl::RangeUI mDirtyVertexBufferRange;
591 
592     // Currently applied primitive topology
593     D3D11_PRIMITIVE_TOPOLOGY mCurrentPrimitiveTopology;
594     gl::PrimitiveMode mLastAppliedDrawMode;
595     bool mCullEverything;
596 
597     // Currently applied shaders
598     gl::ShaderMap<ResourceSerial> mAppliedShaders;
599 
600     // Currently applied sampler states
601     gl::ShaderMap<std::vector<bool>> mForceSetShaderSamplerStates;
602     gl::ShaderMap<std::vector<gl::SamplerState>> mCurShaderSamplerStates;
603 
604     // Special dirty bit for swizzles. Since they use internal shaders, must be done in a pre-pass.
605     bool mDirtySwizzles;
606 
607     // Currently applied index buffer
608     ID3D11Buffer *mAppliedIB;
609     DXGI_FORMAT mAppliedIBFormat;
610     unsigned int mAppliedIBOffset;
611     bool mIndexBufferIsDirty;
612 
613     // Vertex, index and input layouts
614     VertexDataManager mVertexDataManager;
615     IndexDataManager mIndexDataManager;
616     InputLayoutCache mInputLayoutCache;
617     std::vector<const TranslatedAttribute *> mCurrentAttributes;
618     Optional<GLint> mLastFirstVertex;
619 
620     // ANGLE_multiview.
621     bool mIsMultiviewEnabled;
622 
623     bool mIndependentBlendStates;
624 
625     // Driver Constants.
626     gl::ShaderMap<d3d11::Buffer> mShaderDriverConstantBuffers;
627 
628     ResourceSerial mCurrentComputeConstantBuffer;
629     ResourceSerial mCurrentGeometryConstantBuffer;
630 
631     d3d11::Buffer mPointSpriteVertexBuffer;
632     d3d11::Buffer mPointSpriteIndexBuffer;
633 
634     template <typename T>
635     using VertexConstantBufferArray =
636         std::array<T, gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS>;
637 
638     VertexConstantBufferArray<ResourceSerial> mCurrentConstantBufferVS;
639     VertexConstantBufferArray<GLintptr> mCurrentConstantBufferVSOffset;
640     VertexConstantBufferArray<GLsizeiptr> mCurrentConstantBufferVSSize;
641 
642     template <typename T>
643     using FragmentConstantBufferArray =
644         std::array<T, gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS>;
645 
646     FragmentConstantBufferArray<ResourceSerial> mCurrentConstantBufferPS;
647     FragmentConstantBufferArray<GLintptr> mCurrentConstantBufferPSOffset;
648     FragmentConstantBufferArray<GLsizeiptr> mCurrentConstantBufferPSSize;
649 
650     template <typename T>
651     using ComputeConstantBufferArray =
652         std::array<T, gl::IMPLEMENTATION_MAX_COMPUTE_SHADER_UNIFORM_BUFFERS>;
653 
654     ComputeConstantBufferArray<ResourceSerial> mCurrentConstantBufferCS;
655     ComputeConstantBufferArray<GLintptr> mCurrentConstantBufferCSOffset;
656     ComputeConstantBufferArray<GLsizeiptr> mCurrentConstantBufferCSSize;
657 
658     // Currently applied transform feedback buffers
659     Serial mAppliedTFSerial;
660 
661     Serial mEmptySerial;
662 
663     // These objects are cached to avoid having to query the impls.
664     ProgramD3D *mProgramD3D;
665     VertexArray11 *mVertexArray11;
666     Framebuffer11 *mFramebuffer11;
667 };
668 
669 }  // namespace rx
670 #endif  // LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_
671