From b54ad4d67fc194b39932fd09749ec5ced34cb5a6 Mon Sep 17 00:00:00 2001 From: LazyBumHorse Date: Wed, 29 May 2019 18:09:37 +0200 Subject: [PATCH 1/2] implement FrameDirection slang semantic for d3d10,11,12 --- gfx/common/d3d10_common.h | 1 + gfx/common/d3d11_common.h | 1 + gfx/common/d3d12_common.h | 1 + gfx/drivers/d3d10.c | 12 ++++++++---- gfx/drivers/d3d11.c | 12 ++++++++---- gfx/drivers/d3d12.c | 12 ++++++++---- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gfx/common/d3d10_common.h b/gfx/common/d3d10_common.h index 3431244fd3..1784c33a8c 100644 --- a/gfx/common/d3d10_common.h +++ b/gfx/common/d3d10_common.h @@ -1208,6 +1208,7 @@ typedef struct D3D10_VIEWPORT viewport; pass_semantics_t semantics; uint32_t frame_count; + int32_t frame_direction; } pass[GFX_MAX_SHADERS]; struct video_shader* shader_preset; diff --git a/gfx/common/d3d11_common.h b/gfx/common/d3d11_common.h index a88336dfc7..ac6332d227 100644 --- a/gfx/common/d3d11_common.h +++ b/gfx/common/d3d11_common.h @@ -2584,6 +2584,7 @@ typedef struct D3D11_VIEWPORT viewport; pass_semantics_t semantics; uint32_t frame_count; + int32_t frame_direction; } pass[GFX_MAX_SHADERS]; struct video_shader* shader_preset; diff --git a/gfx/common/d3d12_common.h b/gfx/common/d3d12_common.h index 5d4e221a3d..d9381dd5a9 100644 --- a/gfx/common/d3d12_common.h +++ b/gfx/common/d3d12_common.h @@ -1444,6 +1444,7 @@ typedef struct D3D12_RECT scissorRect; pass_semantics_t semantics; uint32_t frame_count; + int32_t frame_direction; D3D12_GPU_DESCRIPTOR_HANDLE textures; D3D12_GPU_DESCRIPTOR_HANDLE samplers; } pass[GFX_MAX_SHADERS]; diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c index 79d65a47bb..60fc65d625 100644 --- a/gfx/drivers/d3d10.c +++ b/gfx/drivers/d3d10.c @@ -27,6 +27,7 @@ #include "../../verbosity.h" #include "../../configuration.h" #include "../../retroarch.h" +#include "../../managers/state_manager.h" #include "../video_driver.h" #include "../font_driver.h" @@ -390,10 +391,11 @@ static bool d3d10_gfx_set_shader(void* data, &d3d10->luts[0].size_data, sizeof(*d3d10->luts)}, }, { - &d3d10->mvp, /* MVP */ - &d3d10->pass[i].rt.size_data, /* OutputSize */ - &d3d10->frame.output_size, /* FinalViewportSize */ - &d3d10->pass[i].frame_count, /* FrameCount */ + &d3d10->mvp, /* MVP */ + &d3d10->pass[i].rt.size_data, /* OutputSize */ + &d3d10->frame.output_size, /* FinalViewportSize */ + &d3d10->pass[i].frame_count, /* FrameCount */ + &d3d10->pass[i].frame_direction, /* FrameDirection */ } }; /* clang-format on */ @@ -1283,6 +1285,8 @@ static bool d3d10_gfx_frame( else d3d10->pass[i].frame_count = frame_count; + d3d10->pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1; + for (j = 0; j < SLANG_CBUFFER_MAX; j++) { D3D10Buffer buffer = d3d10->pass[i].buffers[j]; diff --git a/gfx/drivers/d3d11.c b/gfx/drivers/d3d11.c index 14f98dd1bb..125b9b42f8 100644 --- a/gfx/drivers/d3d11.c +++ b/gfx/drivers/d3d11.c @@ -43,6 +43,7 @@ #include "../../menu/menu_driver.h" #include "../video_shader_parse.h" #include "../drivers_shader/slang_preprocess.h" +#include "../../managers/state_manager.h" #include "../common/d3d_common.h" #include "../common/d3d11_common.h" @@ -408,10 +409,11 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const &d3d11->luts[0].size_data, sizeof(*d3d11->luts)}, }, { - &d3d11->mvp, /* MVP */ - &d3d11->pass[i].rt.size_data, /* OutputSize */ - &d3d11->frame.output_size, /* FinalViewportSize */ - &d3d11->pass[i].frame_count, /* FrameCount */ + &d3d11->mvp, /* MVP */ + &d3d11->pass[i].rt.size_data, /* OutputSize */ + &d3d11->frame.output_size, /* FinalViewportSize */ + &d3d11->pass[i].frame_count, /* FrameCount */ + &d3d11->pass[i].frame_direction, /* FrameDirection */ } }; /* clang-format on */ @@ -1356,6 +1358,8 @@ static bool d3d11_gfx_frame( else d3d11->pass[i].frame_count = frame_count; + d3d11->pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1; + for (j = 0; j < SLANG_CBUFFER_MAX; j++) { D3D11Buffer buffer = d3d11->pass[i].buffers[j]; diff --git a/gfx/drivers/d3d12.c b/gfx/drivers/d3d12.c index dad01e62fa..d99755dab2 100644 --- a/gfx/drivers/d3d12.c +++ b/gfx/drivers/d3d12.c @@ -32,6 +32,7 @@ #include "../../verbosity.h" #include "../../configuration.h" #include "../../retroarch.h" +#include "../../managers/state_manager.h" #ifdef HAVE_MENU #include "../../menu/menu_driver.h" @@ -398,10 +399,11 @@ static bool d3d12_gfx_set_shader(void* data, enum rarch_shader_type type, const &d3d12->luts[0].size_data, sizeof(*d3d12->luts)}, }, { - &d3d12->mvp, /* MVP */ - &d3d12->pass[i].rt.size_data, /* OutputSize */ - &d3d12->frame.output_size, /* FinalViewportSize */ - &d3d12->pass[i].frame_count, /* FrameCount */ + &d3d12->mvp, /* MVP */ + &d3d12->pass[i].rt.size_data, /* OutputSize */ + &d3d12->frame.output_size, /* FinalViewportSize */ + &d3d12->pass[i].frame_count, /* FrameCount */ + &d3d12->pass[i].frame_direction, /* FrameDirection */ } }; /* clang-format on */ @@ -1294,6 +1296,8 @@ static bool d3d12_gfx_frame( else d3d12->pass[i].frame_count = frame_count; + d3d12->pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1; + for (j = 0; j < SLANG_CBUFFER_MAX; j++) { cbuffer_sem_t* buffer_sem = &d3d12->pass[i].semantics.cbuffers[j]; From 9ab49b7b2c2384b1b5ddbc676e39ce9eac0b18be Mon Sep 17 00:00:00 2001 From: LazyBumHorse Date: Wed, 29 May 2019 21:06:44 +0200 Subject: [PATCH 2/2] Add FrameDirection for metal and gx2_gfx --- gfx/common/metal_common.m | 13 +++++++++---- gfx/drivers/gx2_gfx.c | 21 +++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m index d91ca2488e..d9163e9be9 100644 --- a/gfx/common/metal_common.m +++ b/gfx/common/metal_common.m @@ -14,6 +14,7 @@ #include #import +#include "../../managers/state_manager.h" #import "metal_common.h" #import "../../ui/drivers/cocoa/cocoa_common.h" @@ -552,6 +553,7 @@ typedef struct MTLALIGN(16) texture_t rt; texture_t feedback; uint32_t frame_count; + int32_t frame_direction; pass_semantics_t semantics; MTLViewport viewport; __unsafe_unretained id _state; @@ -927,6 +929,8 @@ typedef struct MTLALIGN(16) if (_shader->pass[i].frame_count_mod) _engine.pass[i].frame_count %= _shader->pass[i].frame_count_mod; + _engine.pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1; + for (unsigned j = 0; j < SLANG_CBUFFER_MAX; j++) { id buffer = _engine.pass[i].buffers[j]; @@ -1176,10 +1180,11 @@ typedef struct MTLALIGN(16) &_engine.luts[0].size_data, sizeof(*_engine.luts)}, }, { - mvp, /* MVP */ - &_engine.pass[i].rt.size_data, /* OutputSize */ - &_engine.frame.output_size, /* FinalViewportSize */ - &_engine.pass[i].frame_count, /* FrameCount */ + mvp, /* MVP */ + &_engine.pass[i].rt.size_data, /* OutputSize */ + &_engine.frame.output_size, /* FinalViewportSize */ + &_engine.pass[i].frame_count, /* FrameCount */ + &_engine.pass[i].frame_direction, /* FrameDirection */ } }; /* clang-format on */ diff --git a/gfx/drivers/gx2_gfx.c b/gfx/drivers/gx2_gfx.c index 9b3f797f8a..619d7796ed 100644 --- a/gfx/drivers/gx2_gfx.c +++ b/gfx/drivers/gx2_gfx.c @@ -25,6 +25,7 @@ #include "../../configuration.h" #include "../../verbosity.h" #include "../../retroarch.h" +#include "../../managers/state_manager.h" #ifdef HAVE_CONFIG_H #include "../../config.h" @@ -873,7 +874,8 @@ static bool wiiu_init_frame_textures(wiiu_video_t *wiiu, unsigned width, unsigne } static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu, int pass, float *ubo, int id, - int size, int uniformVarCount, GX2UniformVar *uniformVars, uint64_t frame_count) + int size, int uniformVarCount, GX2UniformVar *uniformVars, + uint64_t frame_count, int32_t frame_direction) { for (int i = 0; i < uniformVarCount; i++) { @@ -916,6 +918,13 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu, int pass, float *u continue; } + if (string_is_equal(id, "FrameDirection")) + { + *dst = frame_direction; + *(u32 *)dst = __builtin_bswap32(*(u32 *)dst); + continue; + } + if (string_is_equal(id, "OriginalSize")) { ((GX2_vec4 *)dst)->x = wiiu->texture.surface.width; @@ -1146,6 +1155,8 @@ static bool wiiu_gfx_frame(void *data, const void *frame, if (wiiu->shader_preset) { + int32_t frame_direction = state_manager_frame_is_reversed() ? -1 : 1; + for (int i = 0; i < wiiu->shader_preset->passes; i++) { @@ -1155,7 +1166,8 @@ static bool wiiu_gfx_frame(void *data, const void *frame, { wiiu_gfx_update_uniform_block(wiiu, i, wiiu->pass[i].vs_ubos[j], j, wiiu->pass[i].gfd->vs->uniformBlocks[j].size, - wiiu->pass[i].gfd->vs->uniformVarCount, wiiu->pass[i].gfd->vs->uniformVars, frame_count); + wiiu->pass[i].gfd->vs->uniformVarCount, wiiu->pass[i].gfd->vs->uniformVars, + frame_count, frame_direction); GX2SetVertexUniformBlock(wiiu->pass[i].gfd->vs->uniformBlocks[j].offset, wiiu->pass[i].gfd->vs->uniformBlocks[j].size, wiiu->pass[i].vs_ubos[j]); } @@ -1166,7 +1178,8 @@ static bool wiiu_gfx_frame(void *data, const void *frame, { wiiu_gfx_update_uniform_block(wiiu, i, wiiu->pass[i].ps_ubos[j], j, wiiu->pass[i].gfd->ps->uniformBlocks[j].size, - wiiu->pass[i].gfd->ps->uniformVarCount, wiiu->pass[i].gfd->ps->uniformVars, frame_count); + wiiu->pass[i].gfd->ps->uniformVarCount, wiiu->pass[i].gfd->ps->uniformVars, + frame_count, frame_direction); GX2SetPixelUniformBlock(wiiu->pass[i].gfd->ps->uniformBlocks[j].offset, wiiu->pass[i].gfd->ps->uniformBlocks[j].size, wiiu->pass[i].ps_ubos[j]); } @@ -1444,7 +1457,7 @@ static bool wiiu_gfx_set_shader(void *data, video_shader_resolve_relative(wiiu->shader_preset, path); #if 0 - video_shader_resolve_parameters(conf, wiiu->shader_preset); + video_shader_resolve_parameters(conf, wiiu->shader_preset); #else for (int i = 0; i < wiiu->shader_preset->passes; i++) slang_preprocess_parse_parameters(wiiu->shader_preset->pass[i].source.path, wiiu->shader_preset);