rsx/overlays: Support disabling vertex-snap on a per-draw-call basis

This commit is contained in:
kd-11 2023-02-04 23:38:18 +03:00 committed by kd-11
parent af6db7d895
commit dc8652806e
7 changed files with 65 additions and 12 deletions

View file

@ -432,6 +432,11 @@ namespace gl
}
}
rsx::overlays::vertex_options vert_opts;
program_handle.uniforms["vertex_config"] = vert_opts
.disable_vertex_snap(cmd.config.disable_vertex_snap)
.get();
rsx::overlays::fragment_options draw_opts;
program_handle.uniforms["fragment_config"] = draw_opts
.texture_mode(texture_mode)

View file

@ -960,6 +960,7 @@ namespace rsx
{
auto& config = draw_cmd.config;
config.color = back_color;
config.disable_vertex_snap = true;
config.pulse_glow = pulse_effect_enabled;
config.pulse_sinus_offset = pulse_sinus_offset;
config.pulse_speed_modifier = pulse_speed_modifier;

View file

@ -83,6 +83,7 @@ namespace rsx
color4f color = { 1.f, 1.f, 1.f, 1.f };
bool pulse_glow = false;
bool disable_vertex_snap = false;
f32 pulse_sinus_offset = 0.0f; // The current pulse offset
f32 pulse_speed_modifier = 0.005f;

View file

@ -20,14 +20,28 @@ layout(%push_block) uniform Configuration
vec4 albedo;
vec4 viewport;
vec4 clip_bounds;
uint vertex_config;
};
#else
uniform vec4 ui_scale;
uniform vec4 albedo;
uniform vec4 viewport;
uniform vec4 clip_bounds;
uniform uint vertex_config;
#endif
struct config_t
{
bool no_vertex_snap;
};
config_t unpack_vertex_options()
{
config_t result;
result.no_vertex_snap = bitfieldExtract(vertex_config, 0, 1) != 0;
return result;
}
vec2 snap_to_grid(const in vec2 normalized)
{
return floor(fma(normalized, viewport.xy, vec2(0.5))) / viewport.xy;
@ -53,8 +67,15 @@ void main()
tc0.xy = in_pos.zw;
color = albedo;
clip_rect = ndc_to_window(clip_to_ndc(clip_bounds));
vec4 pos = vec4(clip_to_ndc(in_pos).xy, 0.5, 1.);
pos.xy = snap_to_grid(pos.xy);
config_t config = unpack_vertex_options();
if (!config.no_vertex_snap)
{
pos.xy = snap_to_grid(pos.xy);
}
gl_Position = (pos + pos) - 1.;
}
)"

View file

@ -56,5 +56,22 @@ namespace rsx
return value;
}
};
class vertex_options
{
u32 value = 0;
public:
vertex_options& disable_vertex_snap(bool enable)
{
value = enable ? 1 : 0;
return *this;
}
u32 get() const
{
return value;
}
};
}
}

View file

@ -370,7 +370,7 @@ namespace vk
fs_src = fmt::replace_all(fs_src,
{
{ "%preprocessor", "// %preprocessor" },
{ "%push_block_offset", "layout(offset=64)" },
{ "%push_block_offset", "layout(offset=68)" },
{ "%push_block", "push_constant" }
});
@ -542,12 +542,12 @@ namespace vk
{
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
.offset = 0,
.size = 64
.size = 68
},
{
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
.offset = 64,
.size = 16
.offset = 68,
.size = 12
}
};
}
@ -559,9 +559,10 @@ namespace vk
// 16: vec4 albedo;
// 32: vec4 viewport;
// 48: vec4 clip_bounds;
// 64: uint fragment_config;
// 68: float timestamp;
// 72: float blur_intensity;
// 64: uint vertex_config;
// 68: uint fragment_config;
// 72: float timestamp;
// 76: float blur_intensity;
f32 push_buf[32];
// 1. Vertex config (00 - 63)
@ -578,6 +579,12 @@ namespace vk
push_buf[14] = m_clip_region.x2;
push_buf[15] = m_clip_region.y2;
rsx::overlays::vertex_options vert_opts;
const auto vert_config = vert_opts
.disable_vertex_snap(m_disable_vertex_snap)
.get();
push_buf[16] = std::bit_cast<f32>(vert_config);
// 2. Fragment stuff
rsx::overlays::fragment_options frag_opts;
const auto frag_config = frag_opts
@ -586,10 +593,9 @@ namespace vk
.pulse_glow(m_pulse_glow)
.get();
std::memcpy(push_buf + 16, &frag_config, 4);
//push_buf[16] = std::bit_cast<f32>(frag_config);
push_buf[17] = m_time;
push_buf[18] = m_blur_strength;
push_buf[17] = std::bit_cast<f32>(frag_config);
push_buf[18] = m_time;
push_buf[19] = m_blur_strength;
vkCmdPushConstants(cmd, m_pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 80, push_buf);
}
@ -670,6 +676,7 @@ namespace vk
m_blur_strength = static_cast<f32>(command.config.blur_strength) * 0.01f;
m_clip_enabled = command.config.clip_region;
m_clip_region = command.config.clip_rect;
m_disable_vertex_snap = command.config.disable_vertex_snap;
vk::image_view* src = nullptr;
switch (command.config.texture_ref)

View file

@ -137,6 +137,7 @@ namespace vk
color4f m_color;
bool m_pulse_glow = false;
bool m_clip_enabled = false;
bool m_disable_vertex_snap = false;
rsx::overlays::texture_sampling_mode m_texture_type;
areaf m_clip_region;
coordf m_viewport;