Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDR output (outdated) #249

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d872172
Add ClearBits for FBitSet
0x4E69676874466F78 Dec 1, 2021
c7aa364
Add FCVAR_READ_ONLY and unlock FCVAR_GLCONFIG (temporary solution for…
0x4E69676874466F78 Dec 1, 2021
0f1c136
add vk_rtx_extension cvar for rtx options, more smart vk_rtx cvar
0x4E69676874466F78 Dec 1, 2021
7694fb6
initial HDR output support
0x4E69676874466F78 Dec 2, 2021
758de30
fix C90 error
0x4E69676874466F78 Dec 2, 2021
236339a
fix C90 error №2
0x4E69676874466F78 Dec 2, 2021
cbdcabb
add check colorSpace for HDR mode, add vk_hdr_extension for option
0x4E69676874466F78 Dec 2, 2021
3ce4b22
force disable HDR if not supported by hardware/software
0x4E69676874466F78 Dec 2, 2021
a218ebf
fix UI in HDR, fix HDR in with/without RTX, specialization for HDR
0x4E69676874466F78 Dec 6, 2021
124878b
Merge branch 'vulkan' into hdr
0x4E69676874466F78 Dec 6, 2021
0dedbac
fix formatting
0x4E69676874466F78 Dec 6, 2021
71ee08d
fix formatting again
0x4E69676874466F78 Dec 6, 2021
67e1113
oops, missing tonemapping.glsl
0x4E69676874466F78 Dec 7, 2021
74ae939
fix formatting again 2
0x4E69676874466F78 Dec 7, 2021
1989690
fix hdr shader init (i'm stupid)
0x4E69676874466F78 Dec 7, 2021
354a525
more control for HDR output and more correct RTX
0x4E69676874466F78 Dec 7, 2021
22e38ed
Merge branch 'vulkan' into hdr
0x4E69676874466F78 Dec 12, 2021
6697ef8
Merge branch 'vulkan' into hdr
0x4E69676874466F78 Jan 22, 2022
4ea65ad
fix hdr for last vulkan branch + tuned
0x4E69676874466F78 Jan 23, 2022
30a57d0
tune hdr for classic render mode
0x4E69676874466F78 Jan 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion engine/common/cvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ void Cvar_DirectSet( convar_t *var, const char *value )
if( var != Cvar_FindVar( var->name ))
return; // how this possible?

if( FBitSet( var->flags, FCVAR_READ_ONLY|FCVAR_GLCONFIG ))
//if( FBitSet( var->flags, FCVAR_READ_ONLY|FCVAR_GLCONFIG ))
if( FBitSet( var->flags, FCVAR_READ_ONLY )) // TODO: fix order VK init render or fix this GL-eccentric
{
Con_Printf( "%s is read-only.\n", var->name );
return;
Expand Down
9 changes: 8 additions & 1 deletion ref_vk/vk_cvar.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "vk_cvar.h"
#include "vk_common.h"
#include "vk_render.h"

#define NONEXTERN_CVAR(cvar) cvar_t *cvar;
DECLARE_CVAR(NONEXTERN_CVAR)
Expand All @@ -19,5 +20,11 @@ void VK_LoadCvars( void )
vk_rtx_light_end = gEngine.Cvar_Get( "vk_rtx_light_end", "0", 0, "DEBUG: disable lights with index higher than this ");
r_lightmap = gEngine.Cvar_Get( "r_lightmap", "0", FCVAR_CHEAT, "lightmap debugging tool" );
ui_infotool = gEngine.Cvar_Get( "ui_infotool", "0", FCVAR_CHEAT, "DEBUG: print entity info under crosshair" );
vk_rtx = gEngine.Cvar_Get( "vk_rtx", "1", FCVAR_ARCHIVE, "Enable or disable ray tracing mode" );
vk_rtx_extension = gEngine.Cvar_Get( "vk_rtx_extension", vk_core.rtx ? "1" : "0", FCVAR_READ_ONLY, "" );
if (vk_core.rtx) {
vk_rtx = gEngine.Cvar_Get( "vk_rtx", "1", FCVAR_GLCONFIG, "Enable or disable Ray Tracing mode" );
} else {
vk_rtx = gEngine.Cvar_Get( "vk_rtx", "0", FCVAR_READ_ONLY, "DISABLED: not supported without -rtx" );
}
vk_hdr = gEngine.Cvar_Get( "vk_hdr", "0", FCVAR_GLCONFIG, "Enable or disable High Dynamic Range output (RESTART REQUIRED)" );
}
5 changes: 5 additions & 0 deletions ref_vk/vk_cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "cvardef.h"

// from engine/common/cvar.h
#define FCVAR_READ_ONLY (1<<17) // cannot be set by user at all, and can't be requested by CvarGetPointer from game dlls

#define CVAR_TO_BOOL( x ) ((x) && ((x)->value != 0.0f) ? true : false )

void VK_LoadCvars( void );
Expand All @@ -16,6 +19,8 @@ void VK_LoadCvars( void );
X(r_lightmap) \
X(ui_infotool) \
X(vk_rtx) \
X(vk_rtx_extension) \
X(vk_hdr) \

#define EXTERN_CVAR(cvar) extern cvar_t *cvar;
DECLARE_CVAR(EXTERN_CVAR)
Expand Down
27 changes: 20 additions & 7 deletions ref_vk/vk_framectl.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ static void destroyDepthImage( void ) {
freeDeviceMemory(&g_frame.depth.device_memory);
}

static VkRenderPass createRenderPass( qboolean ray_tracing ) {
static VkRenderPass createRenderPass( qboolean ray_tracing, qboolean hdr_output ) {
VkRenderPass render_pass;

VkAttachmentDescription attachments[] = {{
.format = VK_FORMAT_B8G8R8A8_UNORM, //SRGB,// FIXME too early swapchain.create_info.imageFormat;
.format = hdr_output ? VK_FORMAT_A2B10G10R10_UNORM_PACK32 : VK_FORMAT_B8G8R8A8_UNORM, //SRGB,// FIXME too early swapchain.create_info.imageFormat;
.samples = VK_SAMPLE_COUNT_1_BIT,
.loadOp = ray_tracing ? VK_ATTACHMENT_LOAD_OP_LOAD : VK_ATTACHMENT_LOAD_OP_CLEAR /* TODO: prod renderer should not care VK_ATTACHMENT_LOAD_OP_DONT_CARE */,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
Expand Down Expand Up @@ -213,6 +213,8 @@ static qboolean createSwapchain( void )
// recreating swapchain means invalidating any previous frames
g_frame.last_frame_index = -1;

qboolean hdr_output = CVAR_TO_BOOL( vk_hdr );

XVK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_core.physical_device.device, vk_core.surface.surface, &g_frame.surface_caps));

vk_frame.width = g_frame.surface_caps.currentExtent.width;
Expand All @@ -230,8 +232,8 @@ static qboolean createSwapchain( void )
create_info->sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
create_info->pNext = NULL;
create_info->surface = vk_core.surface.surface;
create_info->imageFormat = VK_FORMAT_B8G8R8A8_UNORM;//SRGB; // TODO get from surface_formats
create_info->imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; // TODO get from surface_formats
create_info->imageFormat = hdr_output ? VK_FORMAT_A2B10G10R10_UNORM_PACK32 : VK_FORMAT_B8G8R8A8_UNORM;//SRGB; // TODO get from surface_formats
create_info->imageColorSpace = hdr_output ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLORSPACE_SRGB_NONLINEAR_KHR; // TODO get from surface_formats
create_info->imageExtent.width = vk_frame.width;
create_info->imageExtent.height = vk_frame.height;
create_info->imageArrayLayers = 1;
Expand Down Expand Up @@ -315,6 +317,7 @@ void R_BeginFrame( qboolean clearScene )
if (vk_core.rtx && FBitSet( vk_rtx->flags, FCVAR_CHANGED )) {
g_frame.rtx_enabled = CVAR_TO_BOOL( vk_rtx );
}
ClearBits( vk_rtx->flags, FCVAR_CHANGED );
{
gEngine.Con_NPrintf(5, "Perf scopes:");
for (int i = 0; i < g_aprof.num_scopes; ++i) {
Expand Down Expand Up @@ -345,6 +348,14 @@ void R_BeginFrame( qboolean clearScene )
}
}

// TODO: VkFramebufferCreateInfo attachment #0 has format of VK_FORMAT_A2B10G10R10_UNORM_PACK32 that does not match the format of VK_FORMAT_B8G8R8A8_UNORM used by the corresponding attachment for VkRenderPass
/*
if (FBitSet( vk_hdr->flags, FCVAR_CHANGED )) {
createSwapchain();
}
ClearBits( vk_hdr->flags, FCVAR_CHANGED );
*/

for (int i = 0;; ++i)
{
const VkResult acquire_result = vkAcquireNextImageKHR(vk_core.device, g_frame.swapchain, UINT64_MAX, g_frame.image_available,
Expand Down Expand Up @@ -511,15 +522,17 @@ void R_EndFrame( void )
static void toggleRaytracing( void ) {
ASSERT(vk_core.rtx);
g_frame.rtx_enabled = !g_frame.rtx_enabled;
gEngine.Cvar_Set("vk_rtx", g_frame.rtx_enabled ? "1" : "0");
gEngine.Con_Printf(S_WARN "Switching ray tracing to %d\n", g_frame.rtx_enabled);
}

qboolean VK_FrameCtlInit( void )
{
PROFILER_SCOPES(APROF_SCOPE_INIT);
vk_frame.render_pass.raster = createRenderPass(false);
qboolean hdr_output = CVAR_TO_BOOL( vk_hdr );
0x4E69676874466F78 marked this conversation as resolved.
Show resolved Hide resolved
vk_frame.render_pass.raster = createRenderPass(false, hdr_output);
if (vk_core.rtx)
vk_frame.render_pass.after_ray_tracing = createRenderPass(true);
vk_frame.render_pass.after_ray_tracing = createRenderPass(true, hdr_output);

if (!createSwapchain())
return false;
Expand Down Expand Up @@ -762,7 +775,7 @@ static rgbdata_t *XVK_ReadPixels( void ) {
r_shot->buffer = Mem_Malloc( r_temppool, r_shot->size );

if (!blit) {
if (dest_format != VK_FORMAT_R8G8B8A8_UNORM || g_frame.create_info.imageFormat != VK_FORMAT_B8G8R8A8_UNORM) {
if (dest_format != VK_FORMAT_R8G8B8A8_UNORM || g_frame.create_info.imageFormat != VK_FORMAT_B8G8R8A8_UNORM) { // TODO: fix for HDR
gEngine.Con_Printf(S_WARN "Don't have a blit function for this format pair, will save as-is w/o conversion; expect image to look wrong\n");
blit = true;
} else {
Expand Down