| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrVkUniformHandler.h" | 8 #include "GrVkUniformHandler.h" |
| 9 #include "glsl/GrGLSLProgramBuilder.h" | 9 #include "glsl/GrGLSLProgramBuilder.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 0x7, // kMat22f_GrSLType | 25 0x7, // kMat22f_GrSLType |
| 26 0xF, // kMat33f_GrSLType | 26 0xF, // kMat33f_GrSLType |
| 27 0xF, // kMat44f_GrSLType | 27 0xF, // kMat44f_GrSLType |
| 28 0x0, // Sampler2D_GrSLType, should never return this | 28 0x0, // Sampler2D_GrSLType, should never return this |
| 29 0x0, // SamplerExternal_GrSLType, should never return this | 29 0x0, // SamplerExternal_GrSLType, should never return this |
| 30 0x0, // Sampler2DRect_GrSLType, should never return this | 30 0x0, // Sampler2DRect_GrSLType, should never return this |
| 31 0x0, // SamplerBuffer_GrSLType, should never return this | 31 0x0, // SamplerBuffer_GrSLType, should never return this |
| 32 0x0, // kBool_GrSLType | 32 0x0, // kBool_GrSLType |
| 33 0x7, // kInt_GrSLType | 33 0x7, // kInt_GrSLType |
| 34 0x7, // kUint_GrSLType | 34 0x7, // kUint_GrSLType |
| 35 0x0, // Texture2D_GrSLType, should never return this |
| 36 0x0, // Sampler_GrSLType, should never return this |
| 35 }; | 37 }; |
| 36 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 38 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 37 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 39 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 38 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 40 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 39 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 41 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 40 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 42 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 41 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); | 43 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); |
| 42 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); | 44 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); |
| 43 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); | 45 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); |
| 44 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); | 46 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType); |
| 45 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); | 47 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType); |
| 46 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 48 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType); |
| 47 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); | 49 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType); |
| 48 GR_STATIC_ASSERT(12 == kBool_GrSLType); | 50 GR_STATIC_ASSERT(12 == kBool_GrSLType); |
| 49 GR_STATIC_ASSERT(13 == kInt_GrSLType); | 51 GR_STATIC_ASSERT(13 == kInt_GrSLType); |
| 50 GR_STATIC_ASSERT(14 == kUint_GrSLType); | 52 GR_STATIC_ASSERT(14 == kUint_GrSLType); |
| 53 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType); |
| 54 GR_STATIC_ASSERT(16 == kSampler_GrSLType); |
| 51 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAlignmentMask) == kGrSLTypeCount); | 55 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAlignmentMask) == kGrSLTypeCount); |
| 52 return kAlignmentMask[type]; | 56 return kAlignmentMask[type]; |
| 53 } | 57 } |
| 54 | 58 |
| 55 /** Returns the size in bytes taken up in vulkanbuffers for floating point GrSLT
ypes. | 59 /** Returns the size in bytes taken up in vulkanbuffers for floating point GrSLT
ypes. |
| 56 For non floating point type returns 0. Currently this reflects the std140 al
ignment | 60 For non floating point type returns 0. Currently this reflects the std140 al
ignment |
| 57 so a mat22 takes up 8 floats. */ | 61 so a mat22 takes up 8 floats. */ |
| 58 static inline uint32_t grsltype_to_vk_size(GrSLType type) { | 62 static inline uint32_t grsltype_to_vk_size(GrSLType type) { |
| 59 SkASSERT(GrSLTypeIsFloatType(type)); | 63 SkASSERT(GrSLTypeIsFloatType(type)); |
| 60 static const uint32_t kSizes[] = { | 64 static const uint32_t kSizes[] = { |
| 61 0, // kVoid_GrSLType | 65 0, // kVoid_GrSLType |
| 62 sizeof(float), // kFloat_GrSLType | 66 sizeof(float), // kFloat_GrSLType |
| 63 2 * sizeof(float), // kVec2f_GrSLType | 67 2 * sizeof(float), // kVec2f_GrSLType |
| 64 3 * sizeof(float), // kVec3f_GrSLType | 68 3 * sizeof(float), // kVec3f_GrSLType |
| 65 4 * sizeof(float), // kVec4f_GrSLType | 69 4 * sizeof(float), // kVec4f_GrSLType |
| 66 8 * sizeof(float), // kMat22f_GrSLType. TODO: this will be 4 * sz
of(float) on std430. | 70 8 * sizeof(float), // kMat22f_GrSLType. TODO: this will be 4 * sz
of(float) on std430. |
| 67 12 * sizeof(float), // kMat33f_GrSLType | 71 12 * sizeof(float), // kMat33f_GrSLType |
| 68 16 * sizeof(float), // kMat44f_GrSLType | 72 16 * sizeof(float), // kMat44f_GrSLType |
| 69 0, // kSampler2D_GrSLType | 73 0, // kTexture2DSampler_GrSLType |
| 70 0, // kSamplerExternal_GrSLType | 74 0, // kTextureExternalSampler_GrSLType |
| 71 0, // kSampler2DRect_GrSLType | 75 0, // kTexture2DRectSampler_GrSLType |
| 72 0, // kSamplerBuffer_GrSLType | 76 0, // kTextureBufferSampler_GrSLType |
| 73 1, // kBool_GrSLType | 77 1, // kBool_GrSLType |
| 74 4, // kInt_GrSLType | 78 4, // kInt_GrSLType |
| 75 4 // kUint_GrSLType | 79 4, // kUint_GrSLType |
| 80 0, // kTexture2D_GrSLType |
| 81 0, // kSampler_GrSLType |
| 76 }; | 82 }; |
| 77 return kSizes[type]; | 83 return kSizes[type]; |
| 78 | 84 |
| 79 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 85 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 80 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 86 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 81 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 87 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 82 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 88 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 83 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 89 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 84 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); | 90 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); |
| 85 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); | 91 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); |
| 86 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); | 92 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); |
| 87 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); | 93 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType); |
| 88 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); | 94 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType); |
| 89 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 95 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType); |
| 90 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); | 96 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType); |
| 91 GR_STATIC_ASSERT(12 == kBool_GrSLType); | 97 GR_STATIC_ASSERT(12 == kBool_GrSLType); |
| 92 GR_STATIC_ASSERT(13 == kInt_GrSLType); | 98 GR_STATIC_ASSERT(13 == kInt_GrSLType); |
| 93 GR_STATIC_ASSERT(14 == kUint_GrSLType); | 99 GR_STATIC_ASSERT(14 == kUint_GrSLType); |
| 100 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType); |
| 101 GR_STATIC_ASSERT(16 == kSampler_GrSLType); |
| 94 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrSLTypeCount); | 102 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrSLTypeCount); |
| 95 } | 103 } |
| 96 | 104 |
| 97 | 105 |
| 98 // Given the current offset into the ubo, calculate the offset for the uniform w
e're trying to add | 106 // Given the current offset into the ubo, calculate the offset for the uniform w
e're trying to add |
| 99 // taking into consideration all alignment requirements. The uniformOffset is se
t to the offset for | 107 // taking into consideration all alignment requirements. The uniformOffset is se
t to the offset for |
| 100 // the new uniform, and currentOffset is updated to be the offset to the end of
the new uniform. | 108 // the new uniform, and currentOffset is updated to be the offset to the end of
the new uniform. |
| 101 void get_ubo_aligned_offset(uint32_t* uniformOffset, | 109 void get_ubo_aligned_offset(uint32_t* uniformOffset, |
| 102 uint32_t* currentOffset, | 110 uint32_t* currentOffset, |
| 103 GrSLType type, | 111 GrSLType type, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 fSamplers.emplace_back(visibility, config, type, precision, mangleName.c_str
(), | 193 fSamplers.emplace_back(visibility, config, type, precision, mangleName.c_str
(), |
| 186 (uint32_t)fSamplers.count(), kSamplerDescSet); | 194 (uint32_t)fSamplers.count(), kSamplerDescSet); |
| 187 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1); | 195 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1); |
| 188 } | 196 } |
| 189 | 197 |
| 190 void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out) const { | 198 void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out) const { |
| 191 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis
ibility); | 199 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis
ibility); |
| 192 | 200 |
| 193 for (int i = 0; i < fSamplers.count(); ++i) { | 201 for (int i = 0; i < fSamplers.count(); ++i) { |
| 194 const GrVkGLSLSampler& sampler = fSamplers[i]; | 202 const GrVkGLSLSampler& sampler = fSamplers[i]; |
| 195 SkASSERT(sampler.type() == kSampler2D_GrSLType); | 203 SkASSERT(sampler.type() == kTexture2DSampler_GrSLType); |
| 196 if (visibility == sampler.visibility()) { | 204 if (visibility == sampler.visibility()) { |
| 197 sampler.fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out); | 205 sampler.fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out); |
| 198 out->append(";\n"); | 206 out->append(";\n"); |
| 199 } | 207 } |
| 200 } | 208 } |
| 201 | 209 |
| 202 SkString uniformsString; | 210 SkString uniformsString; |
| 203 for (int i = 0; i < fUniforms.count(); ++i) { | 211 for (int i = 0; i < fUniforms.count(); ++i) { |
| 204 const UniformInfo& localUniform = fUniforms[i]; | 212 const UniformInfo& localUniform = fUniforms[i]; |
| 205 if (visibility == localUniform.fVisibility) { | 213 if (visibility == localUniform.fVisibility) { |
| 206 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) { | 214 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) { |
| 207 localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), &
uniformsString); | 215 localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), &
uniformsString); |
| 208 uniformsString.append(";\n"); | 216 uniformsString.append(";\n"); |
| 209 } | 217 } |
| 210 } | 218 } |
| 211 } | 219 } |
| 212 if (!uniformsString.isEmpty()) { | 220 if (!uniformsString.isEmpty()) { |
| 213 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertex
Binding | 221 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertex
Binding |
| 214 : kFragBi
nding; | 222 : kFragBi
nding; |
| 215 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f
ragment"; | 223 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f
ragment"; |
| 216 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n", | 224 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n", |
| 217 kUniformBufferDescSet, uniformBinding, stage); | 225 kUniformBufferDescSet, uniformBinding, stage); |
| 218 out->appendf("%s\n};\n", uniformsString.c_str()); | 226 out->appendf("%s\n};\n", uniformsString.c_str()); |
| 219 } | 227 } |
| 220 } | 228 } |
| OLD | NEW |