Skip to content

Commit

Permalink
Add Frametime Uniforms (#17155)
Browse files Browse the repository at this point in the history
* Initial implementation of CoreAspect uniform

* float -> float_t

* Possibly fix wii_u building

* vulkan: use float instead of float_t;

* slangp: Advertise support of CoreAspect uniform
by defining _RARCH_HAS_COREASPECT_UNIFORM early in the shader source, just after "#extension GL_GOOGLE_cpp_style_line_directive : require"

* CoreAspect + glsl fix: use glUniform1f()

* Add CoreAspectRot uniform.
It reports CoreAspect value or 1/CoreAspect when the content is rotated by 90 or 270 deg.

* Fixed stupid typo

* Just use _HAS_COREASPECT_UNIFORMS to check for CoreAspect uniforms support (was _RARCH_HAS_COREASPECT_UNIFORMS)

* Rename CoreAspect, CoreAspectRot, _HAS_COREASPECT_UNIFORMS to OriginalAspect, OriginlAspectRot, _HAS_ORIGINALASPECT_UNIFORMS

* GLCore: void Pass::build_semantic_float needs glUniform1f.
...how on earth did it worked for UBO !?

* d3d10,11,12, wrong function called by overlook.

* Add test shader, will remove that before PR

* Fix metal rotated aspect reporting

* remove test shader

* Fix C89 Build

* Use OriginalAspectRotated instead of OriginalAspectRot

* Add CoreFPS and FrameTimeDelta Uniforms.
_HAS_ORIGINALASPECT_UNIFORMS is (#)defined and can be used to query for them.

* add test shader

* remote test shader

* Wrong paste.

* gx2: use float

* wrong indentation

* resolved merge conflict

* fix indentation

* Fix comment/Formatting

* Change uniform name from CoreFPS to OriginalFPS

* underliyng references: core_fps -> original_fps
  • Loading branch information
kokoko3k authored Nov 13, 2024
1 parent 9452536 commit 2a56a82
Show file tree
Hide file tree
Showing 22 changed files with 270 additions and 45 deletions.
2 changes: 2 additions & 0 deletions gfx/common/d3d10_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ typedef struct
pass_semantics_t semantics;
uint32_t frame_count;
int32_t frame_direction;
uint32_t frame_time_delta;
float original_fps;
uint32_t rotation;
uint32_t total_subframes;
uint32_t current_subframe;
Expand Down
2 changes: 2 additions & 0 deletions gfx/common/d3d11_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ typedef struct
pass_semantics_t semantics;
uint32_t frame_count;
int32_t frame_direction;
uint32_t frame_time_delta;
float original_fps;
uint32_t rotation;
uint32_t total_subframes;
uint32_t current_subframe;
Expand Down
2 changes: 2 additions & 0 deletions gfx/common/d3d12_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ typedef struct
pass_semantics_t semantics;
uint32_t frame_count;
int32_t frame_direction;
uint32_t frame_time_delta;
float original_fps;
uint32_t rotation;
uint32_t total_subframes;
uint32_t current_subframe;
Expand Down
6 changes: 6 additions & 0 deletions gfx/drivers/d3d10.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,8 @@ static bool d3d10_gfx_set_shader(void* data,
&d3d10->frame.output_size, /* FinalViewportSize */
&d3d10->pass[i].frame_count, /* FrameCount */
&d3d10->pass[i].frame_direction, /* FrameDirection */
&d3d10->pass[i].frame_time_delta,/* FrameTimeDelta */
&d3d10->pass[i].original_fps, /* OriginalFPS */
&d3d10->pass[i].rotation, /* Rotation */
&d3d10->pass[i].core_aspect, /* OriginalAspect */
&d3d10->pass[i].core_aspect_rot, /* OriginalAspectRotated */
Expand Down Expand Up @@ -2331,6 +2333,10 @@ static bool d3d10_gfx_frame(
d3d10->pass[i].frame_direction = 1;
#endif

d3d10->pass[i].frame_time_delta = video_driver_get_frame_time_delta_usec();

d3d10->pass[i].original_fps = video_driver_get_original_fps();

d3d10->pass[i].rotation = retroarch_get_rotation();

d3d10->pass[i].core_aspect = video_driver_get_core_aspect();
Expand Down
5 changes: 5 additions & 0 deletions gfx/drivers/d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,8 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
&d3d11->frame.output_size, /* FinalViewportSize */
&d3d11->pass[i].frame_count, /* FrameCount */
&d3d11->pass[i].frame_direction, /* FrameDirection */
&d3d11->pass[i].frame_time_delta,/* FrameTimeDelta */
&d3d11->pass[i].original_fps, /* OriginalFPS */
&d3d11->pass[i].rotation, /* Rotation */
&d3d11->pass[i].core_aspect, /* OriginalAspect */
&d3d11->pass[i].core_aspect_rot, /* OriginalAspectRotated */
Expand Down Expand Up @@ -3093,6 +3095,9 @@ static bool d3d11_gfx_frame(
#else
d3d11->pass[i].frame_direction = 1;
#endif
d3d11->pass[i].frame_time_delta = video_driver_get_frame_time_delta_usec();

d3d11->pass[i].original_fps = video_driver_get_original_fps();

d3d11->pass[i].rotation = retroarch_get_rotation();

Expand Down
8 changes: 7 additions & 1 deletion gfx/drivers/d3d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,8 @@ static bool d3d12_gfx_set_shader(void* data, enum rarch_shader_type type, const
&d3d12->frame.output_size, /* FinalViewportSize */
&d3d12->pass[i].frame_count, /* FrameCount */
&d3d12->pass[i].frame_direction, /* FrameDirection */
&d3d12->pass[i].frame_time_delta,/* FrameTimeDelta */
&d3d12->pass[i].original_fps, /* OriginalFPS */
&d3d12->pass[i].rotation, /* Rotation */
&d3d12->pass[i].core_aspect, /* OriginalAspect */
&d3d12->pass[i].core_aspect_rot, /* OriginalAspectRotated */
Expand Down Expand Up @@ -3593,7 +3595,11 @@ static bool d3d12_gfx_frame(
d3d12->pass[i].frame_direction = -1;
else
#endif
d3d12->pass[i].frame_direction = 1;
d3d12->pass[i].frame_direction = 1;

d3d12->pass[i].frame_time_delta = video_driver_get_frame_time_delta_usec();

d3d12->pass[i].original_fps = video_driver_get_original_fps();

d3d12->pass[i].rotation = retroarch_get_rotation();

Expand Down
26 changes: 13 additions & 13 deletions gfx/drivers/gl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3559,19 +3559,19 @@ static bool gl2_frame(void *data, const void *frame,

glClear(GL_COLOR_BUFFER_BIT);

params.data = gl;
params.width = frame_width;
params.height = frame_height;
params.tex_width = gl->tex_w;
params.tex_height = gl->tex_h;
params.out_width = gl->vp.width;
params.out_height = gl->vp.height;
params.frame_counter = (unsigned int)frame_count;
params.info = &gl->tex_info;
params.prev_info = gl->prev_info;
params.feedback_info = &feedback_info;
params.fbo_info = NULL;
params.fbo_info_cnt = 0;
params.data = gl;
params.width = frame_width;
params.height = frame_height;
params.tex_width = gl->tex_w;
params.tex_height = gl->tex_h;
params.out_width = gl->vp.width;
params.out_height = gl->vp.height;
params.frame_counter = (unsigned int)frame_count;
params.info = &gl->tex_info;
params.prev_info = gl->prev_info;
params.feedback_info = &feedback_info;
params.fbo_info = NULL;
params.fbo_info_cnt = 0;

gl->shader->set_params(&params, gl->shader_data);

Expand Down
4 changes: 4 additions & 0 deletions gfx/drivers/gl3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2742,6 +2742,10 @@ static bool gl3_frame(void *data, const void *frame,
#else
gl3_filter_chain_set_frame_direction(gl->filter_chain, 1);
#endif
gl3_filter_chain_set_frame_time_delta(gl->filter_chain, video_driver_get_frame_time_delta_usec());

gl3_filter_chain_set_original_fps(gl->filter_chain, video_driver_get_original_fps());

gl3_filter_chain_set_rotation(gl->filter_chain, retroarch_get_rotation());

gl3_filter_chain_set_core_aspect(gl->filter_chain, video_driver_get_core_aspect());
Expand Down
26 changes: 23 additions & 3 deletions gfx/drivers/gx2_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,8 @@ static bool wiiu_init_frame_textures(wiiu_video_t *wiiu, unsigned width, unsigne
static void gx2_update_uniform_block(wiiu_video_t *wiiu,
int pass, float *ubo, int id,
int size, int uniformVarCount, GX2UniformVar *uniformVars,
uint64_t frame_count, int32_t frame_direction, uint32_t rotation, float core_aspect, float core_aspect_rot)
uint64_t frame_count, int32_t frame_direction, uint32_t rotation, float core_aspect,
float core_aspect_rot, uint32_t frame_time_delta, uint32_t original_fps)
{
unsigned i;
for (i = 0; i < uniformVarCount; i++)
Expand Down Expand Up @@ -1716,6 +1717,19 @@ static void gx2_update_uniform_block(wiiu_video_t *wiiu,
continue;
}

if (string_is_equal(id, "FrameTimeDelta"))
{
*dst = frame_time_delta;
*(u32 *)dst = __builtin_bswap32(*(u32 *)dst);
continue;
}

if (string_is_equal(id, "OriginalFPS"))
{
*dst = original_fps;
continue;
}

if (string_is_equal(id, "Rotation"))
{
*dst = rotation;
Expand Down Expand Up @@ -1950,6 +1964,11 @@ static bool gx2_frame(void *data, const void *frame,
#else
int32_t frame_direction = 1;
#endif

uint32_t frame_time_delta = video_driver_get_frame_time_delta_usec();

float original_fps = video_driver_get_original_fps();

uint32_t rotation = retroarch_get_rotation();

float core_aspect = video_driver_get_core_aspect();
Expand All @@ -1969,7 +1988,8 @@ static bool gx2_frame(void *data, const void *frame,
gx2_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, frame_direction, rotation, core_aspect, core_aspect_rot);
frame_count, frame_direction, rotation, core_aspect, core_aspect_rot,frame_time_delta, original_fps);

GX2SetVertexUniformBlock(wiiu->pass[i].gfd->vs->uniformBlocks[j].offset,
wiiu->pass[i].gfd->vs->uniformBlocks[j].size, wiiu->pass[i].vs_ubos[j]);
}
Expand All @@ -1981,7 +2001,7 @@ static bool gx2_frame(void *data, const void *frame,
gx2_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, frame_direction, rotation, core_aspect, core_aspect_rot);
frame_count, frame_direction, rotation, core_aspect, core_aspect_rot,frame_time_delta, original_fps);
GX2SetPixelUniformBlock(wiiu->pass[i].gfd->ps->uniformBlocks[j].offset,
wiiu->pass[i].gfd->ps->uniformBlocks[j].size, wiiu->pass[i].ps_ubos[j]);
}
Expand Down
10 changes: 9 additions & 1 deletion gfx/drivers/metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,8 @@ typedef struct MTLALIGN(16)
texture_t feedback;
uint32_t frame_count;
int32_t frame_direction;
int32_t frame_time_delta;
float original_fps;
uint32_t rotation;
float_t core_aspect;
float_t core_aspect_rot;
Expand Down Expand Up @@ -1576,9 +1578,13 @@ - (void)drawWithContext:(Context *)ctx
_engine.pass[i].frame_direction = -1;
else
#else
_engine.pass[i].frame_direction = 1;
_engine.pass[i].frame_direction = 1;
#endif

_engine.pass[i].frame_time_delta = video_driver_get_frame_time_delta_usec();

_engine.pass[i].original_fps = video_driver_get_original_fps();

_engine.pass[i].rotation = retroarch_get_rotation();

_engine.pass[i].core_aspect = video_driver_get_core_aspect();
Expand Down Expand Up @@ -1846,6 +1852,8 @@ - (BOOL)setShaderFromPath:(NSString *)path
&_engine.frame.output_size, /* FinalViewportSize */
&_engine.pass[i].frame_count, /* FrameCount */
&_engine.pass[i].frame_direction, /* FrameDirection */
&_engine.pass[i].frame_time_delta,/* FrameTimeDelta */
&_engine.pass[i].original_fps, /* OriginalFPS */
&_engine.pass[i].rotation, /* Rotation */
&_engine.pass[i].core_aspect, /* OriginalAspect */
&_engine.pass[i].core_aspect_rot, /* OriginalAspectRotated */
Expand Down
6 changes: 6 additions & 0 deletions gfx/drivers/vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -4571,6 +4571,12 @@ static bool vulkan_frame(void *data, const void *frame,
(vulkan_filter_chain_t*)vk->filter_chain,
1);
#endif
vulkan_filter_chain_set_frame_time_delta(
(vulkan_filter_chain_t*)vk->filter_chain, video_driver_get_frame_time_delta_usec());

vulkan_filter_chain_set_original_fps(
(vulkan_filter_chain_t*)vk->filter_chain, video_driver_get_original_fps());

vulkan_filter_chain_set_rotation(
(vulkan_filter_chain_t*)vk->filter_chain, retroarch_get_rotation());

Expand Down
3 changes: 3 additions & 0 deletions gfx/drivers_shader/glslang_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ bool glslang_read_shader_file(const char *path,
if (!string_list_append(output, "#define _HAS_ORIGINALASPECT_UNIFORMS", attr))
goto error;

if (!string_list_append(output, "#define _HAS_FRAMETIME_UNIFORMS", attr))
goto error;

/* At least VIM treats the first line as line #1,
* so offset everything by one. */
snprintf(tmp, sizeof(tmp), "#line %u \"%s\"", root_file ? 2 : 1, basename);
Expand Down
50 changes: 50 additions & 0 deletions gfx/drivers_shader/shader_gl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,16 @@ class Pass
frame_direction = direction;
}

void set_frame_time_delta(uint32_t time_delta)
{
frame_time_delta = time_delta;
}

void set_original_fps(float fps)
{
original_fps = fps;
}

void set_rotation(uint32_t rot)
{
rotation = rot;
Expand Down Expand Up @@ -883,6 +893,8 @@ class Pass
uint64_t frame_count = 0;
unsigned frame_count_period = 0;
int32_t frame_direction = 1;
uint32_t frame_time_delta = 0;
float original_fps = 0;
uint32_t rotation = 0;
float core_aspect = 0;
float core_aspect_rot = 0;
Expand Down Expand Up @@ -1093,6 +1105,8 @@ bool Pass::init_pipeline()
reflect_parameter("FinalViewportSize", reflection.semantics[SLANG_SEMANTIC_FINAL_VIEWPORT]);
reflect_parameter("FrameCount", reflection.semantics[SLANG_SEMANTIC_FRAME_COUNT]);
reflect_parameter("FrameDirection", reflection.semantics[SLANG_SEMANTIC_FRAME_DIRECTION]);
reflect_parameter("FrameTimeDelta", reflection.semantics[SLANG_SEMANTIC_FRAME_TIME_DELTA]);
reflect_parameter("OriginalFPS", reflection.semantics[SLANG_SEMANTIC_ORIGINAL_FPS]);
reflect_parameter("Rotation", reflection.semantics[SLANG_SEMANTIC_ROTATION]);
reflect_parameter("OriginalAspect", reflection.semantics[SLANG_SEMANTIC_CORE_ASPECT]);
reflect_parameter("OriginalAspectRotated", reflection.semantics[SLANG_SEMANTIC_CORE_ASPECT_ROT]);
Expand Down Expand Up @@ -1560,6 +1574,12 @@ void Pass::build_semantics(uint8_t *buffer,
build_semantic_int(buffer, SLANG_SEMANTIC_FRAME_DIRECTION,
frame_direction);

build_semantic_uint(buffer, SLANG_SEMANTIC_FRAME_TIME_DELTA,
frame_time_delta);

build_semantic_float(buffer, SLANG_SEMANTIC_ORIGINAL_FPS,
original_fps);

build_semantic_uint(buffer, SLANG_SEMANTIC_ROTATION,
rotation);

Expand Down Expand Up @@ -1817,6 +1837,8 @@ struct gl3_filter_chain
void set_frame_count(uint64_t count);
void set_frame_count_period(unsigned pass, unsigned period);
void set_frame_direction(int32_t direction);
void set_frame_time_delta(uint32_t rot);
void set_original_fps(float fps);
void set_rotation(uint32_t rot);
void set_core_aspect(float coreaspect);
void set_core_aspect_rot(float coreaspectrot);
Expand Down Expand Up @@ -2308,6 +2330,20 @@ void gl3_filter_chain::set_frame_direction(int32_t direction)
passes[i]->set_frame_direction(direction);
}

void gl3_filter_chain::set_frame_time_delta(uint32_t time_delta)
{
unsigned i;
for (i = 0; i < passes.size(); i++)
passes[i]->set_frame_time_delta(time_delta);
}

void gl3_filter_chain::set_original_fps(float fps)
{
unsigned i;
for (i = 0; i < passes.size(); i++)
passes[i]->set_original_fps(fps);
}

void gl3_filter_chain::set_rotation(uint32_t rot)
{
unsigned i;
Expand Down Expand Up @@ -2766,6 +2802,20 @@ void gl3_filter_chain_set_frame_direction(
chain->set_frame_direction(direction);
}

void gl3_filter_chain_set_frame_time_delta(
gl3_filter_chain_t *chain,
uint32_t time_delta)
{
chain->set_frame_time_delta(time_delta);
}

void gl3_filter_chain_set_original_fps(
gl3_filter_chain_t *chain,
float fps)
{
chain->set_original_fps(fps);
}

void gl3_filter_chain_set_rotation(
gl3_filter_chain_t *chain,
uint32_t rot)
Expand Down
8 changes: 8 additions & 0 deletions gfx/drivers_shader/shader_gl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ void gl3_filter_chain_set_frame_direction(
gl3_filter_chain_t *chain,
int32_t direction);

void gl3_filter_chain_set_frame_time_delta(
gl3_filter_chain_t *chain,
uint32_t time_delta);

void gl3_filter_chain_set_original_fps(
gl3_filter_chain_t *chain,
float fps);

void gl3_filter_chain_set_rotation(
gl3_filter_chain_t *chain,
uint32_t rotation);
Expand Down
Loading

0 comments on commit 2a56a82

Please sign in to comment.