Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
12#include "src/core/SkChecksum.h"
15
16#include <atomic>
17#include <cinttypes>
18
19class GrSamplerState;
20class GrVkGpu;
21
23public:
25
26 VkSampler sampler() const { return fSampler; }
27 const VkSampler* samplerPtr() const { return &fSampler; }
28
30 struct Key {
31 Key(uint32_t samplerKey, const GrVkSamplerYcbcrConversion::Key& ycbcrKey) {
32 fSamplerKey = samplerKey;
33 fYcbcrKey = ycbcrKey;
34 }
36 uint32_t fSamplerKey;
37 uint32_t fPadding = 0;
38
39 bool operator==(const Key& that) const {
40 return this->fSamplerKey == that.fSamplerKey &&
41 this->fYcbcrKey == that.fYcbcrKey;
42 }
43 };
45
46 // Helpers for hashing GrVkSampler
48
49 static const Key& GetKey(const GrVkSampler& sampler) { return sampler.fKey; }
50 static uint32_t Hash(const Key& key) {
51 return SkChecksum::Hash32(&key, sizeof(Key));
52 }
53
54 uint32_t uniqueID() const { return fUniqueID; }
55
56#ifdef SK_TRACE_MANAGED_RESOURCES
57 void dumpInfo() const override {
58 SkDebugf("GrVkSampler: %" PRIdPTR " (%d refs)\n", (intptr_t)fSampler, this->getRefCnt());
59 }
60#endif
61
62private:
63 GrVkSampler(const GrVkGpu* gpu, VkSampler sampler,
64 GrVkSamplerYcbcrConversion* ycbcrConversion, Key key)
65 : INHERITED(gpu)
66 , fSampler(sampler)
67 , fYcbcrConversion(ycbcrConversion)
68 , fKey(key)
69 , fUniqueID(GenID()) {}
70
71 void freeGPUData() const override;
72
73 static uint32_t GenID() {
74 static std::atomic<uint32_t> nextID{1};
75 uint32_t id;
76 do {
77 id = nextID++;
78 } while (id == SK_InvalidUniqueID);
79 return id;
80 }
81
82 VkSampler fSampler;
83 GrVkSamplerYcbcrConversion* fYcbcrConversion;
84 Key fKey;
85 uint32_t fUniqueID;
86
87 using INHERITED = GrVkManagedResource;
88};
89
90#endif
static sk_sp< Effect > Create()
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
void freeGPUData() const override
static const Key & GetKey(const GrVkSampler &sampler)
Definition GrVkSampler.h:49
static SK_END_REQUIRE_DENSE Key GenerateKey(GrSamplerState, const GrVkYcbcrConversionInfo &)
const VkSampler * samplerPtr() const
Definition GrVkSampler.h:27
static uint32_t Hash(const Key &key)
Definition GrVkSampler.h:50
uint32_t uniqueID() const
Definition GrVkSampler.h:54
VkSampler sampler() const
Definition GrVkSampler.h:26
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
GrVkSamplerYcbcrConversion::Key fYcbcrKey
Definition GrVkSampler.h:35
Key(uint32_t samplerKey, const GrVkSamplerYcbcrConversion::Key &ycbcrKey)
Definition GrVkSampler.h:31
uint32_t fPadding
Definition GrVkSampler.h:37
uint32_t fSamplerKey
Definition GrVkSampler.h:36
bool operator==(const Key &that) const
Definition GrVkSampler.h:39
const uintptr_t id