-
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
23 changed files
with
331 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Wasm Test", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/packages/wasm/c++/build_test/src/sksl-wasm-lib-test", | ||
"args": [], | ||
"stopAtEntry": false, | ||
"cwd": "${workspaceFolder}/packages/wasm/c++/build_test/src", | ||
"environment": [], | ||
"externalConsole": false, | ||
"MIMode": "lldb" | ||
} | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"name": "@workspace/float", | ||
"version": "1.0.0", | ||
"author": "seven332", | ||
"license": "MIT", | ||
"main": "src/float.ts" | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export const kQueryUrl = 'sksl/query' | ||
export const kRunUrl = 'sksl/run' |
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
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,84 @@ | ||
#include "runner/run.h" | ||
|
||
#include <include/core/SkStream.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/SkSLProgram.h> | ||
#include <src/sksl/tracing/SkSLDebugTracePlayer.h> | ||
#include <src/sksl/tracing/SkSLDebugTracePriv.h> | ||
|
||
#include <string> | ||
|
||
#include "data.h" | ||
#include "kind.h" | ||
|
||
static std::unique_ptr<SkSL::Program> CompileProgram(std::string source) { | ||
auto kind_result = GetKind(source); | ||
if (!kind_result) { | ||
return nullptr; | ||
} | ||
|
||
auto kind = ToSkSLProgramKind(kind_result->str); | ||
if (!kind) { | ||
return nullptr; | ||
} | ||
|
||
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(); | ||
} | ||
|
||
RunResult Run(RunParams params) { | ||
RunResult result; | ||
|
||
auto program = CompileProgram(std::move(params.source)); | ||
if (!program) { | ||
return result; | ||
} | ||
|
||
const auto* function = program->getFunction("main"); | ||
if (!function) { | ||
return result; | ||
} | ||
|
||
auto trace = sk_make_sp<SkSL::DebugTracePriv>(); | ||
std::unique_ptr<SkSL::RP::Program> raster_program = | ||
SkSL::MakeRasterPipelineProgram(*program, *function->definition(), trace.get(), true); | ||
if (!raster_program) { | ||
return result; | ||
} | ||
|
||
static constexpr auto kFirstHeapAllocation = 4096; | ||
SkArenaAlloc alloc(kFirstHeapAllocation); | ||
SkRasterPipeline pipeline(&alloc); | ||
// TODO: values | ||
raster_program->appendStages(&pipeline, &alloc, nullptr, {}); | ||
|
||
SkRGBA4f<SkAlphaType::kPremul_SkAlphaType> out {}; | ||
SkRasterPipeline_MemoryCtx out_ctx = {&out, 0}; | ||
pipeline.append(SkRasterPipelineOp::store_f32, &out_ctx); | ||
pipeline.run(0, 0, 1, 1); | ||
|
||
result.succeed = true; | ||
auto unpremul = out.unpremul(); | ||
result.color = SkSLColor { | ||
.r = unpremul.fR, | ||
.g = unpremul.fG, | ||
.b = unpremul.fB, | ||
.a = unpremul.fA, | ||
}; | ||
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 RunParams { | ||
std::string source; | ||
std::vector<std::string> values; | ||
|
||
friend std::size_t Read(std::span<const std::byte> bytes, std::size_t offset, RunParams* value) { | ||
std::size_t read = 0; | ||
read += Read(bytes, offset + read, &value->source); | ||
read += Read(bytes, offset + read, &value->values); | ||
return read; | ||
} | ||
}; | ||
|
||
struct RunResult { | ||
bool succeed = false; | ||
SkSLColor color {}; | ||
|
||
friend void Write(std::vector<std::byte>* bytes, const RunResult& value) { | ||
Write(bytes, value.succeed); | ||
Write(bytes, value.color); | ||
} | ||
}; | ||
|
||
RunResult Run(RunParams params); |
Oops, something went wrong.