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

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

Issue 1806983002: Update how we send draws to gpu backend to reduce state setting. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 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 #include "GrGLGpu.h" 8 #include "GrGLGpu.h"
9 #include "GrGLGLSL.h" 9 #include "GrGLGLSL.h"
10 #include "GrGLStencilAttachment.h" 10 #include "GrGLStencilAttachment.h"
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 fHWScissorSettings.fEnabled = kYes_TriState; 2064 fHWScissorSettings.fEnabled = kYes_TriState;
2065 } 2065 }
2066 return; 2066 return;
2067 } 2067 }
2068 } 2068 }
2069 2069
2070 // See fall through note above 2070 // See fall through note above
2071 this->disableScissor(); 2071 this->disableScissor();
2072 } 2072 }
2073 2073
2074 bool GrGLGpu::flushGLState(const DrawArgs& args) { 2074 bool GrGLGpu::flushGLState(const GrPipeline& pipeline, const GrPrimitiveProcesso r& primProc) {
2075 GrXferProcessor::BlendInfo blendInfo; 2075 GrXferProcessor::BlendInfo blendInfo;
2076 const GrPipeline& pipeline = *args.fPipeline; 2076 pipeline.getXferProcessor().getBlendInfo(&blendInfo);
2077 args.fPipeline->getXferProcessor().getBlendInfo(&blendInfo);
2078 2077
2079 this->flushColorWrite(blendInfo.fWriteColor); 2078 this->flushColorWrite(blendInfo.fWriteColor);
2080 this->flushDrawFace(pipeline.getDrawFace()); 2079 this->flushDrawFace(pipeline.getDrawFace());
2081 2080
2082 SkAutoTUnref<GrGLProgram> program(fProgramCache->refProgram(args)); 2081 SkAutoTUnref<GrGLProgram> program(fProgramCache->refProgram(this, pipeline, primProc));
2083 if (!program) { 2082 if (!program) {
2084 GrCapsDebugf(this->caps(), "Failed to create program!\n"); 2083 GrCapsDebugf(this->caps(), "Failed to create program!\n");
2085 return false; 2084 return false;
2086 } 2085 }
2087 2086
2088 GrGLuint programID = program->programID(); 2087 GrGLuint programID = program->programID();
2089 if (fHWProgramID != programID) { 2088 if (fHWProgramID != programID) {
2090 GL_CALL(UseProgram(programID)); 2089 GL_CALL(UseProgram(programID));
2091 fHWProgramID = programID; 2090 fHWProgramID = programID;
2092 } 2091 }
2093 2092
2094 if (blendInfo.fWriteColor) { 2093 if (blendInfo.fWriteColor) {
2095 // Swizzle the blend to match what the shader will output. 2094 // Swizzle the blend to match what the shader will output.
2096 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e( 2095 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e(
2097 args.fPipeline->getRenderTarget()->config()); 2096 pipeline.getRenderTarget()->config());
2098 this->flushBlend(blendInfo, swizzle); 2097 this->flushBlend(blendInfo, swizzle);
2099 } 2098 }
2100 2099
2101 SkSTArray<8, const GrTextureAccess*> textureAccesses; 2100 SkSTArray<8, const GrTextureAccess*> textureAccesses;
2102 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses); 2101 program->setData(primProc, pipeline, &textureAccesses);
2103 2102
2104 int numTextureAccesses = textureAccesses.count(); 2103 int numTextureAccesses = textureAccesses.count();
2105 for (int i = 0; i < numTextureAccesses; i++) { 2104 for (int i = 0; i < numTextureAccesses; i++) {
2106 this->bindTexture(i, textureAccesses[i]->getParams(), 2105 this->bindTexture(i, textureAccesses[i]->getParams(),
2107 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re())); 2106 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re()));
2108 } 2107 }
2109 2108
2110 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget()); 2109 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
2111 this->flushStencil(pipeline.getStencil()); 2110 this->flushStencil(pipeline.getStencil());
2112 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin()); 2111 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 vbuf->bufferID(), 2162 vbuf->bufferID(),
2164 attribType, 2163 attribType,
2165 stride, 2164 stride,
2166 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset)); 2165 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset));
2167 offset += attrib.fOffset; 2166 offset += attrib.fOffset;
2168 } 2167 }
2169 attribState->disableUnusedArrays(this, usedAttribArraysMask); 2168 attribState->disableUnusedArrays(this, usedAttribArraysMask);
2170 } 2169 }
2171 } 2170 }
2172 2171
2173 void GrGLGpu::buildProgramDesc(GrProgramDesc* desc,
2174 const GrPrimitiveProcessor& primProc,
2175 const GrPipeline& pipeline) const {
2176 if (!GrGLProgramDescBuilder::Build(desc, primProc, pipeline, *this->glCaps() .glslCaps())) {
2177 SkDEBUGFAIL("Failed to generate GL program descriptor");
2178 }
2179 }
2180
2181 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) { 2172 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) {
2182 this->handleDirtyContext(); 2173 this->handleDirtyContext();
2183 switch (type) { 2174 switch (type) {
2184 case GR_GL_ARRAY_BUFFER: 2175 case GR_GL_ARRAY_BUFFER:
2185 this->bindVertexBuffer(id); 2176 this->bindVertexBuffer(id);
2186 break; 2177 break;
2187 case GR_GL_ELEMENT_ARRAY_BUFFER: 2178 case GR_GL_ELEMENT_ARRAY_BUFFER:
2188 this->bindIndexBufferAndDefaultVertexArray(id); 2179 this->bindIndexBufferAndDefaultVertexArray(id);
2189 break; 2180 break;
2190 case GR_GL_TEXTURE_BUFFER: 2181 case GR_GL_TEXTURE_BUFFER:
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2911 GetWindowThreadProcessId(hwnd, &wndProcID); 2902 GetWindowThreadProcessId(hwnd, &wndProcID);
2912 if(wndProcID == procID) { 2903 if(wndProcID == procID) {
2913 SwapBuffers(GetDC(hwnd)); 2904 SwapBuffers(GetDC(hwnd));
2914 } 2905 }
2915 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); 2906 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
2916 } 2907 }
2917 } 2908 }
2918 #endif 2909 #endif
2919 #endif 2910 #endif
2920 2911
2921 void GrGLGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertice s) { 2912 void GrGLGpu::onDraw(const GrPipeline& pipeline,
2922 if (!this->flushGLState(args)) { 2913 const GrPrimitiveProcessor& primProc,
2914 GrPrimitiveType primitiveType,
2915 const GrVertices* vertArray,
2916 int drawCount) {
2917 if (!this->flushGLState(pipeline, primProc)) {
2923 return; 2918 return;
2924 } 2919 }
2920 GrPixelLocalStorageState plsState = primProc.getPixelLocalStorageState();
2925 2921
2926 GrPixelLocalStorageState plsState = args.fPrimitiveProcessor->getPixelLocalS torageState(); 2922
2927 if (!fHWPLSEnabled && plsState != 2923 for (int i = 0; i < drawCount; ++i) {
2928 GrPixelLocalStorageState::kDisabled_GrPixelLocalStorageState) { 2924 if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*this->caps ())) {
2929 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); 2925 this->xferBarrier(pipeline.getRenderTarget(), barrierType);
2930 this->setupPixelLocalStorage(args); 2926 }
2931 fHWPLSEnabled = true; 2927
2932 } 2928 const GrVertices& vertices = vertArray[i];
2933 if (plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState) { 2929 GrVertices::Iterator iter;
2934 GrStencilSettings stencil; 2930 const GrNonInstancedVertices* verts = iter.init(vertices);
2935 stencil.setDisabled(); 2931 do {
2936 this->flushStencil(stencil); 2932 if (!fHWPLSEnabled && plsState !=
egdaniel 2016/03/16 19:55:35 Ethan do you know if all this PLS stuff needs to s
bsalomon 2016/03/16 20:07:22 Seems like it could all move out since all we're d
ethannicholas 2016/03/16 21:14:19 Agreed.
egdaniel 2016/03/17 15:09:36 Done.
2933 GrPixelLocalStorageState::kDisabled_GrPixelLocalStorageState) {
2934 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE));
2935 this->setupPixelLocalStorage(pipeline, primProc);
2936 fHWPLSEnabled = true;
2937 }
2938 if (plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorag eState) {
2939 GrStencilSettings stencil;
2940 stencil.setDisabled();
2941 this->flushStencil(stencil);
2942 }
2943
2944 size_t indexOffsetInBytes = 0;
2945 this->setupGeometry(primProc, *verts, &indexOffsetInBytes);
2946
2947 if (verts->isIndexed()) {
2948 GrGLvoid* indices =
2949 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint 16_t) *
2950 verts->startIndex());
2951 // info.startVertex() was accounted for by setupGeometry.
2952 GL_CALL(DrawElements(gPrimitiveType2GLMode[primitiveType],
2953 verts->indexCount(),
2954 GR_GL_UNSIGNED_SHORT,
2955 indices));
2956 } else {
2957 // Pass 0 for parameter first. We have to adjust glVertexAttribP ointer() to account
2958 // for startVertex in the DrawElements case. So we always rely o n setupGeometry to
2959 // have accounted for startVertex.
2960 GL_CALL(DrawArrays(gPrimitiveType2GLMode[primitiveType], 0,
2961 verts->vertexCount()));
2962 }
2963
2964 if (fHWPLSEnabled &&
2965 plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorag eState) {
2966 // PLS draws always involve multiple draws, finishing up with a non-PLS
2967 // draw that writes to the color buffer. That draw ends up here; we wait
2968 // until after it is complete to actually disable PLS.
2969 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE));
2970 fHWPLSEnabled = false;
2971 this->disableScissor();
2972 }
2973
2974 fStats.incNumDraws();
2975 } while ((verts = iter.next()));
2937 } 2976 }
2938 2977
2939 size_t indexOffsetInBytes = 0;
2940 this->setupGeometry(*args.fPrimitiveProcessor, vertices, &indexOffsetInBytes );
2941
2942 SkASSERT((size_t)vertices.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GL Mode));
2943
2944 if (vertices.isIndexed()) {
2945 GrGLvoid* indices =
2946 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) *
2947 vertices.startIndex());
2948 // info.startVertex() was accounted for by setupGeometry.
2949 GL_CALL(DrawElements(gPrimitiveType2GLMode[vertices.primitiveType()],
2950 vertices.indexCount(),
2951 GR_GL_UNSIGNED_SHORT,
2952 indices));
2953 } else {
2954 // Pass 0 for parameter first. We have to adjust glVertexAttribPointer() to account for
2955 // startVertex in the DrawElements case. So we always rely on setupGeome try to have
2956 // accounted for startVertex.
2957 GL_CALL(DrawArrays(gPrimitiveType2GLMode[vertices.primitiveType()], 0,
2958 vertices.vertexCount()));
2959 }
2960
2961 if (fHWPLSEnabled && plsState == GrPixelLocalStorageState::kFinish_GrPixelLo calStorageState) {
2962 // PLS draws always involve multiple draws, finishing up with a non-PLS
2963 // draw that writes to the color buffer. That draw ends up here; we wait
2964 // until after it is complete to actually disable PLS.
2965 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE));
2966 fHWPLSEnabled = false;
2967 this->disableScissor();
2968 }
2969 2978
2970 #if SWAP_PER_DRAW 2979 #if SWAP_PER_DRAW
2971 glFlush(); 2980 glFlush();
2972 #if defined(SK_BUILD_FOR_MAC) 2981 #if defined(SK_BUILD_FOR_MAC)
2973 aglSwapBuffers(aglGetCurrentContext()); 2982 aglSwapBuffers(aglGetCurrentContext());
2974 int set_a_break_pt_here = 9; 2983 int set_a_break_pt_here = 9;
2975 aglSwapBuffers(aglGetCurrentContext()); 2984 aglSwapBuffers(aglGetCurrentContext());
2976 #elif defined(SK_BUILD_FOR_WIN32) 2985 #elif defined(SK_BUILD_FOR_WIN32)
2977 SwapBuf(); 2986 SwapBuf();
2978 int set_a_break_pt_here = 9; 2987 int set_a_break_pt_here = 9;
(...skipping 23 matching lines...) Expand all
3002 if (!fHWStencilSettings.isDisabled()) { 3011 if (!fHWStencilSettings.isDisabled()) {
3003 GL_CALL(Disable(GR_GL_STENCIL_TEST)); 3012 GL_CALL(Disable(GR_GL_STENCIL_TEST));
3004 } 3013 }
3005 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); 3014 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4));
3006 GL_CALL(UseProgram(fHWProgramID)); 3015 GL_CALL(UseProgram(fHWProgramID));
3007 if (!fHWStencilSettings.isDisabled()) { 3016 if (!fHWStencilSettings.isDisabled()) {
3008 GL_CALL(Enable(GR_GL_STENCIL_TEST)); 3017 GL_CALL(Enable(GR_GL_STENCIL_TEST));
3009 } 3018 }
3010 } 3019 }
3011 3020
3012 void GrGLGpu::setupPixelLocalStorage(const DrawArgs& args) { 3021 void GrGLGpu::setupPixelLocalStorage(const GrPipeline& pipeline,
3022 const GrPrimitiveProcessor& primProc) {
3013 fPLSHasBeenUsed = true; 3023 fPLSHasBeenUsed = true;
3014 const SkRect& bounds = 3024 const SkRect& bounds =
3015 static_cast<const GrPLSGeometryProcessor*>(args.fPrimitiveProcessor) ->getBounds(); 3025 static_cast<const GrPLSGeometryProcessor&>(primProc).getBounds();
3016 // setup pixel local storage -- this means capturing and storing the current framebuffer color 3026 // setup pixel local storage -- this means capturing and storing the current framebuffer color
3017 // and initializing the winding counts to zero 3027 // and initializing the winding counts to zero
3018 GrRenderTarget* rt = args.fPipeline->getRenderTarget(); 3028 GrRenderTarget* rt = pipeline.getRenderTarget();
3019 SkScalar width = SkIntToScalar(rt->width()); 3029 SkScalar width = SkIntToScalar(rt->width());
3020 SkScalar height = SkIntToScalar(rt->height()); 3030 SkScalar height = SkIntToScalar(rt->height());
3021 // dst rect edges in NDC (-1 to 1) 3031 // dst rect edges in NDC (-1 to 1)
3022 // having some issues with rounding, just expand the bounds by 1 and trust t he scissor to keep 3032 // having some issues with rounding, just expand the bounds by 1 and trust t he scissor to keep
3023 // it contained properly 3033 // it contained properly
3024 GrGLfloat dx0 = 2.0f * (bounds.left() - 1) / width - 1.0f; 3034 GrGLfloat dx0 = 2.0f * (bounds.left() - 1) / width - 1.0f;
3025 GrGLfloat dx1 = 2.0f * (bounds.right() + 1) / width - 1.0f; 3035 GrGLfloat dx1 = 2.0f * (bounds.right() + 1) / width - 1.0f;
3026 GrGLfloat dy0 = -2.0f * (bounds.top() - 1) / height + 1.0f; 3036 GrGLfloat dy0 = -2.0f * (bounds.top() - 1) / height + 1.0f;
3027 GrGLfloat dy1 = -2.0f * (bounds.bottom() + 1) / height + 1.0f; 3037 GrGLfloat dy1 = -2.0f * (bounds.bottom() + 1) / height + 1.0f;
3028 SkRect deviceBounds = SkRect::MakeXYWH(dx0, dy0, dx1 - dx0, dy1 - dy0); 3038 SkRect deviceBounds = SkRect::MakeXYWH(dx0, dy0, dx1 - dx0, dy1 - dy0);
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
4387 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 4397 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
4388 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 4398 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
4389 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 4399 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
4390 copyParams->fWidth = texture->width(); 4400 copyParams->fWidth = texture->width();
4391 copyParams->fHeight = texture->height(); 4401 copyParams->fHeight = texture->height();
4392 return true; 4402 return true;
4393 } 4403 }
4394 } 4404 }
4395 return false; 4405 return false;
4396 } 4406 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698