Add OriginalAspect and OriginalAspectRot uniforms (#17123)
Some checks are pending
CI 3DS / build (push) Waiting to run
CI Android / build (push) Waiting to run
CI DOS/DJGPP / build (push) Waiting to run
CI Emscripten / build (push) Waiting to run
CI GameCube / build (push) Waiting to run
CI Linux (i686) / build (push) Waiting to run
CI Windows (MSVC) / msvc (Debug, x64, 2019) (push) Waiting to run
CI Windows (MSVC) / msvc (Debug, x64, 2022) (push) Waiting to run
CI Windows (MSVC) / msvc (Release, x64, 2019) (push) Waiting to run
CI Windows (MSVC) / msvc (Release, x64, 2022) (push) Waiting to run
CI Windows (MSVC) / msvc (Release, x64, UWP) (push) Waiting to run
CI Windows (MSVC) / msvc (ReleaseAngle, x64, UWP) (push) Waiting to run
CI macOS / build (push) Waiting to run
CI Miyoo ARM32 / build (push) Waiting to run
CI PS2 / build (push) Waiting to run
CI PS4/ORBIS / build (push) Waiting to run
CI PSP / build (push) Waiting to run
CI PSVita / build (push) Waiting to run
CI RS90 Odbeta MIPS32 / build (push) Waiting to run
CI RetroFW MIPS32 / build (push) Waiting to run
CI Switch/libnx / build (push) Waiting to run
CI Wii / build (push) Waiting to run
CI WiiU / build (push) Waiting to run
CI Windows i686 (MXE) / build (push) Waiting to run
CI Windows x64 (MXE) / build (push) Waiting to run
RetroArch CI / linux-c89 (push) Waiting to run
CI webOS / build (push) Waiting to run

* 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
This commit is contained in:
Antonio Orefice 2024-11-02 12:04:12 +01:00 committed by GitHub
parent 99610f0de6
commit da5ecaa45a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 329 additions and 23 deletions

View File

@ -218,6 +218,9 @@ typedef struct
uint32_t rotation;
uint32_t total_subframes;
uint32_t current_subframe;
float core_aspect;
float core_aspect_rot;
} pass[GFX_MAX_SHADERS];
struct video_shader* shader_preset;

View File

@ -294,6 +294,8 @@ typedef struct
uint32_t rotation;
uint32_t total_subframes;
uint32_t current_subframe;
float core_aspect;
float core_aspect_rot;
} pass[GFX_MAX_SHADERS];
struct video_shader* shader_preset;

View File

@ -331,6 +331,8 @@ typedef struct
uint32_t rotation;
uint32_t total_subframes;
uint32_t current_subframe;
float core_aspect;
float core_aspect_rot;
D3D12_GPU_DESCRIPTOR_HANDLE textures;
D3D12_GPU_DESCRIPTOR_HANDLE samplers;
} pass[GFX_MAX_SHADERS];

View File

