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

Side by Side Diff: src/gpu/gl/GrGLProgramDesc.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/GrGLProgramDataManager.cpp ('k') | src/gpu/glsl/GrGLSL.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 2013 Google Inc. 2 * Copyright 2013 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 #include "GrGLProgramDesc.h" 7 #include "GrGLProgramDesc.h"
8 8
9 #include "GrProcessor.h" 9 #include "GrProcessor.h"
10 #include "GrPipeline.h" 10 #include "GrPipeline.h"
11 #include "GrRenderTargetPriv.h" 11 #include "GrRenderTargetPriv.h"
12 #include "SkChecksum.h" 12 #include "SkChecksum.h"
13 #include "gl/GrGLDefines.h" 13 #include "gl/GrGLDefines.h"
14 #include "gl/GrGLTexture.h" 14 #include "gl/GrGLTexture.h"
15 #include "gl/GrGLTypes.h" 15 #include "gl/GrGLTypes.h"
16 #include "glsl/GrGLSLFragmentProcessor.h" 16 #include "glsl/GrGLSLFragmentProcessor.h"
17 #include "glsl/GrGLSLFragmentShaderBuilder.h" 17 #include "glsl/GrGLSLFragmentShaderBuilder.h"
18 #include "glsl/GrGLSLCaps.h" 18 #include "glsl/GrGLSLCaps.h"
19 19
20 static uint16_t texture_key(GrSLType samplerType, GrPixelConfig config, GrShader Flags visibility, 20 static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShader Flags visibility,
21 const GrGLSLCaps& caps) { 21 const GrGLSLCaps& caps) {
22 enum { 22 enum {
23 kFirstSamplerType = kSampler2D_GrSLType, 23 kFirstSamplerType = kSampler2D_GrSLType,
24 kLastSamplerType = kSampler2DRect_GrSLType, 24 kLastSamplerType = kSamplerBuffer_GrSLType,
25 kSamplerTypeKeyBits = 4 25 kSamplerTypeKeyBits = 4
26 }; 26 };
27 GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKe yBits)); 27 GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKe yBits));
28 28
29 SkASSERT((int)samplerType >= kFirstSamplerType && (int)samplerType <= kLastS amplerType); 29 SkASSERT((int)samplerType >= kFirstSamplerType && (int)samplerType <= kLastS amplerType);
30 int samplerTypeKey = samplerType - kFirstSamplerType; 30 int samplerTypeKey = samplerType - kFirstSamplerType;
31 31
32 return SkToU16(caps.configTextureSwizzle(config).asKey() | 32 return SkToU16(caps.configTextureSwizzle(config).asKey() |
33 (samplerTypeKey << 8) | 33 (samplerTypeKey << 8) |
34 (caps.samplerPrecision(config, visibility) << (8 + kSamplerTy peKeyBits))); 34 (caps.samplerPrecision(config, visibility) << (8 + kSamplerTy peKeyBits)));
35 } 35 }
36 36
37 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, 37 static void add_sampler_keys(GrProcessorKeyBuilder* b, const GrProcessor& proc,
38 const GrGLSLCaps& caps) { 38 const GrGLSLCaps& caps) {
39 int numTextures = proc.numTextures(); 39 int numTextures = proc.numTextures();
40 int numSamplers = numTextures + proc.numBuffers();
40 // Need two bytes per key (swizzle, sampler type, and precision). 41 // Need two bytes per key (swizzle, sampler type, and precision).
41 int word32Count = (proc.numTextures() + 1) / 2; 42 int word32Count = (numSamplers + 1) / 2;
42 if (0 == word32Count) { 43 if (0 == word32Count) {
43 return; 44 return;
44 } 45 }
45 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); 46 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count));
46 for (int i = 0; i < numTextures; ++i) { 47 int i = 0;
48 for (; i < numTextures; ++i) {
47 const GrTextureAccess& access = proc.textureAccess(i); 49 const GrTextureAccess& access = proc.textureAccess(i);
48 const GrTexture* tex = access.getTexture(); 50 const GrTexture* tex = access.getTexture();
49 k16[i] = texture_key(tex->samplerType(), tex->config(), access.getVisibi lity(), caps); 51 k16[i] = sampler_key(tex->samplerType(), tex->config(), access.getVisibi lity(), caps);
50 } 52 }
51 // zero the last 16 bits if the number of textures is odd. 53 for (; i < numSamplers; ++i) {
52 if (numTextures & 0x1) { 54 const GrBufferAccess& access = proc.bufferAccess(i - numTextures);
53 k16[numTextures] = 0; 55 k16[i] = sampler_key(kSamplerBuffer_GrSLType, access.texelConfig(), acce ss.visibility(),
56 caps);
57 }
58 // zero the last 16 bits if the number of samplers is odd.
59 if (numSamplers & 0x1) {
60 k16[numSamplers] = 0;
54 } 61 }
55 } 62 }
56 63
57 /** 64 /**
58 * A function which emits a meta key into the key builder. This is required bec ause shader code may 65 * A function which emits a meta key into the key builder. This is required bec ause shader code may
59 * be dependent on properties of the effect that the effect itself doesn't use 66 * be dependent on properties of the effect that the effect itself doesn't use
60 * in its key (e.g. the pixel format of textures used). So we create a meta-key for 67 * in its key (e.g. the pixel format of textures used). So we create a meta-key for
61 * every effect using this function. It is also responsible for inserting the ef fect's class ID 68 * every effect using this function. It is also responsible for inserting the ef fect's class ID
62 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many 69 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many
63 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this 70 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this
64 * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms 71 * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
65 */ 72 */
66 static bool gen_meta_key(const GrProcessor& proc, 73 static bool gen_meta_key(const GrProcessor& proc,
67 const GrGLSLCaps& glslCaps, 74 const GrGLSLCaps& glslCaps,
68 uint32_t transformKey, 75 uint32_t transformKey,
69 GrProcessorKeyBuilder* b) { 76 GrProcessorKeyBuilder* b) {
70 size_t processorKeySize = b->size(); 77 size_t processorKeySize = b->size();
71 uint32_t classID = proc.classID(); 78 uint32_t classID = proc.classID();
72 79
73 // Currently we allow 16 bits for the class id and the overall processor key size. 80 // Currently we allow 16 bits for the class id and the overall processor key size.
74 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); 81 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
75 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { 82 if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
76 return false; 83 return false;
77 } 84 }
78 85
79 add_texture_key(b, proc, glslCaps); 86 add_sampler_keys(b, proc, glslCaps);
80 87
81 uint32_t* key = b->add32n(2); 88 uint32_t* key = b->add32n(2);
82 key[0] = (classID << 16) | SkToU32(processorKeySize); 89 key[0] = (classID << 16) | SkToU32(processorKeySize);
83 key[1] = transformKey; 90 key[1] = transformKey;
84 return true; 91 return true;
85 } 92 }
86 93
87 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, 94 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
88 const GrFragmentProcessor& fp, 95 const GrFragmentProcessor& fp,
89 const GrGLSLCaps& glslCaps, 96 const GrGLSLCaps& glslCaps,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } else { 181 } else {
175 header->fIgnoresCoverage = 0; 182 header->fIgnoresCoverage = 0;
176 } 183 }
177 184
178 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); 185 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
179 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); 186 header->fColorEffectCnt = pipeline.numColorFragmentProcessors();
180 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); 187 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors();
181 glDesc->finalize(); 188 glDesc->finalize();
182 return true; 189 return true;
183 } 190 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramDataManager.cpp ('k') | src/gpu/glsl/GrGLSL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698