File: sampler_state.cpp

package info (click to toggle)
vulkan-validationlayers 1.4.335.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 51,728 kB
  • sloc: cpp: 645,254; python: 12,203; sh: 24; makefile: 24; xml: 14
file content (87 lines) | stat: -rw-r--r-- 4,212 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Copyright (c) 2025 The Khronos Group Inc.
 * Copyright (c) 2025 LunarG, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sampler_state.h"
#include <sstream>
#include "utils/hash_util.h"
#include "utils/image_utils.h"

bool DescriptorSlot::operator==(const DescriptorSlot &rhs) const { return set == rhs.set && binding == rhs.binding; }

size_t DescriptorSlot::Hash() const {
    hash_util::HashCombiner hc;
    hc << set << binding;
    return hc.Value();
}

bool SamplerUsedByImage::operator==(const SamplerUsedByImage &rhs) const {
    return sampler_slot == rhs.sampler_slot && sampler_index == rhs.sampler_index;
}

size_t SamplerUsedByImage::Hash() const {
    hash_util::HashCombiner hc;
    hc << sampler_index << sampler_slot;
    return hc.Value();
}

namespace vvl {

Sampler::Sampler(const VkSampler handle, const VkSamplerCreateInfo *pCreateInfo)
    : StateObject(handle, kVulkanObjectTypeSampler),
      safe_create_info(pCreateInfo),
      create_info(*safe_create_info.ptr()),
      sampler_conversion(GetConversion(pCreateInfo)),
      customCreateInfo(GetCustomCreateInfo(pCreateInfo)) {}

SamplerYcbcrConversion::SamplerYcbcrConversion(VkSamplerYcbcrConversion handle,
                                               const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
                                               VkFormatFeatureFlags2 features)
    : StateObject(handle, kVulkanObjectTypeSamplerYcbcrConversion),
      safe_create_info(pCreateInfo),
      create_info(*safe_create_info.ptr()),
      format_features(features),
      external_format(GetExternalFormat(pCreateInfo->pNext)) {}

bool SamplerYcbcrConversion::operator!=(const SamplerYcbcrConversion &rhs) const {
    return (create_info.format != rhs.create_info.format) || (create_info.ycbcrModel != rhs.create_info.ycbcrModel) ||
           (create_info.ycbcrRange != rhs.create_info.ycbcrRange) || (create_info.components.r != rhs.create_info.components.r) ||
           (create_info.components.g != rhs.create_info.components.g) ||
           (create_info.components.b != rhs.create_info.components.b) ||
           (create_info.components.a != rhs.create_info.components.a) ||
           (create_info.xChromaOffset != rhs.create_info.xChromaOffset) ||
           (create_info.yChromaOffset != rhs.create_info.yChromaOffset) ||
           (create_info.chromaFilter != rhs.create_info.chromaFilter) ||
           (create_info.forceExplicitReconstruction != rhs.create_info.forceExplicitReconstruction) ||
           (external_format != rhs.external_format);
}

std::string SamplerYcbcrConversion::Describe() const {
    std::stringstream ss;
    ss << " format (" << string_VkFormat(create_info.format) << ")\n";
    ss << " ycbcrModel (" << string_VkSamplerYcbcrModelConversion(create_info.ycbcrModel) << ")\n";
    ss << " ycbcrRange (" << string_VkSamplerYcbcrRange(create_info.ycbcrRange) << ")\n";
    ss << " components (" << string_VkComponentSwizzle(create_info.components.r) << ", "
       << string_VkComponentSwizzle(create_info.components.g) << ", " << string_VkComponentSwizzle(create_info.components.b) << ", "
       << string_VkComponentSwizzle(create_info.components.a) << ")\n";
    ss << " xChromaOffset (" << string_VkChromaLocation(create_info.xChromaOffset) << ")\n";
    ss << " yChromaOffset (" << string_VkChromaLocation(create_info.yChromaOffset) << ")\n";
    ss << " chromaFilter (" << string_VkFilter(create_info.chromaFilter) << ")\n";
    ss << " forceExplicitReconstruction (" << (create_info.forceExplicitReconstruction ? "VK_TRUE" : "VK_FALSE") << ")\n";
    ss << " externalFormat (" << external_format << ")\n";
    return ss.str();
}

}  // namespace vvl