@ -1336,6 +1336,8 @@ static bool d3d10_gfx_set_shader(void* data,
&d3d10->pass[i].frame_count, /* FrameCount */
&d3d10->pass[i].frame_direction, /* FrameDirection */
&d3d10->pass[i].rotation, /* Rotation */
&d3d10->pass[i].core_aspect, /* OriginalAspect */
&d3d10->pass[i].core_aspect_rot, /* OriginalAspectRotated */
&d3d10->pass[i].total_subframes, /* TotalSubFrames */
&d3d10->pass[i].current_subframe,/* CurrentSubFrame */
}
@ -2331,6 +2333,14 @@ static bool d3d10_gfx_frame(
d3d10->pass[i].rotation = retroarch_get_rotation();
d3d10->pass[i].core_aspect = video_driver_get_core_aspect();
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
d3d10->pass[i].core_aspect_rot = video_driver_get_core_aspect();
uint32_t rot = retroarch_get_rotation();
if (rot == 1 || rot == 3)
d3d10->pass[i].core_aspect_rot = 1/d3d10->pass[i].core_aspect_rot;
/* Sub-frame info for multiframe shaders (per real content frame).
Should always be 1 for non-use of subframes */
if (!(d3d10->flags & D3D10_ST_FLAG_FRAME_DUPE_LOCK))

View File

@ -1538,6 +1538,8 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
&d3d11->pass[i].frame_count, /* FrameCount */
&d3d11->pass[i].frame_direction, /* FrameDirection */
&d3d11->pass[i].rotation, /* Rotation */
&d3d11->pass[i].core_aspect, /* OriginalAspect */
&d3d11->pass[i].core_aspect_rot, /* OriginalAspectRotated */
&d3d11->pass[i].total_subframes, /* TotalSubFrames */
&d3d11->pass[i].current_subframe,/* CurrentSubFrame */
}
@ -3094,6 +3096,14 @@ static bool d3d11_gfx_frame(
d3d11->pass[i].rotation = retroarch_get_rotation();
d3d11->pass[i].core_aspect = video_driver_get_core_aspect();
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
d3d11->pass[i].core_aspect_rot = video_driver_get_core_aspect();
uint32_t rot = retroarch_get_rotation();
if (rot == 1 || rot == 3)
d3d11->pass[i].core_aspect_rot = 1/d3d11->pass[i].core_aspect_rot;
/* Sub-frame info for multiframe shaders (per real content frame).
Should always be 1 for non-use of subframes */
if (!(d3d11->flags & D3D11_ST_FLAG_FRAME_DUPE_LOCK))

View File

@ -1725,6 +1725,8 @@ static bool d3d12_gfx_set_shader(void* data, enum rarch_shader_type type, const
&d3d12->pass[i].frame_count, /* FrameCount */
&d3d12->pass[i].frame_direction, /* FrameDirection */
&d3d12->pass[i].rotation, /* Rotation */
&d3d12->pass[i].core_aspect, /* OriginalAspect */
&d3d12->pass[i].core_aspect_rot, /* OriginalAspectRotated */
&d3d12->pass[i].total_subframes, /* TotalSubFrames */
&d3d12->pass[i].current_subframe,/* CurrentSubFrame */
}
@ -3595,6 +3597,14 @@ static bool d3d12_gfx_frame(
d3d12->pass[i].rotation = retroarch_get_rotation();
d3d12->pass[i].core_aspect = video_driver_get_core_aspect();
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
d3d12->pass[i].core_aspect_rot = video_driver_get_core_aspect();
uint32_t rot = retroarch_get_rotation();
if (rot == 1 || rot == 3)
d3d12->pass[i].core_aspect_rot = 1/d3d12->pass[i].core_aspect_rot;
/* Sub-frame info for multiframe shaders (per real content frame).
Should always be 1 for non-use of subframes */
if (!(d3d12->flags & D3D12_ST_FLAG_FRAME_DUPE_LOCK))

View File

@ -2744,6 +2744,15 @@ static bool gl3_frame(void *data, const void *frame,
#endif
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());
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
uint32_t rot = retroarch_get_rotation();
float core_aspect_rot = video_driver_get_core_aspect();
if (rot == 1 || rot == 3)
core_aspect_rot = 1/core_aspect_rot;
gl3_filter_chain_set_core_aspect_rot(gl->filter_chain, core_aspect_rot);
/* Sub-frame info for multiframe shaders (per real content frame).
Should always be 1 for non-use of subframes*/
if (!(gl->flags & GL3_FLAG_FRAME_DUPE_LOCK))

View File

@ -1665,7 +1665,7 @@ 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)
uint64_t frame_count, int32_t frame_direction, uint32_t rotation, float core_aspect, float core_aspect_rot)
{
unsigned i;
for (i = 0; i < uniformVarCount; i++)
@ -1723,6 +1723,18 @@ static void gx2_update_uniform_block(wiiu_video_t *wiiu,
continue;
}
if (string_is_equal(id, "OriginalAspect"))
{
*dst = core_aspect;
continue;
}
if (string_is_equal(id, "OriginalAspectRotated"))
{
*dst = core_aspect_rot;
continue;
}
if (string_is_equal(id, "OriginalSize"))
{
((GX2_vec4 *)dst)->x = wiiu->texture.surface.width;
@ -1940,6 +1952,13 @@ static bool gx2_frame(void *data, const void *frame,
#endif
uint32_t rotation = retroarch_get_rotation();
float core_aspect = video_driver_get_core_aspect();
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
float core_aspect_rot = core_aspect;
if (rotation == 1 || rotation == 3)
core_aspect_rot = 1/core_aspect;
for (i = 0; i < wiiu->shader_preset->passes; i++)
{
unsigned j;
@ -1950,7 +1969,7 @@ 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);
frame_count, frame_direction, rotation, core_aspect, core_aspect_rot);
GX2SetVertexUniformBlock(wiiu->pass[i].gfd->vs->uniformBlocks[j].offset,
wiiu->pass[i].gfd->vs->uniformBlocks[j].size, wiiu->pass[i].vs_ubos[j]);
}
@ -1962,7 +1981,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);
frame_count, frame_direction, rotation, core_aspect, core_aspect_rot);
GX2SetPixelUniformBlock(wiiu->pass[i].gfd->ps->uniformBlocks[j].offset,
wiiu->pass[i].gfd->ps->uniformBlocks[j].size, wiiu->pass[i].ps_ubos[j]);
}

