GrGpuCommandBuffer.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/GrGpuCommandBuffer.h"
  8. #include "include/core/SkRect.h"
  9. #include "include/gpu/GrContext.h"
  10. #include "include/gpu/GrRenderTarget.h"
  11. #include "src/gpu/GrCaps.h"
  12. #include "src/gpu/GrContextPriv.h"
  13. #include "src/gpu/GrFixedClip.h"
  14. #include "src/gpu/GrGpu.h"
  15. #include "src/gpu/GrMesh.h"
  16. #include "src/gpu/GrPrimitiveProcessor.h"
  17. #include "src/gpu/GrRenderTargetPriv.h"
  18. void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
  19. SkASSERT(fRenderTarget);
  20. // A clear at this level will always be a true clear, so make sure clears were not supposed to
  21. // be redirected to draws instead
  22. SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
  23. SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
  24. this->onClear(clip, color);
  25. }
  26. void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
  27. // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
  28. SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
  29. this->onClearStencilClip(clip, insideStencilMask);
  30. }
  31. bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline,
  32. const GrPipeline::FixedDynamicState* fixedDynamicState,
  33. const GrPipeline::DynamicStateArrays* dynamicStateArrays,
  34. const GrMesh meshes[], int meshCount, const SkRect& bounds) {
  35. #ifdef SK_DEBUG
  36. SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport());
  37. for (int i = 0; i < meshCount; ++i) {
  38. SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
  39. this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
  40. SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData());
  41. SkASSERT(primProc.hasInstanceAttributes() == meshes[i].hasInstanceData());
  42. }
  43. #endif
  44. SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState ||
  45. (dynamicStateArrays && dynamicStateArrays->fScissorRects));
  46. SkASSERT(!pipeline.isBad());
  47. #ifdef SK_DEBUG
  48. if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
  49. GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures;
  50. for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
  51. SkASSERT(processorProxies[i]->isInstantiated());
  52. }
  53. }
  54. if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) {
  55. int n = primProc.numTextureSamplers() * meshCount;
  56. const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures;
  57. for (int i = 0; i < n; ++i) {
  58. SkASSERT(textures[i]->isInstantiated());
  59. }
  60. SkASSERT(meshCount >= 1);
  61. const GrTextureProxy* const* primProcProxies =
  62. dynamicStateArrays->fPrimitiveProcessorTextures;
  63. for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
  64. const GrBackendFormat& format = primProcProxies[i]->backendFormat();
  65. GrTextureType type = primProcProxies[i]->textureType();
  66. GrPixelConfig config = primProcProxies[i]->config();
  67. for (int j = 1; j < meshCount; ++j) {
  68. const GrTextureProxy* testProxy =
  69. primProcProxies[j*primProc.numTextureSamplers() + i];
  70. SkASSERT(testProxy->backendFormat() == format);
  71. SkASSERT(testProxy->textureType() == type);
  72. SkASSERT(testProxy->config() == config);
  73. }
  74. }
  75. }
  76. #endif
  77. if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
  78. this->gpu()->stats()->incNumFailedDraws();
  79. return false;
  80. }
  81. this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
  82. bounds);
  83. #ifdef SK_DEBUG
  84. GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures();
  85. for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
  86. processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures();
  87. }
  88. processorFeatures |= pipeline.getXferProcessor().requestedFeatures();
  89. if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
  90. // Verify we always have the same sample pattern key, regardless of graphics state.
  91. SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
  92. == fRenderTarget->renderTargetPriv().getSamplePatternKey());
  93. }
  94. #endif
  95. return true;
  96. }