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