1 /*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "src/gpu/graphite/Renderer.h"
9
10 namespace skgpu::graphite {
11
next_id()12 static uint32_t next_id() {
13 static std::atomic<uint32_t> nextID{0};
14 // Not worried about overflow since each Context won't have that many RenderSteps, so even if
15 // it wraps back to 0, that RenderStep will not be in the same Context as the original 0.
16 return nextID.fetch_add(1, std::memory_order_relaxed);
17 }
18
RenderStep(std::string_view className,std::string_view variantName,SkEnumBitMask<Flags> flags,std::initializer_list<Uniform> uniforms,PrimitiveType primitiveType,DepthStencilSettings depthStencilSettings,SkSpan<const Attribute> vertexAttrs,SkSpan<const Attribute> instanceAttrs,SkSpan<const Varying> varyings)19 RenderStep::RenderStep(std::string_view className,
20 std::string_view variantName,
21 SkEnumBitMask<Flags> flags,
22 std::initializer_list<Uniform> uniforms,
23 PrimitiveType primitiveType,
24 DepthStencilSettings depthStencilSettings,
25 SkSpan<const Attribute> vertexAttrs,
26 SkSpan<const Attribute> instanceAttrs,
27 SkSpan<const Varying> varyings)
28 : fUniqueID(next_id())
29 , fFlags(flags)
30 , fPrimitiveType(primitiveType)
31 , fDepthStencilSettings(depthStencilSettings)
32 , fUniforms(uniforms)
33 , fVertexAttrs(vertexAttrs.begin(), vertexAttrs.end())
34 , fInstanceAttrs(instanceAttrs.begin(), instanceAttrs.end())
35 , fVaryings(varyings.begin(), varyings.end())
36 , fVertexStride(0)
37 , fInstanceStride(0)
38 , fName(className) {
39 for (auto v : this->vertexAttributes()) {
40 fVertexStride += v.sizeAlign4();
41 }
42 for (auto i : this->instanceAttributes()) {
43 fInstanceStride += i.sizeAlign4();
44 }
45 if (!variantName.empty()) {
46 fName += "[";
47 fName += variantName;
48 fName += "]";
49 }
50 }
51
GetCoverage(SkEnumBitMask<Flags> flags)52 Coverage RenderStep::GetCoverage(SkEnumBitMask<Flags> flags) {
53 return !(flags & Flags::kEmitsCoverage) ? Coverage::kNone
54 : (flags & Flags::kLCDCoverage) ? Coverage::kLCD
55 : Coverage::kSingleChannel;
56 }
57
58 } // namespace skgpu::graphite
59