| 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 |
|
| 11 |
#include "include/core/SkTypes.h" |
| 12 |
#include "include/private/base/SkDebug.h" |
| 13 |
#include "include/private/base/SkMacros.h" |
| 14 |
#include "include/private/gpu/vk/SkiaVulkan.h" |
| 15 |
#include "src/core/SkChecksum.h" |
| 16 |
#include "src/gpu/ganesh/GrManagedResource.h" |
| 17 |
#include "src/gpu/ganesh/vk/GrVkManagedResource.h" |
| 18 |
#include "src/gpu/ganesh/vk/GrVkSamplerYcbcrConversion.h" |
| 19 |
|
| 20 |
#include <cinttypes> |
| 21 |
#include <cstdint> |
| 22 |
|
| 23 |
class GrSamplerState; |
| 24 |
class GrVkGpu; |
| 25 |
namespace skgpu { |
| 26 |
struct VulkanYcbcrConversionInfo; |
| 27 |
} |
| 28 |
|
| 29 |
class GrVkSampler : public GrVkManagedResource { |
| 30 |
public: |
| 31 |
static GrVkSampler* Create(GrVkGpu* gpu, |
| 32 |
GrSamplerState, |
| 33 |
const skgpu::VulkanYcbcrConversionInfo&); |
| 34 |
|
| 35 |
VkSampler sampler() const { return fSampler; } |
| 36 |
const VkSampler* samplerPtr() const { return &fSampler; } |
| 37 |
|
| 38 |
SK_BEGIN_REQUIRE_DENSE |
| 39 |
struct Key { |
| 40 |
Key(uint32_t samplerKey, const GrVkSamplerYcbcrConversion::Key& ycbcrKey) { |
| 41 |
fSamplerKey = samplerKey; |
| 42 |
fYcbcrKey = ycbcrKey; |
| 43 |
} |
| 44 |
GrVkSamplerYcbcrConversion::Key fYcbcrKey; |
| 45 |
uint32_t fSamplerKey; |
| 46 |
uint32_t fPadding = 0; |
| 47 |
|
| 48 |
bool operator==(const Key& that) const { |
| 49 |
return this->fSamplerKey == that.fSamplerKey && |
| 50 |
this->fYcbcrKey == that.fYcbcrKey; |
| 51 |
} |
| 52 |
}; |
| 53 |
SK_END_REQUIRE_DENSE |
| 54 |
|
| 55 |
// Helpers for hashing GrVkSampler |
| 56 |
static Key GenerateKey(GrSamplerState, const skgpu::VulkanYcbcrConversionInfo&); |
| 57 |
|
| 58 |
static const Key& GetKey(const GrVkSampler& sampler) { return sampler.fKey; } |
| 59 |
static uint32_t Hash(const Key& key) { |
| 60 |
return SkChecksum::Hash32(&key, sizeof(Key)); |
| 61 |
} |
| 62 |
|
| 63 |
uint32_t uniqueID() const { return fUniqueID; } |
| 64 |
|
| 65 |
#ifdef SK_TRACE_MANAGED_RESOURCES |
| 66 |
void dumpInfo() const override { |
| 67 |
SkDebugf("GrVkSampler: %" PRIdPTR " (%d refs)\n", (intptr_t)fSampler, this->getRefCnt()); |
| 68 |
} |
| 69 |
#endif |
| 70 |
|
| 71 |
private: |
| 72 |
GrVkSampler(const GrVkGpu* gpu, VkSampler sampler, |
| 73 |
GrVkSamplerYcbcrConversion* ycbcrConversion, Key key) |
| 74 |
: INHERITED(gpu) |
| 75 |
, fSampler(sampler) |
| 76 |
, fYcbcrConversion(ycbcrConversion) |
| 77 |
, fKey(key) |
| 78 |
, fUniqueID(GenID()) {} |
| 79 |
|
| 80 |
void freeGPUData() const override; |
| 81 |
|
| 82 |
static uint32_t GenID(); |
| 83 |
|
| 84 |
VkSampler fSampler; |
| 85 |
GrVkSamplerYcbcrConversion* fYcbcrConversion; |
| 86 |
Key fKey; |
| 87 |
uint32_t fUniqueID; |
| 88 |
|
| 89 |
using INHERITED = GrVkManagedResource; |
| 90 |
}; |
| 91 |
|
| 92 |
#endif |