Add Graphite-only dehydrated modules.
Graphite code snippets can be moved into these files; they will be compiled once at build time and dehydrated for later use. This allows us to avoid synthesizing and compiling them in each shader where they are referenced. (Unfortunately, the GPU driver will still need to compile them each time.) Change-Id: I5cdc5881d71d7b81a02c91a84d52804f2909b483 Bug: skia:13110 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532259 Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
42de32a919
commit
d3ecfb3bb8
2
BUILD.gn
2
BUILD.gn
@ -634,6 +634,8 @@ if (skia_compile_modules || skia_compile_sksl_tests) {
|
||||
sources = [
|
||||
"src/sksl/sksl_frag.sksl",
|
||||
"src/sksl/sksl_gpu.sksl",
|
||||
"src/sksl/sksl_graphite_frag.sksl",
|
||||
"src/sksl/sksl_graphite_vert.sksl",
|
||||
"src/sksl/sksl_public.sksl",
|
||||
"src/sksl/sksl_rt_shader.sksl",
|
||||
"src/sksl/sksl_vert.sksl",
|
||||
|
@ -432,6 +432,17 @@ void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter* log) {
|
||||
bench("sksl_compiler_gpu", after - before);
|
||||
}
|
||||
|
||||
// Heap used by a compiler with the two main Graphite modules (fragment + vertex) loaded
|
||||
{
|
||||
int before = heap_bytes_used();
|
||||
GrShaderCaps caps;
|
||||
SkSL::Compiler compiler(&caps);
|
||||
compiler.moduleForProgramKind(SkSL::ProgramKind::kGraphiteVertex);
|
||||
compiler.moduleForProgramKind(SkSL::ProgramKind::kGraphiteFragment);
|
||||
int after = heap_bytes_used();
|
||||
bench("sksl_compiler_graphite", after - before);
|
||||
}
|
||||
|
||||
// Heap used by a compiler with the runtime shader, color filter and blending modules loaded
|
||||
{
|
||||
int before = heap_bytes_used();
|
||||
|
@ -14,8 +14,10 @@ targetDir = sys.argv[2]
|
||||
modules = sys.argv[3:]
|
||||
|
||||
dependencies = {
|
||||
'sksl_vert': ['sksl_gpu'],
|
||||
'sksl_frag': ['sksl_gpu'],
|
||||
'sksl_vert': ['sksl_gpu'],
|
||||
'sksl_graphite_frag': ['sksl_frag', 'sksl_gpu'],
|
||||
'sksl_graphite_vert': ['sksl_vert', 'sksl_gpu'],
|
||||
'sksl_rt_shader': ['sksl_public'],
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@ namespace SkSL {
|
||||
enum class ProgramKind : int8_t {
|
||||
kFragment,
|
||||
kVertex,
|
||||
kGraphiteFragment,
|
||||
kGraphiteVertex,
|
||||
kRuntimeColorFilter, // Runtime effect only suitable as SkColorFilter
|
||||
kRuntimeShader, // " " " " " SkShader
|
||||
kRuntimeBlender, // " " " " " SkBlender
|
||||
|
@ -507,7 +507,7 @@ sk_sp<MtlGraphicsPipeline> MtlGraphicsPipeline::Make(
|
||||
ShaderErrorHandler* errorHandler = DefaultShaderErrorHandler();
|
||||
if (!SkSLToMSL(gpu,
|
||||
get_sksl_vs(pipelineDesc),
|
||||
SkSL::ProgramKind::kVertex,
|
||||
SkSL::ProgramKind::kGraphiteVertex,
|
||||
settings,
|
||||
&msl[kVertex_ShaderType],
|
||||
&inputs[kVertex_ShaderType],
|
||||
@ -519,7 +519,7 @@ sk_sp<MtlGraphicsPipeline> MtlGraphicsPipeline::Make(
|
||||
auto dict = resourceProvider->shaderCodeDictionary();
|
||||
if (!SkSLToMSL(gpu,
|
||||
get_sksl_fs(dict, pipelineDesc, &blendInfo),
|
||||
SkSL::ProgramKind::kFragment,
|
||||
SkSL::ProgramKind::kGraphiteFragment,
|
||||
settings,
|
||||
&msl[kFragment_ShaderType],
|
||||
&inputs[kFragment_ShaderType],
|
||||
|
@ -9,6 +9,8 @@ filegroup(
|
||||
srcs = [
|
||||
"generated/sksl_frag.dehydrated.sksl",
|
||||
"generated/sksl_gpu.dehydrated.sksl",
|
||||
"generated/sksl_graphite_frag.dehydrated.sksl",
|
||||
"generated/sksl_graphite_vert.dehydrated.sksl",
|
||||
"generated/sksl_public.dehydrated.sksl",
|
||||
"generated/sksl_rt_shader.dehydrated.sksl",
|
||||
"generated/sksl_vert.dehydrated.sksl",
|
||||
|
@ -70,6 +70,8 @@
|
||||
|
||||
// At runtime, we load the dehydrated sksl data files. The data is a (pointer, size) pair.
|
||||
#include "src/sksl/generated/sksl_frag.dehydrated.sksl"
|
||||
#include "src/sksl/generated/sksl_graphite_frag.dehydrated.sksl"
|
||||
#include "src/sksl/generated/sksl_graphite_vert.dehydrated.sksl"
|
||||
#include "src/sksl/generated/sksl_gpu.dehydrated.sksl"
|
||||
#include "src/sksl/generated/sksl_public.dehydrated.sksl"
|
||||
#include "src/sksl/generated/sksl_rt_shader.dehydrated.sksl"
|
||||
@ -259,6 +261,24 @@ const ParsedModule& Compiler::loadVertexModule() {
|
||||
return fVertexModule;
|
||||
}
|
||||
|
||||
const ParsedModule& Compiler::loadGraphiteFragmentModule() {
|
||||
if (!fGraphiteFragmentModule.fSymbols) {
|
||||
fGraphiteFragmentModule = this->parseModule(ProgramKind::kGraphiteFragment,
|
||||
MODULE_DATA(graphite_frag),
|
||||
this->loadFragmentModule());
|
||||
}
|
||||
return fGraphiteFragmentModule;
|
||||
}
|
||||
|
||||
const ParsedModule& Compiler::loadGraphiteVertexModule() {
|
||||
if (!fGraphiteVertexModule.fSymbols) {
|
||||
fGraphiteVertexModule = this->parseModule(ProgramKind::kGraphiteVertex,
|
||||
MODULE_DATA(graphite_vert),
|
||||
this->loadVertexModule());
|
||||
}
|
||||
return fGraphiteVertexModule;
|
||||
}
|
||||
|
||||
static void add_glsl_type_aliases(SkSL::SymbolTable* symbols, const SkSL::BuiltinTypes& types) {
|
||||
// Add some aliases to the runtime effect modules so that it's friendlier, and more like GLSL.
|
||||
symbols->addWithoutOwnership(types.fVec2.get());
|
||||
@ -318,14 +338,16 @@ const ParsedModule& Compiler::loadRuntimeShaderModule() {
|
||||
|
||||
const ParsedModule& Compiler::moduleForProgramKind(ProgramKind kind) {
|
||||
switch (kind) {
|
||||
case ProgramKind::kVertex: return this->loadVertexModule(); break;
|
||||
case ProgramKind::kFragment: return this->loadFragmentModule(); break;
|
||||
case ProgramKind::kRuntimeColorFilter: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kRuntimeShader: return this->loadRuntimeShaderModule(); break;
|
||||
case ProgramKind::kRuntimeBlender: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kCustomMeshVertex: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kCustomMeshFragment: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kGeneric: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kVertex: return this->loadVertexModule(); break;
|
||||
case ProgramKind::kFragment: return this->loadFragmentModule(); break;
|
||||
case ProgramKind::kGraphiteVertex: return this->loadGraphiteVertexModule(); break;
|
||||
case ProgramKind::kGraphiteFragment: return this->loadGraphiteFragmentModule(); break;
|
||||
case ProgramKind::kRuntimeColorFilter: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kRuntimeShader: return this->loadRuntimeShaderModule(); break;
|
||||
case ProgramKind::kRuntimeBlender: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kCustomMeshVertex: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kCustomMeshFragment: return this->loadPublicModule(); break;
|
||||
case ProgramKind::kGeneric: return this->loadPublicModule(); break;
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
@ -235,6 +235,8 @@ private:
|
||||
const ParsedModule& loadGPUModule();
|
||||
const ParsedModule& loadFragmentModule();
|
||||
const ParsedModule& loadVertexModule();
|
||||
const ParsedModule& loadGraphiteFragmentModule();
|
||||
const ParsedModule& loadGraphiteVertexModule();
|
||||
const ParsedModule& loadPublicModule();
|
||||
const ParsedModule& loadRuntimeShaderModule();
|
||||
|
||||
@ -265,6 +267,8 @@ private:
|
||||
ParsedModule fGPUModule; // [Private] + GPU intrinsics, helper functions
|
||||
ParsedModule fVertexModule; // [GPU] + Vertex stage decls
|
||||
ParsedModule fFragmentModule; // [GPU] + Fragment stage decls
|
||||
ParsedModule fGraphiteVertexModule; // [Vert] + Graphite vertex helpers
|
||||
ParsedModule fGraphiteFragmentModule; // [Frag] + Graphite fragment helpers
|
||||
|
||||
ParsedModule fPublicModule; // [Root] + Public features
|
||||
ParsedModule fRuntimeShaderModule; // [Public] + Runtime shader decls
|
||||
|
@ -105,11 +105,13 @@ struct ProgramConfig {
|
||||
}
|
||||
|
||||
static bool IsFragment(ProgramKind kind) {
|
||||
return kind == ProgramKind::kFragment;
|
||||
return kind == ProgramKind::kFragment ||
|
||||
kind == ProgramKind::kGraphiteFragment;
|
||||
}
|
||||
|
||||
static bool IsVertex(ProgramKind kind) {
|
||||
return kind == ProgramKind::kVertex;
|
||||
return kind == ProgramKind::kVertex ||
|
||||
kind == ProgramKind::kGraphiteVertex;
|
||||
}
|
||||
|
||||
static bool IsRuntimeEffect(ProgramKind kind) {
|
||||
|
5
src/sksl/generated/sksl_graphite_frag.dehydrated.sksl
Normal file
5
src/sksl/generated/sksl_graphite_frag.dehydrated.sksl
Normal file
@ -0,0 +1,5 @@
|
||||
static uint8_t SKSL_INCLUDE_sksl_graphite_frag[] = {10,0,0,0,
|
||||
52,1,0,0,0,0,
|
||||
20,
|
||||
21,};
|
||||
static constexpr size_t SKSL_INCLUDE_sksl_graphite_frag_LENGTH = sizeof(SKSL_INCLUDE_sksl_graphite_frag);
|
5
src/sksl/generated/sksl_graphite_vert.dehydrated.sksl
Normal file
5
src/sksl/generated/sksl_graphite_vert.dehydrated.sksl
Normal file
@ -0,0 +1,5 @@
|
||||
static uint8_t SKSL_INCLUDE_sksl_graphite_vert[] = {10,0,0,0,
|
||||
52,1,0,0,0,0,
|
||||
20,
|
||||
21,};
|
||||
static constexpr size_t SKSL_INCLUDE_sksl_graphite_vert_LENGTH = sizeof(SKSL_INCLUDE_sksl_graphite_vert);
|
@ -259,7 +259,8 @@ static bool check_main_signature(const Context& context, Position pos, const Typ
|
||||
case ProgramKind::kGeneric:
|
||||
// No rules apply here
|
||||
break;
|
||||
case ProgramKind::kFragment: {
|
||||
case ProgramKind::kFragment:
|
||||
case ProgramKind::kGraphiteFragment: {
|
||||
bool validParams = (parameters.size() == 0) ||
|
||||
(parameters.size() == 1 && paramIsCoords(0));
|
||||
if (!validParams) {
|
||||
@ -269,6 +270,7 @@ static bool check_main_signature(const Context& context, Position pos, const Typ
|
||||
break;
|
||||
}
|
||||
case ProgramKind::kVertex:
|
||||
case ProgramKind::kGraphiteVertex:
|
||||
if (parameters.size()) {
|
||||
errors.error(pos, "shader 'main' must have zero parameters");
|
||||
return false;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// defines built-in interfaces supported by SkiaSL fragment shaders
|
||||
// defines built-in interfaces supported by SkSL fragment shaders
|
||||
|
||||
// See "enum SpvBuiltIn_" in ./spirv.h
|
||||
layout(builtin=15) in float4 sk_FragCoord;
|
||||
|
1
src/sksl/sksl_graphite_frag.sksl
Normal file
1
src/sksl/sksl_graphite_frag.sksl
Normal file
@ -0,0 +1 @@
|
||||
// Graphite-specific fragment shader code
|
1
src/sksl/sksl_graphite_vert.sksl
Normal file
1
src/sksl/sksl_graphite_vert.sksl
Normal file
@ -0,0 +1 @@
|
||||
// Graphite-specific vertex shader code
|
@ -1,4 +1,4 @@
|
||||
// defines built-in interfaces supported by SkiaSL vertex shaders
|
||||
// defines built-in interfaces supported by SkSL vertex shaders
|
||||
|
||||
out sk_PerVertex {
|
||||
layout(builtin=0) float4 sk_Position;
|
||||
|
Loading…
Reference in New Issue
Block a user