View File

@ -1206,6 +1206,8 @@ typedef struct MTLALIGN(16)
uint32_t frame_count;
int32_t frame_direction;
uint32_t rotation;
float_t core_aspect;
float_t core_aspect_rot;
pass_semantics_t semantics;
MTLViewport viewport;
__unsafe_unretained id<MTLRenderPipelineState> _state;
@ -1579,6 +1581,15 @@ typedef struct MTLALIGN(16)
_engine.pass[i].rotation = retroarch_get_rotation();
_engine.pass[i].core_aspect = video_driver_get_core_aspect();
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
int rot = retroarch_get_rotation();
float core_aspect_rot = video_driver_get_core_aspect();
if (rot == 1 || rot == 3)
core_aspect_rot = 1/core_aspect_rot;
_engine.pass[i].core_aspect_rot = core_aspect_rot;
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
{
id<MTLBuffer> buffer = _engine.pass[i].buffers[j];
@ -1836,6 +1847,8 @@ typedef struct MTLALIGN(16)
&_engine.pass[i].frame_count, /* FrameCount */
&_engine.pass[i].frame_direction, /* FrameDirection */
&_engine.pass[i].rotation, /* Rotation */
&_engine.pass[i].core_aspect, /* OriginalAspect */
&_engine.pass[i].core_aspect_rot, /* OriginalAspectRotated */
}
};
/* clang-format on */

View File

