Compare commits

..

1 Commits

Author SHA1 Message Date
lizzie 2427134c00 [input/sdl] nuke SDL_Vibration thread
Signed-off-by: lizzie <lizzie@eden-emu.dev>
2026-09-07 12:27:39 +02:00
4 changed files with 59 additions and 103 deletions
+1 -40
View File
@@ -697,16 +697,6 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en
SDL_AddEventWatch(&SDLEventWatcher, this);
initialized = true;
if (start_thread) {
vibration_thread = std::thread([this] {
Common::SetCurrentThreadName("SDL_Vibration");
using namespace std::chrono_literals;
while (initialized) {
SendVibrations();
std::this_thread::sleep_for(250ms); // 4 TPS
}
});
}
// Because the events for joystick connection happens before we have our event watcher added, we
// can just open all the joysticks right here
int joystick_count = 0;
@@ -725,7 +715,6 @@ SDLDriver::~SDLDriver() {
initialized = false;
if (start_thread) {
vibration_thread.join();
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD);
}
}
@@ -805,10 +794,7 @@ Common::Input::DriverResult SDLDriver::SetVibration(
.type = Common::Input::VibrationAmplificationType::Exponential,
};
vibration_queue.Push(VibrationRequest{
.identifier = identifier,
.vibration = new_vibration,
});
joystick->RumblePlay(new_vibration);
return Common::Input::DriverResult::Success;
}
@@ -852,31 +838,6 @@ bool SDLDriver::IsVibrationEnabled(const PadIdentifier& identifier) {
return true;
}
void SDLDriver::SendVibrations() {
std::vector<VibrationRequest> filtered_vibrations{};
while (!vibration_queue.Empty()) {
VibrationRequest request;
vibration_queue.Pop(request);
const auto joystick = GetSDLJoystickByGUID(request.identifier.guid.RawString(),
static_cast<int>(request.identifier.port));
const auto it = std::find_if(filtered_vibrations.begin(), filtered_vibrations.end(),
[request](VibrationRequest vibration) {
return vibration.identifier == request.identifier;
});
if (it == filtered_vibrations.end()) {
filtered_vibrations.push_back(std::move(request));
continue;
}
*it = request;
}
for (const auto& vibration : filtered_vibrations) {
const auto joystick = GetSDLJoystickByGUID(vibration.identifier.guid.RawString(),
static_cast<int>(vibration.identifier.port));
joystick->RumblePlay(vibration.vibration);
}
}
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, const Common::UUID& guid,
s32 axis, float value) const {
Common::ParamPackage params{};
+1 -6
View File
@@ -113,16 +113,11 @@ private:
/// Returns true if the button is on the left joycon
bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const;
/// Queue of vibration request to controllers
Common::SPSCQueue<VibrationRequest> vibration_queue;
/// Map of GUID of a list of corresponding virtual Joysticks
::Common::unordered_map<Common::UUID, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
std::mutex joystick_map_mutex;
bool start_thread = false;
std::atomic<bool> initialized = false;
std::thread vibration_thread;
bool start_thread;
};
} // namespace InputCommon
+44 -40
View File
@@ -7,65 +7,69 @@
#version 460
#ifdef VULKAN
#define BINDING_COLOR_TEXTURE 1
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
#define BINDING_COLOR_TEXTURE 0
#endif
layout (location = 0) in vec4 posPos;
layout (location = 0) out vec4 frag_color;
layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D input_texture;
const float FXAA_SPAN_MAX = 8.0;
const float FXAA_REDUCE_MUL = 1.0 / 8.0;
const float FXAA_REDUCE_MIN = 1.0 / 128.0;
#define FxaaTexLod0(t, p) textureLod(t, p, 0.0)
#define FxaaTexOff(t, p, o) textureLodOffset(t, p, 0.0, o)
vec3 FxaaPixelShader(vec4 posPos, sampler2D tex) {
mat4x3 rgb_matrix = mat4x3(
textureLod(tex, posPos.zw, 0.0).xyz,
textureLodOffset(tex, posPos.zw, 0.0, ivec2(1, 0)).xyz,
textureLodOffset(tex, posPos.zw, 0.0, ivec2(0, 1)).xyz,
textureLodOffset(tex, posPos.zw, 0.0, ivec2(1, 1)).xyz
);
vec3 rgbM = textureLod(tex, posPos.xy, 0.0).xyz;
vec3 rgbNW = FxaaTexLod0(tex, posPos.zw).xyz;
vec3 rgbNE = FxaaTexOff(tex, posPos.zw, ivec2(1,0)).xyz;
vec3 rgbSW = FxaaTexOff(tex, posPos.zw, ivec2(0,1)).xyz;
vec3 rgbSE = FxaaTexOff(tex, posPos.zw, ivec2(1,1)).xyz;
vec3 rgbM = FxaaTexLod0(tex, posPos.xy).xyz;
/*---------------------------------------------------------*/
vec3 luma = vec3(0.299, 0.587, 0.114);
// vec4(dot(m1, l), dot(m2, l), ...) => m * l
vec4 lume_per_rgb = luma * rgb_matrix;
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma);
float lumaMin = min(lumaM, min(min(lume_per_rgb.x, lume_per_rgb.y), min(lume_per_rgb.z, lume_per_rgb.w)));
float lumaMax = max(lumaM, max(max(lume_per_rgb.x, lume_per_rgb.y), max(lume_per_rgb.z, lume_per_rgb.w)));
vec2 dir = vec2(
-((lume_per_rgb.x + lume_per_rgb.y) - (lume_per_rgb.z + lume_per_rgb.w)),
+((lume_per_rgb.x + lume_per_rgb.z) - (lume_per_rgb.y + lume_per_rgb.w))
);
float rcp_dir_min = 1.0 / (min(abs(dir.x), abs(dir.y)) + max(
(lume_per_rgb.x + lume_per_rgb.y + lume_per_rgb.z + lume_per_rgb.w) * (0.25 * FXAA_REDUCE_MUL),
FXAA_REDUCE_MIN
));
dir = min(
vec2(FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX), dir * rcp_dir_min)
);
// Constants (calculating via division is faster)
mat4x2 const_dir = mat4x2(
(1.0 / 3.0 - 0.5) / textureSize(tex, 0),
(2.0 / 3.0 - 0.5) / textureSize(tex, 0),
(0.0 / 3.0 - 0.5) / textureSize(tex, 0),
(3.0 / 3.0 - 0.5) / textureSize(tex, 0)
);
// dir * const_dir[i] => dir * const_dir => vec4
/*---------------------------------------------------------*/
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
/*---------------------------------------------------------*/
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
/*---------------------------------------------------------*/
float dirReduce = max(
(lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),
FXAA_REDUCE_MIN);
float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
dir = min(vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir * rcpDirMin)) / textureSize(tex, 0);
/*--------------------------------------------------------*/
vec3 rgbA = (1.0 / 2.0) * (
textureLod(tex, fma(dir, const_dir[0], posPos.xy), 0.0).xyz +
textureLod(tex, fma(dir, const_dir[1], posPos.xy), 0.0).xyz
);
vec3 rgbB = fma(rgbA, vec3(1.0 / 2.0), (1.0 / 4.0) * (
textureLod(tex, fma(dir, const_dir[2], posPos.xy), 0.0).xyz +
textureLod(tex, fma(dir, const_dir[3], posPos.xy), 0.0).xyz
));
FxaaTexLod0(tex, posPos.xy + dir * (1.0 / 3.0 - 0.5)).xyz +
FxaaTexLod0(tex, posPos.xy + dir * (2.0 / 3.0 - 0.5)).xyz);
vec3 rgbB = rgbA * (1.0 / 2.0) + (1.0 / 4.0) * (
FxaaTexLod0(tex, posPos.xy + dir * (0.0 / 3.0 - 0.5)).xyz +
FxaaTexLod0(tex, posPos.xy + dir * (3.0 / 3.0 - 0.5)).xyz);
float lumaB = dot(rgbB, luma);
return ((lumaB < lumaMin) || (lumaB > lumaMax)) ? rgbA : rgbB;
if((lumaB < lumaMin) || (lumaB > lumaMax)) return rgbA;
return rgbB;
}
void main() {
frag_color = vec4(FxaaPixelShader(posPos, input_texture), texture(input_texture, posPos.xy).a);
frag_color = vec4(FxaaPixelShader(posPos, input_texture), texture(input_texture, posPos.xy).a);
}
+13 -17
View File
@@ -7,35 +7,31 @@ out gl_PerVertex {
vec4 gl_Position;
};
const vec2 vertices[3] =
vec2[3](vec2(-1,-1), vec2(3,-1), vec2(-1, 3));
layout (location = 0) out vec4 posPos;
#ifdef VULKAN
#define BINDING_COLOR_TEXTURE 0
#define VERTEX_ID gl_VertexIndex
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
#define BINDING_COLOR_TEXTURE 0
#define VERTEX_ID gl_VertexID
#endif
layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D input_texture;
const float FXAA_SUBPIX_SHIFT = 0;
void main() {
// 0b00 -> (-1, -1) 0b01 -> (-1, 3) 0b10 -> (3, -1)
// ((x * 4) - 1) => 3
// :: (v + 1) / 2 => ((x * 4) + 1) / 2
// => (x * 4 + 1) / 2 => x * (4 / 2) + 1 / 2
// :: (v+1)/2 => v/2 + 1/2 => v*(1/2) + (1/2)
gl_Position = vec4(vec2(
float(((VERTEX_ID & 1) << 2) - 1),
float(((VERTEX_ID & 2) << 1) - 1)
), 0.0, 1.0);
posPos = vec2(
float((VERTEX_ID & 1) << 1),
float((VERTEX_ID & 2) << 0)
).xyxy - vec4(
0.0,
0.0,
(0.5 + FXAA_SUBPIX_SHIFT) / textureSize(input_texture, 0)
);
vec2 vertex = vertices[VERTEX_ID];
gl_Position = vec4(vertex, 0.0, 1.0);
vec2 vert_tex_coord = (vertex + 1.0) / 2.0;
posPos.xy = vert_tex_coord;
posPos.zw = vert_tex_coord - (0.5 + FXAA_SUBPIX_SHIFT) / textureSize(input_texture, 0);
}