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