mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Merge upstream PC input and dual-screen updates
This commit is contained in:
commit
68b0396dfe
819 files changed
+43953
-6186
No files matched your search
@@ -8,7 +8,6 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,max-page-size=16384
|
||||
|
||||
add_subdirectory(adrenotools)
|
||||
|
||||
# DXVK's DXBC->SPIR-V translator is zlib licensed (vendored under thirdparty/dxbc).
|
||||
add_subdirectory(thirdparty/dxbc)
|
||||
|
||||
set(DDFG_UPSTREAM "v0.3.0")
|
||||
@@ -37,13 +36,14 @@ target_link_libraries(sdnative log)
|
||||
add_library(deviceinfo SHARED deviceinfo/vkinfo.c)
|
||||
target_link_libraries(deviceinfo dl)
|
||||
|
||||
add_library(gpuclock SHARED gpuclock/kgsl_clock.c gpuclock/kgsl_busy.c)
|
||||
|
||||
add_library(termux SHARED termux/termux.c)
|
||||
|
||||
add_library(ddvenc SHARED venc/venc_server.cpp)
|
||||
target_compile_features(ddvenc PRIVATE cxx_std_17)
|
||||
target_link_libraries(ddvenc mediandk log)
|
||||
|
||||
# The optional proprietary SDK is supplied locally; its headers/libraries are not vendored.
|
||||
if(DROIDDECK_VITURE_SDK_DIR)
|
||||
add_library(droiddeck_viture SHARED viture/sdk_bridge.cpp)
|
||||
target_compile_features(droiddeck_viture PRIVATE cxx_std_17)
|
||||
|
||||
@@ -62,6 +62,7 @@ Java_com_droiddeck_launcher_gpu_VulkanInfo_nativeQuery(JNIEnv *env, jclass clazz
|
||||
LINE("driver_version=%u.%u.%u\n", p.driverVersion >> 22, (p.driverVersion >> 12) & 0x3ff, p.driverVersion & 0xfff);
|
||||
LINE("vendor_id=0x%04x\ndevice_id=0x%08x\n", p.vendorID, p.deviceID);
|
||||
LINE("max_image_2d=%u\n", p.limits.maxImageDimension2D);
|
||||
LINE("max_push_constants=%u\n", p.limits.maxPushConstantsSize);
|
||||
|
||||
uint32_t extCount = 0;
|
||||
if (vkEnumerateDeviceExtensionProperties) vkEnumerateDeviceExtensionProperties(device, NULL, &extCount, NULL);
|
||||
@@ -91,6 +92,7 @@ Java_com_droiddeck_launcher_gpu_VulkanInfo_nativeQuery(JNIEnv *env, jclass clazz
|
||||
vkGetPhysicalDeviceFeatures(device, &f);
|
||||
LINE("geometry_shader=%s\ntessellation_shader=%s\ntexture_bc=%s\n",
|
||||
f.geometryShader ? "yes" : "no", f.tessellationShader ? "yes" : "no", f.textureCompressionBC ? "yes" : "no");
|
||||
LINE("shader_int64=%s\n", f.shaderInt64 ? "yes" : "no");
|
||||
}
|
||||
if (vkGetPhysicalDeviceMemoryProperties) {
|
||||
VkPhysicalDeviceMemoryProperties m;
|
||||
|
||||
@@ -78,7 +78,6 @@ static constexpr uint8_t GAMEPAD_AXIS_COUNT = 8;
|
||||
static constexpr uint8_t GAMEPAD_BUTTON_COUNT = 11;
|
||||
static constexpr uint32_t FAKE_INPUT_RING_MAGIC = 0x46494252;
|
||||
static constexpr uint32_t FAKE_INPUT_RING_VERSION = 2;
|
||||
// Rings hold the 64-bit input_event layout that the arm64 writers use; 32-bit guests convert on read.
|
||||
struct RingEvent {
|
||||
int64_t sec;
|
||||
int64_t usec;
|
||||
@@ -391,7 +390,6 @@ send_vibration(int strong, int weak, uint16_t duration_ms, uint16_t slot) {
|
||||
syscall(SYS_close, sock);
|
||||
}
|
||||
|
||||
// Must match RumbleComponent.HOLD_MS: play until the slot's next effect or stop.
|
||||
static constexpr uint16_t RUMBLE_HOLD_MS = 0xffff;
|
||||
|
||||
__attribute__((visibility("hidden"))) static void send_ff_effect(const struct ff_effect &effect, uint16_t slot) {
|
||||
@@ -1243,7 +1241,6 @@ static constexpr int TRITON_REPORT_ID_BYTES = 1;
|
||||
static constexpr int TRITON_STATE_BYTES = 45;
|
||||
static constexpr int TRITON_REPORT_INTERVAL_US = 4000;
|
||||
static constexpr int TRITON_FEATURE_TIMEOUT_MS = 500;
|
||||
// The app clears output_length once it has taken a report; a writer waits this long for that before overwriting.
|
||||
static constexpr int TRITON_OUTPUT_TIMEOUT_MS = 50;
|
||||
static constexpr const char *TRITON_NAME = "Steam Controller";
|
||||
static constexpr const char *TRITON_SERIAL = "DROIDDECKSC01";
|
||||
@@ -2673,9 +2670,6 @@ __attribute__((visibility("hidden"))) static int triton_get_feature(DeckHidraw &
|
||||
static constexpr uint32_t TRITON_HWID = 72;
|
||||
static constexpr uint32_t TRITON_FW_TIMESTAMP = 0x6AC686B3;
|
||||
|
||||
// Steam compares the controller's firmware with TRITON_FW_TS in its bundled hardwareupdater.cfg (and blocks
|
||||
// with a required update below MUST_UPDATE_TRITON_FW_TS), so the emulated pad reports at least the build
|
||||
// Steam ships.
|
||||
static uint32_t triton_fw_timestamp() {
|
||||
static const uint32_t timestamp = [] {
|
||||
std::vector<std::string> roots;
|
||||
@@ -3683,7 +3677,6 @@ EXPORT int ioctl(int fd, ioctl_request_t op, ...) {
|
||||
Logger::log("Hooking ioctl EVIOCGRAB for event %s\n", event);
|
||||
return 0;
|
||||
} else if (type == 0x6A && !strncmp(event, "event", 5)) {
|
||||
// Older SDL2 builds treat any JSIOCGNAME answer as a joydev node and skip EVIOCGID, then drop the pad as 0000:0000.
|
||||
Logger::log("Rejecting joydev ioctl %d for event %s\n", number, event);
|
||||
guard.unlock();
|
||||
errno = EINVAL;
|
||||
|
||||
@@ -267,8 +267,6 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
pFlowReg_, flowRegA_, flowRegB_, gmSsbo_, kLevels, cfg_);
|
||||
}
|
||||
|
||||
// Every generation of one real frame is recorded into the same command buffer, so the flow
|
||||
// between prev and curr is computed once and each generation gets its own synth UBO and set.
|
||||
if (reuseFlow && !g_scratch.flowReady) return;
|
||||
if (!reuseFlow) {
|
||||
bool gmEngaged = updateGlobalMotion(gmSlot, extent_);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// LSFG from Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk (PancakeTAS).
|
||||
// Ported to WinNative and DroidDeck by @maxjivi05. GPL-3.0-or-later.
|
||||
// LSFG from Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk (PancakeTAS). Ported to WinNative and DroidDeck by @maxjivi05. GPL-3.0-or-later.
|
||||
|
||||
#include "lsfg_dll.h"
|
||||
#include "lsfg_dxbc.h"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// LSFG from Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk (PancakeTAS).
|
||||
// Ported to WinNative and DroidDeck by @maxjivi05. GPL-3.0-or-later.
|
||||
// LSFG from Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk (PancakeTAS). Ported to WinNative and DroidDeck by @maxjivi05. GPL-3.0-or-later.
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
// DXVK's dxbc subset is zlib licensed; vendored under cpp/thirdparty/dxbc.
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
// Whole-GPU busy share without root on Adreno (KGSL) devices whose kgsl sysfs is blocked for apps: a thread
|
||||
// samples the memstore timestamps (kgsl_busy.h) once a millisecond while running. Ringbuffer entries are used where
|
||||
// the kernel writes them; on hardware-scheduled kernels, which leave them at 0, the contexts' own entries are used.
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../adrenotools/src/hook/kgsl.h"
|
||||
#include "kgsl_busy.h"
|
||||
|
||||
#define SAMPLE_NS 1000000L
|
||||
// Context mode: how many samples between scans of the context entries.
|
||||
#define SCAN_EVERY 200
|
||||
|
||||
enum { MODE_RINGBUFFER = 1, MODE_CONTEXTS = 2 };
|
||||
|
||||
struct reader {
|
||||
int fd;
|
||||
void *map;
|
||||
size_t bytes;
|
||||
int first;
|
||||
int mode;
|
||||
uint32_t last[KGSL_BUSY_SLOTS];
|
||||
uint32_t *seen, *ctx_last;
|
||||
int live[KGSL_BUSY_MAX_LIVE];
|
||||
int live_count;
|
||||
pthread_mutex_t lock;
|
||||
pthread_t thread;
|
||||
int thread_on;
|
||||
atomic_int run;
|
||||
atomic_uint_fast64_t busy, samples, moves;
|
||||
};
|
||||
|
||||
static void *sample_loop(void *arg) {
|
||||
struct reader *r = arg;
|
||||
const struct timespec gap = {0, SAMPLE_NS};
|
||||
int until_scan = 0;
|
||||
while (atomic_load(&r->run)) {
|
||||
int moved = 0, busy;
|
||||
if (r->mode == MODE_CONTEXTS) {
|
||||
if (until_scan-- <= 0) {
|
||||
r->live_count = kgsl_busy_scan_contexts(r->map, r->first, r->seen, r->live, KGSL_BUSY_MAX_LIVE);
|
||||
until_scan = SCAN_EVERY;
|
||||
}
|
||||
busy = kgsl_busy_sample_contexts(r->map, r->live, r->live_count, r->ctx_last, &moved);
|
||||
} else {
|
||||
busy = kgsl_busy_sample(r->map, r->first, r->last, &moved);
|
||||
}
|
||||
if (busy) atomic_fetch_add(&r->busy, 1);
|
||||
if (moved) atomic_fetch_add(&r->moves, 1);
|
||||
atomic_fetch_add(&r->samples, 1);
|
||||
nanosleep(&gap, NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void reader_run(struct reader *r, int on) {
|
||||
pthread_mutex_lock(&r->lock);
|
||||
if (on && !r->thread_on) {
|
||||
atomic_store(&r->run, 1);
|
||||
if (pthread_create(&r->thread, NULL, sample_loop, r) == 0) r->thread_on = 1;
|
||||
else atomic_store(&r->run, 0);
|
||||
} else if (!on && r->thread_on) {
|
||||
atomic_store(&r->run, 0);
|
||||
pthread_join(r->thread, NULL);
|
||||
r->thread_on = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&r->lock);
|
||||
}
|
||||
|
||||
static void reader_close(struct reader *r) {
|
||||
if (!r) return;
|
||||
reader_run(r, 0);
|
||||
if (r->map && r->map != MAP_FAILED) munmap(r->map, r->bytes);
|
||||
if (r->fd >= 0) close(r->fd);
|
||||
free(r->seen);
|
||||
free(r->ctx_last);
|
||||
pthread_mutex_destroy(&r->lock);
|
||||
free(r);
|
||||
}
|
||||
|
||||
// Returns 0 or a negative errno; *out is set on success.
|
||||
static int reader_open(struct reader **out) {
|
||||
struct reader *r = calloc(1, sizeof(*r));
|
||||
if (!r) return -ENOMEM;
|
||||
pthread_mutex_init(&r->lock, NULL);
|
||||
r->fd = open("/dev/kgsl-3d0", O_RDWR | O_CLOEXEC);
|
||||
if (r->fd < 0) { int e = -errno; reader_close(r); return e; }
|
||||
struct kgsl_shadowprop shadow;
|
||||
memset(&shadow, 0, sizeof(shadow));
|
||||
struct kgsl_device_getproperty prop = {.type = KGSL_PROP_DEVICE_SHADOW, .value = &shadow, .sizebytes = sizeof(shadow)};
|
||||
if (ioctl(r->fd, IOCTL_KGSL_DEVICE_GETPROPERTY, &prop)) { int e = -errno; reader_close(r); return e; }
|
||||
r->bytes = shadow.size;
|
||||
r->first = kgsl_busy_first_slot(shadow.size);
|
||||
if (r->first < 0) { reader_close(r); return -ERANGE; }
|
||||
r->map = mmap(NULL, r->bytes, PROT_READ, MAP_SHARED, r->fd, (off_t)shadow.gpuaddr);
|
||||
if (r->map == MAP_FAILED) { int e = -errno; reader_close(r); return e; }
|
||||
int moved = 0, started = 0;
|
||||
kgsl_busy_sample(r->map, r->first, r->last, &moved);
|
||||
for (int i = 0; i < KGSL_BUSY_SLOTS; i++) started |= r->last[i] != 0;
|
||||
if (started) {
|
||||
r->mode = MODE_RINGBUFFER;
|
||||
} else {
|
||||
r->seen = calloc((size_t)r->first, sizeof(uint32_t));
|
||||
r->ctx_last = calloc((size_t)r->first, sizeof(uint32_t));
|
||||
if (!r->seen || !r->ctx_last) { reader_close(r); return -ENOMEM; }
|
||||
r->live_count = kgsl_busy_scan_contexts(r->map, r->first, r->seen, r->live, KGSL_BUSY_MAX_LIVE);
|
||||
kgsl_busy_sample_contexts(r->map, r->live, r->live_count, r->ctx_last, &moved);
|
||||
r->mode = MODE_CONTEXTS;
|
||||
}
|
||||
*out = r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef KGSL_BUSY_NO_JNI
|
||||
#include <jni.h>
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_droiddeck_launcher_session_KgslBusy_nativeOpen(JNIEnv *env, jclass cls, jintArray error) {
|
||||
struct reader *r = NULL;
|
||||
int e = reader_open(&r);
|
||||
if (e && error && (*env)->GetArrayLength(env, error) > 0) {
|
||||
jint v = e;
|
||||
(*env)->SetIntArrayRegion(env, error, 0, 1, &v);
|
||||
}
|
||||
return e ? 0 : (jlong)(intptr_t)r;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_droiddeck_launcher_session_KgslBusy_nativeMode(JNIEnv *env, jclass cls, jlong handle) {
|
||||
return handle ? ((struct reader *)(intptr_t)handle)->mode : 0;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_droiddeck_launcher_session_KgslBusy_nativeRun(JNIEnv *env, jclass cls, jlong handle, jboolean on) {
|
||||
if (handle) reader_run((struct reader *)(intptr_t)handle, on ? 1 : 0);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_droiddeck_launcher_session_KgslBusy_nativeRead(JNIEnv *env, jclass cls, jlong handle, jlongArray out) {
|
||||
if (!handle || !out || (*env)->GetArrayLength(env, out) < 3) return JNI_FALSE;
|
||||
struct reader *r = (struct reader *)(intptr_t)handle;
|
||||
jlong v[3] = {(jlong)atomic_load(&r->busy), (jlong)atomic_load(&r->samples), (jlong)atomic_load(&r->moves)};
|
||||
(*env)->SetLongArrayRegion(env, out, 0, 3, v);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_droiddeck_launcher_session_KgslBusy_nativeClose(JNIEnv *env, jclass cls, jlong handle) {
|
||||
reader_close((struct reader *)(intptr_t)handle);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef DROIDDECK_KGSL_BUSY_H
|
||||
#define DROIDDECK_KGSL_BUSY_H
|
||||
// kgsl lets any client map its memstore read-only (KGSL_PROP_DEVICE_SHADOW). The CP writes a ringbuffer's
|
||||
// start-of-pipe timestamp there before each submission's command buffers and its end-of-pipe timestamp after them
|
||||
// (adreno_gen7_ringbuffer.c gen7_ringbuffer_addcmds), so start != end means that ringbuffer has work on the GPU.
|
||||
// Ringbuffer entries start at KGSL_MEMSTORE_MAX: entries - 2 - 4 levels, or entries - 1 - 4 on kernels without the
|
||||
// LPAC slot. Entries - 6 .. entries - 2 cover both; a context entry in that range follows the same start/end rule.
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define KGSL_BUSY_ENTRY_WORDS 10
|
||||
#define KGSL_BUSY_SOP 0
|
||||
#define KGSL_BUSY_EOP 2
|
||||
#define KGSL_BUSY_SLOTS 5
|
||||
|
||||
static inline int kgsl_busy_first_slot(size_t bytes) {
|
||||
size_t entries = bytes / (KGSL_BUSY_ENTRY_WORDS * sizeof(uint32_t));
|
||||
return entries < 8 ? -1 : (int)(entries - 6);
|
||||
}
|
||||
|
||||
// 1 when a watched slot has a submission between its start and end timestamps. *moved is set when a start
|
||||
// timestamp differs from last[], which then holds the new ones.
|
||||
static inline int kgsl_busy_sample(const volatile uint32_t *memstore, int first, uint32_t last[KGSL_BUSY_SLOTS], int *moved) {
|
||||
int busy = 0;
|
||||
for (int i = 0; i < KGSL_BUSY_SLOTS; i++) {
|
||||
const volatile uint32_t *entry = memstore + (size_t)(first + i) * KGSL_BUSY_ENTRY_WORDS;
|
||||
uint32_t sop = entry[KGSL_BUSY_SOP], eop = entry[KGSL_BUSY_EOP];
|
||||
if (sop != eop) busy = 1;
|
||||
if (sop != last[i]) {
|
||||
*moved = 1;
|
||||
last[i] = sop;
|
||||
}
|
||||
}
|
||||
return busy;
|
||||
}
|
||||
|
||||
// Hardware-scheduled kernels (every gen8 GPU and some gen7 ones: .gpudev = *_hwsched_gpudev in adreno-gpulist.h)
|
||||
// leave the ringbuffer entries at 0. The GMU firmware writes each context's own entry instead
|
||||
// (gen8_hwsched_hfi.c send_context_pointers). Context ids run from 1 below the ringbuffer entries, lowest free first,
|
||||
// and kgsl zeroes an entry when its context is created or destroyed.
|
||||
#define KGSL_BUSY_MAX_LIVE 64
|
||||
|
||||
// Collects the contexts to sample: every entry below first with a non-zero start stamp (kgsl zeroes an entry when its
|
||||
// context is created or destroyed). Entries whose start stamp changed since the previous scan (seen[]) or that are
|
||||
// busy now come first, so the max_live cap only drops idle ones. Returns how many ids went into live[].
|
||||
static inline int kgsl_busy_scan_contexts(const volatile uint32_t *memstore, int first, uint32_t *seen, int *live, int max_live) {
|
||||
int n = 0, idle = 0;
|
||||
int idle_ids[KGSL_BUSY_MAX_LIVE];
|
||||
for (int id = 1; id < first; id++) {
|
||||
const volatile uint32_t *entry = memstore + (size_t)id * KGSL_BUSY_ENTRY_WORDS;
|
||||
uint32_t sop = entry[KGSL_BUSY_SOP], eop = entry[KGSL_BUSY_EOP];
|
||||
int changed = sop != seen[id];
|
||||
seen[id] = sop;
|
||||
if ((changed || sop != eop) && n < max_live) live[n++] = id;
|
||||
else if (sop != 0 && idle < KGSL_BUSY_MAX_LIVE) idle_ids[idle++] = id;
|
||||
}
|
||||
for (int i = 0; i < idle && n < max_live; i++) live[n++] = idle_ids[i];
|
||||
return n;
|
||||
}
|
||||
|
||||
// 1 when a live context has a submission between its start and end timestamps. *moved is set when a start
|
||||
// timestamp differs from last[] (indexed by context id), which then holds the new ones.
|
||||
static inline int kgsl_busy_sample_contexts(const volatile uint32_t *memstore, const int *live, int count, uint32_t *last, int *moved) {
|
||||
int busy = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
const volatile uint32_t *entry = memstore + (size_t)live[i] * KGSL_BUSY_ENTRY_WORDS;
|
||||
uint32_t sop = entry[KGSL_BUSY_SOP], eop = entry[KGSL_BUSY_EOP];
|
||||
if (sop != eop) busy = 1;
|
||||
if (sop != last[live[i]]) {
|
||||
*moved = 1;
|
||||
last[live[i]] = sop;
|
||||
}
|
||||
}
|
||||
return busy;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,159 @@
|
||||
// GPU clock without root on Adreno (KGSL) devices whose kgsl sysfs is blocked for apps.
|
||||
//
|
||||
// kgsl lets any app reserve a performance counter (IOCTL_KGSL_PERFCOUNTER_GET) but refuses to read it back while
|
||||
// /sys/class/kgsl/kgsl-3d0/perfcounter is 0, and clears the counters whenever the GPU switches to another process.
|
||||
// So the counter is read by the GPU itself: a small command buffer copies CP_ALWAYS_ON_COUNTER (19.2 MHz) and the
|
||||
// RBBM ALWAYS_COUNT counter (GPU core cycles) to memory, runs a block of NOP packets, and copies both again.
|
||||
// clock = cycles / always-on ticks * 19.2 MHz. Both reads sit in one command buffer, so a counter clear between
|
||||
// them only happens if the buffer is preempted; such samples fail the range checks and are dropped.
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../adrenotools/src/hook/kgsl.h"
|
||||
#include "kgsl_layout.h"
|
||||
|
||||
#define CP_TYPE7_PKT 0x70000000u
|
||||
#define CP_NOP 0x10u
|
||||
#define CP_REG_TO_MEM 0x3eu
|
||||
#define XO_HZ 19200000.0
|
||||
#define NOP_DWORDS 0x3fffu
|
||||
#define NOP_BLOCKS 4
|
||||
|
||||
struct sampler {
|
||||
int fd;
|
||||
const struct kgsl_layout *layout;
|
||||
unsigned context;
|
||||
unsigned counter_reg;
|
||||
struct kgsl_gpumem_alloc_id ib, out;
|
||||
uint32_t *ib_map;
|
||||
volatile uint64_t *out_map;
|
||||
size_t ib_bytes;
|
||||
};
|
||||
|
||||
static unsigned odd_parity(unsigned v) {
|
||||
v ^= v >> 16;
|
||||
v ^= v >> 8;
|
||||
v ^= v >> 4;
|
||||
v &= 0xf;
|
||||
return (~0x6996u >> v) & 1u;
|
||||
}
|
||||
|
||||
static uint32_t pkt7(unsigned op, unsigned count) {
|
||||
return CP_TYPE7_PKT | count | odd_parity(count) << 15 | (op & 0x7f) << 16 | odd_parity(op) << 23;
|
||||
}
|
||||
|
||||
static void sampler_close(struct sampler *s) {
|
||||
if (!s) return;
|
||||
if (s->fd >= 0) {
|
||||
if (s->ib_map && s->ib_map != MAP_FAILED) munmap(s->ib_map, s->ib.mmapsize);
|
||||
if (s->out_map && s->out_map != MAP_FAILED) munmap((void *)s->out_map, s->out.mmapsize);
|
||||
if (s->ib.id) { struct kgsl_gpumem_free_id f = {.id = s->ib.id}; ioctl(s->fd, IOCTL_KGSL_GPUMEM_FREE_ID, &f); }
|
||||
if (s->out.id) { struct kgsl_gpumem_free_id f = {.id = s->out.id}; ioctl(s->fd, IOCTL_KGSL_GPUMEM_FREE_ID, &f); }
|
||||
if (s->context) { struct kgsl_drawctxt_destroy d = {.drawctxt_id = s->context}; ioctl(s->fd, IOCTL_KGSL_DRAWCTXT_DESTROY, &d); }
|
||||
if (s->counter_reg) {
|
||||
struct kgsl_perfcounter_put p = {.groupid = KGSL_PERFCOUNTER_GROUP_RBBM, .countable = s->layout->cycles};
|
||||
ioctl(s->fd, IOCTL_KGSL_PERFCOUNTER_PUT, &p);
|
||||
}
|
||||
close(s->fd);
|
||||
}
|
||||
free(s);
|
||||
}
|
||||
|
||||
static void emit_reads(struct sampler *s, size_t *n, unsigned pass) {
|
||||
const unsigned regs[2] = {s->layout->always_on, s->counter_reg};
|
||||
for (unsigned k = 0; k < 2; k++) {
|
||||
uint64_t dst = s->out.gpuaddr + (uint64_t)(pass * 2 + k) * sizeof(uint64_t);
|
||||
s->ib_map[(*n)++] = pkt7(CP_REG_TO_MEM, 3);
|
||||
s->ib_map[(*n)++] = regs[k] | (2u << 18) | (1u << 30); // two dwords, 64-bit read
|
||||
s->ib_map[(*n)++] = (uint32_t)dst;
|
||||
s->ib_map[(*n)++] = (uint32_t)(dst >> 32);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns 0 or a negative errno; *out is set on success.
|
||||
static int sampler_open(struct sampler **out) {
|
||||
struct sampler *s = calloc(1, sizeof(*s));
|
||||
if (!s) return -ENOMEM;
|
||||
s->fd = open("/dev/kgsl-3d0", O_RDWR | O_CLOEXEC);
|
||||
if (s->fd < 0) { int e = -errno; s->fd = -1; sampler_close(s); return e; }
|
||||
struct kgsl_devinfo info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
struct kgsl_device_getproperty prop = {.type = KGSL_PROP_DEVICE_INFO, .value = &info, .sizebytes = sizeof(info)};
|
||||
if (ioctl(s->fd, IOCTL_KGSL_DEVICE_GETPROPERTY, &prop)) { int e = -errno; sampler_close(s); return e; }
|
||||
s->layout = kgsl_layout_for(info.chip_id);
|
||||
if (!s->layout) { sampler_close(s); return -ENOTSUP; }
|
||||
struct kgsl_perfcounter_get get = {.groupid = KGSL_PERFCOUNTER_GROUP_RBBM, .countable = s->layout->cycles};
|
||||
if (ioctl(s->fd, IOCTL_KGSL_PERFCOUNTER_GET, &get)) { int e = -errno; sampler_close(s); return e; }
|
||||
s->counter_reg = get.offset;
|
||||
if (!get.offset || get.offset > s->layout->readable_last) { sampler_close(s); return -ERANGE; }
|
||||
struct kgsl_drawctxt_create ctx = {.flags = KGSL_CONTEXT_NO_GMEM_ALLOC | KGSL_CONTEXT_PREAMBLE};
|
||||
if (ioctl(s->fd, IOCTL_KGSL_DRAWCTXT_CREATE, &ctx)) { int e = -errno; sampler_close(s); return e; }
|
||||
s->context = ctx.drawctxt_id;
|
||||
s->ib_bytes = (16 + NOP_BLOCKS * (NOP_DWORDS + 1)) * sizeof(uint32_t);
|
||||
s->ib.size = (s->ib_bytes + 4095) & ~(size_t)4095;
|
||||
s->out.size = 4096;
|
||||
if (ioctl(s->fd, IOCTL_KGSL_GPUMEM_ALLOC_ID, &s->ib)) { int e = -errno; s->ib.id = 0; sampler_close(s); return e; }
|
||||
if (ioctl(s->fd, IOCTL_KGSL_GPUMEM_ALLOC_ID, &s->out)) { int e = -errno; s->out.id = 0; sampler_close(s); return e; }
|
||||
s->ib_map = mmap(NULL, s->ib.mmapsize, PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, (off_t)s->ib.id << 12);
|
||||
s->out_map = mmap(NULL, s->out.mmapsize, PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, (off_t)s->out.id << 12);
|
||||
if (s->ib_map == MAP_FAILED || s->out_map == MAP_FAILED) { int e = -errno; sampler_close(s); return e; }
|
||||
size_t n = 0;
|
||||
emit_reads(s, &n, 0);
|
||||
for (unsigned b = 0; b < NOP_BLOCKS; b++) {
|
||||
s->ib_map[n++] = pkt7(CP_NOP, NOP_DWORDS);
|
||||
memset(&s->ib_map[n], 0, NOP_DWORDS * sizeof(uint32_t));
|
||||
n += NOP_DWORDS;
|
||||
}
|
||||
emit_reads(s, &n, 1);
|
||||
s->ib_bytes = n * sizeof(uint32_t);
|
||||
*out = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// MHz, or a negative value: -errno from kgsl, or -1000 for a sample that failed the range checks.
|
||||
static int sampler_mhz(struct sampler *s) {
|
||||
for (int i = 0; i < 4; i++) s->out_map[i] = 0;
|
||||
struct kgsl_command_object cmd = {.gpuaddr = s->ib.gpuaddr, .size = s->ib_bytes, .flags = KGSL_CMDLIST_IB};
|
||||
struct kgsl_gpu_command submit = {
|
||||
.cmdlist = (uint64_t)(uintptr_t)&cmd, .cmdsize = sizeof(cmd), .numcmds = 1, .context_id = s->context,
|
||||
};
|
||||
if (ioctl(s->fd, IOCTL_KGSL_GPU_COMMAND, &submit)) return -errno;
|
||||
struct kgsl_device_waittimestamp_ctxtid wait = {.context_id = s->context, .timestamp = submit.timestamp, .timeout = 250};
|
||||
if (ioctl(s->fd, IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, &wait)) return -errno;
|
||||
uint64_t xo0 = s->out_map[0], cyc0 = s->out_map[1], xo1 = s->out_map[2], cyc1 = s->out_map[3];
|
||||
if (xo1 <= xo0 || cyc1 <= cyc0) return -1000;
|
||||
uint64_t xo = xo1 - xo0, cycles = cyc1 - cyc0;
|
||||
// 5 us .. 50 ms of always-on time, and a clock between 50 MHz and 2 GHz.
|
||||
if (xo < 96 || xo > 960000) return -1000;
|
||||
double mhz = (double)cycles / (double)xo * XO_HZ / 1e6;
|
||||
if (mhz < 50 || mhz > 2000) return -1000;
|
||||
return (int)(mhz + 0.5);
|
||||
}
|
||||
|
||||
#ifndef KGSL_CLOCK_NO_JNI
|
||||
#include <jni.h>
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_droiddeck_launcher_session_KgslClock_nativeOpen(JNIEnv *env, jclass cls, jintArray error) {
|
||||
struct sampler *s = NULL;
|
||||
int r = sampler_open(&s);
|
||||
if (r && error && (*env)->GetArrayLength(env, error) > 0) {
|
||||
jint e = r;
|
||||
(*env)->SetIntArrayRegion(env, error, 0, 1, &e);
|
||||
}
|
||||
return r ? 0 : (jlong)(intptr_t)s;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_droiddeck_launcher_session_KgslClock_nativeSample(JNIEnv *env, jclass cls, jlong handle) {
|
||||
return handle ? sampler_mhz((struct sampler *)(intptr_t)handle) : -EBADF;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_droiddeck_launcher_session_KgslClock_nativeClose(JNIEnv *env, jclass cls, jlong handle) {
|
||||
sampler_close((struct sampler *)(intptr_t)handle);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef DROIDDECK_KGSL_LAYOUT_H
|
||||
#define DROIDDECK_KGSL_LAYOUT_H
|
||||
#include <stddef.h>
|
||||
|
||||
// Register layout per GPU generation. A counter kgsl places outside the range the kernel's CP protection lets
|
||||
// command buffers read (adreno-gpulist.h *_protected_regs) is not read.
|
||||
struct kgsl_layout {
|
||||
unsigned always_on; // CP_ALWAYS_ON_COUNTER
|
||||
unsigned cycles; // RBBM countable that counts GPU cycles
|
||||
unsigned readable_last; // last register of the readable range starting at 0
|
||||
};
|
||||
// A6xx/A7xx: CP_ALWAYS_ON_COUNTER 0x980, RBBM countable 0 = ALWAYS_COUNT, 0x000-0x4ff readable (gen7 list).
|
||||
static const struct kgsl_layout KGSL_LAYOUT_A7XX = {0x980u, 0u, 0x4ffu};
|
||||
// A8xx: CP_ALWAYS_ON_COUNTER 0x8e7 (gen8_reg.h), RBBM countable 1 = US_ALWAYS_COUNT (0 is NEVER_COUNT, Mesa
|
||||
// a8xx_perfcntrs.xml), 0x000-0x3a3 readable (gen8_0_0_protected_regs).
|
||||
static const struct kgsl_layout KGSL_LAYOUT_A8XX = {0x8e7u, 1u, 0x3a3u};
|
||||
|
||||
// The KGSL chip id's top byte: 0x44 on every A8xx (Adreno 810/829/830/840, Mesa freedreno_devices.py),
|
||||
// 0x43 or the generation number on A6xx/A7xx. Later generations are not known, so nothing is read there.
|
||||
static inline const struct kgsl_layout *kgsl_layout_for(unsigned chip_id) {
|
||||
unsigned core = chip_id >> 24;
|
||||
if (core == 0x44u) return &KGSL_LAYOUT_A8XX;
|
||||
if (core > 0x44u) return NULL;
|
||||
return &KGSL_LAYOUT_A7XX;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -76,7 +76,6 @@ public:
|
||||
}
|
||||
lastFrame_ = frame.header.frame_id;
|
||||
if (state == XrGpuFrameState::Stale) {
|
||||
// No GPU read was submitted, so the producer can safely reclaim a dropped frame.
|
||||
dropped_++;
|
||||
if (!xr_gpu_send(peer_, &frame.header.frame_id, sizeof(frame.header.frame_id))) Disconnect();
|
||||
return false;
|
||||
@@ -88,7 +87,6 @@ public:
|
||||
glBindImageTexture(0, raw_, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
|
||||
glDispatchCompute((width_ + 7) / 8, (height_ + 7) / 8, 1);
|
||||
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
// The producer may overwrite this slot only after the native GPU has finished reading it.
|
||||
glFinish();
|
||||
if (glGetError() != GL_NO_ERROR) { rejected_++; Disconnect(); return false; }
|
||||
if (!xr_gpu_send(peer_, &frame.header.frame_id, sizeof(frame.header.frame_id))) Disconnect();
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* SOCK_SEQPACKET between the guest's Remote Play hooks and the app: the emulated /dev/video-enc0 and
|
||||
* MediaCodec encoder, and remote touches. A config carries the buffer memfds (inputs first) as SCM_RIGHTS;
|
||||
* every frame gets one reply, touches get none. */
|
||||
|
||||
#define VENC_MAX_BUFFERS 16
|
||||
|
||||
enum venc_msg { VENC_CONFIG = 1, VENC_FRAME = 2, VENC_DONE = 3, VENC_BITRATE = 4, VENC_TOUCH = 5, VDEC_CONFIG = 6, VDEC_CAPTURE = 7, VDEC_PACKET = 8, VDEC_RESULT = 9 };
|
||||
@@ -45,7 +41,6 @@ struct venc_bitrate {
|
||||
uint32_t bitrate;
|
||||
};
|
||||
|
||||
/* Remote Play's touch-as-mouse turned back into a touch; x and y are fractions of the screen in 1/65535. */
|
||||
struct venc_touch {
|
||||
uint32_t type;
|
||||
uint32_t action;
|
||||
|
||||
@@ -33,8 +33,8 @@ struct Mapping {
|
||||
constexpr int32_t kColorFormatYuv420SemiPlanar = 21;
|
||||
constexpr uint32_t kBufferFlagKeyFrame = 1;
|
||||
constexpr uint32_t kBufferFlagCodecConfig = 2;
|
||||
constexpr int kTouchWidth = 1920, kTouchHeight = 1080; // InputSpace.kt
|
||||
constexpr int kRemoteTouchId = 31; // the compositor's last touch slot (MAX_TOUCH_POINTS 32)
|
||||
constexpr int kTouchWidth = 1920, kTouchHeight = 1080;
|
||||
constexpr int kRemoteTouchId = 31;
|
||||
|
||||
int32_t avc_profile(int32_t v4l2) {
|
||||
switch (v4l2) {
|
||||
@@ -549,7 +549,7 @@ void serve(int listener) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_session_VideoEncodeBridge_nativeStart(JNIEnv *env, jobject, jstring jpath) {
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
// Our controller uses the standard display-mode vocabulary, even for Beast.
|
||||
// Native mode reuses some numbers with different meanings; never pass them through.
|
||||
namespace droiddeck::viture {
|
||||
constexpr int to_native_mode(int standard) {
|
||||
switch (standard) {
|
||||
case 0x31: return 0x31; // 1080p 60
|
||||
case 0x33: return 0x32; // 1080p 90
|
||||
case 0x34: return 0x33; // 1080p 120
|
||||
case 0x32: return 0x37; // 1080p SBS 60
|
||||
case 0x35: return 0x38; // 1080p SBS 90
|
||||
case 0x41: return 0x34; // 1200p 60
|
||||
case 0x43: return 0x35; // 1200p 90
|
||||
case 0x44: return 0x36; // 1200p 120
|
||||
case 0x42: return 0x3a; // 1200p SBS 60
|
||||
case 0x45: return 0x3b; // 1200p SBS 90
|
||||
case 0x31: return 0x31;
|
||||
case 0x33: return 0x32;
|
||||
case 0x34: return 0x33;
|
||||
case 0x32: return 0x37;
|
||||
case 0x35: return 0x38;
|
||||
case 0x41: return 0x34;
|
||||
case 0x43: return 0x35;
|
||||
case 0x44: return 0x36;
|
||||
case 0x42: return 0x3a;
|
||||
case 0x45: return 0x3b;
|
||||
default: return -4;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +28,7 @@ constexpr int from_native_mode(int native) {
|
||||
case 0x36: return 0x44;
|
||||
case 0x3a: return 0x42;
|
||||
case 0x3b: return 0x45;
|
||||
default: return -4; // Ultrawide is not stereo.
|
||||
default: return -4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
inline std::size_t mjpeg_payload_size(const uint8_t* bytes, std::size_t size) {
|
||||
if (!bytes || size < 4 || size > 4*1024*1024 || bytes[0] != 0xff || bytes[1] != 0xd8) return 0;
|
||||
std::size_t end = size;
|
||||
// Luma Ultra UVC frames can pad the JPEG to an eight-byte boundary with zeros.
|
||||
while (end > 4 && size-end < 7 && bytes[end-1] == 0) --end;
|
||||
return bytes[end-2] == 0xff && bytes[end-1] == 0xd9 ? end : 0;
|
||||
}
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "stereo_frame_gate.h"
|
||||
|
||||
namespace {
|
||||
// SDK callbacks have no user-data parameter. Only one provider may exist at a time.
|
||||
std::mutex api_mutex;
|
||||
std::mutex pose_mutex;
|
||||
std::array<float, 4> latest_pose{};
|
||||
@@ -64,7 +63,6 @@ void on_pose(float* data, uint64_t) {
|
||||
std::lock_guard<std::mutex> lock(pose_mutex);
|
||||
if (!accepting_pose) return;
|
||||
std::copy_n(data + 3, 4, latest_pose.begin());
|
||||
// SDK device ticks are not Android's elapsed-realtime clock.
|
||||
latest_time = now_ns();
|
||||
}
|
||||
|
||||
@@ -234,8 +232,6 @@ int set_display(Session& s, int standard) {
|
||||
if (mode == 0) {
|
||||
int rc = xr_device_provider_set_display_mode(s.device, standard);
|
||||
if (rc != VITURE_GLASSES_ERROR_NOT_SUPPORTED) return rc;
|
||||
// Older Beast firmware exposes fewer bypass modes. Fall back to its
|
||||
// separate native table only when the SDK explicitly rejects the mode.
|
||||
}
|
||||
const int native = droiddeck::viture::to_native_mode(standard);
|
||||
if (native < 0) return native;
|
||||
|
||||
@@ -18,6 +18,7 @@ add_library(droiddeckwayland SHARED
|
||||
src/wl_color_mgmt.c
|
||||
src/hdr_compose.c
|
||||
src/blend_pass.c
|
||||
src/gpu_busy.c
|
||||
generated/color-management-v1-protocol.c
|
||||
generated/xdg-shell-protocol.c
|
||||
generated/linux-dmabuf-v1-protocol.c
|
||||
@@ -43,6 +44,7 @@ target_include_directories(droiddeckwayland PRIVATE
|
||||
prebuilt/include
|
||||
src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../shaders
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../tools/gpuload/src
|
||||
)
|
||||
|
||||
set(DROIDDECK_FRAMEGEN_LSFG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../framegen/lsfg)
|
||||
|
||||
@@ -34,7 +34,6 @@ void cardboard_clamp(struct cardboard_params *p) {
|
||||
p->screen_width_m = clampf(p->screen_width_m, 0.2f, 60.0f);
|
||||
p->k1 = clampf(p->k1, -1.0f, 2.0f);
|
||||
p->k2 = clampf(p->k2, -1.0f, 2.0f);
|
||||
// Optical vertical FOV on supported glasses can be as low as ~22 degrees.
|
||||
p->fov_deg = clampf(p->fov_deg, 20.0f, 140.0f);
|
||||
p->lens_inset = clampf(p->lens_inset, -0.25f, 0.25f);
|
||||
p->chroma = clampf(p->chroma, 0.0f, 0.05f);
|
||||
@@ -186,6 +185,13 @@ int vkp_cardboard_active(void) {
|
||||
return on;
|
||||
}
|
||||
|
||||
int vkp_cardboard_source(void) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
const int source = g_set.enabled ? g_set.source : CARDBOARD_SOURCE_SCREEN;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return source;
|
||||
}
|
||||
|
||||
int vkp_cardboard_pose_changed(void) {
|
||||
if (!g_changed) return 0;
|
||||
g_changed = 0;
|
||||
|
||||
@@ -27,6 +27,7 @@ void vkp_cardboard_set_render_height(int height);
|
||||
|
||||
void vkp_cardboard_bind_device(VkDevice dev, const VkPhysicalDeviceMemoryProperties *memprops);
|
||||
int vkp_cardboard_active(void);
|
||||
int vkp_cardboard_source(void);
|
||||
int vkp_cardboard_pose_changed(void);
|
||||
void vkp_cardboard_begin_frame(void);
|
||||
VkImage vkp_cardboard_run(VkCommandBuffer cmd, VkImage src, int src_w, int src_h, int out_w, int out_h);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// 1115.1.0
|
||||
#pragma once
|
||||
const uint32_t cardboard_frag_code[] = {
|
||||
0x07230203,0x00010000,0x0008000b,0x000001ba,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
|
||||
@@ -289,7 +289,6 @@ static struct wl_event_source *g_fallback_timer;
|
||||
static int g_fallback_armed;
|
||||
|
||||
volatile int g_fps_limit;
|
||||
/* fps limit -1 (phone output, not mirrored): replaced buffers go back to the client at once instead of once per refresh. */
|
||||
volatile int g_release_unpaced;
|
||||
|
||||
volatile int g_hide_shell;
|
||||
@@ -446,6 +445,12 @@ static int g_cursor_w, g_cursor_h;
|
||||
static int g_cursor_hidden = 1;
|
||||
static int g_cursor_serial;
|
||||
|
||||
#define CURSOR_MAX_DRAWS 2
|
||||
static struct vkp_image *g_cursor_img;
|
||||
static int g_cursor_img_w, g_cursor_img_h, g_cursor_img_serial = -1;
|
||||
static atomic_int g_cursor_composite;
|
||||
static atomic_int g_cursor_composite_want;
|
||||
|
||||
static void cursor_publish_shown(void) {
|
||||
pthread_mutex_lock(&g_cursor_lock);
|
||||
if (g_cursor_w > 0) { g_cursor_hidden = 0; g_cursor_serial++; }
|
||||
@@ -1736,6 +1741,8 @@ static void bind_output(struct wl_client *c, void *data, uint32_t ver, uint32_t
|
||||
|
||||
struct draw_list { struct vkp_draw *d; int n, cap; };
|
||||
|
||||
static int add_cursor(struct draw_list *dl, int scene_w);
|
||||
|
||||
static struct vkp_image *surface_image(struct surface *s) {
|
||||
if (!s->has_content) return NULL;
|
||||
if (s->shm_img) return s->shm_img;
|
||||
@@ -1909,7 +1916,7 @@ static int hdr_plan(const struct draw_list *dl, int w, int h, int fx_on, int fra
|
||||
}
|
||||
if (un && g_zero_copy) { hs->color = droiddeck_color_of(un->resource); hs->who = un; return 3; }
|
||||
hs->hf.tonemap = !droiddeck_color_output();
|
||||
if (dl->n <= 0 || !(hs->is_hdr = calloc((size_t)dl->n, 1))) return 0;
|
||||
if (dl->n <= 0 || !(hs->is_hdr = calloc((size_t)dl->n + CURSOR_MAX_DRAWS, 1))) return 0;
|
||||
for (int i = 0; i < dl->n; i++) {
|
||||
struct surface *s = surface_for_image(dl->d[i].img);
|
||||
if (!is_hdr_surface(s)) continue;
|
||||
@@ -2011,12 +2018,6 @@ static void hdr_count_copied(const struct draw_list *dl, const char *reason) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Stream mode (the Xbox Cloud Gaming native player, in its own process): no Wayland clients, the scene is one
|
||||
* picture handed over as AHardwareBuffers (ImageReader images of the decoded video). Each buffer is imported once
|
||||
* and kept while the reader cycles through its few buffers; the newest frame is the scene, so the screen effects
|
||||
* and frame generation apply to it as to a game.
|
||||
*/
|
||||
#define STREAM_SLOTS 6
|
||||
static pthread_mutex_t g_stream_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static atomic_int g_stream_on;
|
||||
@@ -2036,7 +2037,6 @@ static void stream_forget_all(void) {
|
||||
g_stream_img = NULL;
|
||||
}
|
||||
|
||||
/* Compositor thread: the newest handed-over buffer becomes the scene picture. */
|
||||
static void stream_take(void) {
|
||||
pthread_mutex_lock(&g_stream_lock);
|
||||
AHardwareBuffer *ahb = g_stream_pending;
|
||||
@@ -2050,7 +2050,7 @@ static void stream_take(void) {
|
||||
if (g_stream_slots[i].used < g_stream_slots[oldest].used) oldest = i;
|
||||
}
|
||||
if (slot >= 0) {
|
||||
AHardwareBuffer_release(ahb); /* the slot keeps its own reference */
|
||||
AHardwareBuffer_release(ahb);
|
||||
} else {
|
||||
struct vkp_image *img = vkp_image_from_ahb(ahb);
|
||||
if (!img) {
|
||||
@@ -2062,7 +2062,7 @@ static void stream_take(void) {
|
||||
droiddeck_log("stream", "decoded frame buffer imported (%dx%d)", vkp_image_width(img), vkp_image_height(img));
|
||||
slot = oldest;
|
||||
if (g_stream_slots[slot].img) {
|
||||
vkp_wait_idle(); /* the GPU may still read the picture being replaced */
|
||||
vkp_wait_idle();
|
||||
if (g_stream_img == g_stream_slots[slot].img) g_stream_img = NULL;
|
||||
vkp_image_destroy(g_stream_slots[slot].img);
|
||||
}
|
||||
@@ -2108,7 +2108,6 @@ void droiddeck_stream_set(int on) {
|
||||
(void)n;
|
||||
}
|
||||
|
||||
/* Any thread: hands over one decoded frame (acquires its own reference). */
|
||||
void droiddeck_stream_frame(AHardwareBuffer *ahb) {
|
||||
if (!ahb || !atomic_load(&g_stream_on) || g_input_pipe[1] < 0) return;
|
||||
AHardwareBuffer_acquire(ahb);
|
||||
@@ -2116,7 +2115,7 @@ void droiddeck_stream_frame(AHardwareBuffer *ahb) {
|
||||
AHardwareBuffer *dropped = g_stream_pending;
|
||||
g_stream_pending = ahb;
|
||||
pthread_mutex_unlock(&g_stream_lock);
|
||||
if (dropped) { AHardwareBuffer_release(dropped); return; } /* a wake-up is already queued */
|
||||
if (dropped) { AHardwareBuffer_release(dropped); return; }
|
||||
struct input_msg m = { 20, 0, 0, 0, 0 };
|
||||
ssize_t n = write(g_input_pipe[1], &m, sizeof(m));
|
||||
(void)n;
|
||||
@@ -2124,7 +2123,21 @@ void droiddeck_stream_frame(AHardwareBuffer *ahb) {
|
||||
|
||||
unsigned droiddeck_stream_frames(void) { return atomic_load(&g_stream_frames); }
|
||||
|
||||
static int64_t g_scene_due_ns;
|
||||
|
||||
static int scene_held_for_limit(int64_t now, int64_t due, int limit, int unpaced) {
|
||||
if (limit <= 0 || unpaced || due <= 0) return 0;
|
||||
return now < due - 1000000LL;
|
||||
}
|
||||
|
||||
static int64_t scene_next_due(int64_t now, int64_t due, int limit) {
|
||||
if (limit <= 0) return 0;
|
||||
const int64_t interval = 1000000000LL / limit;
|
||||
return due > 0 && now - due < interval ? due + interval : now + interval;
|
||||
}
|
||||
|
||||
static void render_scene(void) {
|
||||
g_scene_due_ns = scene_next_due(now_ns(), g_scene_due_ns, g_fps_limit);
|
||||
if (atomic_load(&g_stream_on)) { g_dirty_since_ns = 0; render_stream(); return; }
|
||||
struct draw_list dl = {0};
|
||||
struct surface *s;
|
||||
@@ -2171,6 +2184,28 @@ static void render_scene(void) {
|
||||
hdr_note_precedence(hdr_route == 3 ? hs.who : NULL, fx_on, framegen);
|
||||
}
|
||||
if (hdr_route == 3) { fx_on = 0; framegen = 0; }
|
||||
struct surface *ahb_only = ahb_layer_only_candidate(w, h);
|
||||
struct surface *layer_only = ahb_only ? ahb_only : hdr_unimported_fullscreen(&dl, w, h);
|
||||
const int cursor_on = hdr_route == 3 || layer_only ? 0 : add_cursor(&dl, w);
|
||||
static int cursor_layer_said;
|
||||
if (layer_only && atomic_load(&g_cursor_composite) && !cursor_layer_said) {
|
||||
cursor_layer_said = 1;
|
||||
droiddeck_log("cursor", "the pointer stays out of the picture: the game's frames cannot be imported, "
|
||||
"so the game is shown on its own display layer");
|
||||
} else if (!layer_only) {
|
||||
cursor_layer_said = 0;
|
||||
}
|
||||
static int cursor_hdr_said;
|
||||
if (cursor_on && hdr_route == 0 && hs.n_hdr > 0 && !cardboard) {
|
||||
hdr_route = 2;
|
||||
if (!cursor_hdr_said) {
|
||||
cursor_hdr_said = 1;
|
||||
droiddeck_log("cursor", "the pointer needs a composed scene: the HDR picture goes through the screen "
|
||||
"swapchain instead of the game's own display layer");
|
||||
}
|
||||
} else {
|
||||
cursor_hdr_said = 0;
|
||||
}
|
||||
if (hdr_route == 1) {
|
||||
static int fell_back;
|
||||
vkp_apply_window_request();
|
||||
@@ -2196,21 +2231,19 @@ static void render_scene(void) {
|
||||
else if (rendered && how == 2) droiddeck_color_frame_shown(hs.color, DROIDDECK_HDR_TONEMAPPED, 0);
|
||||
else if (rendered) hdr_copy = "the HDR composition pass is unavailable on this driver";
|
||||
}
|
||||
if (hdr_route == 0 && vkp_quest_layer_presentation() && !framegen && !cardboard &&
|
||||
!ahb_layer_only_candidate(w, h)) {
|
||||
/* The complete SDR scene stays on one display layer. Do not hide/re-show GAME
|
||||
* on each desktop frame just because it is not a single fullscreen window. */
|
||||
if (hdr_route == 0 && vkp_quest_layer_presentation() && !framegen && !cardboard && !cursor_on &&
|
||||
!ahb_only) {
|
||||
rendered = vkp_render(w, h, dl.d, dl.n) == 0;
|
||||
} else if (hdr_route == 0 || hdr_route == 3) {
|
||||
const int pass_on = fx_on || framegen;
|
||||
int li = (g_zero_copy && !framegen && !cardboard) ? layer_candidate(&dl, w, h) : -1;
|
||||
int li = (g_zero_copy && !framegen && !cardboard && !cursor_on) ? layer_candidate(&dl, w, h) : -1;
|
||||
int over = li >= 0 ? dl.n - 1 - li : 0;
|
||||
const int fx_blocks = (li >= 0 && fx_on && over > 0);
|
||||
if (fx_blocks) { li = -1; over = 0; }
|
||||
const int ov_blocks = (li >= 0 && over > 0 && !fx_blocks && !sc_layer_overlay_affordable());
|
||||
if (ov_blocks) { li = -1; over = 0; }
|
||||
const int blocked = framegen ? 1 : (fx_blocks ? 2 : (ov_blocks ? 3 : 0));
|
||||
if (g_zero_copy && blocked != g_zero_copy_paused) {
|
||||
if (g_zero_copy && !cursor_on && blocked != g_zero_copy_paused) {
|
||||
g_zero_copy_paused = blocked;
|
||||
if (blocked == 1)
|
||||
droiddeck_log("framegen", "zero-copy paused: frame generation needs the compositor pass");
|
||||
@@ -2223,9 +2256,9 @@ static void render_scene(void) {
|
||||
droiddeck_log("effects", "zero-copy resumed: the game is back on its own display layer");
|
||||
}
|
||||
struct surface *ls = li >= 0 ? surface_for_image(dl.d[li].img) : NULL;
|
||||
if (li < 0) ls = ahb_layer_only_candidate(w, h);
|
||||
if (li < 0 && !ls) ls = hdr_unimported_fullscreen(&dl, w, h);
|
||||
if (li < 0) ls = layer_only;
|
||||
if (cardboard) ls = NULL;
|
||||
if (cursor_on) ls = NULL;
|
||||
if (ls && pass_on && li < 0 && !g_zero_copy_fx_skip_said) {
|
||||
g_zero_copy_fx_skip_said = 1;
|
||||
droiddeck_log(framegen ? "framegen" : "effects",
|
||||
@@ -2302,12 +2335,12 @@ static void render_scene(void) {
|
||||
|
||||
static int on_fallback_timer(void *data) {
|
||||
g_fallback_armed = 0;
|
||||
if (g_dirty) render_scene();
|
||||
if (!g_dirty) return 0;
|
||||
if (scene_held_for_limit(now_ns(), g_scene_due_ns, g_fps_limit, g_release_unpaced)) schedule_render();
|
||||
else render_scene();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A new frame is drawn when it arrives instead of at the next screen tick, at most once per refresh,
|
||||
while frames go straight back to the game (no compositor limit), without streaming or frame generation. */
|
||||
static int commit_renders_on(void) {
|
||||
return g_render_on_commit && g_release_unpaced && !atomic_load(&g_stream_on) && !vkp_framegen_active();
|
||||
}
|
||||
@@ -2366,10 +2399,6 @@ static void on_vsync(int64_t frame_time_ns) {
|
||||
if (vkp_effects_sync()) tick_change = 1;
|
||||
if (vkp_cardboard_pose_changed()) tick_change = 1;
|
||||
if (tick_change) g_dirty = 1;
|
||||
/* A frame that arrived after this refresh was already drawn is left for the next arrival to draw;
|
||||
drawing it here would block that arrival too and keep every frame waiting for the tick. A client
|
||||
that draws again only after its frame callback sends no such arrival: once a held frame is still
|
||||
waiting at the next tick, the tick draws every frame for a second before holding one again. */
|
||||
if (g_tick_held && g_dirty) g_hold_missed_ns = now;
|
||||
g_tick_held = 0;
|
||||
if (!tick_change && commit_renders_on() && g_dirty_since_ns && now - g_dirty_since_ns < g_refresh_ns &&
|
||||
@@ -2377,6 +2406,7 @@ static void on_vsync(int64_t frame_time_ns) {
|
||||
g_tick_held = 1;
|
||||
return;
|
||||
}
|
||||
if (g_dirty && scene_held_for_limit(now, g_scene_due_ns, g_fps_limit, g_release_unpaced)) return;
|
||||
if (g_dirty && !scene_waits_for_game(now)) render_scene();
|
||||
}
|
||||
|
||||
@@ -2392,6 +2422,7 @@ static void pointer_set_cursor(struct wl_client *c, struct wl_resource *r, uint3
|
||||
if (g_cursor_surface) g_cursor_surface->role = ROLE_NONE;
|
||||
g_cursor_surface = NULL;
|
||||
cursor_publish_hidden();
|
||||
if (atomic_load(&g_cursor_composite)) schedule_render();
|
||||
return;
|
||||
}
|
||||
struct surface *s = wl_resource_get_user_data(surface);
|
||||
@@ -2399,8 +2430,10 @@ static void pointer_set_cursor(struct wl_client *c, struct wl_resource *r, uint3
|
||||
if (s->role != ROLE_NONE && s->role != ROLE_CURSOR) return;
|
||||
s->role = ROLE_CURSOR;
|
||||
g_cursor_surface = s;
|
||||
pthread_mutex_lock(&g_cursor_lock);
|
||||
g_cursor_hx = hx;
|
||||
g_cursor_hy = hy;
|
||||
pthread_mutex_unlock(&g_cursor_lock);
|
||||
struct wl_resource *buffer = surface_take_idle(s);
|
||||
if (buffer) {
|
||||
cursor_publish_buffer(s, buffer);
|
||||
@@ -2411,6 +2444,7 @@ static void pointer_set_cursor(struct wl_client *c, struct wl_resource *r, uint3
|
||||
cursor_publish_pixels((const uint8_t *)s->idle_px, s->idle_w, s->idle_h, (size_t)s->idle_w * 4, hx, hy);
|
||||
g_cursor_shown = s;
|
||||
}
|
||||
if (atomic_load(&g_cursor_composite)) schedule_render();
|
||||
}
|
||||
static void pointer_release(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); }
|
||||
static const struct wl_pointer_interface pointer_impl = {
|
||||
@@ -2592,6 +2626,97 @@ static int g_ptr_known;
|
||||
static double g_raw_x, g_raw_y;
|
||||
static int g_raw_valid;
|
||||
|
||||
static int pointer_locked_for_cursor(void) {
|
||||
return g_active_constraint && g_active_constraint->is_lock;
|
||||
}
|
||||
|
||||
static int cursor_scene_positions(int scene_w, int source, int ptr_x, int hx, int out[2]) {
|
||||
out[0] = ptr_x - hx; out[1] = -1;
|
||||
if (source != CARDBOARD_SOURCE_SBS || scene_w <= 1) return 1;
|
||||
const int half = scene_w / 2;
|
||||
out[1] = (ptr_x < half ? ptr_x + half : ptr_x - half) - hx;
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int cursor_clip_to_eye(int scene_w, int eye, int x0, int w, int *dx, int *sx, int *dw) {
|
||||
int left = x0, right = x0 + w;
|
||||
if (eye >= 0 && scene_w > 1) {
|
||||
const int half = scene_w / 2;
|
||||
const int band = eye ? half : 0;
|
||||
if (left < band) left = band;
|
||||
if (right > band + half) right = band + half;
|
||||
}
|
||||
if (right <= left) return 0;
|
||||
*dx = left;
|
||||
*sx = left - x0;
|
||||
*dw = right - left;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int add_cursor(struct draw_list *dl, int scene_w) {
|
||||
if (!atomic_load(&g_cursor_composite) || !g_ptr_known || pointer_locked_for_cursor()) return 0;
|
||||
|
||||
int hidden, w, h, hx, hy, serial;
|
||||
uint32_t *copy = NULL;
|
||||
pthread_mutex_lock(&g_cursor_lock);
|
||||
hidden = g_cursor_hidden;
|
||||
w = g_cursor_w; h = g_cursor_h;
|
||||
hx = g_cursor_hx; hy = g_cursor_hy;
|
||||
serial = g_cursor_serial;
|
||||
if (!hidden && w > 0 && h > 0 && serial != g_cursor_img_serial) {
|
||||
copy = malloc((size_t)w * (size_t)h * 4);
|
||||
if (copy) memcpy(copy, g_cursor_px, (size_t)w * (size_t)h * 4);
|
||||
}
|
||||
pthread_mutex_unlock(&g_cursor_lock);
|
||||
if (hidden || w <= 0 || h <= 0) return 0;
|
||||
|
||||
if (copy) {
|
||||
if (g_cursor_img && (g_cursor_img_w != w || g_cursor_img_h != h)) {
|
||||
vkp_wait_idle();
|
||||
vkp_image_destroy(g_cursor_img);
|
||||
g_cursor_img = NULL;
|
||||
}
|
||||
if (!g_cursor_img) g_cursor_img = vkp_image_create_shm(w, h);
|
||||
if (g_cursor_img) {
|
||||
g_cursor_img_w = w; g_cursor_img_h = h;
|
||||
vkp_image_upload_shm(g_cursor_img, copy, w * 4);
|
||||
g_cursor_img_serial = serial;
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
if (!g_cursor_img || g_cursor_img_serial != serial) return 0;
|
||||
|
||||
int xs[CURSOR_MAX_DRAWS];
|
||||
const int source = vkp_cardboard_source();
|
||||
const int ptr_x = (int)(g_ptr_x + 0.5);
|
||||
const int count = cursor_scene_positions(scene_w, source, ptr_x, hx, xs);
|
||||
static int said_w = -1, said_source = -1, said_count = -1;
|
||||
if (scene_w != said_w || source != said_source || count != said_count) {
|
||||
said_w = scene_w; said_source = source; said_count = count;
|
||||
droiddeck_log("cursor", "pointer drawn %d time(s) in a %d wide scene (%s picture)", count, scene_w,
|
||||
source == CARDBOARD_SOURCE_SBS ? "side-by-side" : "single");
|
||||
}
|
||||
if (dl->n + count > dl->cap) {
|
||||
int cap = dl->cap ? dl->cap : 32;
|
||||
while (cap < dl->n + count) cap *= 2;
|
||||
struct vkp_draw *d = realloc(dl->d, (size_t)cap * sizeof(*d));
|
||||
if (!d) return 0;
|
||||
dl->d = d; dl->cap = cap;
|
||||
}
|
||||
const int sbs = source == CARDBOARD_SOURCE_SBS && scene_w > 1;
|
||||
const int pointer_eye = ptr_x < scene_w / 2 ? 0 : 1;
|
||||
int appended = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int dx, sx, cw;
|
||||
const int eye = sbs ? (i ? 1 - pointer_eye : pointer_eye) : -1;
|
||||
if (!cursor_clip_to_eye(scene_w, eye, xs[i], w, &dx, &sx, &cw)) continue;
|
||||
dl->d[dl->n++] = (struct vkp_draw){g_cursor_img, (float)sx, 0, (float)cw, (float)h,
|
||||
dx, (int)(g_ptr_y + 0.5) - hy, cw, h, 1};
|
||||
appended++;
|
||||
}
|
||||
return appended ? 1 : 0;
|
||||
}
|
||||
|
||||
extern void droiddeck_on_pointer_lock(int locked, int x, int y);
|
||||
|
||||
static void sync_lock_notify(void) {
|
||||
@@ -2600,6 +2725,7 @@ static void sync_lock_notify(void) {
|
||||
if (locked == last) return;
|
||||
last = locked;
|
||||
droiddeck_on_pointer_lock(locked, (int)g_ptr_x, (int)g_ptr_y);
|
||||
if (atomic_load(&g_cursor_composite)) schedule_render();
|
||||
}
|
||||
|
||||
static void constraint_describe(const struct constraint *k, char *out, size_t size) {
|
||||
@@ -2679,7 +2805,10 @@ static void constraint_activate(struct constraint *k) {
|
||||
constraint_end(g_active_constraint, 1, "replaced by a newer request");
|
||||
k->active = 1;
|
||||
g_active_constraint = k;
|
||||
const double was_x = g_ptr_x, was_y = g_ptr_y;
|
||||
if (!k->is_lock) confine_clamp(k, &g_ptr_x, &g_ptr_y);
|
||||
if ((g_ptr_x != was_x || g_ptr_y != was_y) && atomic_load(&g_cursor_composite))
|
||||
schedule_render();
|
||||
constraint_origin(k, &ox, &oy);
|
||||
pointer_focus(k->surface->resource, wl_fixed_from_double(g_ptr_x - ox), wl_fixed_from_double(g_ptr_y - oy));
|
||||
int focused = 0;
|
||||
@@ -2738,6 +2867,7 @@ static void constraints_pointer_gone(struct wl_resource *pointer) {
|
||||
|
||||
static void constraints_surface_commit(struct surface *s) {
|
||||
struct constraint *k;
|
||||
const double was_x = g_ptr_x, was_y = g_ptr_y;
|
||||
wl_list_for_each(k, &g_constraints, link) {
|
||||
if (k->surface != s) continue;
|
||||
if (k->pending_hint_set) {
|
||||
@@ -2761,6 +2891,8 @@ static void constraints_surface_commit(struct surface *s) {
|
||||
if (k->active && !k->is_lock) confine_clamp(k, &g_ptr_x, &g_ptr_y);
|
||||
}
|
||||
}
|
||||
if ((g_ptr_x != was_x || g_ptr_y != was_y) && atomic_load(&g_cursor_composite))
|
||||
schedule_render();
|
||||
}
|
||||
|
||||
static void constraint_resource_destroy(struct wl_resource *r) {
|
||||
@@ -2946,6 +3078,7 @@ static void pointer_input(double x, double y, int relative, uint32_t button, int
|
||||
if (k) confine_clamp(k, &x, &y);
|
||||
g_ptr_x = x; g_ptr_y = y;
|
||||
g_ptr_known = 1;
|
||||
if (atomic_load(&g_cursor_composite)) schedule_render();
|
||||
if (k) {
|
||||
target = k->surface;
|
||||
} else if (g_desktop) {
|
||||
@@ -2968,10 +3101,6 @@ static void pointer_input(double x, double y, int relative, uint32_t button, int
|
||||
uint32_t t = now_ms();
|
||||
|
||||
pointer_focus(target->resource, fx, fy);
|
||||
// A button-only input must not replay a cached absolute position. A game
|
||||
// may have warped its cursor since the last motion (before taking lock,
|
||||
// or while releasing it), so that replay can become an unintended pan.
|
||||
// Absolute touch events still carry their position, including on clicks.
|
||||
int rel_consumed = send_relative_motion(client, dx, dy);
|
||||
if (!(k && k->is_lock) && !(relative && rel_consumed) && (!relative || dx != 0 || dy != 0))
|
||||
for_each_pointer_of(client, sp) wl_pointer_send_motion(sp->ptr, t, fx, fy);
|
||||
@@ -3003,9 +3132,6 @@ static void pointer_button(uint32_t button, int pressed) {
|
||||
pointer_input(0, 0, 1, button, pressed);
|
||||
return;
|
||||
}
|
||||
// Releases also clean up interrupted gestures. Deliver them to the existing
|
||||
// pointer focus without motion or hit-testing: native touch has independent
|
||||
// coordinates, so replaying g_ptr_x/y here can warp the game cursor.
|
||||
uint32_t t = now_ms();
|
||||
for (int i = 0; i < g_nptrs; i++) {
|
||||
struct seat_pointer *sp = &g_ptrs[i];
|
||||
@@ -3425,6 +3551,7 @@ static int on_input_readable(int fd, uint32_t mask, void *data) {
|
||||
case 12: axis_event(m.p1, m.p2, 1); break;
|
||||
case 20: stream_take(); break;
|
||||
case 21: if (!m.p1) stream_forget_all(); schedule_render(); break;
|
||||
case 22: schedule_render(); break;
|
||||
default: deliver_pointer(&m); break;
|
||||
}
|
||||
}
|
||||
@@ -3499,6 +3626,17 @@ void droiddeck_wayland_send_scene_input(int type, int a, int b) {
|
||||
(void)n;
|
||||
}
|
||||
|
||||
void droiddeck_wayland_set_cursor_composite(int on) {
|
||||
const int want = on ? 1 : 0;
|
||||
if (atomic_exchange(&g_cursor_composite_want, want) == want) return;
|
||||
atomic_store(&g_cursor_composite, want);
|
||||
droiddeck_log("cursor", "compositing the pointer into the output: %s", on ? "on" : "off");
|
||||
if (g_input_pipe[1] < 0) return;
|
||||
struct input_msg m = { 22, on ? 1 : 0, 0, 0, 0 };
|
||||
ssize_t n = write(g_input_pipe[1], &m, sizeof(m));
|
||||
(void)n;
|
||||
}
|
||||
|
||||
|
||||
const char *droiddeck_client_name(struct wl_client *client) { return client_name(client); }
|
||||
struct wl_display *droiddeck_get_display(void) { return g_display; }
|
||||
@@ -3678,8 +3816,6 @@ int droiddeck_wayland_run(void) {
|
||||
open_session_log();
|
||||
|
||||
if (vkp_ready() != 0) WLOGE("renderer unavailable; clients will connect but nothing is drawn");
|
||||
/* Presentation compatibility is not HDR capability. Set the initial layer mode before
|
||||
* clients bind, including when Desktop is the first session in this app process. */
|
||||
if (vkp_quest_layer_presentation() && sc_layer_available()) g_zero_copy = 1;
|
||||
|
||||
struct wl_display *display = wl_display_create();
|
||||
|
||||
@@ -374,16 +374,11 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
mark_failed(kind);
|
||||
return 0;
|
||||
}
|
||||
/* The ring and the engine's images are new on this frame. Dispatching into them now
|
||||
* null-dereferenced Turnip (vkp_framegen_run, first Steam frame, 2560x1440 to the panel).
|
||||
* Show this frame as it is; generation starts once the size has settled. */
|
||||
if (size_changed || ring == 2) {
|
||||
FGLOG("frame generation catches up at %dx%d; this frame is shown as it is", w, h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The pacer's source rate must be the game's, not this loop's: a loop slowed by its own
|
||||
* generations would otherwise read as a slower game and justify even more generations. */
|
||||
++g_source_frames;
|
||||
const uint64_t game_frames = droiddeck_game_frames();
|
||||
uint32_t n_gen = fge_plan(g_ring_n, game_frames ? game_frames : g_source_frames, g_presented_rate);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#include "gpu_busy.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
#include "gpuload_ring.h"
|
||||
|
||||
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct gpuload_vk g_v;
|
||||
static struct gpuload_ring g_ring;
|
||||
static uint32_t g_family, g_bits;
|
||||
static PFN_vkQueueSubmit g_submit;
|
||||
static int g_was_on;
|
||||
static _Atomic int g_on, g_lost, g_timing;
|
||||
static _Atomic uint64_t g_busy_ns;
|
||||
|
||||
static VkResult VKAPI_CALL timed_submit(VkQueue queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence) {
|
||||
if (!count || !atomic_load(&g_on) || atomic_load(&g_lost)) return g_submit(queue, count, infos, fence);
|
||||
pthread_mutex_lock(&g_lock);
|
||||
if (!atomic_load(&g_on) || atomic_load(&g_lost)) {
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return g_submit(queue, count, infos, fence);
|
||||
}
|
||||
if (g_ring.state == 0 && gpuload_ring_setup(&g_ring, &g_v, g_family, g_bits)) atomic_store(&g_timing, 1);
|
||||
VkSubmitInfo *mine = NULL;
|
||||
uint32_t used = 0;
|
||||
if (g_ring.state == 1) {
|
||||
uint64_t ns = gpuload_ring_harvest(&g_ring, &g_v);
|
||||
if (g_was_on) atomic_fetch_add(&g_busy_ns, ns); // the first harvest after a pause holds work timed before it
|
||||
g_was_on = 1;
|
||||
mine = gpuload_ring_wrap(&g_ring, count, infos, &used);
|
||||
}
|
||||
VkResult r = g_submit(queue, count, mine ? mine : infos, fence);
|
||||
if (mine && r != VK_SUCCESS) gpuload_ring_unwind(&g_ring, used);
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
free(mine);
|
||||
return r;
|
||||
}
|
||||
|
||||
void vkp_gpu_busy_device(VkPhysicalDevice pd, VkDevice dev, uint32_t family) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
memset(&g_ring, 0, sizeof(g_ring));
|
||||
g_was_on = 0;
|
||||
atomic_store(&g_timing, 0);
|
||||
atomic_store(&g_lost, 0);
|
||||
PFN_vkGetDeviceProcAddr gdpa = g_vk.GetDeviceProcAddr;
|
||||
g_v = (struct gpuload_vk){
|
||||
.device = dev,
|
||||
.create_pool = g_vk.CreateCommandPool,
|
||||
.destroy_pool = (PFN_vkDestroyCommandPool)gdpa(dev, "vkDestroyCommandPool"),
|
||||
.alloc_cmds = g_vk.AllocateCommandBuffers,
|
||||
.begin = g_vk.BeginCommandBuffer,
|
||||
.end = g_vk.EndCommandBuffer,
|
||||
.cmd_reset = (PFN_vkCmdResetQueryPool)gdpa(dev, "vkCmdResetQueryPool"),
|
||||
.cmd_timestamp = (PFN_vkCmdWriteTimestamp)gdpa(dev, "vkCmdWriteTimestamp"),
|
||||
.create_queries = (PFN_vkCreateQueryPool)gdpa(dev, "vkCreateQueryPool"),
|
||||
.destroy_queries = (PFN_vkDestroyQueryPool)gdpa(dev, "vkDestroyQueryPool"),
|
||||
.results = (PFN_vkGetQueryPoolResults)gdpa(dev, "vkGetQueryPoolResults"),
|
||||
};
|
||||
VkPhysicalDeviceProperties props;
|
||||
g_vk.GetPhysicalDeviceProperties(pd, &props);
|
||||
gpuload_vk_period(&g_v, props.limits.timestampPeriod);
|
||||
VkQueueFamilyProperties families[16];
|
||||
uint32_t n = 16;
|
||||
g_vk.GetPhysicalDeviceQueueFamilyProperties(pd, &n, families);
|
||||
g_family = family;
|
||||
g_bits = family < n ? families[family].timestampValidBits : 0;
|
||||
// vk_loader_load_device has just put the driver's function back.
|
||||
if (g_vk.QueueSubmit != timed_submit) g_submit = g_vk.QueueSubmit;
|
||||
if (g_submit) g_vk.QueueSubmit = timed_submit;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
void vkp_gpu_busy_device_lost(void) {
|
||||
atomic_store(&g_lost, 1);
|
||||
atomic_store(&g_timing, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeGpuBusyNs(JNIEnv *env, jclass cls) {
|
||||
return atomic_load(&g_timing) ? (jlong)atomic_load(&g_busy_ns) : -1;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetGpuTiming(JNIEnv *env, jclass cls, jboolean on) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
if (!on) g_was_on = 0;
|
||||
atomic_store(&g_on, on ? 1 : 0);
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef GPU_BUSY_H
|
||||
#define GPU_BUSY_H
|
||||
#include "vk_loader.h"
|
||||
|
||||
// Times the compositor's own GPU work for the HUD (tools/gpuload/src/gpuload_ring.h); call after the device and its
|
||||
// functions are loaded. Off until WaylandCompositor.nativeSetGpuTiming(true).
|
||||
void vkp_gpu_busy_device(VkPhysicalDevice pd, VkDevice dev, uint32_t family);
|
||||
void vkp_gpu_busy_device_lost(void);
|
||||
#endif
|
||||
@@ -103,7 +103,6 @@ static bool prepare_pin(void) {
|
||||
(off_t)pin.memory << 12);
|
||||
if (commands == MAP_FAILED) return false;
|
||||
pin.commands = commands;
|
||||
// A3xx/A4xx use type-3 CP_NOP; newer cores use type-7 with zero odd-parity bits.
|
||||
uint32_t *words = commands;
|
||||
words[0] = pin.nop;
|
||||
words[1] = 0;
|
||||
@@ -124,7 +123,6 @@ static void *hold_pin(void *unused) {
|
||||
if (errno == EINTR || errno == ETIMEDOUT) continue;
|
||||
break;
|
||||
}
|
||||
// Constraints expire after idle_timer (normally 80 ms); renew with a NOP, keeping devfreq alive.
|
||||
usleep(25000);
|
||||
if (atomic_load(&running) && !submit_pin()) break;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ struct droiddeck_headpose {
|
||||
float eye_aspect;
|
||||
uint32_t eye_w, eye_h;
|
||||
float display_hz;
|
||||
// Uses a formerly reserved word; older publishers leave this zero.
|
||||
uint32_t render_height;
|
||||
uint32_t reserved[10];
|
||||
};
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "hudframes.h"
|
||||
|
||||
/* Layout written by gamescope patch 0125 (tools/gamescope/patches). */
|
||||
#define HUD_FRAMES_MAGIC 0x46484444u
|
||||
#define HUD_FRAMES_HEADER 128u
|
||||
#define HUD_FRAMES_ENTRY 16u
|
||||
@@ -69,7 +68,6 @@ int hud_frames_poll(struct hud_frames *h, int64_t *frametimes, int64_t *times, i
|
||||
memcpy(&frametimes[n], e, 8);
|
||||
memcpy(×[n], e + 8, 8);
|
||||
}
|
||||
/* The writer may have lapped the ring while we copied: drop what it overwrote. */
|
||||
uint64_t after = load64(h->map + 16);
|
||||
uint64_t valid = after > cap ? after - cap : 0;
|
||||
if (from < valid) {
|
||||
|
||||
@@ -8,9 +8,7 @@ struct hud_frames;
|
||||
|
||||
struct hud_frames *hud_frames_open(const char *path);
|
||||
void hud_frames_close(struct hud_frames *h);
|
||||
/* New frames since the last poll, oldest first; -1 while the file holds no valid ring. */
|
||||
int hud_frames_poll(struct hud_frames *h, int64_t *frametimes, int64_t *times, int max);
|
||||
/* info: pid, output width, output height, refresh mHz, Steam focused. */
|
||||
int hud_frames_info(const struct hud_frames *h, int32_t *info, char *engine, size_t engine_len);
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
/* Presentation only; this does not select a GPU driver or expand driver support. */
|
||||
static inline int quest_device_matches(const char *model, const char *device, const char *maker) {
|
||||
return !strcasecmp(model, "Quest 2") || !strcasecmp(model, "Quest 3") ||
|
||||
!strcasecmp(model, "Quest 3S") ||
|
||||
|
||||
@@ -291,7 +291,7 @@ int sc_layer_base_black(int width, int height) {
|
||||
ARect src = {0, 0, 16, 16}, dst = {0, 0, width, height};
|
||||
api.setBuffer(tx, g_base_sc, black, -1);
|
||||
api.setBufferTransparency(tx, g_base_sc, ASC_TRANSPARENCY_OPAQUE);
|
||||
api.setZOrder(tx, g_base_sc, 0); /* GAME = 1, OVERLAY = 2 */
|
||||
api.setZOrder(tx, g_base_sc, 0);
|
||||
api.setGeometry(tx, g_base_sc, &src, &dst, 0);
|
||||
api.setVisibility(tx, g_base_sc, ASC_VISIBILITY_SHOW);
|
||||
api.txApply(tx); api.txDelete(tx);
|
||||
@@ -381,6 +381,26 @@ static int sniff_modifier(const struct droiddeck_native_handle *h, uint64_t *mod
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define SC_MOD_GRALLOC (~0ULL - 1)
|
||||
|
||||
static const char *pool_kind(uint64_t mod) {
|
||||
return mod == MOD_QCOM_COMPRESSED ? "UBWC" : mod == SC_MOD_GRALLOC ? "gralloc-laid-out" : "linear";
|
||||
}
|
||||
|
||||
static void describe_handle(const struct droiddeck_native_handle *h, char *out, size_t n) {
|
||||
size_t o = 0;
|
||||
out[0] = 0;
|
||||
if (!h) { snprintf(out, n, "no handle"); return; }
|
||||
for (int i = 0; i < h->numFds && i < 4 && o < n; i++) {
|
||||
off_t sz = lseek(h->data[i], 0, SEEK_END);
|
||||
if (sz >= 0) lseek(h->data[i], 0, SEEK_SET);
|
||||
o += (size_t)snprintf(out + o, n - o, "%sfd%d %lld bytes", i ? ", " : "", i, (long long)sz);
|
||||
}
|
||||
if (o < n) o += (size_t)snprintf(out + o, n - o, "; ints");
|
||||
for (int i = 0; i < h->numInts && i < 8 && o < n; i++)
|
||||
o += (size_t)snprintf(out + o, n - o, " %#x", (unsigned)h->data[h->numFds + i]);
|
||||
}
|
||||
|
||||
static int g_alloc_failed;
|
||||
|
||||
enum { TIER_UBWC, TIER_PLAIN, TIER_LINEAR };
|
||||
@@ -416,22 +436,54 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm
|
||||
AHardwareBuffer_Desc got; AHardwareBuffer_describe(ahb, &got);
|
||||
const struct droiddeck_native_handle *nh = api.getNativeHandle(ahb);
|
||||
uint64_t mod = MOD_LINEAR;
|
||||
if (!sniff_modifier(nh, &mod)) {
|
||||
if (tier < TIER_LINEAR) {
|
||||
struct vkp_image *img = NULL;
|
||||
const char *path;
|
||||
char info[160] = "";
|
||||
if (sniff_modifier(nh, &mod)) {
|
||||
img = vkp_image_import_dmabuf(nh->data[0], fmt == AHB_RGB10A2 ? DRM_ABGR2101010 : DRM_ABGR8888, mod, w, h,
|
||||
got.stride * 4, 0, 1);
|
||||
path = "dma-buf (QTI handle)";
|
||||
} else {
|
||||
if (tier == TIER_UBWC) {
|
||||
char hd[256];
|
||||
describe_handle(nh, hd, sizeof(hd));
|
||||
droiddeck_log("layer", "%s: gralloc handle is not a QTI one (%d fds, %d ints: %s): no UBWC request; "
|
||||
"pool buffers are imported %s", l->name, nh ? nh->numFds : -1, nh ? nh->numInts : -1, hd,
|
||||
vkp_can_import_ahb() ? "as AHardwareBuffers (the driver takes gralloc's own layout)"
|
||||
: "as linear dma-bufs (this driver has no AHardwareBuffer import)");
|
||||
AHardwareBuffer_release(ahb);
|
||||
l->alloc_tier = TIER_LINEAR;
|
||||
droiddeck_log("layer", "%s: gralloc handle layout unknown (%d fds, %d ints): using linear pool buffers",
|
||||
l->name, nh ? nh->numFds : -1, nh ? nh->numInts : -1);
|
||||
l->alloc_tier = vkp_can_import_ahb() ? TIER_PLAIN : TIER_LINEAR;
|
||||
continue;
|
||||
}
|
||||
mod = MOD_LINEAR;
|
||||
mod = SC_MOD_GRALLOC;
|
||||
path = "AHardwareBuffer";
|
||||
img = vkp_image_import_ahb(ahb, info, sizeof(info));
|
||||
if (!img && tier == TIER_LINEAR) {
|
||||
const off_t need = (off_t)got.stride * 4 * h;
|
||||
int fd = -1, which = -1;
|
||||
for (int i = 0; nh && i < nh->numFds; i++) {
|
||||
off_t sz = lseek(nh->data[i], 0, SEEK_END);
|
||||
if (sz >= 0) lseek(nh->data[i], 0, SEEK_SET);
|
||||
if (sz >= need) { fd = nh->data[i]; which = i; break; }
|
||||
}
|
||||
if (fd < 0 && nh && nh->numFds > 0) { fd = nh->data[0]; which = 0; }
|
||||
mod = MOD_LINEAR;
|
||||
path = "linear dma-buf";
|
||||
img = fd >= 0 ? vkp_image_import_dmabuf(fd, fmt == AHB_RGB10A2 ? DRM_ABGR2101010 : DRM_ABGR8888, mod,
|
||||
w, h, got.stride * 4, 0, 1) : NULL;
|
||||
snprintf(info, sizeof(info), "handle fd %d of %d", which, nh ? nh->numFds : 0);
|
||||
if (vkp_can_import_ahb())
|
||||
droiddeck_log("layer", "%s: AHardwareBuffer import failed: the linear dma-buf in the handle's fd %d "
|
||||
"(of %d) -> %s", l->name, which, nh ? nh->numFds : 0, img ? "imported" : "failed too");
|
||||
}
|
||||
}
|
||||
int fd = (nh && nh->numFds > 0) ? nh->data[0] : -1;
|
||||
struct vkp_image *img = fd >= 0 ? vkp_image_import_dmabuf(fd, fmt == AHB_RGB10A2 ? DRM_ABGR2101010 : DRM_ABGR8888,
|
||||
mod, w, h, got.stride * 4, 0, 1) : NULL;
|
||||
if (!img) {
|
||||
droiddeck_log("layer", "%s: import of a %s %dx%d pool buffer (stride %u px) into the compositor's Turnip failed",
|
||||
l->name, mod == MOD_QCOM_COMPRESSED ? "UBWC" : "linear", w, h, got.stride);
|
||||
char hd[256];
|
||||
describe_handle(nh, hd, sizeof(hd));
|
||||
droiddeck_log("layer", "%s: import of a %s %dx%d pool buffer (stride %u px, %s, usage %#llx) into the "
|
||||
"compositor's Turnip failed via %s; gralloc handle %d fds / %d ints: %s", l->name,
|
||||
pool_kind(mod), w, h, got.stride, tier_name(tier), (unsigned long long)got.usage, path,
|
||||
nh ? nh->numFds : -1, nh ? nh->numInts : -1, hd);
|
||||
AHardwareBuffer_release(ahb);
|
||||
if (tier < TIER_LINEAR) { l->alloc_tier = tier + 1; continue; }
|
||||
g_alloc_failed = 1;
|
||||
@@ -442,10 +494,11 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm
|
||||
if (l->logged_w != w || l->logged_h != h || l->logged_fmt != fmt || l->logged_mod != mod ||
|
||||
l->logged_tier != tier) {
|
||||
l->logged_w = w; l->logged_h = h; l->logged_fmt = fmt; l->logged_mod = mod; l->logged_tier = tier;
|
||||
droiddeck_log("layer", "%s: pool buffers %dx%d%s: %s (%s), stride %u px, up to %d buffers (gralloc handle %d fds / %d ints)",
|
||||
l->name, w, h, fmt == AHB_RGB10A2 ? " 10-bit RGBA1010102" : "",
|
||||
mod == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)" : "linear", tier_name(tier),
|
||||
got.stride, l->pool_n, nh ? nh->numFds : -1, nh ? nh->numInts : -1);
|
||||
droiddeck_log("layer", "%s: pool buffers %dx%d%s: %s (%s), stride %u px, up to %d buffers (gralloc handle %d fds / "
|
||||
"%d ints), imported as %s%s%s%s", l->name, w, h, fmt == AHB_RGB10A2 ? " 10-bit RGBA1010102" : "",
|
||||
mod == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)" : pool_kind(mod), tier_name(tier),
|
||||
got.stride, l->pool_n, nh ? nh->numFds : -1, nh ? nh->numInts : -1, path,
|
||||
info[0] ? " (" : "", info, info[0] ? ")" : "");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -814,7 +867,7 @@ int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const stru
|
||||
l->first_logged = 1;
|
||||
droiddeck_log("layer", "presenting %dx%d game frames on their own SurfaceControl layer (%s pool, %d buffers); "
|
||||
"HUD and pointer stay Android views above it", sw, sh,
|
||||
l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear", l->pool_n);
|
||||
pool_kind(l->pool_modifier), l->pool_n);
|
||||
}
|
||||
vkp_signal_first_frame();
|
||||
return 0;
|
||||
@@ -836,7 +889,7 @@ int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int
|
||||
l->first_logged = 1;
|
||||
droiddeck_log("layer", "presenting %dx%d frames on their own SurfaceControl layer (%s pool, %d buffers); "
|
||||
"HUD and pointer stay Android views above it", rw, rh,
|
||||
l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear", l->pool_n);
|
||||
pool_kind(l->pool_modifier), l->pool_n);
|
||||
}
|
||||
vkp_signal_first_frame();
|
||||
return 0;
|
||||
@@ -874,12 +927,12 @@ int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct
|
||||
if (tm)
|
||||
droiddeck_log("color", "tone-mapped picture on the game's display layer: %dx%d, %s 8-bit buffers, untagged "
|
||||
"(sRGB) - HDR output is switched off", rw, rh,
|
||||
l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear");
|
||||
pool_kind(l->pool_modifier));
|
||||
else {
|
||||
char cov[96];
|
||||
coverage_text(l, cov, sizeof(cov));
|
||||
droiddeck_log("color", "HDR picture on its own display layer: %dx%d, %s %s buffers, tagged %s%s%s", rw, rh,
|
||||
l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear",
|
||||
pool_kind(l->pool_modifier),
|
||||
g_hdr_pool_fmt == AHB_RGB10A2 ? "10-bit" : "8-bit",
|
||||
color && color->dataspace == DROIDDECK_ADATASPACE_BT2020_PQ ? "BT2020_PQ" : "HDR",
|
||||
cov[0] ? ", " : "", cov);
|
||||
@@ -973,7 +1026,7 @@ void sc_layer_hide_overlay(void) {
|
||||
}
|
||||
|
||||
void sc_layer_window_gone(void) {
|
||||
base_hide(1); /* the backdrop belongs to the old window, just like GAME and OVERLAY */
|
||||
base_hide(1);
|
||||
if (api.state != 1) return;
|
||||
layers_init();
|
||||
for (int i = SC_LAYER_COUNT - 1; i >= 0; i--) retire_sc(&g_layers[i]);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "framegen_bridge.h"
|
||||
#include "hdr_compose.h"
|
||||
#include "blend_pass.h"
|
||||
#include "gpu_busy.h"
|
||||
#include "droiddeck_color.h"
|
||||
#include "quest_device.h"
|
||||
#include <stdio.h>
|
||||
@@ -70,8 +71,6 @@ static int g_first_frame_done;
|
||||
static int g_base_black;
|
||||
|
||||
int vkp_quest_layer_presentation(void) {
|
||||
/* Compositor thread only; this is a process-wide device property, not a session setting.
|
||||
* Quest 2 still needs its separate A6xx driver: this gate only chooses presentation. */
|
||||
static int enabled = -1;
|
||||
if (enabled < 0) {
|
||||
char model[PROP_VALUE_MAX] = {0}, device[PROP_VALUE_MAX] = {0}, maker[PROP_VALUE_MAX] = {0};
|
||||
@@ -94,6 +93,9 @@ static int g_black_state;
|
||||
static PFN_vkImportSemaphoreFdKHR g_import_sem_fd;
|
||||
static VkSemaphore g_wait_sem;
|
||||
|
||||
#define VKP_VENDOR_QUALCOMM 0x5143
|
||||
static uint32_t g_vendor_id;
|
||||
|
||||
static struct vkp_perf g_perf;
|
||||
static int64_t perf_now(void) {
|
||||
struct timespec ts;
|
||||
@@ -461,6 +463,7 @@ static int dev_init(void) {
|
||||
{
|
||||
VkPhysicalDeviceProperties props;
|
||||
g_vk.GetPhysicalDeviceProperties(g_pd, &props);
|
||||
g_vendor_id = props.vendorID;
|
||||
snprintf(g_gpu_name, sizeof(g_gpu_name), "%s", props.deviceName);
|
||||
droiddeck_log("gpu", "compositor renders on %s with %s", props.deviceName,
|
||||
g_library_name ? g_library_name : "the system Vulkan driver");
|
||||
@@ -476,7 +479,6 @@ static int dev_init(void) {
|
||||
g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, NULL);
|
||||
VkExtensionProperties *exts = calloc(ne ? ne : 1, sizeof(*exts));
|
||||
g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, exts);
|
||||
/* Only what the driver has: the system driver lacks the dma-buf ones, which the cloud player never needs. */
|
||||
for (unsigned i = 0; i < 4; i++) {
|
||||
if (has_ext(exts, ne, import_exts[i])) dev_exts[n_dev_exts++] = import_exts[i];
|
||||
else LOGE("present: driver MISSING %s (dmabuf import will fail)", import_exts[i]);
|
||||
@@ -488,7 +490,6 @@ static int dev_init(void) {
|
||||
}
|
||||
const int want_sem_fd = has_ext(exts, ne, VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME);
|
||||
if (want_sem_fd) dev_exts[n_dev_exts++] = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME;
|
||||
/* The cloud player's decoded frames arrive as AHardwareBuffers (vkp_image_from_ahb). */
|
||||
g_ahb_import = has_ext(exts, ne, VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME) &&
|
||||
has_ext(exts, ne, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME);
|
||||
if (g_ahb_import) {
|
||||
@@ -517,6 +518,7 @@ static int dev_init(void) {
|
||||
}
|
||||
vk_loader_load_device(g_dev);
|
||||
g_vk.GetDeviceQueue(g_dev, g_qfam, 0, &g_queue);
|
||||
vkp_gpu_busy_device(g_pd, g_dev, g_qfam);
|
||||
if (want_sem_fd) {
|
||||
g_import_sem_fd = (PFN_vkImportSemaphoreFdKHR)g_vk.GetDeviceProcAddr(g_dev, "vkImportSemaphoreFdKHR");
|
||||
VkSemaphoreCreateInfo wsci = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
|
||||
@@ -991,8 +993,9 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
.allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx};
|
||||
VkResult mr = g_vk.AllocateMemory(g_dev, &mai, NULL, &img->mem);
|
||||
if (mr != VK_SUCCESS) {
|
||||
LOGE("%s: importing the %s dma-buf (%dx%d, %llu bytes) -> %s", as_blit_dst ? "layer" : "dmabuf",
|
||||
vkp_modifier_name(modifier), w, h, (unsigned long long)req.size, vk_result_name(mr));
|
||||
LOGE("%s: importing the %s dma-buf (%dx%d, pitch %u, offset %u, %llu bytes, memory type %d of image types "
|
||||
"%#x & fd types %#x) -> %s", as_blit_dst ? "layer" : "dmabuf", vkp_modifier_name(modifier), w, h,
|
||||
stride, offset, (unsigned long long)req.size, idx, req.memoryTypeBits, allowed, vk_result_name(mr));
|
||||
g_vk.DestroyImage(g_dev, img->image, NULL); close(dupfd); free(img); return NULL;
|
||||
}
|
||||
VkResult br = g_vk.BindImageMemory(g_dev, img->image, img->mem, 0);
|
||||
@@ -1059,6 +1062,101 @@ struct vkp_image *vkp_image_from_ahb(AHardwareBuffer *ahb) {
|
||||
return img;
|
||||
}
|
||||
|
||||
int vkp_can_import_ahb(void) {
|
||||
return dev_init() == 0 && g_vendor_id != VKP_VENDOR_QUALCOMM && g_ahb_import &&
|
||||
g_vk.GetAndroidHardwareBufferPropertiesANDROID;
|
||||
}
|
||||
|
||||
struct vkp_image *vkp_image_import_ahb(struct AHardwareBuffer *ahb, char *info, size_t info_n) {
|
||||
if (info && info_n) info[0] = 0;
|
||||
if (!ahb || !vkp_can_import_ahb()) return NULL;
|
||||
AHardwareBuffer_Desc d;
|
||||
AHardwareBuffer_describe(ahb, &d);
|
||||
VkAndroidHardwareBufferFormatPropertiesANDROID fp = {
|
||||
.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID};
|
||||
VkAndroidHardwareBufferPropertiesANDROID hp = {
|
||||
.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID, .pNext = &fp};
|
||||
VkResult pr = g_vk.GetAndroidHardwareBufferPropertiesANDROID(g_dev, ahb, &hp);
|
||||
if (pr != VK_SUCCESS) {
|
||||
LOGE("layer: vkGetAndroidHardwareBufferPropertiesANDROID(%ux%u, AHB format %#x, usage %#llx) -> %s", d.width,
|
||||
d.height, d.format, (unsigned long long)d.usage, vk_result_name(pr));
|
||||
return NULL;
|
||||
}
|
||||
if (fp.format == VK_FORMAT_UNDEFINED) {
|
||||
LOGE("layer: the driver reports the %ux%u AHB (format %#x) as external format %#llx only: no blit target",
|
||||
d.width, d.height, d.format, (unsigned long long)fp.externalFormat);
|
||||
return NULL;
|
||||
}
|
||||
const VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
if (g_vk.GetPhysicalDeviceImageFormatProperties2) {
|
||||
VkPhysicalDeviceExternalImageFormatInfo ext = {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO,
|
||||
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID};
|
||||
VkPhysicalDeviceImageFormatInfo2 qi = {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, .pNext = &ext, .format = fp.format,
|
||||
.type = VK_IMAGE_TYPE_2D, .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = usage};
|
||||
VkExternalImageFormatProperties extp = {.sType = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES};
|
||||
VkImageFormatProperties2 ip = {.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, .pNext = &extp};
|
||||
VkResult qr = g_vk.GetPhysicalDeviceImageFormatProperties2(g_pd, &qi, &ip);
|
||||
if (qr != VK_SUCCESS ||
|
||||
!(extp.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT)) {
|
||||
LOGE("layer: VkFormat %d as an imported AHB blit target is not supported (%s, external features %#x)",
|
||||
(int)fp.format, vk_result_name(qr), extp.externalMemoryProperties.externalMemoryFeatures);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
struct vkp_image *img = calloc(1, sizeof(*img));
|
||||
if (!img) return NULL;
|
||||
img->w = (int)d.width; img->h = (int)d.height;
|
||||
img->dmabuf = 1; img->blit_dst = 1;
|
||||
img->fmt = fp.format;
|
||||
VkExternalMemoryImageCreateInfo extImg = {
|
||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
|
||||
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID};
|
||||
VkImageCreateInfo ici = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .pNext = &extImg,
|
||||
.imageType = VK_IMAGE_TYPE_2D, .format = fp.format, .extent = {d.width, d.height, 1},
|
||||
.mipLevels = 1, .arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT,
|
||||
.tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||
.usage = usage, .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED};
|
||||
VkResult cr = g_vk.CreateImage(g_dev, &ici, NULL, &img->image);
|
||||
if (cr != VK_SUCCESS) {
|
||||
LOGE("layer: vkCreateImage(AHB %ux%u, VkFormat %d) -> %s", d.width, d.height, (int)fp.format,
|
||||
vk_result_name(cr));
|
||||
free(img); return NULL;
|
||||
}
|
||||
int idx = -1;
|
||||
for (int i = 0; i < 32; i++) if (hp.memoryTypeBits & (1u << i)) { idx = i; break; }
|
||||
if (idx < 0) {
|
||||
LOGE("layer: no memory type can import the %ux%u AHB (memoryTypeBits 0)", d.width, d.height);
|
||||
g_vk.DestroyImage(g_dev, img->image, NULL); free(img); return NULL;
|
||||
}
|
||||
VkImportAndroidHardwareBufferInfoANDROID imp = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID, .buffer = ahb};
|
||||
VkMemoryDedicatedAllocateInfo ded = {.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
|
||||
.pNext = &imp, .image = img->image};
|
||||
VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &ded,
|
||||
.allocationSize = hp.allocationSize, .memoryTypeIndex = (uint32_t)idx};
|
||||
VkResult mr = g_vk.AllocateMemory(g_dev, &mai, NULL, &img->mem);
|
||||
if (mr != VK_SUCCESS) {
|
||||
LOGE("layer: importing the %ux%u AHB (VkFormat %d, %llu bytes, memory type %d of memoryTypeBits %#x) -> %s",
|
||||
d.width, d.height, (int)fp.format, (unsigned long long)hp.allocationSize, idx, hp.memoryTypeBits,
|
||||
vk_result_name(mr));
|
||||
g_vk.DestroyImage(g_dev, img->image, NULL); free(img); return NULL;
|
||||
}
|
||||
VkResult br = g_vk.BindImageMemory(g_dev, img->image, img->mem, 0);
|
||||
if (br != VK_SUCCESS) {
|
||||
LOGE("layer: vkBindImageMemory(AHB) -> %s", vk_result_name(br));
|
||||
g_vk.FreeMemory(g_dev, img->mem, NULL); g_vk.DestroyImage(g_dev, img->image, NULL);
|
||||
free(img); return NULL;
|
||||
}
|
||||
if (info && info_n)
|
||||
snprintf(info, info_n, "VkFormat %d, %llu bytes, memory type %d of memoryTypeBits %#x", (int)fp.format,
|
||||
(unsigned long long)hp.allocationSize, idx, hp.memoryTypeBits);
|
||||
return img;
|
||||
}
|
||||
|
||||
static int shm_sampled(void) {
|
||||
static int known;
|
||||
if (!known) {
|
||||
@@ -1311,6 +1409,7 @@ static void device_lost(const char *where) {
|
||||
g_dev_state = -2;
|
||||
g_base_black = 0;
|
||||
vkp_framegen_device_lost();
|
||||
vkp_gpu_busy_device_lost();
|
||||
droiddeck_log("error", "GPU device lost (VK_ERROR_DEVICE_LOST in %s): the compositor has stopped presenting; "
|
||||
"restart the session", where);
|
||||
for (uint32_t i = 0; i < g_nimg; i++) blendp_forget_image(g_images[i]);
|
||||
@@ -1698,9 +1797,6 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
VkImageLayout result_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
if (fx) {
|
||||
int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f);
|
||||
/* Frame generation samples every output pixel. Upscaling first made it interpolate
|
||||
* the whole panel (3200x1440 on a 1440p phone) and rebuild on Steam's first frame.
|
||||
* Grade at the game's size instead; the screen blit still scales to the panel. */
|
||||
if (fg) { mapped_w = scene_w; mapped_h = scene_h; }
|
||||
vkp_effects_set_formats(scene_fmt, scene_fmt);
|
||||
result = vkp_effects_run(cmd, scene_img, scene_w, scene_h, mapped_w, mapped_h, &rw, &rh);
|
||||
@@ -1800,9 +1896,6 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
|
||||
int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n) {
|
||||
if (vkp_quest_layer_presentation() && !vkp_framegen_active() && !vkp_cardboard_active()) {
|
||||
/* The desktop (multiple windows), overlays and an empty scene must also avoid WSI.
|
||||
* Merely enabling zero-copy handles only a single fullscreen window and leaves both
|
||||
* the letterbox and every fallback frame going through the corrupted swapchain. */
|
||||
vkp_apply_window_request();
|
||||
sc_layer_hide_overlay();
|
||||
if (n > 0) {
|
||||
@@ -1814,9 +1907,6 @@ int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n) {
|
||||
} else {
|
||||
sc_layer_hide();
|
||||
}
|
||||
/* sc_layer_present_pass signals only after submitting client content.
|
||||
* A backdrop alone, or a successful no-op while a layer slot is unavailable,
|
||||
* must not dismiss the app's loading UI or mark Steam's window as shown. */
|
||||
return vkp_base_black(scene_w, scene_h);
|
||||
}
|
||||
return render_impl(scene_w, scene_h, draws, n, NULL, NULL);
|
||||
@@ -1853,8 +1943,6 @@ void vkp_signal_first_frame(void) {
|
||||
int vkp_update_map(int scene_w, int scene_h) {
|
||||
if (g_dev_state == -2 || dev_init() != 0 || !g_window || scene_w <= 0 || scene_h <= 0) return -1;
|
||||
if (vkp_quest_layer_presentation()) {
|
||||
/* Layer geometry needs the window size, not a Vulkan swapchain. In particular, do
|
||||
* not create/present a swapchain just to paint black under an otherwise clean layer. */
|
||||
int w = ANativeWindow_getWidth(g_window), h = ANativeWindow_getHeight(g_window);
|
||||
if (w <= 0 || h <= 0) return -1;
|
||||
g_extent = (VkExtent2D){(uint32_t)w, (uint32_t)h};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef VK_PRESENT_H
|
||||
#define VK_PRESENT_H
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <android/native_window.h>
|
||||
void vk_present_set_driver(const char *driver_path, const char *library_name,
|
||||
const char *native_lib_dir);
|
||||
@@ -33,6 +34,9 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
int w, int h, uint32_t stride, uint32_t offset,
|
||||
int as_blit_dst);
|
||||
int vkp_image_is_dmabuf(const struct vkp_image *img);
|
||||
struct AHardwareBuffer;
|
||||
int vkp_can_import_ahb(void);
|
||||
struct vkp_image *vkp_image_import_ahb(struct AHardwareBuffer *ahb, char *info, size_t info_n);
|
||||
|
||||
struct vkp_image *vkp_image_create_shm(int w, int h);
|
||||
struct AHardwareBuffer;
|
||||
|
||||
@@ -30,6 +30,7 @@ extern void droiddeck_wayland_send_key(int evdev, int state);
|
||||
extern int droiddeck_focus_takes_touch(void);
|
||||
extern int droiddeck_cursor_input_pos(int *x, int *y);
|
||||
extern void droiddeck_wayland_send_scene_input(int type, int a, int b);
|
||||
extern void droiddeck_wayland_set_cursor_composite(int on);
|
||||
extern void droiddeck_wayland_vsync(int64_t frame_time_ns);
|
||||
extern void droiddeck_stream_set(int on);
|
||||
extern void droiddeck_stream_frame(AHardwareBuffer *ahb);
|
||||
@@ -292,6 +293,13 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeCursorSerial(JNIEnv
|
||||
return droiddeck_cursor_serial();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetCursorComposite(
|
||||
JNIEnv *env, jclass clazz, jboolean on) {
|
||||
(void)env; (void)clazz;
|
||||
droiddeck_wayland_set_cursor_composite(on ? 1 : 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSendKey(
|
||||
JNIEnv *env, jclass clazz, jint evdev, jint state) {
|
||||
@@ -690,7 +698,6 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetGpuTurbo(JNIEnv *
|
||||
jclass error = (*env)->FindClass(env, "java/lang/IllegalStateException");
|
||||
if (error) (*env)->ThrowNew(env, error, strerror(saved_errno));
|
||||
}
|
||||
// Clear a legacy global pin when recovering its marker after an app upgrade or crash.
|
||||
if (on != JNI_TRUE) adrenotools_set_turbo(false);
|
||||
}
|
||||
|
||||
@@ -717,7 +724,6 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetCardboardSpatialP
|
||||
vkp_cardboard_set_spatial_pose(m, p, live ? 1 : 0);
|
||||
}
|
||||
|
||||
/* The Xbox Cloud Gaming native player: its decoded frames are the whole scene (no Wayland clients). */
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeStreamMode(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
droiddeck_stream_set(on ? 1 : 0);
|
||||
|
||||
Reference in new issue
Block a user