Skip to content

Commit 6a93e3a

Browse files
authored
vk: clean-up ycbcr conversion enums (#8859)
Moved them out of DriverEnums because only the vk backend needs them.
1 parent e1fb139 commit 6a93e3a

File tree

5 files changed

+87
-116
lines changed

5 files changed

+87
-116
lines changed

filament/backend/include/backend/DriverEnums.h

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,12 @@ struct DescriptorSetLayoutBinding {
495495
DescriptorFlags flags = DescriptorFlags::NONE;
496496
uint16_t count = 0;
497497

498-
// TODO: uncomment when needed. Note that this class is used as hash key. We need to ensure
499-
// no uninitialized padding bytes.
500-
// uint8_t externalSamplerDataIndex = EXTERNAL_SAMPLER_DATA_INDEX_UNUSED;
501-
502498
friend bool operator==(DescriptorSetLayoutBinding const& lhs,
503499
DescriptorSetLayoutBinding const& rhs) noexcept {
504500
return lhs.type == rhs.type &&
505501
lhs.flags == rhs.flags &&
506502
lhs.count == rhs.count &&
507503
lhs.stageFlags == rhs.stageFlags;
508-
// lhs.stageFlags == rhs.stageFlags &&
509-
// lhs.externalSamplerDataIndex == rhs.externalSamplerDataIndex;
510504
}
511505
};
512506

@@ -1254,26 +1248,6 @@ enum class SamplerCompareFunc : uint8_t {
12541248
N //!< Never. The depth / stencil test always fails.
12551249
};
12561250

1257-
//! this API is copied from (and only applies to) the Vulkan spec.
1258-
//! These specify YUV to RGB conversions.
1259-
enum class SamplerYcbcrModelConversion : uint8_t {
1260-
RGB_IDENTITY = 0,
1261-
YCBCR_IDENTITY = 1,
1262-
YCBCR_709 = 2,
1263-
YCBCR_601 = 3,
1264-
YCBCR_2020 = 4,
1265-
};
1266-
1267-
enum class SamplerYcbcrRange : uint8_t {
1268-
ITU_FULL = 0,
1269-
ITU_NARROW = 1,
1270-
};
1271-
1272-
enum class ChromaLocation : uint8_t {
1273-
COSITED_EVEN = 0,
1274-
MIDPOINT = 1,
1275-
};
1276-
12771251
//! Sampler parameters
12781252
struct SamplerParams { // NOLINT
12791253
SamplerMagFilter filterMag : 1; //!< magnification filter (NEAREST)
@@ -1342,94 +1316,9 @@ static_assert(sizeof(SamplerParams) == 4);
13421316
static_assert(sizeof(SamplerParams) <= sizeof(uint64_t),
13431317
"SamplerParams must be no more than 64 bits");
13441318

1345-
//! Sampler parameters
1346-
struct SamplerYcbcrConversion {// NOLINT
1347-
SamplerYcbcrModelConversion ycbcrModel : 4;
1348-
TextureSwizzle r : 4;
1349-
TextureSwizzle g : 4;
1350-
TextureSwizzle b : 4;
1351-
TextureSwizzle a : 4;
1352-
SamplerYcbcrRange ycbcrRange : 1;
1353-
ChromaLocation xChromaOffset : 1;
1354-
ChromaLocation yChromaOffset : 1;
1355-
SamplerMagFilter chromaFilter : 1;
1356-
uint8_t padding;
1357-
1358-
struct Hasher {
1359-
size_t operator()(const SamplerYcbcrConversion p) const noexcept {
1360-
// we don't use std::hash<> here, so we don't have to include <functional>
1361-
return *reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&p));
1362-
}
1363-
};
1364-
1365-
struct EqualTo {
1366-
bool operator()(SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs) const noexcept {
1367-
assert_invariant(lhs.padding == 0);
1368-
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
1369-
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
1370-
return *pLhs == *pRhs;
1371-
}
1372-
};
1373-
1374-
struct LessThan {
1375-
bool operator()(SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs) const noexcept {
1376-
assert_invariant(lhs.padding == 0);
1377-
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
1378-
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
1379-
return *pLhs < *pRhs;
1380-
}
1381-
};
1382-
1383-
private:
1384-
friend bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1385-
noexcept {
1386-
return SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
1387-
}
1388-
friend bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1389-
noexcept {
1390-
return !SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
1391-
}
1392-
friend bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1393-
noexcept {
1394-
return SamplerYcbcrConversion::LessThan{}(lhs, rhs);
1395-
}
1396-
};
1397-
1398-
static_assert(sizeof(SamplerYcbcrConversion) == 4);
1399-
1400-
static_assert(sizeof(SamplerYcbcrConversion) <= sizeof(uint64_t),
1401-
"SamplerYcbcrConversion must be no more than 64 bits");
1402-
1403-
struct ExternalSamplerDatum {
1404-
ExternalSamplerDatum(SamplerYcbcrConversion ycbcr, SamplerParams spm, uint32_t extFmt)
1405-
: YcbcrConversion(ycbcr),
1406-
samplerParams(spm),
1407-
externalFormat(extFmt) {}
1408-
bool operator==(ExternalSamplerDatum const& rhs) const {
1409-
return (YcbcrConversion == rhs.YcbcrConversion && samplerParams == rhs.samplerParams &&
1410-
externalFormat == rhs.externalFormat);
1411-
}
1412-
struct EqualTo {
1413-
bool operator()(const ExternalSamplerDatum& lhs,
1414-
const ExternalSamplerDatum& rhs) const noexcept {
1415-
return (lhs.YcbcrConversion == rhs.YcbcrConversion &&
1416-
lhs.samplerParams == rhs.samplerParams &&
1417-
lhs.externalFormat == rhs.externalFormat);
1418-
}
1419-
};
1420-
SamplerYcbcrConversion YcbcrConversion;
1421-
SamplerParams samplerParams;
1422-
uint32_t externalFormat;
1423-
};
1424-
// No implicit padding allowed due to it being a hash key.
1425-
static_assert(sizeof(ExternalSamplerDatum) == 12);
1426-
14271319
struct DescriptorSetLayout {
14281320
std::variant<utils::StaticString, utils::CString, std::monostate> label;
14291321
utils::FixedCapacityVector<DescriptorSetLayoutBinding> bindings;
1430-
1431-
// TODO: uncomment when needed
1432-
// utils::FixedCapacityVector<ExternalSamplerDatum> externalSamplerData;
14331322
};
14341323

