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