28 bool isValid()
const {
return static_cast<bool>(
fModule); }
31static ShaderInfo compile_shader_module(
const DawnSharedContext* sharedContext,
32 const ComputePipelineDesc& pipelineDesc) {
37 const Caps* caps = sharedContext->caps();
39 ShaderErrorHandler* errorHandler = caps->shaderErrorHandler();
41 if (
step->supportsNativeShader()) {
45 std::string(nativeShader.fSource),
50 info.fEntryPoint = std::move(nativeShader.fEntryPoint);
65 &
info.fModule, errorHandler)) {
68 info.fEntryPoint =
"main";
79 auto [shaderModule, entryPointName] = compile_shader_module(
sharedContext, pipelineDesc);
93 std::vector<wgpu::BindGroupLayoutEntry> bindGroupLayoutEntries;
94 auto resources =
step->resources();
97 size_t resourceCount = 0;
105 bindGroupLayoutEntries.reserve(resourceCount);
106 int declarationIndex = 0;
108 bindGroupLayoutEntries.emplace_back();
109 uint32_t bindingIndex = bindGroupLayoutEntries.size() - 1;
111 wgpu::BindGroupLayoutEntry& entry = bindGroupLayoutEntries.back();
112 entry.binding = bindingIndex;
113 entry.visibility = wgpu::ShaderStage::Compute;
120 entry.buffer.type = wgpu::BufferBindingType::Storage;
123 entry.buffer.type = wgpu::BufferBindingType::ReadOnlyStorage;
126 entry.texture.sampleType = wgpu::TextureSampleType::Float;
127 entry.texture.viewDimension = wgpu::TextureViewDimension::e2D;
130 entry.storageTexture.access = wgpu::StorageTextureAccess::WriteOnly;
131 entry.storageTexture.viewDimension = wgpu::TextureViewDimension::e2D;
133 auto [_,
colorType] =
step->calculateTextureParameters(declarationIndex, r);
135 entry.storageTexture.format = textureInfo.dawnTextureSpec().getViewFormat();
139 entry.sampler.type = wgpu::SamplerBindingType::Filtering;
142 bindGroupLayoutEntries.emplace_back();
143 wgpu::BindGroupLayoutEntry& texEntry = bindGroupLayoutEntries.back();
144 texEntry.binding = bindingIndex + 1;
145 texEntry.visibility = wgpu::ShaderStage::Compute;
146 texEntry.texture.sampleType = wgpu::TextureSampleType::Float;
147 texEntry.texture.viewDimension = wgpu::TextureViewDimension::e2D;
157 wgpu::BindGroupLayoutDescriptor bindGroupLayoutDesc;
158 bindGroupLayoutDesc.entryCount = bindGroupLayoutEntries.size();
159 bindGroupLayoutDesc.entries = bindGroupLayoutEntries.data();
160 wgpu::BindGroupLayout bindGroupLayout =
device.CreateBindGroupLayout(&bindGroupLayoutDesc);
161 if (!bindGroupLayout) {
165 wgpu::PipelineLayoutDescriptor pipelineLayoutDesc;
167 pipelineLayoutDesc.label =
step->name();
169 pipelineLayoutDesc.bindGroupLayoutCount = 1;
170 pipelineLayoutDesc.bindGroupLayouts = &bindGroupLayout;
171 wgpu::PipelineLayout layout =
device.CreatePipelineLayout(&pipelineLayoutDesc);
176 wgpu::ComputePipelineDescriptor descriptor;
178 descriptor.label =
step->name();
179 descriptor.compute.module = std::move(shaderModule);
180 descriptor.compute.entryPoint = entryPointName.c_str();
181 descriptor.layout = std::move(layout);
183 std::optional<DawnErrorChecker> errorChecker;
187 wgpu::ComputePipeline pipeline =
device.CreateComputePipeline(&descriptor);
194 sharedContext, std::move(pipeline), std::move(bindGroupLayout)));
197DawnComputePipeline::DawnComputePipeline(
const SharedContext* sharedContext,
198 wgpu::ComputePipeline pso,
199 wgpu::BindGroupLayout groupLayout)
201 , fPipeline(
std::move(pso))
202 , fGroupLayout(
std::move(groupLayout)) {}
204void DawnComputePipeline::freeGpuData() { fPipeline =
nullptr; }
static int step(int x, SkScalar min, SkScalar max)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
wgpu::ShaderModule fModule
static bool ComputeStep(const SkPoint &a, const SkPoint &b, SkScalar radius, SkPoint *step)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkMeshSpecification::Uniform Uniform
const ResourceBindingRequirements & resourceBindingRequirements() const
virtual TextureInfo getDefaultStorageTextureInfo(SkColorType) const =0
bool setBackendLabels() const
const ComputeStep * computeStep() const
@ kWriteOnlyStorageTexture
static sk_sp< DawnComputePipeline > Make(const DawnSharedContext *, const ComputePipelineDesc &)
const SharedContext * sharedContext() const
const Caps * caps() const
std::string BuildComputeSkSL(const Caps *caps, const ComputeStep *step)
bool DawnCompileWGSLShaderModule(const DawnSharedContext *sharedContext, const char *label, const std::string &wgsl, wgpu::ShaderModule *module, ShaderErrorHandler *errorHandler)
bool SkSLToWGSL(const SkSL::ShaderCaps *caps, const std::string &sksl, SkSL::ProgramKind programKind, const SkSL::ProgramSettings &settings, std::string *wgsl, SkSL::ProgramInterface *outInterface, ShaderErrorHandler *errorHandler)
bool fDistinctIndexRanges