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

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

Issue 1785873003: Implement GL support for buffer textures (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_glTexBuffer
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
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgramDataManager.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // This combination is not supported. 575 // This combination is not supported.
576 return nullptr; 576 return nullptr;
577 } 577 }
578 if (!this->glCaps().glslCaps()->externalTextureSupport()) { 578 if (!this->glCaps().glslCaps()->externalTextureSupport()) {
579 return nullptr; 579 return nullptr;
580 } 580 }
581 } else if (GR_GL_TEXTURE_RECTANGLE == idDesc.fInfo.fTarget) { 581 } else if (GR_GL_TEXTURE_RECTANGLE == idDesc.fInfo.fTarget) {
582 if (!this->glCaps().rectangleTextureSupport()) { 582 if (!this->glCaps().rectangleTextureSupport()) {
583 return nullptr; 583 return nullptr;
584 } 584 }
585 } else if (GR_GL_TEXTURE_BUFFER == idDesc.fInfo.fTarget) {
586 if (!this->glCaps().glslCaps()->bufferTextureSupport()) {
587 SkDEBUGFAIL("Buffer textures are not supported.");
588 return nullptr;
589 }
590 if (renderTarget) {
591 SkDEBUGFAIL("Rendering to a buffer texture is not supported.");
592 return nullptr;
593 }
594 if (0 != desc.fHeight) {
595 // This texture is just a 1-dimensional window into a buffer object. It has no height
596 // and its GPU memory size is effectively zero, because the actual m emory is attributed
597 // to the buffer object itself.
598 SkDEBUGFAIL("Buffer textures must have a height of 0.");
599 return nullptr;
600 }
601 if (0 != desc.fSampleCnt) {
602 SkDEBUGFAIL("Multisampled buffer textures are not supported.");
603 return nullptr;
604 }
585 } else if (GR_GL_TEXTURE_2D != idDesc.fInfo.fTarget) { 605 } else if (GR_GL_TEXTURE_2D != idDesc.fInfo.fTarget) {
586 return nullptr; 606 return nullptr;
587 } 607 }
588 608
589 // Sample count is interpreted to mean the number of samples that Gr code sh ould allocate 609 // Sample count is interpreted to mean the number of samples that Gr code sh ould allocate
590 // for a render buffer that resolves to the texture. We don't support MSAA t extures. 610 // for a render buffer that resolves to the texture. We don't support MSAA t extures.
591 if (desc.fSampleCnt && !renderTarget) { 611 if (desc.fSampleCnt && !renderTarget) {
592 return nullptr; 612 return nullptr;
593 } 613 }
594 614
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e( 2115 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e(
2096 pipeline.getRenderTarget()->config()); 2116 pipeline.getRenderTarget()->config());
2097 this->flushBlend(blendInfo, swizzle); 2117 this->flushBlend(blendInfo, swizzle);
2098 } 2118 }
2099 2119
2100 SkSTArray<8, const GrTextureAccess*> textureAccesses; 2120 SkSTArray<8, const GrTextureAccess*> textureAccesses;
2101 program->setData(primProc, pipeline, &textureAccesses); 2121 program->setData(primProc, pipeline, &textureAccesses);
2102 2122
2103 int numTextureAccesses = textureAccesses.count(); 2123 int numTextureAccesses = textureAccesses.count();
2104 for (int i = 0; i < numTextureAccesses; i++) { 2124 for (int i = 0; i < numTextureAccesses; i++) {
2105 this->bindTexture(i, textureAccesses[i]->getParams(), 2125 GrGLTexture* texture = static_cast<GrGLTexture*>(textureAccesses[i]->get Texture());
2106 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re())); 2126 if (!texture->supportsTextureParams()) {
2127 this->bindTexture(i, texture);
2128 } else {
2129 this->flushTexture(i, textureAccesses[i]->getParams(), texture);
2130 }
2107 } 2131 }
2108 2132
2109 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget()); 2133 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
2110 this->flushStencil(pipeline.getStencil()); 2134 this->flushStencil(pipeline.getStencil());
2111 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin()); 2135 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin());
2112 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc il().isDisabled()); 2136 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc il().isDisabled());
2113 2137
2114 // This must come after textures are flushed because a texture may need 2138 // This must come after textures are flushed because a texture may need
2115 // to be msaa-resolved (which will modify bound FBO state). 2139 // to be msaa-resolved (which will modify bound FBO state).
2116 this->flushRenderTarget(glRT, nullptr); 2140 this->flushRenderTarget(glRT, nullptr);
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
3264 if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blen dConst) { 3288 if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blen dConst) {
3265 GrGLfloat c[4]; 3289 GrGLfloat c[4];
3266 GrColorToRGBAFloat(blendConst, c); 3290 GrColorToRGBAFloat(blendConst, c);
3267 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); 3291 GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
3268 fHWBlendState.fConstColor = blendConst; 3292 fHWBlendState.fConstColor = blendConst;
3269 fHWBlendState.fConstColorValid = true; 3293 fHWBlendState.fConstColorValid = true;
3270 } 3294 }
3271 } 3295 }
3272 } 3296 }
3273 3297
3298 void GrGLGpu::bindTexture(int unitIdx, GrGLTexture* texture) {
3299 SkASSERT(texture);
3300
3301 // If we created a rt/tex and rendered to it without using a texture and now we're texturing
3302 // from the rt it will still be the last bound texture, but it needs resolvi ng. So keep this
3303 // out of the "last != next" check.
3304 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTa rget());
3305 if (texRT) {
3306 this->onResolveRenderTarget(texRT);
3307 }
3308
3309 if (fHWBoundTextureUniqueIDs[unitIdx] != texture->getUniqueID()) {
3310 this->setTextureUnit(unitIdx);
3311 GL_CALL(BindTexture(texture->target(), texture->textureID()));
3312 fHWBoundTextureUniqueIDs[unitIdx] = texture->getUniqueID();
3313 }
3314 }
3315
3274 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { 3316 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) {
3275 static const GrGLenum gWrapModes[] = { 3317 static const GrGLenum gWrapModes[] = {
3276 GR_GL_CLAMP_TO_EDGE, 3318 GR_GL_CLAMP_TO_EDGE,
3277 GR_GL_REPEAT, 3319 GR_GL_REPEAT,
3278 GR_GL_MIRRORED_REPEAT 3320 GR_GL_MIRRORED_REPEAT
3279 }; 3321 };
3280 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); 3322 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes));
3281 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); 3323 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode);
3282 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); 3324 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode);
3283 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); 3325 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode);
(...skipping 20 matching lines...) Expand all
3304 the generated shader code. This potentially allows greater reuse of cached sha ders. */ 3346 the generated shader code. This potentially allows greater reuse of cached sha ders. */
3305 static void get_tex_param_swizzle(GrPixelConfig config, 3347 static void get_tex_param_swizzle(GrPixelConfig config,
3306 const GrGLCaps& caps, 3348 const GrGLCaps& caps,
3307 GrGLenum* glSwizzle) { 3349 GrGLenum* glSwizzle) {
3308 const GrSwizzle& swizzle = caps.configSwizzle(config); 3350 const GrSwizzle& swizzle = caps.configSwizzle(config);
3309 for (int i = 0; i < 4; ++i) { 3351 for (int i = 0; i < 4; ++i) {
3310 glSwizzle[i] = get_component_enum_from_char(swizzle.c_str()[i]); 3352 glSwizzle[i] = get_component_enum_from_char(swizzle.c_str()[i]);
3311 } 3353 }
3312 } 3354 }
3313 3355
3314 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) { 3356 void GrGLGpu::flushTexture(int unitIdx, const GrTextureParams& params, GrGLTextu re* texture) {
3315 SkASSERT(texture); 3357 this->bindTexture(unitIdx, texture);
3316 3358
3317 #ifdef SK_DEBUG 3359 #ifdef SK_DEBUG
3318 if (!this->caps()->npotTextureTileSupport()) { 3360 if (!this->caps()->npotTextureTileSupport()) {
3319 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); 3361 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX();
3320 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); 3362 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY();
3321 if (tileX || tileY) { 3363 if (tileX || tileY) {
3322 const int w = texture->width(); 3364 const int w = texture->width();
3323 const int h = texture->height(); 3365 const int h = texture->height();
3324 SkASSERT(SkIsPow2(w) && SkIsPow2(h)); 3366 SkASSERT(SkIsPow2(w) && SkIsPow2(h));
3325 } 3367 }
3326 } 3368 }
3327 #endif 3369 #endif
3328 3370
3329 // If we created a rt/tex and rendered to it without using a texture and now we're texturing
3330 // from the rt it will still be the last bound texture, but it needs resolvi ng. So keep this
3331 // out of the "last != next" check.
3332 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTa rget());
3333 if (texRT) {
3334 this->onResolveRenderTarget(texRT);
3335 }
3336
3337 uint32_t textureID = texture->getUniqueID();
3338 GrGLenum target = texture->target();
3339 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) {
3340 this->setTextureUnit(unitIdx);
3341 GL_CALL(BindTexture(target, texture->textureID()));
3342 fHWBoundTextureUniqueIDs[unitIdx] = textureID;
3343 }
3344
3345 ResetTimestamp timestamp; 3371 ResetTimestamp timestamp;
3346 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti mestamp); 3372 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti mestamp);
3347 bool setAll = timestamp < this->getResetTimestamp(); 3373 bool setAll = timestamp < this->getResetTimestamp();
3348 GrGLTexture::TexParams newTexParams; 3374 GrGLTexture::TexParams newTexParams;
3349 3375
3350 static GrGLenum glMinFilterModes[] = { 3376 static GrGLenum glMinFilterModes[] = {
3351 GR_GL_NEAREST, 3377 GR_GL_NEAREST,
3352 GR_GL_LINEAR, 3378 GR_GL_LINEAR,
3353 GR_GL_LINEAR_MIPMAP_LINEAR 3379 GR_GL_LINEAR_MIPMAP_LINEAR
3354 }; 3380 };
3355 static GrGLenum glMagFilterModes[] = { 3381 static GrGLenum glMagFilterModes[] = {
3356 GR_GL_NEAREST, 3382 GR_GL_NEAREST,
3357 GR_GL_LINEAR, 3383 GR_GL_LINEAR,
3358 GR_GL_LINEAR 3384 GR_GL_LINEAR
3359 }; 3385 };
3386
3360 GrTextureParams::FilterMode filterMode = params.filterMode(); 3387 GrTextureParams::FilterMode filterMode = params.filterMode();
3388 GrGLenum target = texture->target();
3361 3389
3362 if (GrTextureParams::kMipMap_FilterMode == filterMode) { 3390 if (GrTextureParams::kMipMap_FilterMode == filterMode) {
3363 if (!this->caps()->mipMapSupport() || GrPixelConfigIsCompressed(texture- >config())) { 3391 if (!this->caps()->mipMapSupport() || GrPixelConfigIsCompressed(texture- >config())) {
3364 filterMode = GrTextureParams::kBilerp_FilterMode; 3392 filterMode = GrTextureParams::kBilerp_FilterMode;
3365 } 3393 }
3366 } 3394 }
3367 3395
3368 newTexParams.fMinFilter = glMinFilterModes[filterMode]; 3396 newTexParams.fMinFilter = glMinFilterModes[filterMode];
3369 newTexParams.fMagFilter = glMagFilterModes[filterMode]; 3397 newTexParams.fMagFilter = glMagFilterModes[filterMode];
3370 3398
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
3791 fsOutName = oFragColor.c_str(); 3819 fsOutName = oFragColor.c_str();
3792 } else { 3820 } else {
3793 fsOutName = "gl_FragColor"; 3821 fsOutName = "gl_FragColor";
3794 } 3822 }
3795 fshaderTxt.appendf( 3823 fshaderTxt.appendf(
3796 "// Copy Program FS\n" 3824 "// Copy Program FS\n"
3797 "void main() {" 3825 "void main() {"
3798 " %s = %s(u_texture, v_texCoord);" 3826 " %s = %s(u_texture, v_texCoord);"
3799 "}", 3827 "}",
3800 fsOutName, 3828 fsOutName,
3801 GrGLSLTexture2DFunctionName(kVec2f_GrSLType, kSamplerTypes[i], this- >glslGeneration()) 3829 GrGLSLTextureFunctionName(kVec2f_GrSLType, kSamplerTypes[i], this->g lslGeneration())
3802 ); 3830 );
3803 3831
3804 GL_CALL_RET(fCopyPrograms[i].fProgram, CreateProgram()); 3832 GL_CALL_RET(fCopyPrograms[i].fProgram, CreateProgram());
3805 const char* str; 3833 const char* str;
3806 GrGLint length; 3834 GrGLint length;
3807 3835
3808 str = vshaderTxt.c_str(); 3836 str = vshaderTxt.c_str();
3809 length = SkToInt(vshaderTxt.size()); 3837 length = SkToInt(vshaderTxt.size());
3810 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms [i].fProgram, 3838 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms [i].fProgram,
3811 GR_GL_VERTEX_SHADER, &str, &length, 1, 3839 GR_GL_VERTEX_SHADER, &str, &length, 1,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
4007 4035
4008 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, 4036 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst,
4009 GrSurface* src, 4037 GrSurface* src,
4010 const SkIRect& srcRect, 4038 const SkIRect& srcRect,
4011 const SkIPoint& dstPoint) { 4039 const SkIPoint& dstPoint) {
4012 int w = srcRect.width(); 4040 int w = srcRect.width();
4013 int h = srcRect.height(); 4041 int h = srcRect.height();
4014 4042
4015 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture()); 4043 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture());
4016 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil terMode); 4044 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil terMode);
4017 this->bindTexture(0, params, srcTex); 4045 this->flushTexture(0, params, srcTex);
4018 4046
4019 GrGLIRect dstVP; 4047 GrGLIRect dstVP;
4020 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg et); 4048 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg et);
4021 this->flushViewport(dstVP); 4049 this->flushViewport(dstVP);
4022 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 4050 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
4023 4051
4024 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); 4052 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h);
4025 4053
4026 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target()); 4054 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target());
4027 4055
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
4390 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 4418 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
4391 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 4419 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
4392 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 4420 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
4393 copyParams->fWidth = texture->width(); 4421 copyParams->fWidth = texture->width();
4394 copyParams->fHeight = texture->height(); 4422 copyParams->fHeight = texture->height();
4395 return true; 4423 return true;
4396 } 4424 }
4397 } 4425 }
4398 return false; 4426 return false;
4399 } 4427 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgramDataManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698