Skip to content

Commit 0dfdd8b

Browse files
committed
Remove texture SRGB flag
(use dedicated formats instead)
1 parent f2a9966 commit 0dfdd8b

File tree

10 files changed

+44
-151
lines changed

10 files changed

+44
-151
lines changed

internal/Dx/RenderPassDX.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ static_assert((sizeof(vk_store_ops) / sizeof(vk_store_ops[0])) == int(eStoreOp::
3838
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_1_BIT == 1, "!");
3939
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_2_BIT == 2, "!");
4040
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_4_BIT == 4, "!");
41-
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_8_BIT == 8, "!");
42-
43-
VkFormat ToSRGBFormat(VkFormat format);*/
41+
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_8_BIT == 8, "!");*/
4442
} // namespace Vk
4543
} // namespace Ray
4644

@@ -101,9 +99,6 @@ bool Ray::Dx::RenderPass::Init(Context *ctx, Span<const RenderTargetInfo> _color
10199
102100
auto &att_desc = pass_attachments.emplace_back();
103101
att_desc.format = VKFormatFromTexFormat(_color_rts[i].format);
104-
if (bool(_color_rts[i].flags & eTexFlagBits::SRGB)) {
105-
att_desc.format = ToSRGBFormat(att_desc.format);
106-
}
107102
att_desc.samples = VkSampleCountFlagBits(_color_rts[i].samples);
108103
if (VkImageLayout(_color_rts[i].layout) == VK_IMAGE_LAYOUT_UNDEFINED) {
109104
att_desc.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;

internal/Dx/TextureDX.cpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ static_assert(sizeof(g_formats_dx) / sizeof(g_formats_dx[0]) == size_t(eTexForma
4141

4242
uint32_t TextureHandleCounter = 0;
4343

44-
DXGI_FORMAT ToSRGBFormat(const DXGI_FORMAT format) {
45-
switch (format) {
46-
case DXGI_FORMAT_R8G8B8A8_UNORM:
47-
return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
48-
case DXGI_FORMAT_BC1_UNORM:
49-
return DXGI_FORMAT_BC1_UNORM_SRGB;
50-
case DXGI_FORMAT_BC2_UNORM:
51-
return DXGI_FORMAT_BC2_UNORM_SRGB;
52-
case DXGI_FORMAT_BC3_UNORM:
53-
return DXGI_FORMAT_BC3_UNORM_SRGB;
54-
default:
55-
return format;
56-
}
57-
return DXGI_FORMAT_UNKNOWN;
58-
}
59-
6044
D3D12_RESOURCE_FLAGS to_dx_image_flags(const Bitmask<eTexUsage> usage, const eTexFormat format) {
6145
D3D12_RESOURCE_FLAGS ret = D3D12_RESOURCE_FLAG_NONE;
6246
if (usage & eTexUsage::Storage) {
@@ -171,8 +155,7 @@ void Ray::Dx::Texture::Free() {
171155
}
172156

173157
bool Ray::Dx::Texture::Realloc(const int w, const int h, int mip_count, const int samples, const eTexFormat format,
174-
const bool is_srgb, ID3D12GraphicsCommandList *cmd_buf, MemAllocators *mem_allocs,
175-
ILog *log) {
158+
ID3D12GraphicsCommandList *cmd_buf, MemAllocators *mem_allocs, ILog *log) {
176159
ID3D12Resource *new_image = nullptr;
177160
// VkImageView new_image_view = VK_NULL_HANDLE;
178161
MemAllocation new_alloc = {};
@@ -186,9 +169,6 @@ bool Ray::Dx::Texture::Realloc(const int w, const int h, int mip_count, const in
186169
image_desc.DepthOrArraySize = 1;
187170
image_desc.MipLevels = mip_count;
188171
image_desc.Format = g_formats_dx[int(format)];
189-
if (is_srgb) {
190-
image_desc.Format = ToSRGBFormat(image_desc.Format);
191-
}
192172
image_desc.SampleDesc.Count = samples;
193173
image_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
194174
image_desc.Flags = to_dx_image_flags(Bitmask<eTexUsage>{params.usage}, format);
@@ -247,9 +227,6 @@ bool Ray::Dx::Texture::Realloc(const int w, const int h, int mip_count, const in
247227
view_info.image = new_image;
248228
view_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
249229
view_info.format = g_formats_vk[size_t(format)];
250-
if (is_srgb) {
251-
view_info.format = ToSRGBFormat(view_info.format);
252-
}
253230
view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
254231
view_info.subresourceRange.baseMipLevel = 0;
255232
view_info.subresourceRange.levelCount = mip_count;
@@ -399,11 +376,6 @@ bool Ray::Dx::Texture::Realloc(const int w, const int h, int mip_count, const in
399376
alloc_ = std::move(new_alloc);
400377
params.w = w;
401378
params.h = h;
402-
if (is_srgb) {
403-
params.flags |= eTexFlagBits::SRGB;
404-
} else {
405-
params.flags &= ~eTexFlagBits::SRGB;
406-
}
407379
params.mip_count = mip_count;
408380
params.samples = samples;
409381
params.format = format;
@@ -430,9 +402,6 @@ void Ray::Dx::Texture::InitFromRAWData(Buffer *sbuf, int data_off, ID3D12Graphic
430402
image_desc.DepthOrArraySize = (p.d ? p.d : 1);
431403
image_desc.MipLevels = params.mip_count;
432404
image_desc.Format = g_formats_dx[int(p.format)];
433-
if (p.flags & eTexFlags::SRGB) {
434-
image_desc.Format = ToSRGBFormat(image_desc.Format);
435-
}
436405
image_desc.SampleDesc.Count = p.samples;
437406
image_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
438407
image_desc.Flags = to_dx_image_flags(Bitmask<eTexUsage>{params.usage}, p.format);
@@ -471,9 +440,6 @@ void Ray::Dx::Texture::InitFromRAWData(Buffer *sbuf, int data_off, ID3D12Graphic
471440
{ // create default SRV
472441
D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc = {};
473442
srv_desc.Format = g_formats_dx[int(p.format)];
474-
if (p.flags & eTexFlags::SRGB) {
475-
srv_desc.Format = ToSRGBFormat(srv_desc.Format);
476-
}
477443
if (p.d == 0) {
478444
srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
479445
srv_desc.Texture2D.MipLevels = p.mip_count;
@@ -679,9 +645,6 @@ void Ray::Dx::Texture::SetSubImage(const int level, const int offsetx, const int
679645
src_loc.PlacedFootprint.Footprint.Height = sizey;
680646
src_loc.PlacedFootprint.Footprint.Depth = sizez;
681647
src_loc.PlacedFootprint.Footprint.Format = g_formats_dx[int(params.format)];
682-
if (Bitmask<eTexFlags>{params.flags} & eTexFlags::SRGB) {
683-
src_loc.PlacedFootprint.Footprint.Format = ToSRGBFormat(src_loc.PlacedFootprint.Footprint.Format);
684-
}
685648
if (IsCompressedFormat(params.format)) {
686649
src_loc.PlacedFootprint.Footprint.RowPitch = round_up(
687650
GetBlockCount(sizex, 1, params.format) * GetBlockLenBytes(params.format), TextureDataPitchAlignment);
@@ -884,11 +847,6 @@ void Ray::Dx::_ClearColorImage(Texture &tex, const void *rgba, ID3D12GraphicsCom
884847

885848
DXGI_FORMAT Ray::Dx::DXFormatFromTexFormat(const eTexFormat format) { return g_formats_dx[size_t(format)]; }
886849

887-
bool Ray::Dx::RequiresManualSRGBConversion(const eTexFormat format) {
888-
const DXGI_FORMAT dxgi_format = g_formats_dx[size_t(format)];
889-
return dxgi_format == ToSRGBFormat(dxgi_format);
890-
}
891-
892850
bool Ray::Dx::CanBeBlockCompressed(int w, int h, const int mip_count) {
893851
// NOTE: Assume only BC-formats for now
894852
static const int block_res[2] = {4, 4};

internal/Dx/TextureDX.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class Texture {
104104
void Init(const void *data, uint32_t size, const TexParams &p, Buffer &stage_buf,
105105
ID3D12GraphicsCommandList *cmd_buf, MemAllocators *mem_allocs, eTexLoadStatus *load_status, ILog *log);
106106

107-
bool Realloc(int w, int h, int mip_count, int samples, eTexFormat format, bool is_srgb,
108-
ID3D12GraphicsCommandList *cmd_buf, MemAllocators *mem_allocs, ILog *log);
107+
bool Realloc(int w, int h, int mip_count, int samples, eTexFormat format, ID3D12GraphicsCommandList *cmd_buf,
108+
MemAllocators *mem_allocs, ILog *log);
109109

110110
Context *ctx() { return ctx_; }
111111
const TexHandle &handle() const { return handle_; }
@@ -149,9 +149,7 @@ inline void ClearColorImage(Texture &tex, const uint32_t rgba[4], ID3D12Graphics
149149
}
150150

151151
DXGI_FORMAT DXFormatFromTexFormat(eTexFormat format);
152-
DXGI_FORMAT ToSRGBFormat(DXGI_FORMAT format);
153152

154-
bool RequiresManualSRGBConversion(eTexFormat format);
155153
bool CanBeBlockCompressed(int w, int h, int mip_count);
156154

157155
} // namespace Dx

internal/SceneGPU.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,12 @@ inline Ray::TextureHandle Ray::NS::Scene::AddBindlessTexture_nolock(const tex_de
701701
TexParams p = {};
702702
p.w = _t.w;
703703
p.h = _t.h;
704+
p.format = fmt;
704705
if (_t.is_srgb && !is_YCoCg && !RequiresManualSRGBConversion(fmt)) {
705-
p.flags |= eTexFlags::SRGB;
706+
p.format = ToSRGBFormat(p.format);
706707
}
707708
p.mip_count = mip_count;
708709
p.usage = Bitmask<eTexUsage>(eTexUsage::Transfer) | eTexUsage::Sampled;
709-
p.format = fmt;
710710
p.sampling.filter = eTexFilter::Nearest;
711711

712712
std::pair<uint32_t, uint32_t> ret =
@@ -1785,8 +1785,7 @@ Ray::NS::Scene::PrepareSkyEnvMap_nolock(const std::function<void(int, int, Paral
17851785
TexParams params;
17861786
params.w = MOON_TEX_W;
17871787
params.h = MOON_TEX_H;
1788-
params.format = eTexFormat::RGBA8;
1789-
params.flags = eTexFlags::SRGB;
1788+
params.format = eTexFormat::RGBA8_srgb;
17901789
params.usage = Bitmask<eTexUsage>(eTexUsage::Sampled) | eTexUsage::Transfer;
17911790
params.sampling.filter = eTexFilter::Bilinear;
17921791
params.sampling.wrap = eTexWrap::ClampToEdge;
@@ -1865,8 +1864,7 @@ Ray::NS::Scene::PrepareSkyEnvMap_nolock(const std::function<void(int, int, Paral
18651864
if (!sky_curl_tex_) {
18661865
TexParams params;
18671866
params.w = params.h = CURL_TEX_RES;
1868-
params.format = eTexFormat::RGBA8;
1869-
params.flags = eTexFlags::SRGB;
1867+
params.format = eTexFormat::RGBA8_srgb;
18701868
params.usage = Bitmask<eTexUsage>(eTexUsage::Sampled) | eTexUsage::Transfer;
18711869
params.sampling.filter = eTexFilter::Bilinear;
18721870
params.sampling.wrap = eTexWrap::Repeat;

internal/TextureFormat.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
X(Undefined, 0 /* channel count */, 0 /* PP data len*/, 0 /* block_x */, 0 /* block_y */, VK_FORMAT_UNDEFINED, DXGI_FORMAT_UNKNOWN)
22
X(RGB8, 3, 3, 0, 0, VK_FORMAT_R8G8B8_UNORM, DXGI_FORMAT_UNKNOWN)
3+
X(RGB8_srgb, 3, 3, 0, 0, VK_FORMAT_R8G8B8_SRGB, DXGI_FORMAT_UNKNOWN)
34
X(RGBA8, 4, 4, 0, 0, VK_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM)
5+
X(RGBA8_srgb, 4, 4, 0, 0, VK_FORMAT_R8G8B8A8_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
46
X(RGBA8_snorm, 4, 4, 0, 0, VK_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM)
57
X(BGRA8, 4, 4, 0, 0, VK_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM)
8+
X(BGRA8_srgb, 4, 4, 0, 0, VK_FORMAT_B8G8R8A8_SRGB, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB)
69
X(R32F, 1, 4, 0, 0, VK_FORMAT_R32_SFLOAT, DXGI_FORMAT_R32_FLOAT)
710
X(R16F, 1, 2, 0, 0, VK_FORMAT_R16_SFLOAT, DXGI_FORMAT_R16_FLOAT)
811
X(R8, 1, 1, 0, 0, VK_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM)
@@ -25,7 +28,10 @@ X(D24_S8, 2, 4, 0, 0, VK_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_D
2528
X(D32_S8, 2, 8, 0, 0, VK_FORMAT_D32_SFLOAT_S8_UINT, DXGI_FORMAT_D32_FLOAT_S8X24_UINT)
2629
X(D32, 1, 4, 0, 0, VK_FORMAT_D32_SFLOAT, DXGI_FORMAT_D32_FLOAT)
2730
X(BC1, 3, 0, 4, 4, VK_FORMAT_BC1_RGBA_UNORM_BLOCK, DXGI_FORMAT_BC1_UNORM)
31+
X(BC1_srgb, 3, 0, 4, 4, VK_FORMAT_BC1_RGBA_SRGB_BLOCK, DXGI_FORMAT_BC1_UNORM_SRGB)
2832
X(BC2, 4, 0, 4, 4, VK_FORMAT_BC2_UNORM_BLOCK, DXGI_FORMAT_BC2_UNORM)
33+
X(BC2_srgb, 4, 0, 4, 4, VK_FORMAT_BC2_SRGB_BLOCK, DXGI_FORMAT_BC2_UNORM_SRGB)
2934
X(BC3, 4, 0, 4, 4, VK_FORMAT_BC3_UNORM_BLOCK, DXGI_FORMAT_BC3_UNORM)
35+
X(BC3_srgb, 4, 0, 4, 4, VK_FORMAT_BC3_SRGB_BLOCK, DXGI_FORMAT_BC3_UNORM_SRGB)
3036
X(BC4, 1, 0, 4, 4, VK_FORMAT_BC4_UNORM_BLOCK, DXGI_FORMAT_BC4_UNORM)
3137
X(BC5, 2, 0, 4, 4, VK_FORMAT_BC5_UNORM_BLOCK, DXGI_FORMAT_BC5_UNORM)

internal/TextureParams.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ int Ray::GetChannelCount(const eTexFormat format) { return g_tex_format_info[int
2222
int Ray::GetPerPixelDataLen(const eTexFormat format) { return g_tex_format_info[int(format)].pp_data_len; }
2323

2424
int Ray::GetBlockLenBytes(const eTexFormat format) {
25-
static_assert(int(eTexFormat::_Count) == 31, "Update the list below!");
25+
static_assert(int(eTexFormat::_Count) == 37, "Update the list below!");
2626
switch (format) {
2727
case eTexFormat::BC1:
28+
case eTexFormat::BC1_srgb:
2829
return 8;
2930
case eTexFormat::BC2:
31+
case eTexFormat::BC2_srgb:
3032
case eTexFormat::BC3:
33+
case eTexFormat::BC3_srgb:
3134
case eTexFormat::BC5:
3235
return 16;
3336
case eTexFormat::BC4:

internal/TextureParams.h

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,25 @@ enum class eTexFormat : uint8_t {
1414
#undef X
1515

1616
inline bool IsDepthFormat(const eTexFormat format) {
17-
static_assert(int(eTexFormat::_Count) == 31, "Update the list below!");
17+
static_assert(int(eTexFormat::_Count) == 37, "Update the list below!");
1818
return format == eTexFormat::D16 || format == eTexFormat::D24_S8 || format == eTexFormat::D32_S8 ||
1919
format == eTexFormat::D32;
2020
}
2121

2222
inline bool IsDepthStencilFormat(const eTexFormat format) {
23-
static_assert(int(eTexFormat::_Count) == 31, "Update the list below!");
23+
static_assert(int(eTexFormat::_Count) == 37, "Update the list below!");
2424
return format == eTexFormat::D24_S8 || format == eTexFormat::D32_S8;
2525
}
2626

2727
inline bool IsCompressedFormat(const eTexFormat format) {
28-
static_assert(int(eTexFormat::_Count) == 31, "Update the list below!");
28+
static_assert(int(eTexFormat::_Count) == 37, "Update the list below!");
2929
switch (format) {
3030
case eTexFormat::BC1:
31+
case eTexFormat::BC1_srgb:
3132
case eTexFormat::BC2:
33+
case eTexFormat::BC2_srgb:
3234
case eTexFormat::BC3:
35+
case eTexFormat::BC3_srgb:
3336
case eTexFormat::BC4:
3437
case eTexFormat::BC5:
3538
return true;
@@ -40,14 +43,30 @@ inline bool IsCompressedFormat(const eTexFormat format) {
4043
}
4144

4245
inline bool IsUintFormat(const eTexFormat format) {
43-
static_assert(int(eTexFormat::_Count) == 31, "Update the list below!");
46+
static_assert(int(eTexFormat::_Count) == 37, "Update the list below!");
4447
if (format == eTexFormat::R16UI || format == eTexFormat::R32UI || format == eTexFormat::RG32UI) {
4548
return true;
4649
}
4750
return false;
4851
}
4952

50-
enum class eTexFlags : uint8_t { NoOwnership, SRGB };
53+
inline eTexFormat ToSRGBFormat(const eTexFormat format) {
54+
static_assert(int(eTexFormat::_Count) == 37, "Update the list below!");
55+
switch (format) {
56+
case eTexFormat::BC1:
57+
return eTexFormat::BC1_srgb;
58+
case eTexFormat::BC2:
59+
return eTexFormat::BC2_srgb;
60+
case eTexFormat::BC3:
61+
return eTexFormat::BC3_srgb;
62+
default:
63+
return format;
64+
}
65+
}
66+
67+
inline bool RequiresManualSRGBConversion(const eTexFormat format) { return format == ToSRGBFormat(format); }
68+
69+
enum class eTexFlags : uint8_t { NoOwnership };
5170

5271
enum class eTexUsage : uint8_t { Transfer, Sampled, Storage, RenderTarget };
5372

internal/Vk/RenderPassVK.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_1_BIT == 1, "!");
3939
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_2_BIT == 2, "!");
4040
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_4_BIT == 4, "!");
4141
static_assert(VkSampleCountFlagBits::VK_SAMPLE_COUNT_8_BIT == 8, "!");
42-
43-
VkFormat ToSRGBFormat(VkFormat format);
4442
} // namespace Vk
4543
} // namespace Ray
4644

@@ -101,9 +99,6 @@ bool Ray::Vk::RenderPass::Init(Context *ctx, Span<const RenderTargetInfo> _color
10199

102100
auto &att_desc = pass_attachments.emplace_back();
103101
att_desc.format = VKFormatFromTexFormat(_color_rts[i].format);
104-
if (_color_rts[i].flags & eTexFlags::SRGB) {
105-
att_desc.format = ToSRGBFormat(att_desc.format);
106-
}
107102
att_desc.samples = VkSampleCountFlagBits(_color_rts[i].samples);
108103
if (VkImageLayout(_color_rts[i].layout) == VK_IMAGE_LAYOUT_UNDEFINED) {
109104
att_desc.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;

0 commit comments

Comments
 (0)