| 1 |
/* |
| 2 |
* Copyright 2023 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 "include/gpu/vk/VulkanMutableTextureState.h" |
| 9 |
|
| 10 |
#include "include/gpu/GpuTypes.h" |
| 11 |
#include "include/gpu/MutableTextureState.h" |
| 12 |
#include "include/private/base/SkAssert.h" |
| 13 |
#include "include/private/base/SkDebug.h" |
| 14 |
#include "src/gpu/MutableTextureStatePriv.h" |
| 15 |
#include "src/gpu/vk/VulkanMutableTextureStatePriv.h" |
| 16 |
|
| 17 |
namespace skgpu::MutableTextureStates { |
| 18 |
|
| 19 |
class VulkanMutableTextureState : public MutableTextureStateData { |
| 20 |
public: |
| 21 |
VulkanMutableTextureState(VkImageLayout layout, uint32_t queueFamilyIndex) |
| 22 |
: fLayout(layout) |
| 23 |
, fQueueFamilyIndex(queueFamilyIndex) {} |
| 24 |
|
| 25 |
#if defined(SK_DEBUG) |
| 26 |
BackendApi type() const override { return BackendApi::kVulkan; } |
| 27 |
#endif |
| 28 |
|
| 29 |
void copyTo(AnyStateData& formatData) const override { |
| 30 |
formatData.emplace<VulkanMutableTextureState>(fLayout, fQueueFamilyIndex); |
| 31 |
} |
| 32 |
|
| 33 |
VkImageLayout fLayout; |
| 34 |
uint32_t fQueueFamilyIndex; |
| 35 |
}; |
| 36 |
|
| 37 |
MutableTextureState MakeVulkan(VkImageLayout layout, uint32_t queueFamilyIndex) { |
| 38 |
return MutableTextureStatePriv::MakeMutableTextureState( |
| 39 |
BackendApi::kVulkan, |
| 40 |
VulkanMutableTextureState(layout, queueFamilyIndex)); |
| 41 |
} |
| 42 |
|
| 43 |
static const VulkanMutableTextureState* get_and_cast_data(const MutableTextureState& mts) { |
| 44 |
auto data = skgpu::MutableTextureStatePriv::GetStateData(mts); |
| 45 |
SkASSERT(!data || data->type() == BackendApi::kVulkan); |
| 46 |
return static_cast<const VulkanMutableTextureState*>(data); |
| 47 |
} |
| 48 |
|
| 49 |
static const VulkanMutableTextureState* get_and_cast_data(const MutableTextureState* mts) { |
| 50 |
auto data = skgpu::MutableTextureStatePriv::GetStateData(mts); |
| 51 |
SkASSERT(!data || data->type() == BackendApi::kVulkan); |
| 52 |
return static_cast<const VulkanMutableTextureState*>(data); |
| 53 |
} |
| 54 |
|
| 55 |
static VulkanMutableTextureState* get_and_cast_data(MutableTextureState* mts) { |
| 56 |
auto data = skgpu::MutableTextureStatePriv::GetStateData(mts); |
| 57 |
SkASSERT(!data || data->type() == BackendApi::kVulkan); |
| 58 |
return static_cast<VulkanMutableTextureState*>(data); |
| 59 |
} |
| 60 |
|
| 61 |
VkImageLayout GetVkImageLayout(const MutableTextureState& state) { |
| 62 |
SkASSERT(state.backend() == BackendApi::kVulkan); |
| 63 |
return get_and_cast_data(state)->fLayout; |
| 64 |
} |
| 65 |
|
| 66 |
VkImageLayout GetVkImageLayout(const MutableTextureState* state) { |
| 67 |
SkASSERT(state); |
| 68 |
SkASSERT(state->backend() == BackendApi::kVulkan); |
| 69 |
return get_and_cast_data(state)->fLayout; |
| 70 |
} |
| 71 |
|
| 72 |
void SetVkImageLayout(MutableTextureState* state, VkImageLayout layout) { |
| 73 |
SkASSERT(state->backend() == BackendApi::kVulkan); |
| 74 |
get_and_cast_data(state)->fLayout = layout; |
| 75 |
} |
| 76 |
|
| 77 |
uint32_t GetVkQueueFamilyIndex(const MutableTextureState& state) { |
| 78 |
SkASSERT(state.backend() == BackendApi::kVulkan); |
| 79 |
return get_and_cast_data(state)->fQueueFamilyIndex; |
| 80 |
} |
| 81 |
|
| 82 |
uint32_t GetVkQueueFamilyIndex(const MutableTextureState* state) { |
| 83 |
SkASSERT(state); |
| 84 |
SkASSERT(state->backend() == BackendApi::kVulkan); |
| 85 |
return get_and_cast_data(state)->fQueueFamilyIndex; |
| 86 |
} |
| 87 |
|
| 88 |
void SetVkQueueFamilyIndex(MutableTextureState* state, uint32_t queueFamilyIndex) { |
| 89 |
SkASSERT(state->backend() == BackendApi::kVulkan); |
| 90 |
get_and_cast_data(state)->fQueueFamilyIndex = queueFamilyIndex; |
| 91 |
} |
| 92 |
|
| 93 |
} // namespace skgpu::MutableTextureStates |