Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/gpu/gl/GrGLUniformHandler.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015 Google Inc.
3
 *
4
 * Use of this source code is governed by a BSD-style license that can be
5
 * found in the LICENSE file.
6
 */
7
8
#include "src/gpu/gl/GrGLUniformHandler.h"
9
10
#include "src/gpu/GrTexture.h"
11
#include "src/gpu/gl/GrGLCaps.h"
12
#include "src/gpu/gl/GrGLGpu.h"
13
#include "src/gpu/gl/builders/GrGLProgramBuilder.h"
14
#include "src/sksl/SkSLCompiler.h"
15
16
0
#define GL_CALL(X) GR_GL_CALL(this->glGpu()->glInterface(), X)
17
0
#define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->glGpu()->glInterface(), R, X)
18
19
0
bool valid_name(const char* name) {
20
    // disallow unknown names that start with "sk_"
21
0
    if (!strncmp(name, GR_NO_MANGLE_PREFIX, strlen(GR_NO_MANGLE_PREFIX))) {
22
0
        return !strcmp(name, SkSL::Compiler::RTADJUST_NAME);
23
0
    }
24
0
    return true;
25
0
}
26
27
GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray(
28
                                                                   const GrFragmentProcessor* owner,
29
                                                                   uint32_t visibility,
30
                                                                   GrSLType type,
31
                                                                   const char* name,
32
                                                                   bool mangleName,
33
                                                                   int arrayCount,
34
0
                                                                   const char** outName) {
35
0
    SkASSERT(name && strlen(name));
36
0
    SkASSERT(valid_name(name));
37
0
    SkASSERT(0 != visibility);
38
39
    // TODO this is a bit hacky, lets think of a better way.  Basically we need to be able to use
40
    // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
41
    // exactly what name it wants to use for the uniform view matrix.  If we prefix anythings, then
42
    // the names will mismatch.  I think the correct solution is to have all GPs which need the
43
    // uniform view matrix, they should upload the view matrix in their setData along with regular
44
    // uniforms.
45
0
    char prefix = 'u';
46
0
    if ('u' == name[0] || !strncmp(name, GR_NO_MANGLE_PREFIX, strlen(GR_NO_MANGLE_PREFIX))) {
47
0
        prefix = '\0';
48
0
    }
49
0
    SkString resolvedName = fProgramBuilder->nameVariable(prefix, name, mangleName);
50
0
    GLUniformInfo& uni = fUniforms.push_back(GrGLProgramDataManager::GLUniformInfo{
51
0
        {
52
0
            GrShaderVar{std::move(resolvedName), type, GrShaderVar::TypeModifier::Uniform,
53
0
                        arrayCount},
54
0
            visibility, owner, SkString(name)
55
0
        },
56
0
        -1
57
0
    });
58
59
0
    if (outName) {
60
0
        *outName = uni.fVariable.c_str();
61
0
    }
62
0
    return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
63
0
}
Unexecuted instantiation: GrGLUniformHandler::internalAddUniformArray(GrFragmentProcessor const*, unsigned int, GrSLType, char const*, bool, int, char const**)
Unexecuted instantiation: GrGLUniformHandler::internalAddUniformArray(GrFragmentProcessor const*, unsigned int, GrSLType, char const*, bool, int, char const**)
64
65
GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::addSampler(
66
        const GrBackendFormat& backendFormat, GrSamplerState, const GrSwizzle& swizzle,
67
0
        const char* name, const GrShaderCaps* shaderCaps) {
68
0
    SkASSERT(name && strlen(name));
69
70
0
    constexpr char prefix = 'u';
71
0
    SkString mangleName = fProgramBuilder->nameVariable(prefix, name, true);
72
73
0
    GrTextureType type = backendFormat.textureType();
74
75
0
    fSamplers.push_back(GrGLProgramDataManager::GLUniformInfo{
76
0
        {
77
0
            GrShaderVar{std::move(mangleName), GrSLCombinedSamplerTypeForTextureType(type),
78
0
                          GrShaderVar::TypeModifier::Uniform},
79
0
            kFragment_GrShaderFlag, nullptr, SkString(name)
80
0
        },
81
0
        -1
82
0
    });
83
84
0
    fSamplerSwizzles.push_back(swizzle);
85
0
    SkASSERT(fSamplers.count() == fSamplerSwizzles.count());
86
0
    return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
87
0
}
Unexecuted instantiation: GrGLUniformHandler::addSampler(GrBackendFormat const&, GrSamplerState, GrSwizzle const&, char const*, GrShaderCaps const*)
Unexecuted instantiation: GrGLUniformHandler::addSampler(GrBackendFormat const&, GrSamplerState, GrSwizzle const&, char const*, GrShaderCaps const*)
88
89
0
void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
90
0
    for (const UniformInfo& uniform : fUniforms.items()) {
91
0
        if (uniform.fVisibility & visibility) {
92
0
            uniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
93
0
            out->append(";");
94
0
        }
95
0
    }
96
0
    for (const UniformInfo& sampler : fSamplers.items()) {
97
0
        if (sampler.fVisibility & visibility) {
98
0
            sampler.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
99
0
            out->append(";\n");
100
0
        }
101
0
    }
102
0
}
103
104
0
void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps& caps) {
105
0
    if (caps.bindUniformLocationSupport()) {
106
0
        int currUniform = 0;
107
0
        for (GLUniformInfo& uniform : fUniforms.items()) {
108
0
            GL_CALL(BindUniformLocation(programID, currUniform, uniform.fVariable.c_str()));
109
0
            uniform.fLocation = currUniform;
110
0
            ++currUniform;
111
0
        }
112
0
        for (GLUniformInfo& sampler : fSamplers.items()) {
113
0
            GL_CALL(BindUniformLocation(programID, currUniform, sampler.fVariable.c_str()));
114
0
            sampler.fLocation = currUniform;
115
0
            ++currUniform;
116
0
        }
117
0
    }
118
0
}
Unexecuted instantiation: GrGLUniformHandler::bindUniformLocations(unsigned int, GrGLCaps const&)
Unexecuted instantiation: GrGLUniformHandler::bindUniformLocations(unsigned int, GrGLCaps const&)
119
120
0
void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force) {
121
0
    if (!caps.bindUniformLocationSupport() || force) {
122
0
        for (GLUniformInfo& uniform : fUniforms.items()) {
123
0
            GrGLint location;
124
0
            GL_CALL_RET(location, GetUniformLocation(programID, uniform.fVariable.c_str()));
125
0
            uniform.fLocation = location;
126
0
        }
127
0
        for (GLUniformInfo& sampler : fSamplers.items()) {
128
0
            GrGLint location;
129
0
            GL_CALL_RET(location, GetUniformLocation(programID, sampler.fVariable.c_str()));
130
0
            sampler.fLocation = location;
131
0
        }
132
0
    }
133
0
}
Unexecuted instantiation: GrGLUniformHandler::getUniformLocations(unsigned int, GrGLCaps const&, bool)
Unexecuted instantiation: GrGLUniformHandler::getUniformLocations(unsigned int, GrGLCaps const&, bool)
134
135
0
const GrGLGpu* GrGLUniformHandler::glGpu() const {
136
0
    GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder;
137
0
    return glPB->gpu();
138
0
}