14351324
//! blending equation function

filament/backend/src/vulkan/VulkanYcbcrConversionCache.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ using namespace bluevk;
2929

3030
namespace filament::backend {
3131

32+
using namespace fvkutils;
33+
3234
VulkanYcbcrConversionCache::VulkanYcbcrConversionCache(VkDevice device)
3335
: mDevice(device) {}
3436

filament/backend/src/vulkan/VulkanYcbcrConversionCache.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef TNT_FILAMENT_BACKEND_VULKANYCBCRCONVERSIONCACHE_H
1818
#define TNT_FILAMENT_BACKEND_VULKANYCBCRCONVERSIONCACHE_H
1919

20+
#include "utils/Definitions.h"
21+
2022
#include <backend/DriverEnums.h>
2123

2224
#include <utils/Hash.h>
@@ -30,7 +32,7 @@ namespace filament::backend {
3032
class VulkanYcbcrConversionCache {
3133
public:
3234
struct Params {
33-
SamplerYcbcrConversion conversion = {}; // 4
35+
fvkutils::SamplerYcbcrConversion conversion = {}; // 4
3436
VkFormat format; // 4
3537
uint64_t externalFormat = 0; // 8
3638
};
@@ -45,16 +47,15 @@ class VulkanYcbcrConversionCache {
4547

4648
struct ConversionEqualTo {
4749
bool operator()(Params lhs, Params rhs) const noexcept {
48-
SamplerYcbcrConversion::EqualTo equal;
50+
fvkutils::SamplerYcbcrConversion::EqualTo equal;
4951
return equal(lhs.conversion, rhs.conversion) &&
50-
lhs.externalFormat == rhs.externalFormat &&
51-
lhs.format == rhs.format;
52+
lhs.externalFormat == rhs.externalFormat && lhs.format == rhs.format;
5253
}
5354
};
5455
using ConversionHashFn = utils::hash::MurmurHashFn<Params>;
5556
tsl::robin_map<Params, VkSamplerYcbcrConversion, ConversionHashFn, ConversionEqualTo> mCache;
5657
};
5758

58-
}// namespace filament::backend
59+
} // namespace filament::backend
5960

6061
#endif// TNT_FILAMENT_BACKEND_VULKANYCBCRCONVERSIONCACHE_H

filament/backend/src/vulkan/utils/Conversion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef TNT_FILAMENT_BACKEND_VULKAN_UTILS_CONVERSION_H
1818
#define TNT_FILAMENT_BACKEND_VULKAN_UTILS_CONVERSION_H
1919

20+
#include "Definitions.h"
21+
2022
#include <backend/DriverEnums.h>
2123

2224
#include <private/backend/BackendUtils.h> // for getFormatSize()

filament/backend/src/vulkan/utils/Definitions.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef TNT_FILAMENT_BACKEND_VULKAN_UTILS_DEFINITIONS_H
1818
#define TNT_FILAMENT_BACKEND_VULKAN_UTILS_DEFINITIONS_H
1919

20+
#include <backend/DriverEnums.h>
21+
2022
#include <utils/bitset.h>
2123
#include <utils/FixedCapacityVector.h>
2224

@@ -379,6 +381,81 @@ static constexpr uint8_t getFragmentStageShift() noexcept {
379381
// We have at most 4 descriptor sets. This is to indicate which ones are active.
380382
using DescriptorSetMask = utils::bitset8;
381383

384+
//! this API is copied from (and only applies to) the Vulkan spec.
385+
//! These specify YUV to RGB conversions.
386+
enum class SamplerYcbcrModelConversion : uint8_t {
387+
RGB_IDENTITY = 0,
388+
YCBCR_IDENTITY = 1,
389+
YCBCR_709 = 2,
390+
YCBCR_601 = 3,
391+
YCBCR_2020 = 4,
392+
};
393+
394+
enum class SamplerYcbcrRange : uint8_t {
395+
ITU_FULL = 0,
396+
ITU_NARROW = 1,
397+
};
398+
399+
enum class ChromaLocation : uint8_t {
400+
COSITED_EVEN = 0,
401+
MIDPOINT = 1,
402+
};
403+
404+
//! Sampler parameters
405+
struct SamplerYcbcrConversion { // NOLINT
406+
SamplerYcbcrModelConversion ycbcrModel : 4;
407+
TextureSwizzle r : 4;
408+
TextureSwizzle g : 4;
409+
TextureSwizzle b : 4;
410+
TextureSwizzle a : 4;
411+
SamplerYcbcrRange ycbcrRange : 1;
412+
ChromaLocation xChromaOffset : 1;
413+
ChromaLocation yChromaOffset : 1;
414+
SamplerMagFilter chromaFilter : 1;
415+
uint8_t padding;
416+
417+
struct Hasher {
418+
size_t operator()(const SamplerYcbcrConversion p) const noexcept {
419+
// we don't use std::hash<> here, so we don't have to include <functional>
420+
return *reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&p));
421+
}
422+
};
423+
424+
struct EqualTo {
425+
bool operator()(SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs) const noexcept {
426+
assert_invariant(lhs.padding == 0);
427+
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
428+
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
429+
return *pLhs == *pRhs;
430+
}
431+
};
432+
433+
struct LessThan {
434+
bool operator()(SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs) const noexcept {
435+
assert_invariant(lhs.padding == 0);
436+
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
437+
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
438+
return *pLhs < *pRhs;
439+
}
440+
};
441+
442+
private:
443+
friend bool operator==(SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs) noexcept {
444+
return SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
445+
}
446+
friend bool operator!=(SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs) noexcept {
447+
return !SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
448+
}
449+
friend bool operator<(SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs) noexcept {
450+
return SamplerYcbcrConversion::LessThan{}(lhs, rhs);
451+
}
452+
};
453+
454+
static_assert(sizeof(SamplerYcbcrConversion) == 4);
455+
456+
static_assert(sizeof(SamplerYcbcrConversion) <= sizeof(uint64_t),
457+
"SamplerYcbcrConversion must be no more than 64 bits");
458+
382459
} // namespace filament::backend::fvkutils
383460

384461
#endif // TNT_FILAMENT_BACKEND_VULKAN_UTILS_DEFINITIONS_H

0 commit comments

Comments
 (0)