Flutter Engine
The Flutter Engine
GrVkSampler.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
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#ifndef GrVkSampler_DEFINED
9#define GrVkSampler_DEFINED
10
13#include "src/core/SkChecksum.h"
16
17#include <atomic>
18#include <cinttypes>
19
20class GrSamplerState;
21class GrVkGpu;
22
24public:
25 static GrVkSampler* Create(GrVkGpu* gpu,
28
29 VkSampler sampler() const { return fSampler; }
30 const VkSampler* samplerPtr() const { return &fSampler; }
31
33 struct Key {
34 Key(uint32_t samplerKey, const GrVkSamplerYcbcrConversion::Key& ycbcrKey) {
35 fSamplerKey = samplerKey;
36 fYcbcrKey = ycbcrKey;
37 }
39 uint32_t fSamplerKey;
40 uint32_t fPadding = 0;
41
42 bool operator==(const Key& that) const {
43 return this->fSamplerKey == that.fSamplerKey &&
44 this->fYcbcrKey == that.fYcbcrKey;
45 }
46 };
48
49 // Helpers for hashing GrVkSampler
51
52 static const Key& GetKey(const GrVkSampler& sampler) { return sampler.fKey; }
53 static uint32_t Hash(const Key& key) {
54 return SkChecksum::Hash32(&key, sizeof(Key));
55 }
56
57 uint32_t uniqueID() const { return fUniqueID; }
58
59#ifdef SK_TRACE_MANAGED_RESOURCES
60 void dumpInfo() const override {
61 SkDebugf("GrVkSampler: %" PRIdPTR " (%d refs)\n", (intptr_t)fSampler, this->getRefCnt());
62 }
63#endif
64
65private:
66 GrVkSampler(const GrVkGpu* gpu, VkSampler sampler,
67 GrVkSamplerYcbcrConversion* ycbcrConversion, Key key)
68 : INHERITED(gpu)
69 , fSampler(sampler)
70 , fYcbcrConversion(ycbcrConversion)
71 , fKey(key)
72 , fUniqueID(GenID()) {}
73
74 void freeGPUData() const override;
75
76 static uint32_t GenID() {
77 static std::atomic<uint32_t> nextID{1};
78 uint32_t id;
79 do {
80 id = nextID++;
81 } while (id == SK_InvalidUniqueID);
82 return id;
83 }
84
85 VkSampler fSampler;
86 GrVkSamplerYcbcrConversion* fYcbcrConversion;
87 Key fKey;
88 uint32_t fUniqueID;
89
90 using INHERITED = GrVkManagedResource;
91};
92
93#endif
TArray< uint32_t > Key
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SK_BEGIN_REQUIRE_DENSE
Definition: SkMacros.h:37
#define SK_END_REQUIRE_DENSE
Definition: SkMacros.h:38
static constexpr uint32_t SK_InvalidUniqueID
Definition: SkTypes.h:196
GrVkManagedResource(const GrVkGpu *gpu)
static const Key & GetKey(const GrVkSampler &sampler)
Definition: GrVkSampler.h:52
const VkSampler * samplerPtr() const
Definition: GrVkSampler.h:30
static uint32_t Hash(const Key &key)
Definition: GrVkSampler.h:53
uint32_t uniqueID() const
Definition: GrVkSampler.h:57
VkSampler sampler() const
Definition: GrVkSampler.h:29
static GrVkSampler * Create(GrVkGpu *gpu, GrSamplerState, const skgpu::VulkanYcbcrConversionInfo &)
Definition: GrVkSampler.cpp:39
static SK_END_REQUIRE_DENSE Key GenerateKey(GrSamplerState, const skgpu::VulkanYcbcrConversionInfo &)
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition: SkChecksum.cpp:113
GrVkSamplerYcbcrConversion::Key fYcbcrKey
Definition: GrVkSampler.h:38
Key(uint32_t samplerKey, const GrVkSamplerYcbcrConversion::Key &ycbcrKey)
Definition: GrVkSampler.h:34
uint32_t fPadding
Definition: GrVkSampler.h:40
uint32_t fSamplerKey
Definition: GrVkSampler.h:39
bool operator==(const Key &that) const
Definition: GrVkSampler.h:42
const uintptr_t id