Skip to content

Commit a675dbd

Browse files
Replaced lvk::ComponentMapping with VkComponentMapping
1 parent edec4d8 commit a675dbd

File tree

4 files changed

+30
-73
lines changed

4 files changed

+30
-73
lines changed

lvk/LVK.h

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,6 @@ enum TextureType : uint8_t {
251251
TextureType_Cube,
252252
};
253253

254-
struct HWDeviceDesc {
255-
enum { LVK_MAX_PHYSICAL_DEVICE_NAME_SIZE = 256 };
256-
uintptr_t guid = 0;
257-
VkPhysicalDeviceType type = VK_PHYSICAL_DEVICE_TYPE_CPU;
258-
char name[LVK_MAX_PHYSICAL_DEVICE_NAME_SIZE] = {0};
259-
};
260-
261254
enum StorageType {
262255
StorageType_Device,
263256
StorageType_HostVisible,
@@ -702,26 +695,6 @@ enum TextureUsageBits : uint8_t {
702695
TextureUsageBits_InputAttachment = 1 << 3,
703696
};
704697

705-
enum Swizzle : uint8_t {
706-
Swizzle_Default = 0,
707-
Swizzle_0,
708-
Swizzle_1,
709-
Swizzle_R,
710-
Swizzle_G,
711-
Swizzle_B,
712-
Swizzle_A,
713-
};
714-
715-
struct ComponentMapping {
716-
Swizzle r = Swizzle_Default;
717-
Swizzle g = Swizzle_Default;
718-
Swizzle b = Swizzle_Default;
719-
Swizzle a = Swizzle_Default;
720-
bool identity() const {
721-
return r == Swizzle_Default && g == Swizzle_Default && b == Swizzle_Default && a == Swizzle_Default;
722-
}
723-
};
724-
725698
struct TextureDesc {
726699
TextureType type = TextureType_2D;
727700
Format format = Format_Invalid;
@@ -732,7 +705,7 @@ struct TextureDesc {
732705
uint8_t usage = TextureUsageBits_Sampled;
733706
uint32_t numMipLevels = 1;
734707
StorageType storage = StorageType_Device;
735-
ComponentMapping components = {};
708+
VkComponentMapping components = {};
736709
const void* data = nullptr;
737710
uint32_t dataNumMipLevels = 1; // how many mip-levels we want to upload
738711
bool generateMipmaps = false; // generate mip-levels immediately, valid only with non-null data
@@ -745,7 +718,7 @@ struct TextureViewDesc {
745718
uint32_t numLayers = 1;
746719
uint32_t mipLevel = 0;
747720
uint32_t numMipLevels = 1;
748-
ComponentMapping components = {};
721+
VkComponentMapping components = {};
749722
};
750723

751724
enum AccelStructType : uint8_t {

lvk/vulkan/VulkanClasses.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,14 @@
3737

3838
uint32_t lvk::VulkanPipelineBuilder::numPipelinesCreated_ = 0;
3939

40-
static_assert(lvk::HWDeviceDesc::LVK_MAX_PHYSICAL_DEVICE_NAME_SIZE == VK_MAX_PHYSICAL_DEVICE_NAME_SIZE);
41-
static_assert(lvk::Swizzle_Default == (uint32_t)VK_COMPONENT_SWIZZLE_IDENTITY);
42-
static_assert(lvk::Swizzle_0 == (uint32_t)VK_COMPONENT_SWIZZLE_ZERO);
43-
static_assert(lvk::Swizzle_1 == (uint32_t)VK_COMPONENT_SWIZZLE_ONE);
44-
static_assert(lvk::Swizzle_R == (uint32_t)VK_COMPONENT_SWIZZLE_R);
45-
static_assert(lvk::Swizzle_G == (uint32_t)VK_COMPONENT_SWIZZLE_G);
46-
static_assert(lvk::Swizzle_B == (uint32_t)VK_COMPONENT_SWIZZLE_B);
47-
static_assert(lvk::Swizzle_A == (uint32_t)VK_COMPONENT_SWIZZLE_A);
4840
static_assert(sizeof(lvk::AccelStructInstance) == sizeof(VkAccelerationStructureInstanceKHR));
4941
static_assert(sizeof(lvk::mat3x4) == sizeof(VkTransformMatrixKHR));
5042

5143
namespace {
5244

53-
const char* kDefaultValidationLayers[] = {"VK_LAYER_KHRONOS_validation"};
45+
const char* kDefaultValidationLayers[] = {
46+
"VK_LAYER_KHRONOS_validation",
47+
};
5448

5549
// These bindings should match GLSL declarations injected into shaders in VulkanContext::createShaderModule().
5650
enum Bindings {
@@ -73,6 +67,11 @@ uint64_t getAlignedAddress(uint64_t addr, uint64_t align) {
7367
return offs ? addr + (align - offs) : addr;
7468
}
7569

70+
bool isIdentityMapping(const VkComponentMapping& m) {
71+
return m.r == VK_COMPONENT_SWIZZLE_IDENTITY && m.g == VK_COMPONENT_SWIZZLE_IDENTITY && m.b == VK_COMPONENT_SWIZZLE_IDENTITY &&
72+
m.a == VK_COMPONENT_SWIZZLE_IDENTITY;
73+
}
74+
7675
VKAPI_ATTR VkBool32 VKAPI_CALL vulkanDebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT msgSeverity,
7776
[[maybe_unused]] VkDebugUtilsMessageTypeFlagsEXT msgType,
7877
const VkDebugUtilsMessengerCallbackDataEXT* cbData,
@@ -4111,20 +4110,13 @@ lvk::Holder<lvk::TextureHandle> lvk::VulkanContext::createTexture(const TextureD
41114110
aspect = VK_IMAGE_ASPECT_COLOR_BIT;
41124111
}
41134112

4114-
const VkComponentMapping components = {
4115-
.r = VkComponentSwizzle(desc.components.r),
4116-
.g = VkComponentSwizzle(desc.components.g),
4117-
.b = VkComponentSwizzle(desc.components.b),
4118-
.a = VkComponentSwizzle(desc.components.a),
4119-
};
4120-
41214113
const VkSamplerYcbcrConversionInfo* ycbcrInfo = isDisjoint ? getOrCreateYcbcrConversionInfo(desc.format) : nullptr;
41224114

41234115
image.imageView_ = image.createImageView(
4124-
vkDevice_, vkImageViewType, vkFormat, aspect, 0, VK_REMAINING_MIP_LEVELS, 0, numLayers, components, ycbcrInfo, debugNameImageView);
4116+
vkDevice_, vkImageViewType, vkFormat, aspect, 0, VK_REMAINING_MIP_LEVELS, 0, numLayers, desc.components, ycbcrInfo, debugNameImageView);
41254117

41264118
if (image.vkUsageFlags_ & VK_IMAGE_USAGE_STORAGE_BIT) {
4127-
if (!desc.components.identity()) {
4119+
if (!isIdentityMapping(desc.components)) {
41284120
// use identity swizzle for storage images
41294121
image.imageViewStorage_ = image.createImageView(
41304122
vkDevice_, vkImageViewType, vkFormat, aspect, 0, VK_REMAINING_MIP_LEVELS, 0, numLayers, {}, ycbcrInfo, debugNameImageView);
@@ -4206,13 +4198,6 @@ lvk::Holder<lvk::TextureHandle> lvk::VulkanContext::createTextureView(lvk::Textu
42064198
return {};
42074199
}
42084200

4209-
const VkComponentMapping components = {
4210-
.r = VkComponentSwizzle(desc.components.r),
4211-
.g = VkComponentSwizzle(desc.components.g),
4212-
.b = VkComponentSwizzle(desc.components.b),
4213-
.a = VkComponentSwizzle(desc.components.a),
4214-
};
4215-
42164201
LVK_ASSERT_MSG(lvk::getNumImagePlanes(image.vkImageFormat_) == 1, "Unsupported multiplanar image");
42174202

42184203
image.imageView_ = image.createImageView(vkDevice_,
@@ -4223,7 +4208,7 @@ lvk::Holder<lvk::TextureHandle> lvk::VulkanContext::createTextureView(lvk::Textu
42234208
desc.numMipLevels,
42244209
desc.layer,
42254210
desc.numLayers,
4226-
components,
4211+
desc.components,
42274212
nullptr,
42284213
debugName);
42294214

@@ -4233,7 +4218,7 @@ lvk::Holder<lvk::TextureHandle> lvk::VulkanContext::createTextureView(lvk::Textu
42334218
}
42344219

42354220
if (image.vkUsageFlags_ & VK_IMAGE_USAGE_STORAGE_BIT) {
4236-
if (!desc.components.identity()) {
4221+
if (!isIdentityMapping(desc.components)) {
42374222
// use identity swizzle for storage images
42384223
image.imageViewStorage_ = image.createImageView(vkDevice_,
42394224
vkImageViewType,

samples/010_OmniShadows.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ VULKAN_APP_MAIN {
509509
layers[l] = ctx->createTextureView(shadowMap,
510510
{.layer = l,
511511
.components = {
512-
.r = lvk::Swizzle_R,
513-
.g = lvk::Swizzle_R,
514-
.b = lvk::Swizzle_R,
515-
.a = lvk::Swizzle_1,
512+
.r = VK_COMPONENT_SWIZZLE_R,
513+
.g = VK_COMPONENT_SWIZZLE_R,
514+
.b = VK_COMPONENT_SWIZZLE_R,
515+
.a = VK_COMPONENT_SWIZZLE_ONE,
516516
}});
517517
}
518518

samples/Tiny_MeshLarge.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,15 @@ void createOffscreenFramebuffer();
668668
bool init(lvk::LVKwindow* window) {
669669
{
670670
const uint32_t pixel = 0xFFFFFFFF;
671-
textureDummyWhite_ = ctx_->createTexture(
672-
{
673-
.type = lvk::TextureType_2D,
674-
.format = lvk::Format_R_UN8,
675-
.dimensions = {1, 1},
676-
.usage = lvk::TextureUsageBits_Sampled,
677-
.components = {lvk::Swizzle_1, lvk::Swizzle_1, lvk::Swizzle_1, lvk::Swizzle_1},
678-
.data = &pixel,
679-
.debugName = "dummy 1x1 (white)",
680-
},
681-
nullptr);
671+
textureDummyWhite_ = ctx_->createTexture({
672+
.type = lvk::TextureType_2D,
673+
.format = lvk::Format_R_UN8,
674+
.dimensions = {1, 1},
675+
.usage = lvk::TextureUsageBits_Sampled,
676+
.components = {VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_ONE},
677+
.data = &pixel,
678+
.debugName = "dummy 1x1 (white)",
679+
});
682680
}
683681

684682
ubPerFrame_ = ctx_->createBuffer({
@@ -1889,8 +1887,9 @@ lvk::TextureHandle createTexture(const LoadedImage& img) {
18891887
.dimensions = {img.w, img.h},
18901888
.usage = lvk::TextureUsageBits_Sampled,
18911889
.numMipLevels = lvk::calcNumMipLevels(img.w, img.h),
1892-
.components = (img.channels == 1) ? lvk::ComponentMapping{lvk::Swizzle_R, lvk::Swizzle_R, lvk::Swizzle_R, lvk::Swizzle_R}
1893-
: lvk::ComponentMapping{},
1890+
.components = (img.channels == 1)
1891+
? VkComponentMapping{VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R}
1892+
: VkComponentMapping{},
18941893
.data = initialData,
18951894
.dataNumMipLevels = initialDataNumMipLevels,
18961895
.generateMipmaps = generateMipmaps,

0 commit comments

Comments
 (0)