blob: 3eb6fa2e7d28572ba2c211dace2677db5c20a0c6 [file] [log] [blame]
/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "experimental/graphite/include/Context.h"
#include "experimental/graphite/src/Caps.h"
#include "experimental/graphite/src/CommandBuffer.h"
#include "experimental/graphite/src/ContextUtils.h"
#include "experimental/graphite/src/Gpu.h"
#include "experimental/graphite/src/ProgramCache.h"
#include "experimental/graphite/src/Recorder.h"
#include "experimental/graphite/src/Recording.h"
#ifdef SK_METAL
#include "experimental/graphite/src/mtl/MtlTrampoline.h"
#endif
namespace skgpu {
Context::Context(sk_sp<Gpu> gpu) : fGpu(std::move(gpu)) {}
Context::~Context() {}
#ifdef SK_METAL
sk_sp<Context> Context::MakeMetal(const mtl::BackendContext& backendContext) {
sk_sp<Gpu> gpu = mtl::Trampoline::MakeGpu(backendContext);
if (!gpu) {
return nullptr;
}
return sk_sp<Context>(new Context(std::move(gpu)));
}
#endif
sk_sp<Recorder> Context::createRecorder() {
return sk_make_sp<Recorder>(sk_ref_sp(this));
}
void Context::insertRecording(std::unique_ptr<Recording> recording) {
fRecordings.emplace_back(std::move(recording));
}
void Context::submit(SyncToCpu syncToCpu) {
// TODO: we want Gpu::submit to take an array of command buffers but, for now, it just takes
// one. Once we have more than one recording queued up we will need to extract the
// command buffers and submit them as a block.
SkASSERT(fRecordings.size() == 1);
fGpu->submit(fRecordings[0]->fCommandBuffer);
fGpu->checkForFinishedWork(syncToCpu);
fRecordings.clear();
}
void Context::preCompile(const PaintCombo& paintCombo) {
ProgramCache cache;
for (auto bm: paintCombo.fBlendModes) {
for (auto& shaderCombo: paintCombo.fShaders) {
for (auto shaderType: shaderCombo.fTypes) {
for (auto tm: shaderCombo.fTileModes) {
Combination c {shaderType, tm, bm};
sk_sp<ProgramCache::ProgramInfo> pi = cache.findOrCreateProgram(c);
// TODO: this should be getSkSL
// TODO: it should also return the uniform information
std::string msl = pi->getMSL();
// TODO: compile the MSL and store the result back into the ProgramInfo
// To do this we will need the path rendering options from Chris and
// a stock set of RenderPasses.
}
}
}
}
}
} // namespace skgpu