Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Dec 19, 2024
1 parent a03990b commit 345a1c8
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 201 deletions.
14 changes: 7 additions & 7 deletions internal/Dx/TextureAtlasDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ int round_up(int v, int align);
namespace Dx {
template <typename T, int N> eTexFormat tex_format();

template <> eTexFormat tex_format<uint8_t, 4>() { return eTexFormat::RawRGBA8888; }
template <> eTexFormat tex_format<uint8_t, 3>() { return eTexFormat::RawRGB888; }
template <> eTexFormat tex_format<uint8_t, 2>() { return eTexFormat::RawRG88; }
template <> eTexFormat tex_format<uint8_t, 1>() { return eTexFormat::RawR8; }
template <> eTexFormat tex_format<uint8_t, 4>() { return eTexFormat::RGBA8; }
template <> eTexFormat tex_format<uint8_t, 3>() { return eTexFormat::RGB8; }
template <> eTexFormat tex_format<uint8_t, 2>() { return eTexFormat::RG8; }
template <> eTexFormat tex_format<uint8_t, 1>() { return eTexFormat::R8; }

extern const DXGI_FORMAT g_dx_formats[];

Expand Down Expand Up @@ -245,10 +245,10 @@ bool Ray::Dx::TextureAtlas::Resize(const int pages_count) {
image_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
image_desc.Flags = D3D12_RESOURCE_FLAG_NONE;

if (format_ == eTexFormat::RawRGB888 && !ctx_->rgb8_unorm_is_supported()) {
if (format_ == eTexFormat::RGB8 && !ctx_->rgb8_unorm_is_supported()) {
// Fallback to 4-component texture
image_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
real_format_ = eTexFormat::RawRGBA8888;
real_format_ = eTexFormat::RGBA8;
}

D3D12_HEAP_PROPERTIES heap_properties = {};
Expand Down Expand Up @@ -423,7 +423,7 @@ void Ray::Dx::TextureAtlas::WritePageData(const int page, const int posx, const
}
}
const uint32_t data_size = round_up(pitch, TextureDataPitchAlignment) * lines;
const bool rgb_as_rgba = (format_ == eTexFormat::RawRGB888 && real_format_ == eTexFormat::RawRGBA8888);
const bool rgb_as_rgba = (format_ == eTexFormat::RGB8 && real_format_ == eTexFormat::RGBA8);

Buffer temp_sbuf("Temp Stage", ctx_, eBufType::Upload, data_size);

Expand Down
50 changes: 25 additions & 25 deletions internal/Dx/TextureDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@ extern const float AnisotropyLevel;

extern const DXGI_FORMAT g_dx_formats[] = {
DXGI_FORMAT_UNKNOWN, // Undefined
DXGI_FORMAT_UNKNOWN, // RawRGB888
DXGI_FORMAT_R8G8B8A8_UNORM, // RawRGBA8888
DXGI_FORMAT_UNKNOWN, // RGB8
DXGI_FORMAT_R8G8B8A8_UNORM, // RGBA8
DXGI_FORMAT_R8G8B8A8_SNORM, // RawRGBA8888Signed
DXGI_FORMAT_B8G8R8A8_UNORM, // RawBGRA8888
DXGI_FORMAT_R32_FLOAT, // RawR32F
DXGI_FORMAT_R16_FLOAT, // RawR16F
DXGI_FORMAT_R8_UNORM, // RawR8
DXGI_FORMAT_B8G8R8A8_UNORM, // BGRA8
DXGI_FORMAT_R32_FLOAT, // R32F
DXGI_FORMAT_R16_FLOAT, // R16F
DXGI_FORMAT_R8_UNORM, // R8
DXGI_FORMAT_R16_UINT, // RawR16UI
DXGI_FORMAT_R32_UINT, // RawR32UI
DXGI_FORMAT_R8G8_UNORM, // RawRG88
DXGI_FORMAT_R32G32B32_FLOAT, // RawRGB32F
DXGI_FORMAT_R32G32B32A32_FLOAT, // RawRGBA32F
DXGI_FORMAT_UNKNOWN, // RawRGBE8888
DXGI_FORMAT_UNKNOWN, // RawRGB16F
DXGI_FORMAT_R16G16B16A16_FLOAT, // RawRGBA16F
DXGI_FORMAT_R16G16_SNORM, // RawRG16Snorm
DXGI_FORMAT_R16G16_UNORM, // RawRG16
DXGI_FORMAT_R16G16_FLOAT, // RawRG16F
DXGI_FORMAT_R32G32_FLOAT, // RawRG32F
DXGI_FORMAT_R32_UINT, // R32UI
DXGI_FORMAT_R8G8_UNORM, // RG8
DXGI_FORMAT_R32G32B32_FLOAT, // RGB32F
DXGI_FORMAT_R32G32B32A32_FLOAT, // RGBA32F
DXGI_FORMAT_UNKNOWN, // RGBE8
DXGI_FORMAT_UNKNOWN, // RGB16F
DXGI_FORMAT_R16G16B16A16_FLOAT, // RGBA16F
DXGI_FORMAT_R16G16_SNORM, // RG16_snorm
DXGI_FORMAT_R16G16_UNORM, // RG16
DXGI_FORMAT_R16G16_FLOAT, // RG16F
DXGI_FORMAT_R32G32_FLOAT, // RG32F
DXGI_FORMAT_R32G32_UINT, // RawRG32U
DXGI_FORMAT_R10G10B10A2_UNORM, // RawRGB10_A2
DXGI_FORMAT_R11G11B10_FLOAT, // RawRG11F_B10F
DXGI_FORMAT_D16_UNORM, // Depth16
DXGI_FORMAT_D24_UNORM_S8_UINT, // Depth24Stencil8
DXGI_FORMAT_D32_FLOAT_S8X24_UINT, // Depth32Stencil8
DXGI_FORMAT_D32_FLOAT, // Depth32
DXGI_FORMAT_R10G10B10A2_UNORM, // RGB10_A2
DXGI_FORMAT_R11G11B10_FLOAT, // RG11F_B10F
DXGI_FORMAT_D16_UNORM, // D16
DXGI_FORMAT_D24_UNORM_S8_UINT, // D24_S8
DXGI_FORMAT_D32_FLOAT_S8X24_UINT, // D32_S8
DXGI_FORMAT_D32_FLOAT, // D32
DXGI_FORMAT_BC1_UNORM, // BC1
DXGI_FORMAT_BC2_UNORM, // BC2
DXGI_FORMAT_BC3_UNORM, // BC3
Expand Down Expand Up @@ -198,7 +198,7 @@ void Ray::Dx::Texture2D::Init(const void *data, const uint32_t size, const Tex2D
Tex2DParams _p = p;
_p.w = _p.h = 1;
_p.mip_count = 1;
_p.format = eTexFormat::RawRGBA8888;
_p.format = eTexFormat::RGBA8;
_p.usage = eTexUsage::Sampled | eTexUsage::Transfer;

InitFromRAWData(&sbuf, 0, cmd_buf, mem_allocs, _p, log);
Expand Down Expand Up @@ -230,7 +230,7 @@ void Ray::Dx::Texture2D::Init(const void *data[6], const int size[6], const Tex2

Tex2DParams _p = p;
_p.w = _p.h = 1;
_p.format = eTexFormat::RawRGBA8888;
_p.format = eTexFormat::RGBA8;
_p.usage = eTexUsage::Sampled | eTexUsage::Transfer;

InitFromRAWData(sbuf, data_off, cmd_buf, mem_allocs, _p, log);
Expand Down
4 changes: 2 additions & 2 deletions internal/RendererDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Ray::Dx::Renderer::Renderer(const settings_t &s, ILog *log,
Tex3DParams params = {};
params.w = params.h = params.d = LUT_DIMS;
params.usage = eTexUsage::Sampled | eTexUsage::Transfer;
params.format = eTexFormat::RawRGB10_A2;
params.format = eTexFormat::RGB10_A2;
params.sampling.filter = eTexFilter::BilinearNoMipmap;
params.sampling.wrap = eTexWrap::ClampToEdge;

Expand Down Expand Up @@ -334,7 +334,7 @@ void Ray::Dx::Renderer::RenderScene(const SceneBase &scene, RegionContext &regio
{&tonemap_lut_, eResState::CopyDst}};
TransitionResourceStates(cmd_buf, AllStages, AllStages, res_transitions);

tonemap_lut_.SetSubImage(0, 0, 0, LUT_DIMS, LUT_DIMS, LUT_DIMS, eTexFormat::RawRGB10_A2, temp_upload_buf,
tonemap_lut_.SetSubImage(0, 0, 0, LUT_DIMS, LUT_DIMS, LUT_DIMS, eTexFormat::RGB10_A2, temp_upload_buf,
cmd_buf, 0, data_len);

EndSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->graphics_queue(), cmd_buf,
Expand Down
2 changes: 1 addition & 1 deletion internal/RendererGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ inline void Ray::NS::Renderer::Resize(const int w, const int h) {
Tex2DParams params;
params.w = w;
params.h = h;
params.format = eTexFormat::RawRGBA32F;
params.format = eTexFormat::RGBA32F;
params.usage = eTexUsageBits::Sampled | eTexUsageBits::Storage | eTexUsageBits::Transfer;
params.sampling.wrap = eTexWrap::ClampToEdge;

Expand Down
4 changes: 2 additions & 2 deletions internal/RendererVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Ray::Vk::Renderer::Renderer(const settings_t &s, ILog *log,
Tex3DParams params = {};
params.w = params.h = params.d = LUT_DIMS;
params.usage = eTexUsage::Sampled | eTexUsage::Transfer;
params.format = eTexFormat::RawRGB10_A2;
params.format = eTexFormat::RGB10_A2;
params.sampling.filter = eTexFilter::BilinearNoMipmap;
params.sampling.wrap = eTexWrap::ClampToEdge;

Expand Down Expand Up @@ -382,7 +382,7 @@ void Ray::Vk::Renderer::RenderScene(const SceneBase &scene, RegionContext &regio
{&tonemap_lut_, eResState::CopyDst}};
TransitionResourceStates(cmd_buf, AllStages, AllStages, res_transitions);

tonemap_lut_.SetSubImage(0, 0, 0, LUT_DIMS, LUT_DIMS, LUT_DIMS, eTexFormat::RawRGB10_A2, temp_upload_buf,
tonemap_lut_.SetSubImage(0, 0, 0, LUT_DIMS, LUT_DIMS, LUT_DIMS, eTexFormat::RGB10_A2, temp_upload_buf,
cmd_buf, 0, data_len);

EndSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->graphics_queue(), cmd_buf,
Expand Down
Loading

0 comments on commit 345a1c8

Please sign in to comment.