aboutsummaryrefslogtreecommitdiffstats
path: root/steamvr/vrcompositor/shared.h
blob: 2fdd755a07a5fc00ecb72095dd7c22bd2eb9d8ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-FileCopyrightText: 2026 Tomasz Kramkowski <tomasz@kramkow.ski>
// SPDX-License-Identifier: CC0-1.0

#ifndef STEAMVR_VRCOMPOSITOR_SHARED_H
#define STEAMVR_VRCOMPOSITOR_SHARED_H

#include <layout.h>
#include <stddef.h>
#include <stdint.h>

ASSERT_SIZE(void *, 8);

struct Image;
struct SharedResource;
struct Semaphore;
struct NativeDevice;

typedef uint32_t GetOwner(struct Image *);
typedef struct Semaphore *GetSemaphore(struct SharedResource *);
typedef uint64_t SemaphoreGetU64(struct Semaphore *);
typedef unsigned char
SubmitWait(struct Semaphore *, uint64_t, struct NativeDevice *, unsigned char);

struct ImageVtable {
	unsigned char unknown_000[0xd8];
	GetOwner *get_owner;
};
ASSERT_OFFSET(struct ImageVtable, get_owner, 0xd8);

// vr::IVRSharedImage
struct Image {
	const struct ImageVtable *vtable;
};

struct SharedResourceVtable {
	unsigned char unknown_000[0x30];
	GetSemaphore *get_semaphore;
};
ASSERT_OFFSET(struct SharedResourceVtable, get_semaphore, 0x30);

// vr::IVRSharedResource
struct SharedResource {
	const struct SharedResourceVtable *vtable;
};

struct SemaphoreVtable {
	unsigned char unknown_000[0x40];
	SemaphoreGetU64 *get_handle;
	unsigned char unknown_048[0x70 - 0x48];
	SemaphoreGetU64 *get_value;
	unsigned char unknown_078[8];
	SubmitWait *submit_wait;
};
ASSERT_OFFSET(struct SemaphoreVtable, get_handle, 0x40);
ASSERT_OFFSET(struct SemaphoreVtable, get_value, 0x70);
ASSERT_OFFSET(struct SemaphoreVtable, submit_wait, 0x80);

// vr::IVRSharedSemaphore
struct Semaphore {
	const struct SemaphoreVtable *vtable;
};

typedef struct {
	uintptr_t semaphore;
	uint64_t value;
} SemaphoreEntry;
ASSERT_SIZE(SemaphoreEntry, 16);
ASSERT_OFFSET(SemaphoreEntry, value, 8);

static inline struct SharedResource *image_to_resource(struct Image *image)
{
	// The vbase offset entry for converting `vr::IVRSharedImage *` to
	// `vr::IVRSharedResource *` is located at `image->vtable - 0x50`.
	ptrdiff_t resource_offset =
		*(const ptrdiff_t *)((const char *)image->vtable - 0x50);
	return (void *)((char *)image + resource_offset);
}

#endif