-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
198 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const kQueryUrl = 'sksl/query' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './runner-data' | ||
export * from './sksl-server' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export interface QueryParams { | ||
source: string | ||
} | ||
|
||
export interface SkSLUniform { | ||
type: string | ||
name: string | ||
} | ||
|
||
export const dummySkSLUniform: SkSLUniform = { | ||
type: '', | ||
name: '', | ||
} | ||
|
||
export interface QueryResult { | ||
succeed: boolean | ||
kind: string | ||
uniforms: SkSLUniform[] | ||
} | ||
|
||
export const dummyQueryResult: QueryResult = { | ||
succeed: false, | ||
kind: '', | ||
uniforms: [dummySkSLUniform], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "runner/query.h" | ||
|
||
#include <src/core/SkRasterPipeline.h> | ||
#include <src/sksl/SkSLCompiler.h> | ||
#include <src/sksl/SkSLParser.h> | ||
#include <src/sksl/SkSLProgramSettings.h> | ||
#include <src/sksl/SkSLUtil.h> | ||
#include <src/sksl/codegen/SkSLRasterPipelineBuilder.h> | ||
#include <src/sksl/codegen/SkSLRasterPipelineCodeGenerator.h> | ||
#include <src/sksl/ir/SkSLFunctionDeclaration.h> | ||
#include <src/sksl/ir/SkSLIRNode.h> | ||
#include <src/sksl/ir/SkSLProgram.h> | ||
#include <src/sksl/ir/SkSLVarDeclarations.h> | ||
|
||
#include <optional> | ||
|
||
#include "kind.h" | ||
|
||
static std::unique_ptr<SkSL::Program> CompileProgram(std::string source, SkSL::ProgramKind kind) { | ||
SkSL::Compiler compiler(SkSL::ShaderCapsFactory::Standalone()); | ||
SkSL::ProgramSettings settings; | ||
settings.fUseMemoryPool = false; | ||
settings.fOptimize = false; | ||
settings.fForceNoInline = true; | ||
if (SkSL::ProgramConfig::IsRuntimeEffect(kind)) { | ||
settings.fAllowNarrowingConversions = true; | ||
} | ||
SkSL::Parser parser(&compiler, settings, kind, std::move(source)); | ||
return parser.program(); | ||
} | ||
|
||
QueryResult Query(QueryParams params) { | ||
QueryResult result; | ||
|
||
auto kind_result = GetKind(params.source); | ||
if (!kind_result) { | ||
return result; | ||
} | ||
|
||
auto kind = ToSkSLProgramKind(kind_result->str); | ||
if (!kind) { | ||
return result; | ||
} | ||
|
||
auto program = CompileProgram(std::move(params.source), *kind); | ||
if (!kind) { | ||
return result; | ||
} | ||
|
||
result.succeed = true; | ||
result.kind = kind_result->str; | ||
for (const auto& element : program->fOwnedElements) { | ||
if (element->kind() == SkSL::ProgramElementKind::kGlobalVar) { | ||
auto* var = element->as<SkSL::GlobalVarDeclaration>().varDeclaration().var(); | ||
if (var->modifierFlags().isUniform()) { | ||
result.uniforms.push_back(SkSLUniform {var->type().abbreviatedName(), std::string(var->name())}); | ||
} | ||
} | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "data.h" | ||
#include "simple_codec.h" | ||
|
||
struct QueryParams { | ||
std::string source; | ||
|
||
friend std::size_t Read(std::span<const std::byte> bytes, std::size_t offset, QueryParams* value) { | ||
std::size_t read = 0; | ||
read += Read(bytes, offset + read, &value->source); | ||
return read; | ||
} | ||
}; | ||
|
||
struct QueryResult { | ||
bool succeed = false; | ||
std::string kind; | ||
std::vector<SkSLUniform> uniforms; | ||
|
||
friend void Write(std::vector<std::byte>* bytes, const QueryResult& value) { | ||
Write(bytes, value.succeed); | ||
Write(bytes, value.kind); | ||
Write(bytes, value.uniforms); | ||
} | ||
}; | ||
|
||
QueryResult Query(QueryParams params); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters