Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1001503002: Implement support for mixed sampled render targets (Closed) Base URL: https://skia.googlesource.com/skia.git@mix1
Patch Set: Fixes and squash with 3rd commit Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "GrGLStencilBuffer.h" 10 #include "GrGLStencilBuffer.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 440 }
441 441
442 return texture; 442 return texture;
443 } 443 }
444 444
445 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc) { 445 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc) {
446 GrGLRenderTarget::IDDesc idDesc; 446 GrGLRenderTarget::IDDesc idDesc;
447 GrGLuint fboID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); 447 GrGLuint fboID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle);
448 idDesc.fRenderFBO.reset(SkNEW_ARGS(GrGLFBO, (fboID))); 448 idDesc.fRenderFBO.reset(SkNEW_ARGS(GrGLFBO, (fboID)));
449 idDesc.fMSColorRenderbufferID = 0; 449 idDesc.fMSColorRenderbufferID = 0;
450 idDesc.fSampleConfig = wrapDesc.fSampleConfig;
450 idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle; 451 idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle;
451 452
452 GrSurfaceDesc desc; 453 GrSurfaceDesc desc;
453 desc.fConfig = wrapDesc.fConfig; 454 desc.fConfig = wrapDesc.fConfig;
454 desc.fFlags = kCheckAllocation_GrSurfaceFlag; 455 desc.fFlags = kCheckAllocation_GrSurfaceFlag;
455 desc.fWidth = wrapDesc.fWidth; 456 desc.fWidth = wrapDesc.fWidth;
456 desc.fHeight = wrapDesc.fHeight; 457 desc.fHeight = wrapDesc.fHeight;
457 desc.fSampleCnt = wrapDesc.fSampleCnt; 458 desc.fSampleCnt = wrapDesc.fSampleCnt;
458 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); 459 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
459 460
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 788
788 static bool renderbuffer_storage_msaa(GrGLContext& ctx, 789 static bool renderbuffer_storage_msaa(GrGLContext& ctx,
789 int sampleCount, 790 int sampleCount,
790 GrGLenum format, 791 GrGLenum format,
791 int width, int height) { 792 int width, int height) {
792 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); 793 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface());
793 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); 794 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType());
794 switch (ctx.caps()->msFBOType()) { 795 switch (ctx.caps()->msFBOType()) {
795 case GrGLCaps::kDesktop_ARB_MSFBOType: 796 case GrGLCaps::kDesktop_ARB_MSFBOType:
796 case GrGLCaps::kDesktop_EXT_MSFBOType: 797 case GrGLCaps::kDesktop_EXT_MSFBOType:
798 case GrGLCaps::kStencil_MSFBOType:
797 case GrGLCaps::kES_3_0_MSFBOType: 799 case GrGLCaps::kES_3_0_MSFBOType:
798 GL_ALLOC_CALL(ctx.interface(), 800 GL_ALLOC_CALL(ctx.interface(),
799 RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, 801 RenderbufferStorageMultisample(GR_GL_RENDERBUFFER,
800 sampleCount, 802 sampleCount,
801 format, 803 format,
802 width, height)); 804 width, height));
803 break; 805 break;
804 case GrGLCaps::kES_Apple_MSFBOType: 806 case GrGLCaps::kES_Apple_MSFBOType:
805 GL_ALLOC_CALL(ctx.interface(), 807 GL_ALLOC_CALL(ctx.interface(),
806 RenderbufferStorageMultisampleES2APPLE(GR_GL_RENDERB UFFER, 808 RenderbufferStorageMultisampleES2APPLE(GR_GL_RENDERB UFFER,
(...skipping 14 matching lines...) Expand all
821 break; 823 break;
822 } 824 }
823 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));; 825 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));;
824 } 826 }
825 827
826 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted , GrGLuint texID, 828 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted , GrGLuint texID,
827 GrGLRenderTarget::IDDesc* idDesc) { 829 GrGLRenderTarget::IDDesc* idDesc) {
828 idDesc->fMSColorRenderbufferID = 0; 830 idDesc->fMSColorRenderbufferID = 0;
829 idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : 831 idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
830 GrGpuResource::kUncached_LifeCycle; 832 GrGpuResource::kUncached_LifeCycle;
833 idDesc->fSampleConfig = GrGLCaps::kStencil_MSFBOType ==
834 this->glCaps().msFBOType() ? kStencil_GrSampleConfig :
835 kUnified_GrSampleConfig ;
831 836
832 GrGLenum status; 837 GrGLenum status;
833 838
834 GrGLenum msColorFormat = 0; // suppress warning 839 GrGLenum msColorFormat = 0; // suppress warning
835 GrGLenum fboTarget = 0; // suppress warning 840 GrGLenum fboTarget = 0; // suppress warning
836 841
837 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) { 842 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) {
838 goto FAILED; 843 goto FAILED;
839 } 844 }
840 845
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 } 1145 }
1141 } 1146 }
1142 1147
1143 bool GrGLGpu::createStencilBufferForRenderTarget(GrRenderTarget* rt, int width, int height) { 1148 bool GrGLGpu::createStencilBufferForRenderTarget(GrRenderTarget* rt, int width, int height) {
1144 // All internally created RTs are also textures. We don't create 1149 // All internally created RTs are also textures. We don't create
1145 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . 1150 // SBs for a client's standalone RT (that is a RT that isn't also a texture) .
1146 SkASSERT(rt->asTexture()); 1151 SkASSERT(rt->asTexture());
1147 SkASSERT(width >= rt->width()); 1152 SkASSERT(width >= rt->width());
1148 SkASSERT(height >= rt->height()); 1153 SkASSERT(height >= rt->height());
1149 1154
1150 int samples = rt->numSamples(); 1155 int samples = rt->numSamples(kStencil_GrSampleConfig);
1151 GrGLStencilBuffer::IDDesc sbDesc; 1156 GrGLStencilBuffer::IDDesc sbDesc;
1152 1157
1153 int stencilFmtCnt = this->glCaps().stencilFormats().count(); 1158 int stencilFmtCnt = this->glCaps().stencilFormats().count();
1154 for (int i = 0; i < stencilFmtCnt; ++i) { 1159 for (int i = 0; i < stencilFmtCnt; ++i) {
1155 if (!sbDesc.fRenderbufferID) { 1160 if (!sbDesc.fRenderbufferID) {
1156 GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID)); 1161 GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID));
1157 } 1162 }
1158 if (!sbDesc.fRenderbufferID) { 1163 if (!sbDesc.fRenderbufferID) {
1159 return false; 1164 return false;
1160 } 1165 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 fHWScissorSettings.fEnabled = kYes_TriState; 1388 fHWScissorSettings.fEnabled = kYes_TriState;
1384 } 1389 }
1385 return; 1390 return;
1386 } 1391 }
1387 } 1392 }
1388 1393
1389 // See fall through note above 1394 // See fall through note above
1390 this->disableScissor(); 1395 this->disableScissor();
1391 } 1396 }
1392 1397
1393 bool GrGLGpu::flushGLState(const DrawArgs& args, bool isLineDraw) { 1398 bool GrGLGpu::flushGLState(const DrawArgs& args, bool isLineDraw, GrSampleConfig sampleConfig) {
1394 GrXferProcessor::BlendInfo blendInfo; 1399 GrXferProcessor::BlendInfo blendInfo;
1395 const GrPipeline& pipeline = *args.fPipeline; 1400 const GrPipeline& pipeline = *args.fPipeline;
1396 args.fPipeline->getXferProcessor()->getBlendInfo(&blendInfo); 1401 args.fPipeline->getXferProcessor()->getBlendInfo(&blendInfo);
1397 1402
1398 this->flushDither(pipeline.isDitherState()); 1403 this->flushDither(pipeline.isDitherState());
1399 this->flushColorWrite(blendInfo.fWriteColor); 1404 this->flushColorWrite(blendInfo.fWriteColor);
1400 this->flushDrawFace(pipeline.getDrawFace()); 1405 this->flushDrawFace(pipeline.getDrawFace());
1401 1406
1402 fCurrentProgram.reset(fProgramCache->getProgram(args)); 1407 fCurrentProgram.reset(fProgramCache->getProgram(args));
1403 if (NULL == fCurrentProgram.get()) { 1408 if (NULL == fCurrentProgram.get()) {
(...skipping 11 matching lines...) Expand all
1415 1420
1416 if (blendInfo.fWriteColor) { 1421 if (blendInfo.fWriteColor) {
1417 this->flushBlend(blendInfo); 1422 this->flushBlend(blendInfo);
1418 } 1423 }
1419 1424
1420 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr acker); 1425 fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTr acker);
1421 1426
1422 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget()); 1427 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
1423 this->flushStencil(pipeline.getStencil()); 1428 this->flushStencil(pipeline.getStencil());
1424 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin()); 1429 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin());
1425 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), isLineDraw); 1430 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), isLineDraw, sample Config);
1426 1431
1427 // This must come after textures are flushed because a texture may need 1432 // This must come after textures are flushed because a texture may need
1428 // to be msaa-resolved (which will modify bound FBO state). 1433 // to be msaa-resolved (which will modify bound FBO state).
1429 this->prepareToDrawToRenderTarget(glRT, NULL); 1434 this->prepareToDrawToRenderTarget(glRT, NULL);
1430 1435
1431 return true; 1436 return true;
1432 } 1437 }
1433 1438
1434 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, 1439 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
1435 const GrDrawTarget::DrawInfo& info, 1440 const GrDrawTarget::DrawInfo& info,
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o rigin()); 1948 this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->o rigin());
1944 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); 1949 this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin());
1945 this->flushHWAAState(rt, state.fUseHWAA, false); 1950 this->flushHWAAState(rt, state.fUseHWAA, false);
1946 this->prepareToDrawToRenderTarget(rt, NULL); 1951 this->prepareToDrawToRenderTarget(rt, NULL);
1947 1952
1948 fPathRendering->stencilPath(path, *state.fStencil); 1953 fPathRendering->stencilPath(path, *state.fStencil);
1949 } 1954 }
1950 1955
1951 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path, 1956 void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path,
1952 const GrStencilSettings& stencil) { 1957 const GrStencilSettings& stencil) {
1953 if (!this->flushGLState(args, false)) { 1958 if (!this->flushGLState(args, false, kStencil_GrSampleConfig)) {
1954 return; 1959 return;
1955 } 1960 }
1956 fPathRendering->drawPath(path, stencil); 1961 fPathRendering->drawPath(path, stencil);
1957 } 1962 }
1958 1963
1959 void GrGLGpu::onDrawPaths(const DrawArgs& args, 1964 void GrGLGpu::onDrawPaths(const DrawArgs& args,
1960 const GrPathRange* pathRange, 1965 const GrPathRange* pathRange,
1961 const void* indices, 1966 const void* indices,
1962 GrDrawTarget::PathIndexType indexType, 1967 GrDrawTarget::PathIndexType indexType,
1963 const float transformValues[], 1968 const float transformValues[],
1964 GrDrawTarget::PathTransformType transformType, 1969 GrDrawTarget::PathTransformType transformType,
1965 int count, 1970 int count,
1966 const GrStencilSettings& stencil) { 1971 const GrStencilSettings& stencil) {
1967 if (!this->flushGLState(args, false)) { 1972 if (!this->flushGLState(args, false, kStencil_GrSampleConfig)) {
1968 return; 1973 return;
1969 } 1974 }
1970 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, 1975 fPathRendering->drawPaths(pathRange, indices, indexType, transformValues,
1971 transformType, count, stencil); 1976 transformType, count, stencil);
1972 } 1977 }
1973 1978
1974 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { 1979 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) {
1975 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); 1980 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target);
1976 if (rt->needsResolve()) { 1981 if (rt->needsResolve()) {
1977 // Some extensions automatically resolves the texture when it is read. 1982 // Some extensions automatically resolves the texture when it is read.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 set_gl_stencil(this->glInterface(), 2092 set_gl_stencil(this->glInterface(),
2088 stencilSettings, 2093 stencilSettings,
2089 GR_GL_FRONT_AND_BACK, 2094 GR_GL_FRONT_AND_BACK,
2090 GrStencilSettings::kFront_Face); 2095 GrStencilSettings::kFront_Face);
2091 } 2096 }
2092 } 2097 }
2093 fHWStencilSettings = stencilSettings; 2098 fHWStencilSettings = stencilSettings;
2094 } 2099 }
2095 } 2100 }
2096 2101
2097 void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool isLineDraw) { 2102 void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool isLineDraw,
2103 GrSampleConfig sampleConfig) {
2098 // At least some ATI linux drivers will render GL_LINES incorrectly when MSAA st ate is enabled but 2104 // At least some ATI linux drivers will render GL_LINES incorrectly when MSAA st ate is enabled but
2099 // the target is not multisampled. Single pixel wide lines are rendered thicker than 1 pixel wide. 2105 // the target is not multisampled. Single pixel wide lines are rendered thicker than 1 pixel wide.
2100 #if 0 2106 #if 0
2101 // Replace RT_HAS_MSAA with this definition once this driver bug is no longe r a relevant concern 2107 // Replace RT_HAS_MSAA with this definition once this driver bug is no longe r a relevant concern
2102 #define RT_HAS_MSAA rt->isMultisampled() 2108 #define RT_HAS_MSAA rt->isMultisampled(sampleConfig)
2103 #else 2109 #else
2104 #define RT_HAS_MSAA (rt->isMultisampled() || isLineDraw) 2110 #define RT_HAS_MSAA (rt->isMultisampled(sampleConfig) || isLineDraw)
2105 #endif 2111 #endif
2106 2112
2107 if (kGL_GrGLStandard == this->glStandard()) { 2113 if (kGL_GrGLStandard == this->glStandard()) {
Chris Dalton 2015/03/14 02:51:30 GL_MULTISAMPLE doesn't traditionally exist in ES 2
2108 if (RT_HAS_MSAA) { 2114 if (RT_HAS_MSAA && useHWAA) {
2109 if (useHWAA) { 2115 if (kYes_TriState != fMSAAEnabled) {
2110 if (kYes_TriState != fMSAAEnabled) { 2116 GL_CALL(Enable(GR_GL_MULTISAMPLE));
2111 GL_CALL(Enable(GR_GL_MULTISAMPLE)); 2117 fMSAAEnabled = kYes_TriState;
2112 fMSAAEnabled = kYes_TriState;
2113 }
2114 } else {
2115 if (kNo_TriState != fMSAAEnabled) {
2116 GL_CALL(Disable(GR_GL_MULTISAMPLE));
2117 fMSAAEnabled = kNo_TriState;
2118 }
2119 } 2118 }
2119 } else {
2120 if (kNo_TriState != fMSAAEnabled) {
2121 GL_CALL(Disable(GR_GL_MULTISAMPLE));
2122 fMSAAEnabled = kNo_TriState;
2123 }
2124 }
2125 }
2126 if (this->glCaps().fbMixedSamplesSupport()) {
2127 if (rt->isMultisampled(kStencil_GrSampleConfig)) {
Chris Dalton 2015/03/14 02:51:30 I think this would want to say: (after applying ht
2128 GL_CALL(CoverageModulation(GR_GL_RGBA));
Chris Dalton 2015/03/14 02:51:30 We should add a state variable for fCoverageModula
2129 } else {
2130 GL_CALL(CoverageModulation(GR_GL_NONE));
2120 } 2131 }
2121 } 2132 }
2122 } 2133 }
2123 2134
2124 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { 2135 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) {
2125 // Any optimization to disable blending should have already been applied and 2136 // Any optimization to disable blending should have already been applied and
2126 // tweaked the coeffs to (1, 0). 2137 // tweaked the coeffs to (1, 0).
2127 2138
2128 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; 2139 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
2129 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; 2140 GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 this->setVertexArrayID(gpu, 0); 2833 this->setVertexArrayID(gpu, 0);
2823 } 2834 }
2824 int attrCount = gpu->glCaps().maxVertexAttributes(); 2835 int attrCount = gpu->glCaps().maxVertexAttributes();
2825 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2836 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2826 fDefaultVertexArrayAttribState.resize(attrCount); 2837 fDefaultVertexArrayAttribState.resize(attrCount);
2827 } 2838 }
2828 attribState = &fDefaultVertexArrayAttribState; 2839 attribState = &fDefaultVertexArrayAttribState;
2829 } 2840 }
2830 return attribState; 2841 return attribState;
2831 } 2842 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698