Large simplification of the CType mapper logic in SkSL
- Arrays were unused - Each ctype was used with exactly one mapper - remove the SkSL type list - After that, the mapper was just a key + value, so make it just a value and use a map (rather than vector) Change-Id: Ibc150ecc9ac9724ecd1e7056614ca5836ce99d5b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/409998 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
bfeba24b06
commit
fa6a127310
@ -68,8 +68,8 @@ private:
|
||||
const GrAlphaThresholdFragmentProcessor& _outer =
|
||||
_proc.cast<GrAlphaThresholdFragmentProcessor>();
|
||||
{
|
||||
pdman.set1f(innerThresholdVar, (_outer.innerThreshold));
|
||||
pdman.set1f(outerThresholdVar, (_outer.outerThreshold));
|
||||
pdman.set1f(innerThresholdVar, _outer.innerThreshold);
|
||||
pdman.set1f(outerThresholdVar, _outer.outerThreshold);
|
||||
}
|
||||
}
|
||||
UniformHandle innerThresholdVar;
|
||||
|
@ -55,7 +55,7 @@ private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrArithmeticProcessor& _outer = _proc.cast<GrArithmeticProcessor>();
|
||||
{ pdman.set4fv(kVar, 1, (_outer.k).ptr()); }
|
||||
{ pdman.set4fv(kVar, 1, _outer.k.ptr()); }
|
||||
}
|
||||
UniformHandle kVar;
|
||||
};
|
||||
|
@ -73,9 +73,8 @@ private:
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrColorMatrixFragmentProcessor& _outer = _proc.cast<GrColorMatrixFragmentProcessor>();
|
||||
{
|
||||
static_assert(1 == 1);
|
||||
pdman.setSkM44(mVar, (_outer.m));
|
||||
pdman.set4fv(vVar, 1, (_outer.v).ptr());
|
||||
pdman.setSkM44(mVar, _outer.m);
|
||||
pdman.set4fv(vVar, 1, _outer.v.ptr());
|
||||
}
|
||||
}
|
||||
UniformHandle mVar;
|
||||
|
@ -53,7 +53,7 @@ private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrDitherEffect& _outer = _proc.cast<GrDitherEffect>();
|
||||
{ pdman.set1f(rangeVar, (_outer.range)); }
|
||||
{ pdman.set1f(rangeVar, _outer.range); }
|
||||
}
|
||||
UniformHandle rangeVar;
|
||||
};
|
||||
|
@ -86,10 +86,10 @@ private:
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrMagnifierEffect& _outer = _proc.cast<GrMagnifierEffect>();
|
||||
{
|
||||
pdman.set1f(xInvZoomVar, (_outer.xInvZoom));
|
||||
pdman.set1f(yInvZoomVar, (_outer.yInvZoom));
|
||||
pdman.set1f(xInvInsetVar, (_outer.xInvInset));
|
||||
pdman.set1f(yInvInsetVar, (_outer.yInvInset));
|
||||
pdman.set1f(xInvZoomVar, _outer.xInvZoom);
|
||||
pdman.set1f(yInvZoomVar, _outer.yInvZoom);
|
||||
pdman.set1f(xInvInsetVar, _outer.xInvInset);
|
||||
pdman.set1f(yInvInsetVar, _outer.yInvInset);
|
||||
}
|
||||
auto bounds = _outer.bounds;
|
||||
(void)bounds;
|
||||
|
@ -58,7 +58,7 @@ private:
|
||||
_proc.cast<GrOverrideInputFragmentProcessor>();
|
||||
{
|
||||
if (uniformColorVar.isValid()) {
|
||||
pdman.set4fv(uniformColorVar, 1, (_outer.uniformColor).vec());
|
||||
pdman.set4fv(uniformColorVar, 1, _outer.uniformColor.vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrRRectBlurEffect& _outer = _proc.cast<GrRRectBlurEffect>();
|
||||
{ pdman.set1f(cornerRadiusVar, (_outer.cornerRadius)); }
|
||||
{ pdman.set1f(cornerRadiusVar, _outer.cornerRadius); }
|
||||
auto sigma = _outer.sigma;
|
||||
(void)sigma;
|
||||
auto rect = _outer.rect;
|
||||
|
@ -129,8 +129,7 @@ private:
|
||||
const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>();
|
||||
{
|
||||
if (invVMVar.isValid()) {
|
||||
static_assert(1 == 1);
|
||||
pdman.setSkMatrix(invVMVar, (_outer.invVM));
|
||||
pdman.setSkMatrix(invVMVar, _outer.invVM);
|
||||
}
|
||||
}
|
||||
auto rect = _outer.rect;
|
||||
|
@ -73,8 +73,8 @@ private:
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrClampedGradientEffect& _outer = _proc.cast<GrClampedGradientEffect>();
|
||||
{
|
||||
pdman.set4fv(leftBorderColorVar, 1, (_outer.leftBorderColor).vec());
|
||||
pdman.set4fv(rightBorderColorVar, 1, (_outer.rightBorderColor).vec());
|
||||
pdman.set4fv(leftBorderColorVar, 1, _outer.leftBorderColor.vec());
|
||||
pdman.set4fv(rightBorderColorVar, 1, _outer.rightBorderColor.vec());
|
||||
}
|
||||
}
|
||||
UniformHandle leftBorderColorVar;
|
||||
|
@ -73,11 +73,11 @@ private:
|
||||
const GrDualIntervalGradientColorizer& _outer =
|
||||
_proc.cast<GrDualIntervalGradientColorizer>();
|
||||
{
|
||||
pdman.set4fv(scale01Var, 1, (_outer.scale01).vec());
|
||||
pdman.set4fv(bias01Var, 1, (_outer.bias01).vec());
|
||||
pdman.set4fv(scale23Var, 1, (_outer.scale23).vec());
|
||||
pdman.set4fv(bias23Var, 1, (_outer.bias23).vec());
|
||||
pdman.set1f(thresholdVar, (_outer.threshold));
|
||||
pdman.set4fv(scale01Var, 1, _outer.scale01.vec());
|
||||
pdman.set4fv(bias01Var, 1, _outer.bias01.vec());
|
||||
pdman.set4fv(scale23Var, 1, _outer.scale23.vec());
|
||||
pdman.set4fv(bias23Var, 1, _outer.bias23.vec());
|
||||
pdman.set1f(thresholdVar, _outer.threshold);
|
||||
}
|
||||
}
|
||||
UniformHandle scale01Var;
|
||||
|
@ -47,8 +47,8 @@ private:
|
||||
const GrSingleIntervalGradientColorizer& _outer =
|
||||
_proc.cast<GrSingleIntervalGradientColorizer>();
|
||||
{
|
||||
pdman.set4fv(startVar, 1, (_outer.start).vec());
|
||||
pdman.set4fv(endVar, 1, (_outer.end).vec());
|
||||
pdman.set4fv(startVar, 1, _outer.start.vec());
|
||||
pdman.set4fv(endVar, 1, _outer.end.vec());
|
||||
}
|
||||
}
|
||||
UniformHandle startVar;
|
||||
|
@ -51,8 +51,8 @@ private:
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrSweepGradientLayout& _outer = _proc.cast<GrSweepGradientLayout>();
|
||||
{
|
||||
pdman.set1f(biasVar, (_outer.bias));
|
||||
pdman.set1f(scaleVar, (_outer.scale));
|
||||
pdman.set1f(biasVar, _outer.bias);
|
||||
pdman.set1f(scaleVar, _outer.scale);
|
||||
}
|
||||
}
|
||||
UniformHandle biasVar;
|
||||
|
@ -149,10 +149,7 @@ private:
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrTwoPointConicalGradientLayout& _outer =
|
||||
_proc.cast<GrTwoPointConicalGradientLayout>();
|
||||
{
|
||||
const SkPoint& focalParamsValue = _outer.focalParams;
|
||||
pdman.set2f(focalParamsVar, focalParamsValue.fX, focalParamsValue.fY);
|
||||
}
|
||||
{ pdman.set2f(focalParamsVar, _outer.focalParams.fX, _outer.focalParams.fY); }
|
||||
}
|
||||
UniformHandle focalParamsVar;
|
||||
};
|
||||
|
@ -224,54 +224,54 @@ private:
|
||||
const GrUnrolledBinaryGradientColorizer& _outer =
|
||||
_proc.cast<GrUnrolledBinaryGradientColorizer>();
|
||||
{
|
||||
pdman.set4fv(scale0_1Var, 1, (_outer.scale0_1).vec());
|
||||
pdman.set4fv(scale0_1Var, 1, _outer.scale0_1.vec());
|
||||
if (scale2_3Var.isValid()) {
|
||||
pdman.set4fv(scale2_3Var, 1, (_outer.scale2_3).vec());
|
||||
pdman.set4fv(scale2_3Var, 1, _outer.scale2_3.vec());
|
||||
}
|
||||
if (scale4_5Var.isValid()) {
|
||||
pdman.set4fv(scale4_5Var, 1, (_outer.scale4_5).vec());
|
||||
pdman.set4fv(scale4_5Var, 1, _outer.scale4_5.vec());
|
||||
}
|
||||
if (scale6_7Var.isValid()) {
|
||||
pdman.set4fv(scale6_7Var, 1, (_outer.scale6_7).vec());
|
||||
pdman.set4fv(scale6_7Var, 1, _outer.scale6_7.vec());
|
||||
}
|
||||
if (scale8_9Var.isValid()) {
|
||||
pdman.set4fv(scale8_9Var, 1, (_outer.scale8_9).vec());
|
||||
pdman.set4fv(scale8_9Var, 1, _outer.scale8_9.vec());
|
||||
}
|
||||
if (scale10_11Var.isValid()) {
|
||||
pdman.set4fv(scale10_11Var, 1, (_outer.scale10_11).vec());
|
||||
pdman.set4fv(scale10_11Var, 1, _outer.scale10_11.vec());
|
||||
}
|
||||
if (scale12_13Var.isValid()) {
|
||||
pdman.set4fv(scale12_13Var, 1, (_outer.scale12_13).vec());
|
||||
pdman.set4fv(scale12_13Var, 1, _outer.scale12_13.vec());
|
||||
}
|
||||
if (scale14_15Var.isValid()) {
|
||||
pdman.set4fv(scale14_15Var, 1, (_outer.scale14_15).vec());
|
||||
pdman.set4fv(scale14_15Var, 1, _outer.scale14_15.vec());
|
||||
}
|
||||
pdman.set4fv(bias0_1Var, 1, (_outer.bias0_1).vec());
|
||||
pdman.set4fv(bias0_1Var, 1, _outer.bias0_1.vec());
|
||||
if (bias2_3Var.isValid()) {
|
||||
pdman.set4fv(bias2_3Var, 1, (_outer.bias2_3).vec());
|
||||
pdman.set4fv(bias2_3Var, 1, _outer.bias2_3.vec());
|
||||
}
|
||||
if (bias4_5Var.isValid()) {
|
||||
pdman.set4fv(bias4_5Var, 1, (_outer.bias4_5).vec());
|
||||
pdman.set4fv(bias4_5Var, 1, _outer.bias4_5.vec());
|
||||
}
|
||||
if (bias6_7Var.isValid()) {
|
||||
pdman.set4fv(bias6_7Var, 1, (_outer.bias6_7).vec());
|
||||
pdman.set4fv(bias6_7Var, 1, _outer.bias6_7.vec());
|
||||
}
|
||||
if (bias8_9Var.isValid()) {
|
||||
pdman.set4fv(bias8_9Var, 1, (_outer.bias8_9).vec());
|
||||
pdman.set4fv(bias8_9Var, 1, _outer.bias8_9.vec());
|
||||
}
|
||||
if (bias10_11Var.isValid()) {
|
||||
pdman.set4fv(bias10_11Var, 1, (_outer.bias10_11).vec());
|
||||
pdman.set4fv(bias10_11Var, 1, _outer.bias10_11.vec());
|
||||
}
|
||||
if (bias12_13Var.isValid()) {
|
||||
pdman.set4fv(bias12_13Var, 1, (_outer.bias12_13).vec());
|
||||
pdman.set4fv(bias12_13Var, 1, _outer.bias12_13.vec());
|
||||
}
|
||||
if (bias14_15Var.isValid()) {
|
||||
pdman.set4fv(bias14_15Var, 1, (_outer.bias14_15).vec());
|
||||
pdman.set4fv(bias14_15Var, 1, _outer.bias14_15.vec());
|
||||
}
|
||||
pdman.set4fv(
|
||||
thresholds1_7Var, 1, reinterpret_cast<const float*>(&(_outer.thresholds1_7)));
|
||||
thresholds1_7Var, 1, reinterpret_cast<const float*>(&_outer.thresholds1_7));
|
||||
pdman.set4fv(
|
||||
thresholds9_13Var, 1, reinterpret_cast<const float*>(&(_outer.thresholds9_13)));
|
||||
thresholds9_13Var, 1, reinterpret_cast<const float*>(&_outer.thresholds9_13));
|
||||
}
|
||||
}
|
||||
UniformHandle scale0_1Var;
|
||||
|
@ -11,8 +11,7 @@
|
||||
#include "src/sksl/SkSLStringStream.h"
|
||||
#include "src/sksl/codegen/SkSLHCodeGenerator.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#if defined(SKSL_STANDALONE) || GR_TEST_UTILS
|
||||
|
||||
@ -47,141 +46,36 @@ static String eval_template(const String& format,
|
||||
return str;
|
||||
}
|
||||
|
||||
static bool determine_inline_from_template(const String& uniformTemplate) {
|
||||
// True if there is at most one instance of the ${var} template matcher in fUniformTemplate.
|
||||
int firstMatch = uniformTemplate.find("${var}");
|
||||
|
||||
if (firstMatch < 0) {
|
||||
// Template doesn't use the value variable at all, so it can "inlined"
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for another occurrence of ${var}, after firstMatch + 6
|
||||
int secondMatch = uniformTemplate.find("${var}", firstMatch + strlen("${var}"));
|
||||
// If there's no second match, then the value can be inlined in the c++ code
|
||||
return secondMatch < 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
// UniformCTypeMapper implementation //
|
||||
///////////////////////////////////////
|
||||
|
||||
String UniformCTypeMapper::setUniform(const String& pdman, const String& uniform,
|
||||
const String& var) const {
|
||||
String count;
|
||||
String finalVar;
|
||||
const String* activeTemplate;
|
||||
if (fArrayCount != -1) {
|
||||
count = to_string(fArrayCount);
|
||||
finalVar = var + "[0]";
|
||||
activeTemplate = &fUniformArrayTemplate;
|
||||
} else {
|
||||
count = "1";
|
||||
finalVar = std::move(var);
|
||||
activeTemplate = &fUniformSingleTemplate;
|
||||
}
|
||||
|
||||
return eval_template(*activeTemplate,
|
||||
{"${pdman}", "${uniform}", "${var}", "${count}"},
|
||||
{pdman, uniform, finalVar, count});
|
||||
return eval_template(fSetUniformTemplate,
|
||||
{"${pdman}", "${uniform}", "${var}"},
|
||||
{pdman, uniform, var});
|
||||
}
|
||||
|
||||
UniformCTypeMapper::UniformCTypeMapper(Layout::CType ctype,
|
||||
const std::vector<String>& skslTypes,
|
||||
const String& setUniformSingleFormat,
|
||||
const String& setUniformArrayFormat)
|
||||
: fCType(ctype)
|
||||
, fSKSLTypes(skslTypes)
|
||||
, fUniformSingleTemplate(setUniformSingleFormat)
|
||||
, fUniformArrayTemplate(setUniformArrayFormat)
|
||||
, fInlineValue(determine_inline_from_template(setUniformSingleFormat) &&
|
||||
determine_inline_from_template(setUniformArrayFormat)) {}
|
||||
|
||||
const UniformCTypeMapper* UniformCTypeMapper::arrayMapper(int count) const {
|
||||
static SkMutex& mutex = *(new SkMutex);
|
||||
SkAutoMutexExclusive guard(mutex);
|
||||
using Key = std::pair<const UniformCTypeMapper*, int>;
|
||||
static std::map<Key, UniformCTypeMapper> registered;
|
||||
Key key(this, count);
|
||||
auto result = registered.find(key);
|
||||
if (result == registered.end()) {
|
||||
auto [iter, didInsert] = registered.insert({key, *this});
|
||||
SkASSERT(didInsert);
|
||||
UniformCTypeMapper* inserted = &iter->second;
|
||||
inserted->fArrayCount = count;
|
||||
return inserted;
|
||||
}
|
||||
return &result->second;
|
||||
}
|
||||
|
||||
static UniformCTypeMapper register_array(Layout::CType ctype,
|
||||
const std::vector<String>& skslTypes,
|
||||
const char* singleSet,
|
||||
const char* arraySet) {
|
||||
return UniformCTypeMapper(ctype, skslTypes, singleSet, arraySet);
|
||||
}
|
||||
|
||||
static UniformCTypeMapper register_type(Layout::CType ctype,
|
||||
const std::vector<String>& skslTypes,
|
||||
const char* uniformFormat) {
|
||||
return register_array(ctype, skslTypes, uniformFormat, uniformFormat);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Currently defined ctypes //
|
||||
//////////////////////////////
|
||||
|
||||
static const std::vector<UniformCTypeMapper>& get_mappers() {
|
||||
static const std::vector<UniformCTypeMapper> kRegisteredMappers = {
|
||||
register_type(Layout::CType::kSkRect, { "half4", "float4", "double4" },
|
||||
"${pdman}.set4fv(${uniform}, ${count}, reinterpret_cast<const float*>(&${var}))"), // to gpu
|
||||
|
||||
register_type(Layout::CType::kSkIRect, { "int4", "short4", "byte4" },
|
||||
"${pdman}.set4iv(${uniform}, ${count}, reinterpret_cast<const int*>(&${var}))"), // to gpu
|
||||
|
||||
register_type(Layout::CType::kSkPMColor4f, { "half4", "float4", "double4" },
|
||||
"${pdman}.set4fv(${uniform}, ${count}, ${var}.vec())"), // to gpu
|
||||
|
||||
register_type(Layout::CType::kSkV4, { "half4", "float4", "double4" },
|
||||
"${pdman}.set4fv(${uniform}, ${count}, ${var}.ptr())"), // to gpu
|
||||
|
||||
register_array(Layout::CType::kSkPoint, { "half2", "float2", "double2" } ,
|
||||
"${pdman}.set2f(${uniform}, ${var}.fX, ${var}.fY)", // single
|
||||
"${pdman}.set2fv(${uniform}, ${count}, &${var}.fX)"), // array
|
||||
|
||||
register_array(Layout::CType::kSkIPoint, { "int2", "short2", "byte2" },
|
||||
"${pdman}.set2i(${uniform}, ${var}.fX, ${var}.fY)", // single
|
||||
"${pdman}.set2iv(${uniform}, ${count}, ${var}.fX, ${var}.fY)"), // array
|
||||
|
||||
register_type(Layout::CType::kSkMatrix, { "half3x3", "float3x3", "double3x3" },
|
||||
"static_assert(${count} == 1); ${pdman}.setSkMatrix(${uniform}, ${var})"), // to gpu
|
||||
|
||||
register_type(Layout::CType::kSkM44, { "half4x4", "float4x4", "double4x4" },
|
||||
"static_assert(${count} == 1); ${pdman}.setSkM44(${uniform}, ${var})"), // to gpu
|
||||
|
||||
register_array(Layout::CType::kFloat, { "half", "float", "double" },
|
||||
"${pdman}.set1f(${uniform}, ${var})", // single
|
||||
"${pdman}.set1fv(${uniform}, ${count}, &${var})"), // array
|
||||
|
||||
register_array(Layout::CType::kInt32, { "int", "short", "byte" },
|
||||
"${pdman}.set1i(${uniform}, ${var})", // single
|
||||
"${pdman}.set1iv(${uniform}, ${count}, &${var})"), // array
|
||||
};
|
||||
|
||||
return kRegisteredMappers;
|
||||
}
|
||||
|
||||
/////
|
||||
|
||||
// Greedy search through registered handlers for one that has a matching
|
||||
// ctype and supports the sksl type of the variable.
|
||||
const UniformCTypeMapper* UniformCTypeMapper::Get(const Context& context, const Type& type,
|
||||
const Layout& layout) {
|
||||
if (type.isArray()) {
|
||||
const UniformCTypeMapper* base = Get(context, type.componentType(), layout);
|
||||
return base ? base->arrayMapper(type.columns()) : nullptr;
|
||||
}
|
||||
const std::vector<UniformCTypeMapper>& registeredMappers = get_mappers();
|
||||
SkASSERT(!type.isArray());
|
||||
|
||||
static const auto* kRegisteredMappers =
|
||||
new std::unordered_map<Layout::CType, UniformCTypeMapper>{
|
||||
{Layout::CType::kSkRect,
|
||||
"${pdman}.set4fv(${uniform}, 1, reinterpret_cast<const float*>(&${var}))"},
|
||||
{Layout::CType::kSkIRect,
|
||||
"${pdman}.set4iv(${uniform}, 1, reinterpret_cast<const int*>(&${var}))"},
|
||||
{Layout::CType::kSkPMColor4f, "${pdman}.set4fv(${uniform}, 1, ${var}.vec())"},
|
||||
{Layout::CType::kSkV4, "${pdman}.set4fv(${uniform}, 1, ${var}.ptr())"},
|
||||
{Layout::CType::kSkPoint, "${pdman}.set2f(${uniform}, ${var}.fX, ${var}.fY)"},
|
||||
{Layout::CType::kSkIPoint, "${pdman}.set2i(${uniform}, ${var}.fX, ${var}.fY)"},
|
||||
{Layout::CType::kSkMatrix, "${pdman}.setSkMatrix(${uniform}, ${var})"},
|
||||
{Layout::CType::kSkM44, "${pdman}.setSkM44(${uniform}, ${var})"},
|
||||
{Layout::CType::kFloat, "${pdman}.set1f(${uniform}, ${var})"},
|
||||
{Layout::CType::kInt32, "${pdman}.set1i(${uniform}, ${var})"},
|
||||
};
|
||||
|
||||
Layout::CType ctype = layout.fCType;
|
||||
// If there's no custom ctype declared in the layout, use the default type mapping
|
||||
@ -189,21 +83,8 @@ const UniformCTypeMapper* UniformCTypeMapper::Get(const Context& context, const
|
||||
ctype = HCodeGenerator::ParameterCType(context, type, layout);
|
||||
}
|
||||
|
||||
for (const UniformCTypeMapper& mapper : registeredMappers) {
|
||||
if (mapper.ctype() == ctype) {
|
||||
// Check for SkSL support, since some C types (e.g. SkMatrix) can be used in multiple
|
||||
// uniform types and send data to the GPU differently depending on the uniform type.
|
||||
for (const String& mapperSupportedType : mapper.supportedTypeNames()) {
|
||||
if (mapperSupportedType == type.name()) {
|
||||
// Return the match that we found.
|
||||
return &mapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Didn't find a match.
|
||||
return nullptr;
|
||||
auto it = kRegisteredMappers->find(ctype);
|
||||
return it == kRegisteredMappers->end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
} // namespace SkSL
|
||||
|
@ -29,10 +29,7 @@ namespace SkSL {
|
||||
// semicolons or newlines, which will be handled by the code generation itself.
|
||||
class UniformCTypeMapper {
|
||||
public:
|
||||
UniformCTypeMapper(Layout::CType ctype,
|
||||
const std::vector<String>& skslTypes,
|
||||
const String& setUniformSingleFormat,
|
||||
const String& setUniformArrayFormat);
|
||||
UniformCTypeMapper(const char* setUniformTemplate) : fSetUniformTemplate(setUniformTemplate) {}
|
||||
|
||||
// Returns nullptr if the type and layout are not supported; the returned pointer's ownership
|
||||
// is not transfered to the caller.
|
||||
@ -46,16 +43,6 @@ public:
|
||||
return Get(context, variable.type(), variable.modifiers().fLayout);
|
||||
}
|
||||
|
||||
// The C++ type name that this mapper applies to
|
||||
Layout::CType ctype() const {
|
||||
return fCType;
|
||||
}
|
||||
|
||||
// The sksl type names that the mapper's ctype can be mapped to
|
||||
const std::vector<String>& supportedTypeNames() const {
|
||||
return fSKSLTypes;
|
||||
}
|
||||
|
||||
// Return a statement that invokes the appropriate setX method on the GrGLSLProgramDataManager
|
||||
// specified by pdmanName, where the uniform is provided by the expression stored in
|
||||
// uniformHandleName, and valueVarName is the variable name pointing to the ctype instance
|
||||
@ -65,22 +52,8 @@ public:
|
||||
String setUniform(const String& pdmanName, const String& uniformHandleName,
|
||||
const String& valueVarName) const;
|
||||
|
||||
// True if the setUniform() template only uses the value variable once in its expression. The
|
||||
// variable does not necessarily get inlined if this returns true, since a local variable may be
|
||||
// needed if state tracking is employed for a particular uniform.
|
||||
bool canInlineUniformValue() const {
|
||||
return fInlineValue;
|
||||
}
|
||||
|
||||
private:
|
||||
const UniformCTypeMapper* arrayMapper(int arrayCount) const;
|
||||
|
||||
Layout::CType fCType;
|
||||
int fArrayCount = -1;
|
||||
std::vector<String> fSKSLTypes;
|
||||
String fUniformSingleTemplate;
|
||||
String fUniformArrayTemplate;
|
||||
bool fInlineValue; // Cached value calculated from fUniformTemplate
|
||||
String fSetUniformTemplate;
|
||||
};
|
||||
|
||||
} // namespace SkSL
|
||||
|
@ -969,14 +969,10 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
||||
const UniformCTypeMapper* mapper = UniformCTypeMapper::Get(fContext, *u);
|
||||
SkASSERT(mapper);
|
||||
|
||||
String nameString(u->name());
|
||||
const char* name = nameString.c_str();
|
||||
|
||||
// Switches for setData behavior in the generated code
|
||||
bool conditionalUniform = u->modifiers().fLayout.fWhen != "";
|
||||
bool needsValueDeclaration = !mapper->canInlineUniformValue();
|
||||
|
||||
String uniformName = HCodeGenerator::FieldName(name) + "Var";
|
||||
String uniformName = u->name() + "Var";
|
||||
String valueVar = "_outer." + u->name();
|
||||
|
||||
String indent = " "; // 8 by default, 12 when nested for conditional uniforms
|
||||
if (conditionalUniform) {
|
||||
@ -986,20 +982,6 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
||||
indent += " ";
|
||||
}
|
||||
|
||||
String valueVar = "";
|
||||
if (needsValueDeclaration) {
|
||||
valueVar.appendf("%sValue", name);
|
||||
// Use AccessType since that will match the return type of _outer's public API.
|
||||
String valueType = HCodeGenerator::AccessType(fContext, u->type(),
|
||||
u->modifiers().fLayout);
|
||||
this->writef("%s%s %s = _outer.%s;\n",
|
||||
indent.c_str(), valueType.c_str(), valueVar.c_str(), name);
|
||||
} else {
|
||||
// The mapper only needs to use the value once so send it a safe expression instead
|
||||
// of the variable name
|
||||
valueVar.appendf("(_outer.%s)", name);
|
||||
}
|
||||
|
||||
this->writef("%s%s;\n",
|
||||
indent.c_str(), mapper->setUniform(pdman, uniformName, valueVar).c_str());
|
||||
|
||||
|
@ -1059,14 +1059,10 @@ void DSLCPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
||||
const UniformCTypeMapper* mapper = UniformCTypeMapper::Get(fContext, *u);
|
||||
SkASSERT(mapper);
|
||||
|
||||
String nameString(u->name());
|
||||
const char* name = nameString.c_str();
|
||||
|
||||
// Switches for setData behavior in the generated code
|
||||
bool conditionalUniform = u->modifiers().fLayout.fWhen != "";
|
||||
bool needsValueDeclaration = !mapper->canInlineUniformValue();
|
||||
|
||||
String uniformName = HCodeGenerator::FieldName(name) + "Var";
|
||||
String uniformName = u->name() + "Var";
|
||||
String valueVar = "_outer." + u->name();
|
||||
|
||||
String indent = " "; // 8 by default, 12 when nested for conditional uniforms
|
||||
if (conditionalUniform) {
|
||||
@ -1076,20 +1072,6 @@ void DSLCPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
||||
indent += " ";
|
||||
}
|
||||
|
||||
String valueVar = "";
|
||||
if (needsValueDeclaration) {
|
||||
valueVar.appendf("%sValue", name);
|
||||
// Use AccessType since that will match the return type of _outer's public API.
|
||||
String valueType = HCodeGenerator::AccessType(fContext, u->type(),
|
||||
u->modifiers().fLayout);
|
||||
this->writef("%s%s %s = _outer.%s;\n",
|
||||
indent.c_str(), valueType.c_str(), valueVar.c_str(), name);
|
||||
} else {
|
||||
// The mapper only needs to use the value once so send it a safe expression instead
|
||||
// of the variable name
|
||||
valueVar.appendf("(_outer.%s)", name);
|
||||
}
|
||||
|
||||
this->writef("%s%s;\n",
|
||||
indent.c_str(), mapper->setUniform(pdman, uniformName, valueVar).c_str());
|
||||
|
||||
|
@ -79,16 +79,16 @@ private:
|
||||
const GrDSLFPTest_Ternary& _outer = _proc.cast<GrDSLFPTest_Ternary>();
|
||||
{
|
||||
if (colorGreenVar.isValid()) {
|
||||
pdman.set4fv(colorGreenVar, 1, (_outer.colorGreen).vec());
|
||||
pdman.set4fv(colorGreenVar, 1, _outer.colorGreen.vec());
|
||||
}
|
||||
if (colorRedVar.isValid()) {
|
||||
pdman.set4fv(colorRedVar, 1, (_outer.colorRed).vec());
|
||||
pdman.set4fv(colorRedVar, 1, _outer.colorRed.vec());
|
||||
}
|
||||
if (colorOrangeVar.isValid()) {
|
||||
pdman.set4fv(colorOrangeVar, 1, (_outer.colorOrange).vec());
|
||||
pdman.set4fv(colorOrangeVar, 1, _outer.colorOrange.vec());
|
||||
}
|
||||
if (colorPurpleVar.isValid()) {
|
||||
pdman.set4fv(colorPurpleVar, 1, (_outer.colorPurple).vec());
|
||||
pdman.set4fv(colorPurpleVar, 1, _outer.colorPurple.vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ private:
|
||||
const GrConditionalInUniform& _outer = _proc.cast<GrConditionalInUniform>();
|
||||
{
|
||||
if (colorVar.isValid()) {
|
||||
pdman.set4fv(colorVar, 1, (_outer.color).vec());
|
||||
pdman.set4fv(colorVar, 1, _outer.color.vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
|
||||
const GrInUniform& _outer = _proc.cast<GrInUniform>();
|
||||
{
|
||||
pdman.set4fv(colorVar, 1, reinterpret_cast<const float*>(&(_outer.color)));
|
||||
pdman.set4fv(colorVar, 1, reinterpret_cast<const float*>(&_outer.color));
|
||||
}
|
||||
}
|
||||
UniformHandle colorVar;
|
||||
|
@ -31,7 +31,7 @@ private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
|
||||
const GrInUniformCType& _outer = _proc.cast<GrInUniformCType>();
|
||||
{
|
||||
pdman.set4fv(colorVar, 1, (_outer.color).vec());
|
||||
pdman.set4fv(colorVar, 1, _outer.color.vec());
|
||||
}
|
||||
}
|
||||
UniformHandle colorVar;
|
||||
|
@ -31,8 +31,7 @@ private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
|
||||
const GrNonInlinedInUniform& _outer = _proc.cast<GrNonInlinedInUniform>();
|
||||
{
|
||||
const SkPoint& pointValue = _outer.point;
|
||||
pdman.set2f(pointVar, pointValue.fX, pointValue.fY);
|
||||
pdman.set2f(pointVar, _outer.point.fX, _outer.point.fY);
|
||||
}
|
||||
}
|
||||
UniformHandle pointVar;
|
||||
|
Loading…
Reference in New Issue
Block a user