Revert "When converting runtime SkSL to FP SkSL, use default settings"
This reverts commit 48fcf36e15
.
Reason for revert: causing shader compiler errors in sksl
Original change's description:
> When converting runtime SkSL to FP SkSL, use default settings
>
> Anything related to caps should be resolved in the second compile.
> However, when calling toPipelineStage, the settings stored in the
> base Program are used, so we need to inject them at that point.
>
> This also removes the cache of specialized programs. We only hit
> that code path when we're about to do a full compile, including
> generating SkSL, turning that into GLSL, etc. The specialization
> is implicitly cached as part of the entire program for common
> cases, so the second level isn't that useful.
>
> Change-Id: I53bc54b0611951e1d97278d59881308c6b152090
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259162
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
TBR=bsalomon@google.com,brianosman@google.com,ethannicholas@google.com
Change-Id: I73e81f2dbacb329da819555c949f5c5ea32b7fda
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259429
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
ef957a5643
commit
f4107946e4
@ -73,7 +73,7 @@ protected:
|
||||
SkASSERT(caps && !FPFactoryCache);
|
||||
SkASSERT(!fThreadSafeProxy);
|
||||
|
||||
FPFactoryCache.reset(new GrSkSLFPFactoryCache());
|
||||
FPFactoryCache.reset(new GrSkSLFPFactoryCache(caps->refShaderCaps()));
|
||||
fThreadSafeProxy = GrContextThreadSafeProxyPriv::Make(this->backend(),
|
||||
this->options(),
|
||||
this->contextID(),
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
#include "include/core/SkRefCnt.h"
|
||||
|
||||
class GrShaderCaps;
|
||||
class GrSkSLFPFactory;
|
||||
|
||||
// This is a cache used by GrSkSLFP to retain GrSkSLFPFactory instances, so we don't have to
|
||||
@ -20,6 +21,7 @@ class GrSkSLFPFactory;
|
||||
// onGetGLSLProcessorKey.
|
||||
class GrSkSLFPFactoryCache : public SkNVRefCnt<GrSkSLFPFactoryCache> {
|
||||
public:
|
||||
GrSkSLFPFactoryCache(sk_sp<const GrShaderCaps> shaderCaps) : fShaderCaps(shaderCaps) {}
|
||||
~GrSkSLFPFactoryCache();
|
||||
|
||||
sk_sp<GrSkSLFPFactory> findOrCreate(int index, const char* name, const char* skSL);
|
||||
@ -35,6 +37,7 @@ private:
|
||||
mutable SkMutex fCacheMutex;
|
||||
|
||||
std::vector<sk_sp<GrSkSLFPFactory>> fFactories;
|
||||
sk_sp<const GrShaderCaps> fShaderCaps;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -18,9 +18,10 @@
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
|
||||
|
||||
GrSkSLFPFactory::GrSkSLFPFactory(const char* name, const char* sksl)
|
||||
GrSkSLFPFactory::GrSkSLFPFactory(const char* name, const GrShaderCaps* shaderCaps, const char* sksl)
|
||||
: fName(name) {
|
||||
SkSL::Program::Settings settings;
|
||||
settings.fCaps = shaderCaps;
|
||||
fBaseProgram = fCompiler.convertProgram(SkSL::Program::kPipelineStage_Kind,
|
||||
SkSL::String(sksl), settings);
|
||||
if (fCompiler.errorCount()) {
|
||||
@ -57,8 +58,13 @@ static std::tuple<const SkSL::Type*, int> strip_array(const SkSL::Type* type) {
|
||||
return std::make_tuple(type, arrayCount);
|
||||
}
|
||||
|
||||
std::unique_ptr<SkSL::Program> GrSkSLFPFactory::getSpecialization(const void* inputs,
|
||||
size_t inputSize) {
|
||||
const SkSL::Program* GrSkSLFPFactory::getSpecialization(const SkSL::String& key, const void* inputs,
|
||||
size_t inputSize) {
|
||||
const auto& found = fSpecializations.find(key);
|
||||
if (found != fSpecializations.end()) {
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
std::unordered_map<SkSL::String, SkSL::Program::Settings::Value> inputMap;
|
||||
size_t offset = 0;
|
||||
for (const auto& v : fInAndUniformVars) {
|
||||
@ -110,7 +116,9 @@ std::unique_ptr<SkSL::Program> GrSkSLFPFactory::getSpecialization(const void* in
|
||||
SkDebugf("%s\n", fCompiler.errorText().c_str());
|
||||
SkASSERT(false);
|
||||
}
|
||||
return specialized;
|
||||
const SkSL::Program* result = specialized.get();
|
||||
fSpecializations.insert(std::make_pair(key, std::move(specialized)));
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::tuple<SkSL::Layout::CType, int> get_ctype(const SkSL::Context& context,
|
||||
@ -372,7 +380,6 @@ std::unique_ptr<GrSkSLFP> GrSkSLFP::Make(GrContext_Base* context, int index, con
|
||||
const char* sksl, const void* inputs, size_t inputSize,
|
||||
const SkMatrix* matrix) {
|
||||
return std::unique_ptr<GrSkSLFP>(new GrSkSLFP(context->priv().fpFactoryCache(),
|
||||
context->priv().caps()->refShaderCaps(),
|
||||
index, name, sksl, SkString(),
|
||||
inputs, inputSize, matrix));
|
||||
}
|
||||
@ -381,18 +388,16 @@ std::unique_ptr<GrSkSLFP> GrSkSLFP::Make(GrContext_Base* context, int index, con
|
||||
SkString sksl, const void* inputs, size_t inputSize,
|
||||
const SkMatrix* matrix) {
|
||||
return std::unique_ptr<GrSkSLFP>(new GrSkSLFP(context->priv().fpFactoryCache(),
|
||||
context->priv().caps()->refShaderCaps(),
|
||||
index, name, nullptr, std::move(sksl),
|
||||
inputs, inputSize, matrix));
|
||||
}
|
||||
|
||||
GrSkSLFP::GrSkSLFP(sk_sp<GrSkSLFPFactoryCache> factoryCache, sk_sp<const GrShaderCaps> shaderCaps,
|
||||
GrSkSLFP::GrSkSLFP(sk_sp<GrSkSLFPFactoryCache> factoryCache,
|
||||
int index, const char* name, const char* sksl,
|
||||
SkString skslString, const void* inputs, size_t inputSize,
|
||||
const SkMatrix* matrix)
|
||||
: INHERITED(kGrSkSLFP_ClassID, kNone_OptimizationFlags)
|
||||
, fFactoryCache(factoryCache)
|
||||
, fShaderCaps(std::move(shaderCaps))
|
||||
, fIndex(index)
|
||||
, fName(name)
|
||||
, fSkSLString(skslString)
|
||||
@ -411,7 +416,6 @@ GrSkSLFP::GrSkSLFP(sk_sp<GrSkSLFPFactoryCache> factoryCache, sk_sp<const GrShade
|
||||
GrSkSLFP::GrSkSLFP(const GrSkSLFP& other)
|
||||
: INHERITED(kGrSkSLFP_ClassID, kNone_OptimizationFlags)
|
||||
, fFactoryCache(other.fFactoryCache)
|
||||
, fShaderCaps(other.fShaderCaps)
|
||||
, fFactory(other.fFactory)
|
||||
, fIndex(other.fIndex)
|
||||
, fName(other.fName)
|
||||
@ -444,9 +448,7 @@ void GrSkSLFP::addChild(std::unique_ptr<GrFragmentProcessor> child) {
|
||||
|
||||
GrGLSLFragmentProcessor* GrSkSLFP::onCreateGLSLInstance() const {
|
||||
this->createFactory();
|
||||
auto specialized = fFactory->getSpecialization(fInputs.get(), fInputSize);
|
||||
specialized->fSettings.fCaps = fShaderCaps.get();
|
||||
|
||||
const SkSL::Program* specialized = fFactory->getSpecialization(fKey, fInputs.get(), fInputSize);
|
||||
SkSL::String glsl;
|
||||
std::vector<SkSL::Compiler::FormatArg> formatArgs;
|
||||
std::vector<SkSL::Compiler::GLSLFunction> functions;
|
||||
@ -458,6 +460,19 @@ GrGLSLFragmentProcessor* GrSkSLFP::onCreateGLSLInstance() const {
|
||||
formatArgs, functions);
|
||||
}
|
||||
|
||||
static void copy_floats_key(char* inputs, GrProcessorKeyBuilder* b, bool isIn, int count,
|
||||
size_t* offset, SkSL::String* key) {
|
||||
if (isIn) {
|
||||
for (size_t i = 0; i < sizeof(float) * count; ++i) {
|
||||
(*key) += inputs[*offset + i];
|
||||
b->add32(*(int32_t*) (inputs + *offset));
|
||||
(*offset) += sizeof(float);
|
||||
}
|
||||
} else {
|
||||
(*offset) += sizeof(float) * count;
|
||||
}
|
||||
}
|
||||
|
||||
void GrSkSLFP::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
GrProcessorKeyBuilder* b) const {
|
||||
this->createFactory();
|
||||
@ -474,6 +489,7 @@ void GrSkSLFP::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
switch (ctype) {
|
||||
case SkSL::Layout::CType::kBool:
|
||||
if (v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag) {
|
||||
fKey += inputs[offset];
|
||||
b->add32(inputs[offset]);
|
||||
}
|
||||
++offset;
|
||||
@ -481,6 +497,10 @@ void GrSkSLFP::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
case SkSL::Layout::CType::kInt32: {
|
||||
offset = SkAlign4(offset);
|
||||
if (v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag) {
|
||||
fKey += inputs[offset + 0];
|
||||
fKey += inputs[offset + 1];
|
||||
fKey += inputs[offset + 2];
|
||||
fKey += inputs[offset + 3];
|
||||
b->add32(*(int32_t*)(inputs + offset));
|
||||
}
|
||||
offset += sizeof(int32_t);
|
||||
@ -489,33 +509,28 @@ void GrSkSLFP::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
case SkSL::Layout::CType::kFloat: {
|
||||
offset = SkAlign4(offset);
|
||||
if (v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag) {
|
||||
fKey += inputs[offset + 0];
|
||||
fKey += inputs[offset + 1];
|
||||
fKey += inputs[offset + 2];
|
||||
fKey += inputs[offset + 3];
|
||||
b->add32(*(float*)(inputs + offset));
|
||||
}
|
||||
offset += sizeof(float);
|
||||
break;
|
||||
}
|
||||
case SkSL::Layout::CType::kFloat2:
|
||||
offset = SkAlign4(offset);
|
||||
if (v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag) {
|
||||
memcpy(b->add32n(2), inputs + offset, 2 * sizeof(float));
|
||||
}
|
||||
offset += 2 * sizeof(float);
|
||||
copy_floats_key(inputs, b, v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag, 2,
|
||||
&offset, &fKey);
|
||||
break;
|
||||
case SkSL::Layout::CType::kFloat3:
|
||||
offset = SkAlign4(offset);
|
||||
if (v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag) {
|
||||
memcpy(b->add32n(3), inputs + offset, 3 * sizeof(float));
|
||||
}
|
||||
offset += 3 * sizeof(float);
|
||||
copy_floats_key(inputs, b, v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag, 3,
|
||||
&offset, &fKey);
|
||||
break;
|
||||
case SkSL::Layout::CType::kSkPMColor:
|
||||
case SkSL::Layout::CType::kSkPMColor4f:
|
||||
case SkSL::Layout::CType::kSkRect:
|
||||
offset = SkAlign4(offset);
|
||||
if (v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag) {
|
||||
memcpy(b->add32n(4), inputs + offset, 4 * sizeof(float));
|
||||
}
|
||||
offset += 4 * sizeof(float);
|
||||
copy_floats_key(inputs, b, v->fModifiers.fFlags & SkSL::Modifiers::kIn_Flag, 4,
|
||||
&offset, &fKey);
|
||||
break;
|
||||
default:
|
||||
// unsupported input var type
|
||||
@ -551,7 +566,7 @@ sk_sp<GrSkSLFPFactory> GrSkSLFPFactoryCache::findOrCreate(int index, const char*
|
||||
|
||||
sk_sp<GrSkSLFPFactory> factory = this->get(index);
|
||||
if (!factory) {
|
||||
factory = sk_sp<GrSkSLFPFactory>(new GrSkSLFPFactory(name, skSL));
|
||||
factory = sk_sp<GrSkSLFPFactory>(new GrSkSLFPFactory(name, fShaderCaps.get(), skSL));
|
||||
this->set(index, factory);
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public:
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
|
||||
private:
|
||||
GrSkSLFP(sk_sp<GrSkSLFPFactoryCache> factoryCache, sk_sp<const GrShaderCaps> shaderCaps,
|
||||
GrSkSLFP(sk_sp<GrSkSLFPFactoryCache> factoryCache,
|
||||
int fIndex, const char* name, const char* sksl,
|
||||
SkString skslString, const void* inputs, size_t inputSize, const SkMatrix* matrix);
|
||||
|
||||
@ -125,7 +125,6 @@ private:
|
||||
void createFactory() const;
|
||||
|
||||
sk_sp<GrSkSLFPFactoryCache> fFactoryCache;
|
||||
sk_sp<const GrShaderCaps> fShaderCaps;
|
||||
|
||||
mutable sk_sp<GrSkSLFPFactory> fFactory;
|
||||
|
||||
@ -149,6 +148,8 @@ private:
|
||||
|
||||
GrCoordTransform fCoordTransform;
|
||||
|
||||
mutable SkSL::String fKey;
|
||||
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
|
||||
typedef GrFragmentProcessor INHERITED;
|
||||
@ -171,9 +172,10 @@ public:
|
||||
* the produced shaders to differ), so it is important to reuse the same factory instance for
|
||||
* the same shader in order to avoid repeatedly re-parsing the SkSL.
|
||||
*/
|
||||
GrSkSLFPFactory(const char* name, const char* sksl);
|
||||
GrSkSLFPFactory(const char* name, const GrShaderCaps* shaderCaps, const char* sksl);
|
||||
|
||||
std::unique_ptr<SkSL::Program> getSpecialization(const void* inputs, size_t inputSize);
|
||||
const SkSL::Program* getSpecialization(const SkSL::String& key, const void* inputs,
|
||||
size_t inputSize);
|
||||
|
||||
const char* fName;
|
||||
|
||||
@ -183,6 +185,8 @@ public:
|
||||
|
||||
std::vector<const SkSL::Variable*> fInAndUniformVars;
|
||||
|
||||
std::unordered_map<SkSL::String, std::unique_ptr<const SkSL::Program>> fSpecializations;
|
||||
|
||||
friend class GrSkSLFP;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user