hdr support

fixes #15
This commit is contained in:
PancakeTAS 2025-07-06 21:15:15 +02:00
parent 01379439f4
commit 92c7f98a12
No known key found for this signature in database
4 changed files with 23 additions and 7 deletions

View file

@ -14,14 +14,18 @@ using namespace LSFG;
Context::Context(const Core::Device& device, Pool::ShaderPool& shaderpool,
uint32_t width, uint32_t height, int in0, int in1,
const std::vector<int>& outN) {
const VkFormat format = getenv("LSFG_HDR") == nullptr
? VK_FORMAT_R8G8B8A8_UNORM
: VK_FORMAT_R16G16B16A16_SFLOAT;
// import images
this->inImg_0 = Core::Image(device, { width, height },
VK_FORMAT_R8G8B8A8_UNORM,
format,
VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VK_IMAGE_ASPECT_COLOR_BIT,
in0);
this->inImg_1 = Core::Image(device, { width, height },
VK_FORMAT_R8G8B8A8_UNORM,
format,
VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VK_IMAGE_ASPECT_COLOR_BIT,
in1);

View file

@ -36,10 +36,12 @@ Merge::Merge(const Core::Device& device, Pool::ShaderPool& shaderpool,
auto extent = this->inImg1.getExtent();
const VkFormat format = getenv("LSFG_HDR") == nullptr
? VK_FORMAT_R8G8B8A8_UNORM
: VK_FORMAT_R16G16B16A16_SFLOAT;
for (size_t i = 0; i < genc; i++)
this->outImgs.emplace_back(device,
extent,
VK_FORMAT_R8G8B8A8_UNORM,
extent, format,
VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VK_IMAGE_ASPECT_COLOR_BIT,
outFds.at(i));

View file

@ -2,6 +2,7 @@
#include "core/buffer.hpp"
#include "lsfg.hpp"
#include <cstdlib>
#include <fstream>
using namespace LSFG;
@ -188,6 +189,8 @@ void Globals::initializeGlobals(const Core::Device& device) {
// initialize global constant buffer
fgBuffer = {
.inputOffset = { 0, 29 },
.advancedColorKind = getenv("LSFG_HDR") == nullptr ? 0U : 2U,
.hdrSupport = getenv("LSFG_HDR") != nullptr,
.resolutionInvScale = 1.0F,
.timestamp = 0.5F,
.uiThreshold = 0.1F,

View file

@ -12,11 +12,18 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain,
VkExtent2D extent, const std::vector<VkImage>& swapchainImages)
: swapchain(swapchain), swapchainImages(swapchainImages),
extent(extent) {
// we could take the format from the swapchain,
// but honestly this is safer.
const VkFormat format = getenv("LSFG_HDR") == nullptr
? VK_FORMAT_R8G8B8A8_UNORM
: VK_FORMAT_R16G16B16A16_SFLOAT;
// prepare textures for lsfg
int frame_0_fd{};
this->frame_0 = Mini::Image(
info.device, info.physicalDevice,
extent, VK_FORMAT_R8G8B8A8_UNORM,
extent, format,
VK_IMAGE_USAGE_TRANSFER_DST_BIT,
VK_IMAGE_ASPECT_COLOR_BIT,
&frame_0_fd);
@ -26,7 +33,7 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain,
int frame_1_fd{};
this->frame_1 = Mini::Image(
info.device, info.physicalDevice,
extent, VK_FORMAT_R8G8B8A8_UNORM,
extent, format,
VK_IMAGE_USAGE_TRANSFER_DST_BIT,
VK_IMAGE_ASPECT_COLOR_BIT,
&frame_1_fd);
@ -37,7 +44,7 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain,
for (size_t i = 0; i < info.frameGen; ++i) {
this->out_n.emplace_back(
info.device, info.physicalDevice,
extent, VK_FORMAT_R8G8B8A8_UNORM,
extent, format,
VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
VK_IMAGE_ASPECT_COLOR_BIT,
&out_n_fds.at(i));