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

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

Issue 1870893002: Implement texel buffers (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_texelfetch
Patch Set: GrBuffer(Access) into include/gpu Created 4 years, 8 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/GrGLProgram.h » ('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 "GrGLBuffer.h" 9 #include "GrGLBuffer.h"
10 #include "GrGLGLSL.h" 10 #include "GrGLGLSL.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 static bool gPrintStartupSpew; 187 static bool gPrintStartupSpew;
188 188
189 GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context) 189 GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context)
190 : GrGpu(context) 190 : GrGpu(context)
191 , fGLContext(ctx) 191 , fGLContext(ctx)
192 , fProgramCache(new ProgramCache(this)) 192 , fProgramCache(new ProgramCache(this))
193 , fHWProgramID(0) 193 , fHWProgramID(0)
194 , fTempSrcFBOID(0) 194 , fTempSrcFBOID(0)
195 , fTempDstFBOID(0) 195 , fTempDstFBOID(0)
196 , fStencilClearFBOID(0) 196 , fStencilClearFBOID(0)
197 , fHWMaxUsedBufferTextureUnit(-1)
197 , fHWPLSEnabled(false) 198 , fHWPLSEnabled(false)
198 , fPLSHasBeenUsed(false) 199 , fPLSHasBeenUsed(false)
199 , fHWMinSampleShading(0.0) { 200 , fHWMinSampleShading(0.0) {
200 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { 201 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) {
201 fCopyPrograms[i].fProgram = 0; 202 fCopyPrograms[i].fProgram = 0;
202 } 203 }
203 fWireRectProgram.fProgram = 0; 204 fWireRectProgram.fProgram = 0;
204 fPLSSetupProgram.fProgram = 0; 205 fPLSSetupProgram.fProgram = 0;
205 206
206 SkASSERT(ctx); 207 SkASSERT(ctx);
207 fCaps.reset(SkRef(ctx->caps())); 208 fCaps.reset(SkRef(ctx->caps()));
208 209
209 fHWBoundTextureUniqueIDs.reset(this->glCaps().glslCaps()->maxCombinedSampler s()); 210 fHWBoundTextureUniqueIDs.reset(this->glCaps().glslCaps()->maxCombinedSampler s());
210 211
211 fHWBufferState[kVertex_GrBufferType].fGLTarget = GR_GL_ARRAY_BUFFER; 212 fHWBufferState[kVertex_GrBufferType].fGLTarget = GR_GL_ARRAY_BUFFER;
212 fHWBufferState[kIndex_GrBufferType].fGLTarget = GR_GL_ELEMENT_ARRAY_BUFFER; 213 fHWBufferState[kIndex_GrBufferType].fGLTarget = GR_GL_ELEMENT_ARRAY_BUFFER;
213 fHWBufferState[kTexel_GrBufferType].fGLTarget = GR_GL_TEXTURE_BUFFER; 214 fHWBufferState[kTexel_GrBufferType].fGLTarget = GR_GL_TEXTURE_BUFFER;
214 fHWBufferState[kDrawIndirect_GrBufferType].fGLTarget = GR_GL_DRAW_INDIRECT_B UFFER; 215 fHWBufferState[kDrawIndirect_GrBufferType].fGLTarget = GR_GL_DRAW_INDIRECT_B UFFER;
215 if (GrGLCaps::kChromium_TransferBufferType == this->glCaps().transferBufferT ype()) { 216 if (GrGLCaps::kChromium_TransferBufferType == this->glCaps().transferBufferT ype()) {
216 fHWBufferState[kXferCpuToGpu_GrBufferType].fGLTarget = 217 fHWBufferState[kXferCpuToGpu_GrBufferType].fGLTarget =
217 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM; 218 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM;
218 fHWBufferState[kXferGpuToCpu_GrBufferType].fGLTarget = 219 fHWBufferState[kXferGpuToCpu_GrBufferType].fGLTarget =
219 GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; 220 GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM;
220 } else { 221 } else {
221 fHWBufferState[kXferCpuToGpu_GrBufferType].fGLTarget = GR_GL_PIXEL_UNPAC K_BUFFER; 222 fHWBufferState[kXferCpuToGpu_GrBufferType].fGLTarget = GR_GL_PIXEL_UNPAC K_BUFFER;
222 fHWBufferState[kXferGpuToCpu_GrBufferType].fGLTarget = GR_GL_PIXEL_PACK_ BUFFER; 223 fHWBufferState[kXferGpuToCpu_GrBufferType].fGLTarget = GR_GL_PIXEL_PACK_ BUFFER;
223 } 224 }
224 GR_STATIC_ASSERT(6 == SK_ARRAY_COUNT(fHWBufferState)); 225 GR_STATIC_ASSERT(6 == SK_ARRAY_COUNT(fHWBufferState));
225 226
227 if (this->caps()->shaderCaps()->texelBufferSupport()) {
228 fHWBufferTextures.reset(this->glCaps().glslCaps()->maxCombinedSamplers() );
229 }
230
226 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { 231 if (this->glCaps().shaderCaps()->pathRenderingSupport()) {
227 fPathRendering.reset(new GrGLPathRendering(this)); 232 fPathRendering.reset(new GrGLPathRendering(this));
228 } 233 }
229 234
230 GrGLClearErr(this->glInterface()); 235 GrGLClearErr(this->glInterface());
231 if (gPrintStartupSpew) { 236 if (gPrintStartupSpew) {
232 const GrGLubyte* vendor; 237 const GrGLubyte* vendor;
233 const GrGLubyte* renderer; 238 const GrGLubyte* renderer;
234 const GrGLubyte* version; 239 const GrGLubyte* version;
235 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); 240 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR));
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 GL_CALL(CoverageModulation(GR_GL_RGBA)); 520 GL_CALL(CoverageModulation(GR_GL_RGBA));
516 } 521 }
517 } 522 }
518 523
519 fHWActiveTextureUnitIdx = -1; // invalid 524 fHWActiveTextureUnitIdx = -1; // invalid
520 525
521 if (resetBits & kTextureBinding_GrGLBackendState) { 526 if (resetBits & kTextureBinding_GrGLBackendState) {
522 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) { 527 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) {
523 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID; 528 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID;
524 } 529 }
530 for (int b = 0; b < fHWBufferTextures.count(); ++b) {
531 SkASSERT(this->caps()->shaderCaps()->texelBufferSupport());
532 fHWBufferTextures[b].fKnownBound = false;
533 }
525 } 534 }
526 535
527 if (resetBits & kBlend_GrGLBackendState) { 536 if (resetBits & kBlend_GrGLBackendState) {
528 fHWBlendState.invalidate(); 537 fHWBlendState.invalidate();
529 } 538 }
530 539
531 if (resetBits & kView_GrGLBackendState) { 540 if (resetBits & kView_GrGLBackendState) {
532 fHWScissorSettings.invalidate(); 541 fHWScissorSettings.invalidate();
533 fHWViewport.invalidate(); 542 fHWViewport.invalidate();
534 } 543 }
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 fHWProgramID = programID; 2054 fHWProgramID = programID;
2046 } 2055 }
2047 2056
2048 if (blendInfo.fWriteColor) { 2057 if (blendInfo.fWriteColor) {
2049 // Swizzle the blend to match what the shader will output. 2058 // Swizzle the blend to match what the shader will output.
2050 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e( 2059 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e(
2051 pipeline.getRenderTarget()->config()); 2060 pipeline.getRenderTarget()->config());
2052 this->flushBlend(blendInfo, swizzle); 2061 this->flushBlend(blendInfo, swizzle);
2053 } 2062 }
2054 2063
2055 SkSTArray<8, const GrTextureAccess*> textureAccesses; 2064 program->setData(primProc, pipeline);
2056 program->setData(primProc, pipeline, &textureAccesses);
2057
2058 int numTextureAccesses = textureAccesses.count();
2059 for (int i = 0; i < numTextureAccesses; i++) {
2060 this->bindTexture(i, textureAccesses[i]->getParams(), pipeline.getAllowS RGBInputs(),
2061 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re()));
2062 }
2063 2065
2064 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget()); 2066 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
2065 this->flushStencil(pipeline.getStencil()); 2067 this->flushStencil(pipeline.getStencil());
2066 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin()); 2068 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin());
2067 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc il().isDisabled()); 2069 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc il().isDisabled());
2068 2070
2069 // This must come after textures are flushed because a texture may need 2071 // This must come after textures are flushed because a texture may need
2070 // to be msaa-resolved (which will modify bound FBO state). 2072 // to be msaa-resolved (which will modify bound FBO state).
2071 this->flushRenderTarget(glRT, nullptr, pipeline.getDisableOutputConversionTo SRGB()); 2073 this->flushRenderTarget(glRT, nullptr, pipeline.getDisableOutputConversionTo SRGB());
2072 2074
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 if (!buffer->isCPUBacked() || !bufferState.fBufferZeroKnownBound) { 2142 if (!buffer->isCPUBacked() || !bufferState.fBufferZeroKnownBound) {
2141 GL_CALL(BindBuffer(bufferState.fGLTarget, buffer->bufferID())); 2143 GL_CALL(BindBuffer(bufferState.fGLTarget, buffer->bufferID()));
2142 bufferState.fBufferZeroKnownBound = buffer->isCPUBacked(); 2144 bufferState.fBufferZeroKnownBound = buffer->isCPUBacked();
2143 } 2145 }
2144 bufferState.fBoundBufferUniqueID = buffer->getUniqueID(); 2146 bufferState.fBoundBufferUniqueID = buffer->getUniqueID();
2145 } 2147 }
2146 2148
2147 return bufferState.fGLTarget; 2149 return bufferState.fGLTarget;
2148 } 2150 }
2149 2151
2152 void GrGLGpu::notifyBufferReleased(const GrGLBuffer* buffer) {
2153 if (buffer->hasAttachedToTexture()) {
2154 // Detach this buffer from any textures to ensure the underlying memory is freed.
2155 uint32_t uniqueID = buffer->getUniqueID();
2156 for (int i = fHWMaxUsedBufferTextureUnit; i >= 0; --i) {
2157 auto& buffTex = fHWBufferTextures[i];
2158 if (uniqueID != buffTex.fAttachedBufferUniqueID) {
2159 continue;
2160 }
2161 if (i == fHWMaxUsedBufferTextureUnit) {
2162 --fHWMaxUsedBufferTextureUnit;
2163 }
2164
2165 this->setTextureUnit(i);
2166 if (!buffTex.fKnownBound) {
2167 SkASSERT(buffTex.fTextureID);
2168 GL_CALL(BindTexture(GR_GL_TEXTURE_BUFFER, buffTex.fTextureID));
2169 buffTex.fKnownBound = true;
2170 }
2171 GL_CALL(TexBuffer(GR_GL_TEXTURE_BUFFER,
2172 this->glCaps().configSizedInternalFormat(buffTex.f TexelConfig), 0));
2173 }
2174 }
2175 }
2176
2150 void GrGLGpu::disableScissor() { 2177 void GrGLGpu::disableScissor() {
2151 if (kNo_TriState != fHWScissorSettings.fEnabled) { 2178 if (kNo_TriState != fHWScissorSettings.fEnabled) {
2152 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); 2179 GL_CALL(Disable(GR_GL_SCISSOR_TEST));
2153 fHWScissorSettings.fEnabled = kNo_TriState; 2180 fHWScissorSettings.fEnabled = kNo_TriState;
2154 return; 2181 return;
2155 } 2182 }
2156 } 2183 }
2157 2184
2158 void GrGLGpu::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color ) { 2185 void GrGLGpu::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color ) {
2159 // parent class should never let us get here with no RT 2186 // parent class should never let us get here with no RT
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
3257 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) ); 3284 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS) );
3258 } 3285 }
3259 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { 3286 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) {
3260 this->setTextureUnit(unitIdx); 3287 this->setTextureUnit(unitIdx);
3261 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) ); 3288 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT) );
3262 } 3289 }
3263 if (this->glCaps().textureSwizzleSupport() && 3290 if (this->glCaps().textureSwizzleSupport() &&
3264 (setAll || memcmp(newTexParams.fSwizzleRGBA, 3291 (setAll || memcmp(newTexParams.fSwizzleRGBA,
3265 oldTexParams.fSwizzleRGBA, 3292 oldTexParams.fSwizzleRGBA,
3266 sizeof(newTexParams.fSwizzleRGBA)))) { 3293 sizeof(newTexParams.fSwizzleRGBA)))) {
3267 this->setTextureUnit(unitIdx); 3294 this->setTextureSwizzle(unitIdx, target, newTexParams.fSwizzleRGBA);
3268 if (this->glStandard() == kGLES_GrGLStandard) {
3269 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA.
3270 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA;
3271 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0]));
3272 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1]));
3273 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2]));
3274 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_A, swizzle[3]));
3275 } else {
3276 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL int));
3277 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara ms.fSwizzleRGBA);
3278 GL_CALL(TexParameteriv(target, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle)) ;
3279 }
3280 } 3295 }
3281 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); 3296 texture->setCachedTexParams(newTexParams, this->getResetTimestamp());
3282 } 3297 }
3283 3298
3299 void GrGLGpu::bindTexelBuffer(int unitIdx, intptr_t offsetInBytes, GrPixelConfig texelConfig,
3300 GrGLBuffer* buffer) {
3301 SkASSERT(this->glCaps().canUseConfigWithTexelBuffer(texelConfig));
3302 SkASSERT(unitIdx >= 0 && unitIdx < fHWBufferTextures.count());
3303 SkASSERT(offsetInBytes >= 0 && offsetInBytes < (intptr_t) buffer->glSizeInBy tes());
3304
3305 BufferTexture& buffTex = fHWBufferTextures[unitIdx];
3306
3307 if (!buffTex.fKnownBound) {
3308 if (!buffTex.fTextureID) {
3309 GL_CALL(GenTextures(1, &buffTex.fTextureID));
3310 if (!buffTex.fTextureID) {
3311 return;
3312 }
3313 }
3314
3315 this->setTextureUnit(unitIdx);
3316 GL_CALL(BindTexture(GR_GL_TEXTURE_BUFFER, buffTex.fTextureID));
3317
3318 buffTex.fKnownBound = true;
3319 }
3320
3321 if (buffer->getUniqueID() != buffTex.fAttachedBufferUniqueID ||
3322 buffTex.fOffsetInBytes != offsetInBytes ||
3323 buffTex.fTexelConfig != texelConfig ||
3324 buffTex.fAttachedSizeInBytes != buffer->glSizeInBytes() - offsetInBytes) {
3325
3326 size_t attachmentSizeInBytes = buffer->glSizeInBytes() - offsetInBytes;
3327
3328 this->setTextureUnit(unitIdx);
3329 GL_CALL(TexBufferRange(GR_GL_TEXTURE_BUFFER,
3330 this->glCaps().configSizedInternalFormat(texelCon fig),
3331 buffer->bufferID(),
3332 offsetInBytes,
3333 attachmentSizeInBytes));
3334
3335 buffTex.fOffsetInBytes = offsetInBytes;
3336 buffTex.fTexelConfig = texelConfig;
3337 buffTex.fAttachedSizeInBytes = attachmentSizeInBytes;
3338 buffTex.fAttachedBufferUniqueID = buffer->getUniqueID();
3339
3340 if (this->glCaps().textureSwizzleSupport() &&
3341 this->glCaps().configSwizzle(texelConfig) != buffTex.fSwizzle) {
3342 GrGLenum glSwizzle[4];
3343 get_tex_param_swizzle(texelConfig, this->glCaps(), glSwizzle);
3344 this->setTextureSwizzle(unitIdx, GR_GL_TEXTURE_BUFFER, glSwizzle);
3345 buffTex.fSwizzle = this->glCaps().configSwizzle(texelConfig);
3346 }
3347
3348 buffer->setHasAttachedToTexture();
3349 fHWMaxUsedBufferTextureUnit = SkTMax(unitIdx, fHWMaxUsedBufferTextureUni t);
3350 }
3351 }
3352
3353 void GrGLGpu::setTextureSwizzle(int unitIdx, GrGLenum target, const GrGLenum swi zzle[]) {
3354 this->setTextureUnit(unitIdx);
3355 if (this->glStandard() == kGLES_GrGLStandard) {
3356 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA.
3357 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0]));
3358 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1]));
3359 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2]));
3360 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_A, swizzle[3]));
3361 } else {
3362 GR_STATIC_ASSERT(sizeof(swizzle[0]) == sizeof(GrGLint));
3363 GL_CALL(TexParameteriv(target, GR_GL_TEXTURE_SWIZZLE_RGBA,
3364 reinterpret_cast<const GrGLint*>(swizzle)));
3365 }
3366 }
3367
3284 void GrGLGpu::flushColorWrite(bool writeColor) { 3368 void GrGLGpu::flushColorWrite(bool writeColor) {
3285 if (!writeColor) { 3369 if (!writeColor) {
3286 if (kNo_TriState != fHWWriteToColor) { 3370 if (kNo_TriState != fHWWriteToColor) {
3287 GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE, 3371 GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE,
3288 GR_GL_FALSE, GR_GL_FALSE)); 3372 GR_GL_FALSE, GR_GL_FALSE));
3289 fHWWriteToColor = kNo_TriState; 3373 fHWWriteToColor = kNo_TriState;
3290 } 3374 }
3291 } else { 3375 } else {
3292 if (kYes_TriState != fHWWriteToColor) { 3376 if (kYes_TriState != fHWWriteToColor) {
3293 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); 3377 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
4233 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 4317 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
4234 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 4318 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
4235 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 4319 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
4236 copyParams->fWidth = texture->width(); 4320 copyParams->fWidth = texture->width();
4237 copyParams->fHeight = texture->height(); 4321 copyParams->fHeight = texture->height();
4238 return true; 4322 return true;
4239 } 4323 }
4240 } 4324 }
4241 return false; 4325 return false;
4242 } 4326 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698