Skip to content

Commit 6f531a8

Browse files
Fixes for HDR
Fixed EnableHDR being the wrong value in shaders Fixed D3D11/D3D12 scanlines being different to Vulkans Optimised Vulkan scanlines to be the same as D3D11/D3D12 Deleted the high risk changes in Vulkan that were commented out as Vulkan seems to be working for the majority of users
1 parent d74f410 commit 6f531a8

8 files changed

Lines changed: 907 additions & 940 deletions

File tree

gfx/drivers/d3d11.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ static void d3d11_set_hdr_paper_white_nits(void* data, float paper_white_nits)
16301630
{
16311631
for (unsigned i = 0; i < d3d11->shader_preset->passes; i++)
16321632
{
1633-
d3d11->pass[i].paper_white_nits = paper_white_nits;
1633+
d3d11->pass[i].paper_white_nits = paper_white_nits;
16341634
}
16351635
}
16361636
}
@@ -3611,7 +3611,7 @@ static bool d3d11_gfx_frame(
36113611
#ifdef HAVE_DXGI_HDR
36123612
settings_t* settings = config_get_ptr();
36133613

3614-
d3d11->pass[i].enable_hdr = d3d11->flags & D3D11_ST_FLAG_HDR_ENABLE;
3614+
d3d11->pass[i].enable_hdr = (d3d11->flags & D3D11_ST_FLAG_HDR_ENABLE) ? 1.0f : 0.0f;
36153615

36163616
if(d3d11->flags & D3D11_ST_FLAG_HDR_ENABLE)
36173617
{
@@ -4493,8 +4493,8 @@ static const video_poke_interface_t d3d11_poke_interface = {
44934493
#else
44944494
NULL, /* set_hdr_max_nits */
44954495
NULL, /* set_hdr_paper_white_nits */
4496-
NULL, /* set_hdr_expand_gamut */
4497-
NULL, /* set_hdr_scanlines */
4496+
NULL, /* set_hdr_expand_gamut */
4497+
NULL, /* set_hdr_scanlines */
44984498
NULL /* d3d11_set_hdr_subpixel_layout */
44994499
#endif
45004500
};

gfx/drivers/d3d12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,7 @@ static bool d3d12_gfx_frame(
42134213
#ifdef HAVE_DXGI_HDR
42144214
settings_t* settings = config_get_ptr();
42154215

4216-
d3d12->pass[i].enable_hdr = d3d12->flags & D3D12_ST_FLAG_HDR_ENABLE;
4216+
d3d12->pass[i].enable_hdr = (d3d12->flags & D3D12_ST_FLAG_HDR_ENABLE) ? 1.0f : 0.0f;
42174217

42184218
if(d3d12->flags & D3D12_ST_FLAG_HDR_ENABLE)
42194219
{

gfx/drivers/d3d_shaders/hdr_sm5.hlsl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ static const float k_crt_green_horizontal_convergence = 0.0f;
8282
static const float k_crt_blue_horizontal_convergence = 0.0f;
8383

8484
static const float k_crt_red_scanline_min = 0.45f;
85-
static const float k_crt_red_scanline_max = 1.00f;
85+
static const float k_crt_red_scanline_max = 0.70f;
8686
static const float k_crt_red_scanline_attack = 0.30f;
8787
static const float k_crt_green_scanline_min = 0.45f;
88-
static const float k_crt_green_scanline_max = 1.00f;
88+
static const float k_crt_green_scanline_max = 0.70f;
8989
static const float k_crt_green_scanline_attack = 0.30f;
9090
static const float k_crt_blue_scanline_min = 0.45f;
91-
static const float k_crt_blue_scanline_max = 1.00f;
91+
static const float k_crt_blue_scanline_max = 0.70f;
9292
static const float k_crt_blue_scanline_attack = 0.30f;
9393

9494
static const float k_crt_red_beam_sharpness = 1.30f;

gfx/drivers/vulkan.c

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ typedef struct vk
179179
struct vk_image *backbuffer;
180180
#ifdef VULKAN_HDR_SWAPCHAIN
181181
VkRenderPass readback_render_pass;
182-
/* struct vk_image main_buffer; */
183182
struct vk_image readback_image;
184183
#endif /* VULKAN_HDR_SWAPCHAIN */
185184

@@ -231,7 +230,6 @@ typedef struct vk
231230
VkPipeline font;
232231
VkPipeline rgb565_to_rgba8888;
233232
#ifdef VULKAN_HDR_SWAPCHAIN
234-
/* VkPipeline hdr; */
235233
VkPipeline hdr_to_sdr; /* for readback */
236234
#endif /* VULKAN_HDR_SWAPCHAIN */
237235
VkDescriptorSetLayout set_layout;
@@ -2419,9 +2417,6 @@ static void vulkan_init_pipeline_layout(
24192417
static void vulkan_init_pipelines(vk_t *vk)
24202418
{
24212419
#ifdef VULKAN_HDR_SWAPCHAIN
2422-
/* static const uint32_t hdr_frag[] =
2423-
#include "vulkan_shaders/hdr.frag.inc"
2424-
;*/
24252420
static const uint32_t hdr_tonemap_frag[] =
24262421
#include "vulkan_shaders/hdr_tonemap.frag.inc"
24272422
;
@@ -2648,30 +2643,6 @@ if (vk->context->flags & VK_CTX_FLAG_HDR_SUPPORT)
26482643
{
26492644
blend_attachment.blendEnable = VK_FALSE;
26502645

2651-
/* HDR pipeline. */
2652-
/*
2653-
module_info.codeSize = sizeof(hdr_frag);
2654-
module_info.pCode = hdr_frag;
2655-
shader_stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
2656-
shader_stages[1].pName = "main";
2657-
vkCreateShaderModule(vk->context->device,
2658-
&module_info, NULL, &shader_stages[1].module);
2659-
2660-
vkCreateGraphicsPipelines(vk->context->device, vk->pipelines.cache,
2661-
1, &pipe, NULL, &vk->pipelines.hdr);
2662-
*/
2663-
2664-
/* Build display hdr pipelines. */
2665-
/*
2666-
for (i = 4; i < 6; i++)
2667-
{
2668-
input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2669-
vkCreateGraphicsPipelines(vk->context->device, vk->pipelines.cache,
2670-
1, &pipe, NULL, &vk->display.pipelines[i]);
2671-
}
2672-
2673-
vkDestroyShaderModule(vk->context->device, shader_stages[1].module, NULL);
2674-
*/
26752646

26762647
/* HDR->SDR tonemapping readback pipeline. */
26772648
module_info.codeSize = sizeof(hdr_tonemap_frag);
@@ -2978,8 +2949,6 @@ static void vulkan_deinit_pipelines(vk_t *vk)
29782949
#ifdef VULKAN_HDR_SWAPCHAIN
29792950
if (vk->context->flags & VK_CTX_FLAG_HDR_SUPPORT)
29802951
{
2981-
/* vkDestroyPipeline(vk->context->device,
2982-
vk->pipelines.hdr, NULL); */
29832952
vkDestroyPipeline(vk->context->device,
29842953
vk->pipelines.hdr_to_sdr, NULL);
29852954
}
@@ -3477,7 +3446,6 @@ static void vulkan_free(void *data)
34773446
if (vk->context->flags & VK_CTX_FLAG_HDR_SUPPORT)
34783447
{
34793448
vulkan_destroy_buffer(vk->context->device, &vk->hdr.ubo);
3480-
/* vulkan_destroy_hdr_buffer(vk->context->device, &vk->main_buffer); */
34813449
vulkan_destroy_hdr_buffer(vk->context->device, &vk->readback_image);
34823450
vulkan_deinit_hdr_readback_render_pass(vk);
34833451
video_driver_unset_hdr_support();
@@ -4947,7 +4915,7 @@ static bool vulkan_frame(void *data, const void *frame,
49474915

49484916
#ifdef VULKAN_HDR_SWAPCHAIN
49494917
vulkan_filter_chain_set_enable_hdr(
4950-
(vulkan_filter_chain_t*)filter_chain, vk->context->flags & VK_CTX_FLAG_HDR_ENABLE);
4918+
(vulkan_filter_chain_t*)filter_chain, (vk->context->flags & VK_CTX_FLAG_HDR_ENABLE) ? 1.0f : 0.0f);
49514919
#endif /* VULKAN_HDR_SWAPCHAIN */
49524920

49534921
/* Render offscreen filter chain passes. */
@@ -5047,12 +5015,6 @@ static bool vulkan_frame(void *data, const void *frame,
50475015
}
50485016
#endif
50495017

5050-
/*
5051-
#ifdef VULKAN_HDR_SWAPCHAIN
5052-
if (use_main_buffer)
5053-
backbuffer = &vk->main_buffer;
5054-
#endif /* VULKAN_HDR_SWAPCHAIN */
5055-
50565018
/* Render to backbuffer. */
50575019
if ( (backbuffer->image != VK_NULL_HANDLE)
50585020
&& (vk->context->flags & VK_CTX_FLAG_HAS_ACQUIRED_SWAPCHAIN))
@@ -5365,7 +5327,6 @@ static bool vulkan_frame(void *data, const void *frame,
53655327
#ifdef HAVE_THREADS
53665328
slock_unlock(vk->context->queue_lock);
53675329
#endif
5368-
/* vulkan_destroy_hdr_buffer(vk->context->device, &vk->main_buffer); */
53695330
vulkan_destroy_hdr_buffer(vk->context->device, &vk->readback_image);
53705331
}
53715332
else
@@ -5383,9 +5344,6 @@ static bool vulkan_frame(void *data, const void *frame,
53835344
#ifdef VULKAN_HDR_SWAPCHAIN
53845345
if (vk->context->flags & VK_CTX_FLAG_HDR_ENABLE)
53855346
{
5386-
/* Create intermediary buffer to render filter chain output to */
5387-
/* vulkan_init_render_target(&vk->main_buffer, video_width, video_height,
5388-
vk->context->swapchain_format, vk->render_pass, vk->context); */
53895347
/* Create image for readback target in bgra8 format */
53905348
vulkan_init_render_target(&vk->readback_image, video_width, video_height,
53915349
VK_FORMAT_B8G8R8A8_UNORM, vk->readback_render_pass, vk->context);

gfx/drivers/vulkan_shaders/hdr.frag

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,18 @@ float GenerateScanline( const uint channel,
202202
scanline_min, scanline_max, scanline_attack,
203203
0.0);
204204

205-
total_light += ScanlineColour( channel, tex_coord, source_size, scanline_size, source_tex_coord_x,
206-
narrowed_source_pixel_offset, vertical_convergence, beam_attack,
207-
scanline_min, scanline_max, scanline_attack,
208-
1.0);
209-
210-
total_light += ScanlineColour( channel, tex_coord, source_size, scanline_size, source_tex_coord_x,
211-
narrowed_source_pixel_offset, vertical_convergence, beam_attack,
212-
scanline_min, scanline_max, scanline_attack,
213-
-1.0);
205+
if(k_crt_bloom_strength > 0.0f)
206+
{
207+
total_light += ScanlineColour( channel, tex_coord, source_size, scanline_size, source_tex_coord_x,
208+
narrowed_source_pixel_offset, vertical_convergence, beam_attack,
209+
scanline_min, scanline_max, scanline_attack,
210+
1.0);
211+
212+
total_light += ScanlineColour( channel, tex_coord, source_size, scanline_size, source_tex_coord_x,
213+
narrowed_source_pixel_offset, vertical_convergence, beam_attack,
214+
scanline_min, scanline_max, scanline_attack,
215+
-1.0);
216+
}
214217

215218
return total_light;
216219
}

0 commit comments

Comments
 (0)