@ -4574,6 +4574,17 @@ static bool vulkan_frame(void *data, const void *frame,
vulkan_filter_chain_set_rotation(
(vulkan_filter_chain_t*)vk->filter_chain, retroarch_get_rotation());
vulkan_filter_chain_set_core_aspect(
(vulkan_filter_chain_t*)vk->filter_chain, video_driver_get_core_aspect());
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
uint32_t rot = retroarch_get_rotation();
float core_aspect_rot = video_driver_get_core_aspect();
if (rot == 1 || rot == 3)
core_aspect_rot = 1/core_aspect_rot;
vulkan_filter_chain_set_core_aspect_rot(
(vulkan_filter_chain_t*)vk->filter_chain, core_aspect_rot);
/* Render offscreen filter chain passes. */
{
/* Set the source texture in the filter chain */

View File

@ -177,6 +177,10 @@ bool glslang_read_shader_file(const char *path,
goto error;
}
/* Add defines about supported retroarch features */
if (!string_list_append(output, "#define _HAS_ORIGINALASPECT_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);

View File

@ -757,6 +757,16 @@ public:
rotation = rot;
}
void set_core_aspect(float coreaspect)
{
core_aspect = coreaspect;
}
void set_core_aspect_rot(float coreaspectrot)
{
core_aspect_rot = coreaspectrot;
}
void set_shader_subframes(uint32_t tot_subframes)
{
total_subframes = tot_subframes;
@ -855,6 +865,8 @@ private:
slang_semantic semantic, uint32_t value);
void build_semantic_int(uint8_t *data,
slang_semantic semantic, int32_t value);
void build_semantic_float(uint8_t *data,
slang_semantic semantic, float value);
void build_semantic_parameter(uint8_t *data, unsigned index, float value);
void build_semantic_texture_vec4(uint8_t *data,
slang_texture_semantic semantic,
@ -872,6 +884,8 @@ private:
unsigned frame_count_period = 0;
int32_t frame_direction = 1;
uint32_t rotation = 0;
float core_aspect = 0;
float core_aspect_rot = 0;
unsigned pass_number = 0;
uint32_t total_subframes = 1;
uint32_t current_subframe = 1;
@ -1080,6 +1094,8 @@ bool Pass::init_pipeline()
reflect_parameter("FrameCount", reflection.semantics[SLANG_SEMANTIC_FRAME_COUNT]);
reflect_parameter("FrameDirection", reflection.semantics[SLANG_SEMANTIC_FRAME_DIRECTION]);
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]);
reflect_parameter("TotalSubFrames", reflection.semantics[SLANG_SEMANTIC_TOTAL_SUBFRAMES]);
reflect_parameter("CurrentSubFrame", reflection.semantics[SLANG_SEMANTIC_CURRENT_SUBFRAME]);
@ -1319,6 +1335,38 @@ void Pass::build_semantic_int(uint8_t *data, slang_semantic semantic,
}
}
void Pass::build_semantic_float(uint8_t *data, slang_semantic semantic,
float value)
{
auto &refl = reflection.semantics[semantic];
if (data && refl.uniform)
{
if (refl.location.ubo_vertex >= 0 || refl.location.ubo_fragment >= 0)
{
if (refl.location.ubo_vertex >= 0)
glUniform1f(refl.location.ubo_vertex, value);
if (refl.location.ubo_fragment >= 0)
glUniform1f(refl.location.ubo_fragment, value);
}
else
*reinterpret_cast<float *>(data + reflection.semantics[semantic].ubo_offset) = value;
}
if (refl.push_constant)
{
if (refl.location.push_vertex >= 0 || refl.location.push_fragment >= 0)
{
if (refl.location.push_vertex >= 0)
glUniform1f(refl.location.push_vertex, value);
if (refl.location.push_fragment >= 0)
glUniform1f(refl.location.push_fragment, value);
}
else
*reinterpret_cast<float *>(push_constant_buffer.data() + refl.push_constant_offset) = value;
}
}
void Pass::build_semantic_texture(uint8_t *buffer,
slang_texture_semantic semantic, const Texture &texture)
{
@ -1515,6 +1563,12 @@ void Pass::build_semantics(uint8_t *buffer,
build_semantic_uint(buffer, SLANG_SEMANTIC_ROTATION,
rotation);
build_semantic_float(buffer, SLANG_SEMANTIC_CORE_ASPECT,
core_aspect);
build_semantic_float(buffer, SLANG_SEMANTIC_CORE_ASPECT_ROT,
core_aspect_rot);
build_semantic_uint(buffer, SLANG_SEMANTIC_TOTAL_SUBFRAMES,
total_subframes);
build_semantic_uint(buffer, SLANG_SEMANTIC_CURRENT_SUBFRAME,
@ -1764,6 +1818,8 @@ public:
void set_frame_count_period(unsigned pass, unsigned period);
void set_frame_direction(int32_t direction);
void set_rotation(uint32_t rot);
void set_core_aspect(float coreaspect);
void set_core_aspect_rot(float coreaspectrot);
void set_shader_subframes(uint32_t tot_subframes);
void set_current_shader_subframe(uint32_t cur_subframe);
#ifdef GL3_ROLLING_SCANLINE_SIMULATION
@ -2259,6 +2315,21 @@ void gl3_filter_chain::set_rotation(uint32_t rot)
passes[i]->set_rotation(rot);
}
void gl3_filter_chain::set_core_aspect(float coreaspect)
{
unsigned i;
for (i = 0; i < passes.size(); i++)
passes[i]->set_core_aspect(coreaspect);
}
void gl3_filter_chain::set_core_aspect_rot(float coreaspectrot)
{
unsigned i;
for (i = 0; i < passes.size(); i++)
passes[i]->set_core_aspect_rot(coreaspectrot);
}
void gl3_filter_chain::set_shader_subframes(uint32_t tot_subframes)
{
unsigned i;
@ -2702,6 +2773,20 @@ void gl3_filter_chain_set_rotation(
chain->set_rotation(rot);
}
void gl3_filter_chain_set_core_aspect(
gl3_filter_chain_t *chain,
float coreaspect)
{
chain->set_core_aspect(coreaspect);
}
void gl3_filter_chain_set_core_aspect_rot(
gl3_filter_chain_t *chain,
float coreaspectrot)
{
chain->set_core_aspect_rot(coreaspectrot);
}
void gl3_filter_chain_set_shader_subframes(
gl3_filter_chain_t *chain,
uint32_t tot_subframes)

View File

@ -119,6 +119,14 @@ void gl3_filter_chain_set_rotation(
gl3_filter_chain_t *chain,
uint32_t rotation);
void gl3_filter_chain_set_core_aspect(
gl3_filter_chain_t *chain,
float coreaspect);
void gl3_filter_chain_set_core_aspect_rot(
gl3_filter_chain_t *chain,
float coreaspectrot);
void gl3_filter_chain_set_shader_subframes(
gl3_filter_chain_t *chain,
uint32_t tot_subframes);

View File

@ -87,12 +87,16 @@ struct shader_program_cg
CGparameter frame_cnt_f;
CGparameter frame_dir_f;
CGparameter rotation_f;
CGparameter originalaspect_f;
CGparameter originalaspectrotated_f;
CGparameter vid_size_v;
CGparameter tex_size_v;
CGparameter out_size_v;
CGparameter frame_cnt_v;
CGparameter frame_dir_v;
CGparameter rotation_v;
CGparameter originalaspect_v;
CGparameter originalaspectrotated_v;
CGparameter mvp;
struct cg_fbo_params fbo[GFX_MAX_SHADERS];
@ -310,7 +314,9 @@ static void gl_cg_set_texture_info(
static void gl_cg_set_params(void *dat, void *shader_data)
{
unsigned i;
unsigned int i;
int rot;
float originalaspectrotated;
video_shader_ctx_params_t *params =
(video_shader_ctx_params_t*)dat;
unsigned width = params->width;
@ -361,6 +367,17 @@ static void gl_cg_set_params(void *dat, void *shader_data)
cg_gl_set_param_1f(cg->prg[cg->active_idx].rotation_f, (float)retroarch_get_rotation());
cg_gl_set_param_1f(cg->prg[cg->active_idx].rotation_v, (float)retroarch_get_rotation());
cg_gl_set_param_1f(cg->prg[cg->active_idx].originalaspect_f, (float)video_driver_get_core_aspect());
cg_gl_set_param_1f(cg->prg[cg->active_idx].originalaspect_v, (float)video_driver_get_core_aspect());
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
rot = retroarch_get_rotation();
originalaspectrotated = video_driver_get_core_aspect();
if (rot == 1 || rot == 3)
originalaspectrotated = 1/originalaspectrotated;
cg_gl_set_param_1f(cg->prg[cg->active_idx].originalaspectrotated_f, (float)originalaspectrotated);
cg_gl_set_param_1f(cg->prg[cg->active_idx].originalaspectrotated_v, (float)originalaspectrotated);
set_param_2f(cg->prg[cg->active_idx].vid_size_v, width, height);
set_param_2f(cg->prg[cg->active_idx].tex_size_v, tex_width, tex_height);
set_param_2f(cg->prg[cg->active_idx].out_size_v, out_width, out_height);
@ -797,12 +814,16 @@ static void gl_cg_set_program_attributes(void *data, unsigned i)
cg->prg[i].frame_cnt_f = cgGetNamedParameter(cg->prg[i].fprg, "IN.frame_count");
cg->prg[i].frame_dir_f = cgGetNamedParameter(cg->prg[i].fprg, "IN.frame_direction");
cg->prg[i].rotation_f = cgGetNamedParameter(cg->prg[i].fprg, "IN.rotation");
cg->prg[i].originalaspect_f = cgGetNamedParameter(cg->prg[i].fprg, "IN.originalaspect");
cg->prg[i].originalaspectrotated_f = cgGetNamedParameter(cg->prg[i].fprg, "IN.originalaspectrotated");
cg->prg[i].vid_size_v = cgGetNamedParameter (cg->prg[i].vprg, "IN.video_size");
cg->prg[i].tex_size_v = cgGetNamedParameter (cg->prg[i].vprg, "IN.texture_size");
cg->prg[i].out_size_v = cgGetNamedParameter (cg->prg[i].vprg, "IN.output_size");
cg->prg[i].frame_cnt_v = cgGetNamedParameter(cg->prg[i].vprg, "IN.frame_count");
cg->prg[i].frame_dir_v = cgGetNamedParameter(cg->prg[i].vprg, "IN.frame_direction");
cg->prg[i].rotation_v = cgGetNamedParameter(cg->prg[i].vprg, "IN.rotation");
cg->prg[i].originalaspect_v = cgGetNamedParameter(cg->prg[i].fprg, "IN.originalaspect");
cg->prg[i].originalaspectrotated_v = cgGetNamedParameter(cg->prg[i].fprg, "IN.originalaspectrotated");
cg->prg[i].mvp = cgGetNamedParameter(cg->prg[i].vprg, "modelViewProj");
if (!cg->prg[i].mvp)

View File

@ -101,6 +101,9 @@ struct shader_uniforms
/* Use int for maximal compatibility despite other drivers using uint. */
int rotation;
float core_aspect;
float core_aspect_rot;
int lut_texture[GFX_MAX_TEXTURES];
unsigned frame_count_mod;
@ -486,7 +489,8 @@ static bool gl_glsl_compile_program(
if (!gl_glsl_compile_shader(
glsl,
program->vprg,
"#define VERTEX\n#define PARAMETER_UNIFORM\n", program_info->vertex))
"#define VERTEX\n#define PARAMETER_UNIFORM\n#define _HAS_ORIGINALASPECT_UNIFORMS\n",
program_info->vertex))
{
RARCH_ERR("Failed to compile vertex shader #%u\n", idx);
goto error;
@ -500,7 +504,7 @@ static bool gl_glsl_compile_program(
RARCH_LOG("[GLSL]: Found GLSL fragment shader.\n");
program->fprg = glCreateShader(GL_FRAGMENT_SHADER);
if (!gl_glsl_compile_shader(glsl, program->fprg,
"#define FRAGMENT\n#define PARAMETER_UNIFORM\n",
"#define FRAGMENT\n#define PARAMETER_UNIFORM\n#define _HAS_ORIGINALASPECT_UNIFORMS\n",
program_info->fragment))
{
RARCH_ERR("Failed to compile fragment shader #%u\n", idx);
@ -750,6 +754,8 @@ static void gl_glsl_find_uniforms(glsl_shader_data_t *glsl,
uni->frame_count = gl_glsl_get_uniform(glsl, prog, "FrameCount");
uni->frame_direction = gl_glsl_get_uniform(glsl, prog, "FrameDirection");
uni->rotation = gl_glsl_get_uniform(glsl, prog, "Rotation");
uni->core_aspect = gl_glsl_get_uniform(glsl, prog, "OriginalAspect");
uni->core_aspect_rot = gl_glsl_get_uniform(glsl, prog, "OriginalAspectRotated");
for (i = 0; i < glsl->shader->luts; i++)
uni->lut_texture[i] = glGetUniformLocation(prog, glsl->shader->lut[i].id);
@ -1358,6 +1364,18 @@ static void gl_glsl_set_params(void *dat, void *shader_data)
if (uni->rotation >= 0)
glUniform1i(uni->rotation, retroarch_get_rotation());
if (uni->core_aspect >= 0)
glUniform1f(uni->core_aspect, video_driver_get_core_aspect());
if (uni->core_aspect_rot >= 0) {
/* OriginalAspectRotated: return 1/aspect for 90 and 270 rotated content */
float core_aspect_rot = video_driver_get_core_aspect();
uint32_t rot = retroarch_get_rotation();
if (rot == 1 || rot == 3)
core_aspect_rot = 1/core_aspect_rot;
glUniform1f(uni->core_aspect_rot, core_aspect_rot);
}
/* Set lookup textures. */
for (i = 0; i < glsl->shader->luts; i++)
{

View File

@ -254,6 +254,8 @@ class Pass
#endif /* VULKAN_ROLLING_SCANLINE_SIMULATION */
void set_frame_direction(int32_t dir) { frame_direction = dir; }
void set_rotation(uint32_t rot) { rotation = rot; }
void set_core_aspect(float coreaspect) { core_aspect = coreaspect; }
void set_core_aspect_rot(float coreaspectrot) { core_aspect_rot = coreaspectrot; }
void set_name(const char *name) { pass_name = name; }
const std::string &get_name() const { return pass_name; }
glslang_filter_chain_filter get_source_filter() const {
@ -328,6 +330,7 @@ class Pass
unsigned width, unsigned height);
void build_semantic_uint(uint8_t *data, slang_semantic semantic, uint32_t value);
void build_semantic_int(uint8_t *data, slang_semantic semantic, int32_t value);
void build_semantic_float(uint8_t *data,slang_semantic semantic, float value);
void build_semantic_parameter(uint8_t *data, unsigned index, float value);
void build_semantic_texture_vec4(uint8_t *data,
slang_texture_semantic semantic,
@ -343,6 +346,8 @@ class Pass
uint64_t frame_count = 0;
int32_t frame_direction = 1;
uint32_t rotation = 0;
float core_aspect = 0;
float core_aspect_rot = 0;
unsigned frame_count_period = 0;
unsigned pass_number = 0;
uint32_t total_subframes = 1;
@ -411,6 +416,8 @@ struct vulkan_filter_chain
#endif /* VULKAN_ROLLING_SCANLINE_SIMULATION */
void set_frame_direction(int32_t direction);
void set_rotation(uint32_t rot);
void set_core_aspect(float coreaspect);
void set_core_aspect_rot(float coreaspect);
void set_pass_name(unsigned pass, const char *name);
void add_static_texture(std::unique_ptr<StaticTexture> texture);
@ -1441,6 +1448,21 @@ void vulkan_filter_chain::set_rotation(uint32_t rot)
passes[i]->set_rotation(rot);
}
void vulkan_filter_chain::set_core_aspect(float coreaspect)
{
unsigned i;
for (i = 0; i < passes.size(); i++)
passes[i]->set_core_aspect(coreaspect);
}
void vulkan_filter_chain::set_core_aspect_rot(float coreaspectrot)
{
unsigned i;
for (i = 0; i < passes.size(); i++)
passes[i]->set_core_aspect_rot(coreaspectrot);
}
void vulkan_filter_chain::set_pass_name(unsigned pass, const char *name)
{
passes[pass]->set_name(name);
@ -2279,6 +2301,19 @@ void Pass::build_semantic_int(uint8_t *data, slang_semantic semantic,
*reinterpret_cast<int32_t*>(push.buffer.data() + (refl.push_constant_offset >> 2)) = value;
}
void Pass::build_semantic_float(uint8_t *data, slang_semantic semantic,
float value)
{
auto &refl = reflection.semantics[semantic];
if (data && refl.uniform)
*reinterpret_cast<float*>(data + reflection.semantics[semantic].ubo_offset) = value;
if (refl.push_constant)
*reinterpret_cast<float*>(push.buffer.data() + (refl.push_constant_offset >> 2)) = value;
}
void Pass::build_semantic_texture(VkDescriptorSet set, uint8_t *buffer,
slang_texture_semantic semantic, const Texture &texture)
{
@ -2344,6 +2379,12 @@ void Pass::build_semantics(VkDescriptorSet set, uint8_t *buffer,
build_semantic_uint(buffer, SLANG_SEMANTIC_ROTATION,
rotation);
build_semantic_float(buffer, SLANG_SEMANTIC_CORE_ASPECT,
core_aspect);
build_semantic_float(buffer, SLANG_SEMANTIC_CORE_ASPECT_ROT,
core_aspect_rot);
/* Standard inputs */
build_semantic_texture(set, buffer, SLANG_TEXTURE_SEMANTIC_ORIGINAL, original);
build_semantic_texture(set, buffer, SLANG_TEXTURE_SEMANTIC_SOURCE, source);
@ -3188,6 +3229,20 @@ void vulkan_filter_chain_set_rotation(
chain->set_rotation(rot);
}
void vulkan_filter_chain_set_core_aspect(
vulkan_filter_chain_t *chain,
float coreaspect)
{
chain->set_core_aspect(coreaspect);
}
void vulkan_filter_chain_set_core_aspect_rot(
vulkan_filter_chain_t *chain,
float coreaspectrot)
{
chain->set_core_aspect_rot(coreaspectrot);
}
void vulkan_filter_chain_set_pass_name(
vulkan_filter_chain_t *chain,
unsigned pass,

View File

@ -139,6 +139,12 @@ void vulkan_filter_chain_set_frame_direction(vulkan_filter_chain_t *chain,
void vulkan_filter_chain_set_rotation(vulkan_filter_chain_t *chain,
uint32_t rot);
void vulkan_filter_chain_set_core_aspect(vulkan_filter_chain_t *chain,
float coreaspect);
void vulkan_filter_chain_set_core_aspect_rot(vulkan_filter_chain_t *chain,
float coreaspectrot);
void vulkan_filter_chain_build_offscreen_passes(vulkan_filter_chain_t *chain,
VkCommandBuffer cmd, const VkViewport *vp);
void vulkan_filter_chain_build_viewport_pass(vulkan_filter_chain_t *chain,

View File

@ -157,6 +157,8 @@ static bool slang_process_reflection(
"FrameCount",
"FrameDirection",
"Rotation",
"OriginalAspect",
"OriginalAspectRotated",
"TotalSubFrames",
"CurrentSubFrame",
};

View File

@ -51,6 +51,8 @@ static const char *semantic_uniform_names[] = {
"FrameCount",
"FrameDirection",
"Rotation",
"OriginalAspect",
"OriginalAspectRotated",
"TotalSubFrames",
"CurrentSubFrame",
};
@ -270,6 +272,14 @@ static bool validate_type_for_semantic(const spirv_cross::SPIRType &type, slang_
return type.basetype == spirv_cross::SPIRType::UInt
&& type.vecsize == 1
&& type.columns == 1;
case SLANG_SEMANTIC_CORE_ASPECT:
return type.basetype == spirv_cross::SPIRType::Float
&& type.vecsize == 1
&& type.columns == 1;
case SLANG_SEMANTIC_CORE_ASPECT_ROT:
return type.basetype == spirv_cross::SPIRType::Float
&& type.vecsize == 1
&& type.columns == 1;
/* float */
case SLANG_SEMANTIC_FLOAT_PARAMETER:
return type.basetype == spirv_cross::SPIRType::Float

View File

@ -72,14 +72,18 @@ enum slang_semantic
SLANG_SEMANTIC_FRAME_DIRECTION = 4,
/* uint, rotation */
SLANG_SEMANTIC_ROTATION = 5,
/* float, rotation */
SLANG_SEMANTIC_CORE_ASPECT = 6,
SLANG_SEMANTIC_CORE_ASPECT_ROT = 7,
/* uint, sub frames per content frame */
SLANG_SEMANTIC_TOTAL_SUBFRAMES = 6,
SLANG_SEMANTIC_TOTAL_SUBFRAMES = 8,
/* uint, current sub frame */
SLANG_SEMANTIC_CURRENT_SUBFRAME = 7,
SLANG_SEMANTIC_CURRENT_SUBFRAME = 9,
SLANG_NUM_BASE_SEMANTICS,
/* float, user defined parameter, arrayed */
SLANG_SEMANTIC_FLOAT_PARAMETER = 8,
SLANG_SEMANTIC_FLOAT_PARAMETER = 10,
SLANG_NUM_SEMANTICS,
SLANG_INVALID_SEMANTIC = -1

View File

@ -50,6 +50,8 @@ def replace_global_in(source):
('IN.frame_count', 'FrameCount'),
('IN.frame_direction', 'FrameDirection'),
('IN.rotation', 'Rotation'),
('IN.core_aspect', 'OriginalAspect'),
('IN.core_aspect_rot', 'OriginalAspectRotated'),
]
for line in source.splitlines():
@ -109,6 +111,8 @@ def no_uniform(elem):
'_frame_count',
'_frame_direction',
'_rotation',
'_core_aspect',
'_core_aspect_rot',
'_mvp_matrix',
'_vertex_coord',
'sampler2D'