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

Side by Side Diff: src/gpu/vk/GrVkProgramDesc.cpp

Issue 1718693002: Add vulkan files into skia repo. (Closed) Base URL: https://skia.googlesource.com/skia.git@merge
Patch Set: fix path Created 4 years, 10 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/vk/GrVkProgramDesc.h ('k') | src/gpu/vk/GrVkRenderPass.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 2015 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 "GrVkProgramDesc.h"
8 8
9 //#include "GrVkProcessor.h"
9 #include "GrProcessor.h" 10 #include "GrProcessor.h"
10 #include "GrPipeline.h" 11 #include "GrPipeline.h"
12 #include "GrVkGpu.h"
13 #include "GrVkUtil.h"
11 #include "SkChecksum.h" 14 #include "SkChecksum.h"
12 #include "gl/GrGLDefines.h"
13 #include "gl/GrGLTexture.h"
14 #include "gl/GrGLTypes.h"
15 #include "glsl/GrGLSLFragmentProcessor.h" 15 #include "glsl/GrGLSLFragmentProcessor.h"
16 #include "glsl/GrGLSLFragmentShaderBuilder.h" 16 #include "glsl/GrGLSLFragmentShaderBuilder.h"
17 #include "glsl/GrGLSLCaps.h" 17 #include "glsl/GrGLSLCaps.h"
18 18
19 static uint8_t texture_target_key(GrGLenum target) { 19 #include "shaderc/shaderc.h"
20 switch (target) {
21 case GR_GL_TEXTURE_2D:
22 return 0;
23 case GR_GL_TEXTURE_EXTERNAL:
24 return 1;
25 case GR_GL_TEXTURE_RECTANGLE:
26 return 2;
27 default:
28 SkFAIL("Unexpected texture target.");
29 return 0;
30 }
31 }
32 20
33 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, 21 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc,
34 const GrGLSLCaps& caps) { 22 const GrGLSLCaps& caps) {
35 int numTextures = proc.numTextures(); 23 int numTextures = proc.numTextures();
36 // Need two bytes per key (swizzle and target). 24 // Need two bytes per key (swizzle and target).
37 int word32Count = (proc.numTextures() + 1) / 2; 25 int word32Count = (proc.numTextures() + 1) / 2;
38 if (0 == word32Count) { 26 if (0 == word32Count) {
39 return; 27 return;
40 } 28 }
41 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); 29 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count));
42 for (int i = 0; i < numTextures; ++i) { 30 for (int i = 0; i < numTextures; ++i) {
43 const GrTextureAccess& access = proc.textureAccess(i); 31 const GrTextureAccess& access = proc.textureAccess(i);
44 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()); 32 GrTexture* texture = access.getTexture();
45 k16[i] = SkToU16(caps.configTextureSwizzle(texture->config()).asKey() | 33 k16[i] = SkToU16(caps.configTextureSwizzle(texture->config()).asKey());
46 (texture_target_key(texture->target()) << 8));
47 } 34 }
48 // zero the last 16 bits if the number of textures is odd. 35 // zero the last 16 bits if the number of textures is odd.
49 if (numTextures & 0x1) { 36 if (numTextures & 0x1) {
50 k16[numTextures] = 0; 37 k16[numTextures] = 0;
51 } 38 }
52 } 39 }
53 40
54 /** 41 /**
55 * A function which emits a meta key into the key builder. This is required bec ause shader code may 42 * A function which emits a meta key into the key builder. This is required beca use shader code may
56 * be dependent on properties of the effect that the effect itself doesn't use 43 * be dependent on properties of the effect that the effect itself doesn't use
57 * in its key (e.g. the pixel format of textures used). So we create a meta-key for 44 * in its key (e.g. the pixel format of textures used). So we create a meta-key f or
58 * every effect using this function. It is also responsible for inserting the ef fect's class ID 45 * every effect using this function. It is also responsible for inserting the eff ect's class ID
59 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many 46 * which must be different for every GrProcessor subclass. It can fail if an effe ct uses too many
60 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this 47 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and G Ps share this
61 * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms 48 * function because it is hairy, though FPs do not have attribs, and GPs do not h ave transforms
62 */ 49 */
63 static bool gen_meta_key(const GrProcessor& proc, 50 static bool gen_meta_key(const GrProcessor& proc,
64 const GrGLSLCaps& glslCaps, 51 const GrGLSLCaps& glslCaps,
65 uint32_t transformKey, 52 uint32_t transformKey,
66 GrProcessorKeyBuilder* b) { 53 GrProcessorKeyBuilder* b) {
67 size_t processorKeySize = b->size(); 54 size_t processorKeySize = b->size();
68 uint32_t classID = proc.classID(); 55 uint32_t classID = proc.classID();
69 56
70 // Currently we allow 16 bits for the class id and the overall processor key size. 57 // Currently we allow 16 bits for the class id and the overall processor key size.
71 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); 58 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16);
72 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { 59 if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
73 return false; 60 return false;
74 } 61 }
75 62
76 add_texture_key(b, proc, glslCaps); 63 add_texture_key(b, proc, glslCaps);
77 64
78 uint32_t* key = b->add32n(2); 65 uint32_t* key = b->add32n(2);
79 key[0] = (classID << 16) | SkToU32(processorKeySize); 66 key[0] = (classID << 16) | SkToU32(processorKeySize);
80 key[1] = transformKey; 67 key[1] = transformKey;
81 return true; 68 return true;
82 } 69 }
83 70
84 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, 71 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
85 const GrFragmentProcessor& fp, 72 const GrFragmentProcessor& fp,
86 const GrGLSLCaps& glslCaps, 73 const GrGLSLCaps& glslCaps,
87 GrProcessorKeyBuilder* b) { 74 GrProcessorKeyBuilder* b) {
88 for (int i = 0; i < fp.numChildProcessors(); ++i) { 75 for (int i = 0; i < fp.numChildProcessors(); ++i) {
89 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), glslCap s, b)) { 76 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), glslCap s, b)) {
90 return false; 77 return false;
91 } 78 }
92 } 79 }
93 80
94 fp.getGLSLProcessorKey(glslCaps, b); 81 fp.getGLSLProcessorKey(glslCaps, b);
95 82
96 return gen_meta_key(fp, glslCaps, primProc.getTransformKey(fp.coordTransform s(), 83 return gen_meta_key(fp, glslCaps, primProc.getTransformKey(fp.coordTransform s(),
97 fp.numTransformsE xclChildren()), b); 84 fp.numTransformsExclChildren()), b);
98 } 85 }
99 86
100 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, 87 bool GrVkProgramDescBuilder::Build(GrProgramDesc* desc,
101 const GrPrimitiveProcessor& primProc, 88 const GrPrimitiveProcessor& primProc,
102 const GrPipeline& pipeline, 89 const GrPipeline& pipeline,
103 const GrGLSLCaps& glslCaps) { 90 const GrGLSLCaps& glslCaps) {
104 // The descriptor is used as a cache key. Thus when a field of the 91 // The descriptor is used as a cache key. Thus when a field of the
105 // descriptor will not affect program generation (because of the attribute 92 // descriptor will not affect program generation (because of the attribute
106 // bindings in use or other descriptor field settings) it should be set 93 // bindings in use or other descriptor field settings) it should be set
107 // to a canonical value to avoid duplicate programs with different keys. 94 // to a canonical value to avoid duplicate programs with different keys.
108 95
109 GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc; 96 GrVkProgramDesc* vkDesc = (GrVkProgramDesc*)desc;
110 97
111 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); 98 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
112 // Make room for everything up to the effect keys. 99 // Make room for everything up to the effect keys.
113 glDesc->key().reset(); 100 vkDesc->key().reset();
114 glDesc->key().push_back_n(kProcessorKeysOffset); 101 vkDesc->key().push_back_n(kProcessorKeysOffset);
115 102
116 GrProcessorKeyBuilder b(&glDesc->key()); 103 GrProcessorKeyBuilder b(&vkDesc->key());
117 104
118 primProc.getGLSLProcessorKey(glslCaps, &b); 105 primProc.getGLSLProcessorKey(glslCaps, &b);
119 if (!gen_meta_key(primProc, glslCaps, 0, &b)) { 106 if (!gen_meta_key(primProc, glslCaps, 0, &b)) {
120 glDesc->key().reset(); 107 vkDesc->key().reset();
121 return false; 108 return false;
122 } 109 }
123 110
124 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) { 111 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
125 const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i); 112 const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i);
126 if (!gen_frag_proc_and_meta_keys(primProc, fp, glslCaps, &b)) { 113 if (!gen_frag_proc_and_meta_keys(primProc, fp, glslCaps, &b)) {
127 glDesc->key().reset(); 114 vkDesc->key().reset();
128 return false; 115 return false;
129 } 116 }
130 } 117 }
131 118
132 const GrXferProcessor& xp = pipeline.getXferProcessor(); 119 const GrXferProcessor& xp = pipeline.getXferProcessor();
133 xp.getGLSLProcessorKey(glslCaps, &b); 120 xp.getGLSLProcessorKey(glslCaps, &b);
134 if (!gen_meta_key(xp, glslCaps, 0, &b)) { 121 if (!gen_meta_key(xp, glslCaps, 0, &b)) {
135 glDesc->key().reset(); 122 vkDesc->key().reset();
136 return false; 123 return false;
137 } 124 }
138 125
139 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- ------------------- 126 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- -------------------
140 // Because header is a pointer into the dynamic array, we can't push any new data into the key 127 // Because header is a pointer into the dynamic array, we can't push any new data into the key
141 // below here. 128 // below here.
142 KeyHeader* header = glDesc->atOffset<KeyHeader, kHeaderOffset>(); 129 KeyHeader* header = vkDesc->atOffset<KeyHeader, kHeaderOffset>();
143 130
144 // make sure any padding in the header is zeroed. 131 // make sure any padding in the header is zeroed.
145 memset(header, 0, kHeaderSize); 132 memset(header, 0, kHeaderSize);
146 133
147 if (pipeline.readsFragPosition()) { 134 if (pipeline.readsFragPosition()) {
148 header->fFragPosKey = 135 header->fFragPosKey =
149 GrGLSLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.get RenderTarget()); 136 GrGLSLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRend erTarget());
150 } else { 137 } else {
151 header->fFragPosKey = 0; 138 header->fFragPosKey = 0;
152 } 139 }
153 140
154 header->fOutputSwizzle = 141 header->fOutputSwizzle =
155 glslCaps.configOutputSwizzle(pipeline.getRenderTarget()->config()).asKey (); 142 glslCaps.configOutputSwizzle(pipeline.getRenderTarget()->config()).asKey ();
156 143
157 if (pipeline.ignoresCoverage()) { 144 if (pipeline.ignoresCoverage()) {
158 header->fIgnoresCoverage = 1; 145 header->fIgnoresCoverage = 1;
159 } else { 146 } else {
160 header->fIgnoresCoverage = 0; 147 header->fIgnoresCoverage = 0;
161 } 148 }
162 149
163 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); 150 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
164 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); 151 header->fColorEffectCnt = pipeline.numColorFragmentProcessors();
165 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); 152 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors();
166 glDesc->finalize(); 153 vkDesc->finalize();
167 return true; 154 return true;
168 } 155 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkProgramDesc.h ('k') | src/gpu/vk/GrVkRenderPass.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698