Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcb9136f49 |
No files matched your search
@@ -133,10 +133,10 @@ static void handle_released(uint64_t id, int fd) {
|
||||
if (fd >= 0) {
|
||||
struct droiddeck_dma_buf_sync_file imp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = fd};
|
||||
int dmabuf_fd = droiddeck_dmabuf_fd(ab->b);
|
||||
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) {
|
||||
if (!ab->display && dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) {
|
||||
close(fd);
|
||||
} else {
|
||||
if (!g_import_failed_logged) {
|
||||
if (!ab->display && !g_import_failed_logged) {
|
||||
g_import_failed_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: DMA_BUF_IOCTL_IMPORT_SYNC_FILE failed (%s): releases wait for the display's fence here instead",
|
||||
strerror(errno));
|
||||
|
||||
@@ -2020,6 +2020,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
SessionPrefs.setMicAsked(this)
|
||||
}
|
||||
if (wanted.isNotEmpty()) requestPermissions(wanted.toTypedArray(), 1)
|
||||
com.droiddeck.launcher.session.Onboarding.onFirstRunReady = {
|
||||
runOnUiThread {
|
||||
if (!isFinishing && !isDestroyed && !SessionState.running && lifecycle.currentState.isAtLeast(androidx.lifecycle.Lifecycle.State.RESUMED)) playSteam()
|
||||
}
|
||||
}
|
||||
Thread({ com.droiddeck.launcher.stores.StoreAccounts.encryptAll(this) }, "store-credentials").start()
|
||||
if (!SessionState.running) Thread({
|
||||
com.droiddeck.launcher.session.LogMigration.run(this)
|
||||
@@ -2443,6 +2448,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
|
||||
override fun onDestroy() {
|
||||
// The queued launch was saved before this; a restored activity keeps its copy, and this one must not start it too.
|
||||
com.droiddeck.launcher.session.Onboarding.onFirstRunReady = null
|
||||
queuedLaunchRunner.destroy()
|
||||
triggerKeys.cancel()
|
||||
launchCoordinator.cancelAll()
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class PadBridge {
|
||||
private final PadState[] playerStates = new PadState[SLOTS];
|
||||
private final float[][] rawSticks = new float[SLOTS][4];
|
||||
private final Map<Integer, Boolean> rightStickLayouts = new HashMap<>();
|
||||
private final TriggerKey[][] keyTriggers = TriggerKey.slots(SLOTS);
|
||||
private final boolean[][] keyTriggers = new boolean[SLOTS][2];
|
||||
private final int[] retainedSticks = new int[SLOTS];
|
||||
private final PadState effectiveState = new PadState();
|
||||
private final PadState homeGuideReport = new PadState();
|
||||
@@ -484,7 +484,7 @@ public final class PadBridge {
|
||||
stateFor(slot).clear();
|
||||
retainedSticks[slot] = 0;
|
||||
Arrays.fill(rawSticks[slot], 0f);
|
||||
for (TriggerKey key : keyTriggers[slot]) key.reset();
|
||||
Arrays.fill(keyTriggers[slot], false);
|
||||
}
|
||||
|
||||
private void mutateState(java.util.function.Consumer<PadState> mutation) {
|
||||
@@ -570,76 +570,26 @@ public final class PadBridge {
|
||||
return true;
|
||||
}
|
||||
|
||||
static final class TriggerKey {
|
||||
static final float RELEASE_FROM_PEAK = 0.05f;
|
||||
boolean held;
|
||||
boolean handoff;
|
||||
boolean axisLive;
|
||||
boolean axisMovedWhilePressed;
|
||||
float peak;
|
||||
float axis;
|
||||
|
||||
static TriggerKey[][] slots(int count) {
|
||||
TriggerKey[][] keys = new TriggerKey[count][2];
|
||||
for (TriggerKey[] pair : keys) {
|
||||
pair[0] = new TriggerKey();
|
||||
pair[1] = new TriggerKey();
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
held = false;
|
||||
handoff = false;
|
||||
axisLive = false;
|
||||
axisMovedWhilePressed = false;
|
||||
peak = 0f;
|
||||
axis = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog, TriggerKey[] keys, int side) {
|
||||
TriggerKey key = keys[side];
|
||||
static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog, boolean[] held, int side) {
|
||||
if (repeatCount > 0) return current;
|
||||
if (!analog) {
|
||||
key.held = pressed;
|
||||
held[side] = pressed;
|
||||
return pressed ? 1f : 0f;
|
||||
}
|
||||
if (pressed) {
|
||||
key.axisMovedWhilePressed = false;
|
||||
if (key.axisLive || current != 0f) return current;
|
||||
key.held = true;
|
||||
if (current != 0f) return current;
|
||||
held[side] = true;
|
||||
return 1f;
|
||||
}
|
||||
if (!key.axisMovedWhilePressed) key.axisLive = false;
|
||||
if (key.handoff) {
|
||||
key.handoff = false;
|
||||
return key.axis;
|
||||
}
|
||||
if (!key.held) return current;
|
||||
key.held = false;
|
||||
if (!held[side]) return current;
|
||||
held[side] = false;
|
||||
return 0f;
|
||||
}
|
||||
|
||||
static float axisTrigger(float value, TriggerKey[] keys, int side) {
|
||||
TriggerKey key = keys[side];
|
||||
key.axis = value;
|
||||
if (value != 0f) {
|
||||
key.axisLive = true;
|
||||
key.axisMovedWhilePressed = true;
|
||||
}
|
||||
if (key.held) {
|
||||
if (value == 0f) return 1f;
|
||||
key.held = false;
|
||||
key.handoff = true;
|
||||
key.peak = value;
|
||||
return 1f;
|
||||
}
|
||||
if (key.handoff) {
|
||||
key.peak = Math.max(key.peak, value);
|
||||
if (value > key.peak - TriggerKey.RELEASE_FROM_PEAK) return 1f;
|
||||
key.handoff = false;
|
||||
}
|
||||
static float axisTrigger(float value, boolean[] held, int side) {
|
||||
if (!held[side]) return value;
|
||||
if (value == 0f) return 1f;
|
||||
held[side] = false;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ object Onboarding {
|
||||
/** The setup screens belong to the first run; later runtime, Proton and Steam client updates keep the usual Play button. */
|
||||
val firstRun = MutableStateFlow(true)
|
||||
|
||||
/** Called once, when this process finishes the first-run downloads itself; not when everything was already in place. */
|
||||
@Volatile var onFirstRunReady: (() -> Unit)? = null
|
||||
@Volatile private var worked = false
|
||||
|
||||
fun attach(context: Context) {
|
||||
appContext = context.applicationContext
|
||||
val prefs = context.applicationContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
@@ -52,8 +56,10 @@ object Onboarding {
|
||||
|
||||
private fun markFirstRunDone() {
|
||||
val context = appContext ?: return
|
||||
val live = firstRun.value && worked
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(KEY_FIRST_RUN_DONE, true).apply()
|
||||
firstRun.value = false
|
||||
if (live) onFirstRunReady?.invoke()
|
||||
}
|
||||
|
||||
/** Keeps the process in the foreground, with one notification, while a step downloads and the runtime installer is not already doing so. */
|
||||
@@ -90,6 +96,7 @@ object Onboarding {
|
||||
}
|
||||
|
||||
fun report(step: Step, label: String, percent: Int) {
|
||||
worked = true
|
||||
failed.value = failed.value - step
|
||||
active.value = active.value + (step to Progress(label, percent))
|
||||
keepAlive()
|
||||
|
||||
@@ -259,7 +259,7 @@ class PadPartialAxesTest {
|
||||
}
|
||||
|
||||
@Test fun keyTriggerDecision() {
|
||||
val held = PadBridge.TriggerKey.slots(1)[0]
|
||||
val held = BooleanArray(2)
|
||||
assertEquals(1f, PadBridge.keyTrigger(0f, true, 0, false, held, 0))
|
||||
assertEquals(0f, PadBridge.keyTrigger(1f, false, 0, false, held, 0))
|
||||
assertEquals(0.25f, PadBridge.keyTrigger(0.25f, true, 1, false, held, 0))
|
||||
@@ -271,64 +271,6 @@ class PadPartialAxesTest {
|
||||
assertEquals(0f, PadBridge.axisTrigger(0f, held, 1))
|
||||
}
|
||||
|
||||
@Test fun keyBeforeAxisOnAFullPullIsOnePress() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
for (value in listOf(0.1f, 0.3f, 0.6f, 1f, 0.98f)) {
|
||||
motion(device, MotionEvent.AXIS_GAS to value)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
}
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.7f)
|
||||
assertEquals(0.7f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0.7f, pad().rightTrigger)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun releasingDuringTheHandoffFollowsTheAxis() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.4f)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0.4f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun movingTriggerAxisStaysAnalogWhenItsKeyFiresFirst() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.5f)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.1f)
|
||||
assertEquals(0.1f, pad().rightTrigger)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.35f)
|
||||
assertEquals(0.35f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun triggerSwitchedToDigitalPressesAgainAfterOneSilentPress() {
|
||||
val device = device(MotionEvent.AXIS_GAS)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0.5f)
|
||||
motion(device, MotionEvent.AXIS_GAS to 0f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
motion(device)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
motion(device)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun silentTriggerAxesLetTheirKeysPress() {
|
||||
val device = device(MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER)
|
||||
motion(device)
|
||||
@@ -352,15 +294,11 @@ class PadPartialAxesTest {
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
assertEquals(1f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0.4f)
|
||||
assertEquals(1f, pad().leftTrigger)
|
||||
assertEquals(0.4f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0f)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0.4f)
|
||||
assertEquals(0.4f, pad().leftTrigger)
|
||||
}
|
||||
|
||||
private fun pad(): PadState = requireNotNull(JoyConPadTest.RecordingWriter.pads[0])
|
||||
|
||||
@@ -474,13 +474,3 @@ Short strokes never released it, and taps kept landing at the relative pointer i
|
||||
counts its touch-down warps, and a frame that contains one is left out of the hold decision. Touch drags, mouse motion
|
||||
and mouse warps still count, so a drag on a game that follows the pointer releases the hold and a recentring game is
|
||||
still held. `tools/tests/test_gamescope_pointer_hold_touch_down.py` compiles the rule with the 0133 rule.
|
||||
|
||||
## 0146 rendervulkan: composite only into output images the display has finished scanning out
|
||||
|
||||
The host compositor now releases a zero-copy display buffer as soon as the display latches the next one, and attaches
|
||||
the display's release fence to the buffer's dma-buf instead of waiting for it on the CPU. That wait had held every
|
||||
release back by about one refresh, so a chain of three buffers ran at two thirds of the refresh rate. KGSL Turnip does
|
||||
not wait on fences attached to a dma-buf, so the composite now checks each output image's dma-buf with `poll(POLLOUT)`.
|
||||
It picks the next image that is neither held by the host nor still being scanned out. Only when every free image is
|
||||
still on the display does it wait for one, up to 100 ms. On kernels that cannot attach the fence, the host keeps
|
||||
waiting itself and nothing changes. `tools/gamescope/tests/nested-swapchain.cpp` covers the choice and the busy check.
|
||||
@@ -1,106 +0,0 @@
|
||||
diff --git a/src/output_image_pick.hpp b/src/output_image_pick.hpp
|
||||
new file mode 100644
|
||||
index 0000000..193d9de
|
||||
--- /dev/null
|
||||
+++ b/src/output_image_pick.hpp
|
||||
@@ -0,0 +1,50 @@
|
||||
+#pragma once
|
||||
+#include <cstdint>
|
||||
+#include <poll.h>
|
||||
+
|
||||
+namespace gamescope
|
||||
+{
|
||||
+struct OutputImagePick
|
||||
+{
|
||||
+ uint32_t image;
|
||||
+ bool scanoutPending;
|
||||
+};
|
||||
+
|
||||
+template <typename Held, typename Busy>
|
||||
+inline OutputImagePick PickOutputImage( uint32_t count, uint32_t first, uint32_t last, uint32_t deferred,
|
||||
+ Held &&held, Busy &&busy )
|
||||
+{
|
||||
+ for ( int pass = 0; pass < 2; pass++ )
|
||||
+ {
|
||||
+ for ( uint32_t i = 0; i < count; i++ )
|
||||
+ {
|
||||
+ const uint32_t image = ( first + i ) % count;
|
||||
+ if ( count > 3 && ( image == last || image == deferred ) )
|
||||
+ continue;
|
||||
+ if ( held( image ) )
|
||||
+ continue;
|
||||
+ const bool pending = busy( image );
|
||||
+ if ( pass == 0 && pending )
|
||||
+ continue;
|
||||
+ return { image, pending };
|
||||
+ }
|
||||
+ }
|
||||
+ return { first, busy( first ) };
|
||||
+}
|
||||
+
|
||||
+inline bool DmabufScanoutPending( int fd )
|
||||
+{
|
||||
+ if ( fd < 0 )
|
||||
+ return false;
|
||||
+ pollfd p = { .fd = fd, .events = POLLOUT, .revents = 0 };
|
||||
+ return poll( &p, 1, 0 ) == 0;
|
||||
+}
|
||||
+
|
||||
+inline void WaitDmabufScanout( int fd, int timeoutMs )
|
||||
+{
|
||||
+ if ( fd < 0 )
|
||||
+ return;
|
||||
+ pollfd p = { .fd = fd, .events = POLLOUT, .revents = 0 };
|
||||
+ poll( &p, 1, timeoutMs );
|
||||
+}
|
||||
+}
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index 1d3a80c..3668a10 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "steamcompmgr.hpp"
|
||||
#include "log.hpp"
|
||||
#include "Utils/Process.h"
|
||||
+#include "output_image_pick.hpp"
|
||||
|
||||
#include "cs_composite_blit.h"
|
||||
#include "cs_composite_blur.h"
|
||||
@@ -4297,18 +4298,29 @@ static bool vulkan_output_image_held( uint32_t nImage )
|
||||
return false;
|
||||
}
|
||||
|
||||
+static bool vulkan_output_image_scanout_pending( uint32_t nImage )
|
||||
+{
|
||||
+ for ( const auto &pImage : { g_output.outputImages[ nImage ], g_output.outputImagesPartialOverlay[ nImage ] } )
|
||||
+ {
|
||||
+ if ( pImage != nullptr && pImage->GetBackendFb() != nullptr && gamescope::DmabufScanoutPending( pImage->dmabuf().fd[0] ) )
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
static uint32_t vulkan_free_output_image( uint32_t nFirst )
|
||||
{
|
||||
- const uint32_t uCount = g_output.outputImages.size();
|
||||
- for ( uint32_t i = 0; i < uCount; i++ )
|
||||
+ const gamescope::OutputImagePick pick = gamescope::PickOutputImage( g_output.outputImages.size(), nFirst,
|
||||
+ g_output.nLastOutImage, g_output.nDeferredOutImage, vulkan_output_image_held, vulkan_output_image_scanout_pending );
|
||||
+ if ( pick.scanoutPending )
|
||||
{
|
||||
- const uint32_t nImage = ( nFirst + i ) % uCount;
|
||||
- if ( uCount > 3 && ( nImage == g_output.nLastOutImage || nImage == g_output.nDeferredOutImage ) )
|
||||
- continue;
|
||||
- if ( !vulkan_output_image_held( nImage ) )
|
||||
- return nImage;
|
||||
+ for ( const auto &pImage : { g_output.outputImages[ pick.image ], g_output.outputImagesPartialOverlay[ pick.image ] } )
|
||||
+ {
|
||||
+ if ( pImage != nullptr && pImage->GetBackendFb() != nullptr )
|
||||
+ gamescope::WaitDmabufScanout( pImage->dmabuf().fd[0], 100 );
|
||||
+ }
|
||||
}
|
||||
- return nFirst;
|
||||
+ return pick.image;
|
||||
}
|
||||
|
||||
std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamescope::Rc<CVulkanTexture> pPipewireTexture, bool partial, gamescope::Rc<CVulkanTexture> pOutputOverride, bool increment, std::unique_ptr<CVulkanCmdBuffer> pInCommandBuffer )
|
||||
@@ -1,3 +1,3 @@
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-f3a45b31
|
||||
GAMESCOPE_SHA256=3908af87b2ee8a328e9780fc805c6a7bddd11d7405b9992d717b94e16c019313
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-1a29c65d
|
||||
GAMESCOPE_SHA256=18620dfedb65860da00003e965cc09784a650ef6ecc9a17056405fe0a1392a02
|
||||
@@ -2,9 +2,6 @@
|
||||
#include "nested_surface_format.hpp"
|
||||
#include "dmabuf_import.hpp"
|
||||
#include "sdl_refresh.hpp"
|
||||
#include "output_image_pick.hpp"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
@@ -155,43 +152,5 @@ int main()
|
||||
assert(DmabufMemoryType(memory, 7, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == UINT32_MAX);
|
||||
assert(DmabufMemoryType(memory, 7, 4, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == UINT32_MAX);
|
||||
|
||||
using gamescope::PickOutputImage;
|
||||
auto none = [](uint32_t) { return false; };
|
||||
auto pick = PickOutputImage(5, 2, 1, 0, none, none);
|
||||
assert(pick.image == 2 && !pick.scanoutPending);
|
||||
auto heldTwo = [](uint32_t i) { return i == 2; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, heldTwo, none);
|
||||
assert(pick.image == 3 && !pick.scanoutPending);
|
||||
auto scanningTwo = [](uint32_t i) { return i == 2; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, none, scanningTwo);
|
||||
assert(pick.image == 3 && !pick.scanoutPending);
|
||||
auto scanningAll = [](uint32_t) { return true; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, heldTwo, scanningAll);
|
||||
assert(pick.image == 3 && pick.scanoutPending);
|
||||
auto heldAll = [](uint32_t) { return true; };
|
||||
auto scanningOne = [](uint32_t i) { return i == 1; };
|
||||
pick = PickOutputImage(5, 2, 1, 0, heldAll, none);
|
||||
assert(pick.image == 2 && !pick.scanoutPending);
|
||||
pick = PickOutputImage(5, 1, 0, 1, heldAll, scanningOne);
|
||||
assert(pick.image == 1 && pick.scanoutPending);
|
||||
pick = PickOutputImage(3, 1, 0, 2, none, none);
|
||||
assert(pick.image == 1 && !pick.scanoutPending);
|
||||
pick = PickOutputImage(3, 1, 0, 2, none, scanningOne);
|
||||
assert(pick.image == 2 && !pick.scanoutPending);
|
||||
|
||||
int fds[2];
|
||||
assert(pipe(fds) == 0);
|
||||
assert(!gamescope::DmabufScanoutPending(fds[1]));
|
||||
assert(!gamescope::DmabufScanoutPending(-1));
|
||||
fcntl(fds[1], F_SETFL, O_NONBLOCK);
|
||||
char block[4096] = {};
|
||||
while (write(fds[1], block, sizeof(block)) > 0) {}
|
||||
assert(gamescope::DmabufScanoutPending(fds[1]));
|
||||
gamescope::WaitDmabufScanout(fds[1], 1);
|
||||
while (read(fds[0], block, sizeof(block)) == sizeof(block) && gamescope::DmabufScanoutPending(fds[1])) {}
|
||||
assert(!gamescope::DmabufScanoutPending(fds[1]));
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
std::puts("Gamescope presentation and DMA-BUF import tests passed");
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from test_vk_pending_completion import function
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SRC = ROOT / 'app/src/main/cpp/waylandcomp/src'
|
||||
|
||||
HARNESS = r'''
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-util.h>
|
||||
struct wl_listener { struct wl_list link; void (*notify)(struct wl_listener *, void *); };
|
||||
struct wl_event_source { int unused; };
|
||||
struct wl_event_loop;
|
||||
enum { WL_EVENT_READABLE = 1 };
|
||||
struct wl_client;
|
||||
struct wl_resource { int unused; };
|
||||
struct surface;
|
||||
struct dmabuf_buffer { int fd; };
|
||||
typedef struct AHardwareBuffer { int unused; } AHardwareBuffer;
|
||||
DEFINES
|
||||
STRUCT
|
||||
static struct wl_list g_bufs;
|
||||
static struct wl_event_loop *g_loop;
|
||||
static int g_import_failed_logged;
|
||||
static int import_ok, imports, imported_flags, deferred_releases, frees, sources;
|
||||
static struct wl_event_source g_source;
|
||||
void wl_list_init(struct wl_list *l) { l->prev = l; l->next = l; }
|
||||
void wl_list_insert(struct wl_list *l, struct wl_list *e) {
|
||||
e->next = l->next; e->prev = l; l->next->prev = e; l->next = e;
|
||||
}
|
||||
static int fake_ioctl(int fd, unsigned long req, void *arg) {
|
||||
struct droiddeck_dma_buf_sync_file *f = arg;
|
||||
(void)fd;
|
||||
assert(req == DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE);
|
||||
++imports; imported_flags = (int)f->flags;
|
||||
if (import_ok) return 0;
|
||||
errno = ENOTTY; return -1;
|
||||
}
|
||||
#define ioctl fake_ioctl
|
||||
static int droiddeck_dmabuf_fd(struct dmabuf_buffer *b) { return b->fd; }
|
||||
static void droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; }
|
||||
static struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *l, int fd, uint32_t m,
|
||||
int (*cb)(int, uint32_t, void *), void *d) {
|
||||
(void)l; (void)fd; (void)m; (void)cb; (void)d; ++sources; return &g_source;
|
||||
}
|
||||
static int on_fence_readable(int fd, uint32_t mask, void *data) { (void)fd; (void)mask; (void)data; return 0; }
|
||||
static void send_deferred_release(struct ahb_buf *ab) { ++deferred_releases; ab->release_pending = 0; }
|
||||
static void maybe_free(struct ahb_buf *ab) { (void)ab; ++frees; }
|
||||
FUNCTIONS
|
||||
static void reset(void) { import_ok = imports = imported_flags = deferred_releases = frees = sources = 0; }
|
||||
static void run(int display, int can_import, int fence_signalled) {
|
||||
reset();
|
||||
wl_list_init(&g_bufs);
|
||||
struct dmabuf_buffer b = {.fd = 7};
|
||||
struct ahb_buf ab;
|
||||
memset(&ab, 0, sizeof(ab));
|
||||
ab.id = 42; ab.b = &b; ab.display = display; ab.on_layer = 1; ab.release_pending = 1; ab.fence_fd = -1;
|
||||
wl_list_insert(&g_bufs, &ab.link);
|
||||
int fds[2]; assert(pipe(fds) == 0);
|
||||
if (fence_signalled) assert(write(fds[1], "x", 1) == 1);
|
||||
import_ok = can_import;
|
||||
handle_released(42, fds[0]);
|
||||
assert(!ab.on_layer && imports == 1 && imported_flags == DROIDDECK_DMA_BUF_SYNC_READ);
|
||||
if (can_import || fence_signalled) {
|
||||
assert(deferred_releases == 1 && frees == 1 && !ab.fence_src && ab.fence_fd == -1);
|
||||
errno = 0; assert(fcntl(fds[0], F_GETFD) == -1 && errno == EBADF);
|
||||
} else {
|
||||
assert(deferred_releases == 0 && sources == 1 && ab.fence_src == &g_source && ab.fence_fd == fds[0]);
|
||||
close(fds[0]);
|
||||
}
|
||||
close(fds[1]);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 4);
|
||||
run(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ZeroCopyReleaseAtLatchTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cc = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if not cc:
|
||||
raise AssertionError('C compiler required')
|
||||
source_dir = Path(os.environ.get('DROIDDECK_DMABUF_TEST_SOURCE', SRC))
|
||||
ahb = (source_dir / 'ahb_swapchain.c').read_text()
|
||||
defines = '\n'.join(re.findall(r'^(?:struct droiddeck_dma_buf_sync_file \{.*?\};|#define DROIDDECK_DMA_BUF_\w+ .*)$',
|
||||
ahb, re.M))
|
||||
struct = re.search(r'struct ahb_buf \{.*?\n\};', ahb, re.S).group()
|
||||
functions = '\n'.join(function(ahb, n) for n in ('find_buf', 'handle_released'))
|
||||
source = HARNESS.replace('DEFINES', '#include <fcntl.h>\n#include <sys/ioctl.h>\n' + defines)
|
||||
source = source.replace('STRUCT', struct).replace('FUNCTIONS', functions)
|
||||
cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-release-latch-')
|
||||
cls.addClassCleanup(cls.tmp.cleanup)
|
||||
probe = Path(cls.tmp.name) / 'probe.c'
|
||||
probe.write_text(source)
|
||||
cls.binary = probe.with_suffix('')
|
||||
built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror', '-Wno-unused-function', '-UNDEBUG',
|
||||
'-I', str(SRC.parent / 'prebuilt/include'), str(probe), '-o', str(cls.binary)],
|
||||
capture_output=True, text=True)
|
||||
if built.returncode:
|
||||
raise AssertionError(built.stdout + built.stderr)
|
||||
|
||||
def scenario(self, display, can_import, fence_signalled):
|
||||
result = subprocess.run([str(self.binary), str(display), str(can_import), str(fence_signalled)],
|
||||
capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
def test_display_buffer_released_at_latch_when_fence_attaches(self):
|
||||
self.scenario(1, 1, 0)
|
||||
|
||||
def test_swapchain_buffer_released_at_latch_when_fence_attaches(self):
|
||||
self.scenario(0, 1, 0)
|
||||
|
||||
def test_display_buffer_waits_for_fence_when_kernel_cannot_attach(self):
|
||||
self.scenario(1, 0, 0)
|
||||
|
||||
def test_swapchain_buffer_waits_for_fence_when_kernel_cannot_attach(self):
|
||||
self.scenario(0, 0, 0)
|
||||
|
||||
def test_signalled_fence_releases_without_waiting(self):
|
||||
self.scenario(1, 0, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user