Skip to content

Commit b807039

Browse files
committed
initial webrogue support
1 parent 3b6d7cd commit b807039

25 files changed

+212
-36
lines changed

include/renderdoc_app.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#define RENDERDOC_CC
4040
#elif defined(__APPLE__)
4141
#define RENDERDOC_CC
42+
#elif defined(__wasi__)
43+
#define RENDERDOC_CC
4244
#else
4345
#error "Unknown platform"
4446
#endif

meson.build

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ with_platform_wayland = _platforms.contains('wayland')
416416
with_platform_haiku = _platforms.contains('haiku')
417417
with_platform_windows = _platforms.contains('windows')
418418
with_platform_macos = _platforms.contains('macos')
419+
with_platform_webrogue = _platforms.contains('webrogue')
419420

420421
with_glx = get_option('glx')
421422
if with_glx == 'auto'
@@ -467,7 +468,7 @@ with_xlib_lease = get_option('xlib-lease') \
467468
.allowed()
468469

469470
with_egl = get_option('egl') \
470-
.require(with_platform_windows or with_platform_haiku or with_dri or with_platform_android, error_message : 'EGL requires DRI, Haiku, Windows or Android') \
471+
.require(with_platform_windows or with_platform_haiku or with_dri or with_platform_android or with_platform_webrogue, error_message : 'EGL requires DRI, Haiku, Windows, Android or Webrogue') \
471472
.require(with_glx != 'xlib', error_message :'EGL requires DRI, but GLX is being built with xlib support') \
472473
.disable_auto_if(with_platform_haiku) \
473474
.allowed()
@@ -946,7 +947,7 @@ if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
946947
endif
947948

948949
# Support systems without ETIME (e.g. FreeBSD)
949-
if cc.get_define('ETIME', prefix : '#include <errno.h>') == ''
950+
if with_platform_webrogue or cc.get_define('ETIME', prefix : '#include <errno.h>') == ''
950951
pre_args += '-DETIME=ETIMEDOUT'
951952
endif
952953

@@ -1279,7 +1280,7 @@ if cc.compiles('''#include <stdint.h>
12791280
#
12801281
# This can happen for 64-bit atomic operations on 32-bit architectures such
12811282
# as ARM.
1282-
if not cc.links('''#include <stdint.h>
1283+
if host_machine.cpu_family() != 'wasm' and not cc.links('''#include <stdint.h>
12831284
int main() {
12841285
struct {
12851286
uint64_t *v;
@@ -1521,7 +1522,7 @@ ld_args_build_id = cc.get_supported_link_arguments('-Wl,--build-id=sha1')
15211522

15221523
# check for dl support
15231524
dep_dl = null_dep
1524-
if host_machine.system() != 'windows'
1525+
if host_machine.cpu_family() != 'wasm' and host_machine.system() != 'windows'
15251526
if not cc.has_function('dlopen')
15261527
dep_dl = cc.find_library('dl', required : true)
15271528
endif
@@ -1542,7 +1543,7 @@ if with_any_intel and ['x86', 'x86_64'].contains(host_machine.cpu_family())
15421543
endif
15431544

15441545
# Determine whether or not the rt library is needed for time functions
1545-
if host_machine.system() == 'windows' or cc.has_function('clock_gettime')
1546+
if host_machine.system() == 'windows' or host_machine.cpu_family() == 'wasm' or cc.has_function('clock_gettime')
15461547
dep_clock = null_dep
15471548
else
15481549
dep_clock = cc.find_library('rt')

meson.options

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ option(
1212
type : 'array',
1313
value : ['auto'],
1414
choices : [
15-
'auto', 'x11', 'wayland', 'haiku', 'android', 'windows', 'macos',
15+
'auto', 'x11', 'wayland', 'haiku', 'android', 'windows', 'macos', 'webrogue',
1616
],
1717
description : 'window systems to support. If this is set to `auto`, all ' +
1818
'platforms applicable will be enabled.'

src/c11/impl/threads_posix.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ _Noreturn
284284
void
285285
thrd_exit(int res)
286286
{
287-
pthread_exit((void*)(intptr_t)res);
287+
abort();
288+
// pthread_exit((void*)(intptr_t)res);
288289
}
289290

290291
// 7.25.5.6

src/gfxstream/guest/connection-manager/GfxStreamConnectionManager.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ bool GfxStreamConnectionManager::initialize() {
4040
break;
4141
}
4242
#endif
43+
#ifndef DETECT_OS_WASI
4344
case GFXSTREAM_TRANSPORT_QEMU_PIPE: {
4445
mStream = new QemuPipeStream(STREAM_BUFFER_SIZE);
4546
if (mStream->connect() < 0) {
@@ -84,6 +85,17 @@ bool GfxStreamConnectionManager::initialize() {
8485

8586
break;
8687
}
88+
#else
89+
case GFXSTREAM_TRANSPORT_WEBROGUE: {
90+
mStream = new makeWebrogueStream(STREAM_BUFFER_SIZE);
91+
if (mStream->connect() < 0) {
92+
mesa_loge("Failed to connect to host (makeWebrogueStream)\n");
93+
return false;
94+
}
95+
96+
break;
97+
}
98+
#endif
8799
default:
88100
return false;
89101
}

src/gfxstream/guest/connection-manager/GfxStreamConnectionManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum GfxStreamTransportType {
2525
GFXSTREAM_TRANSPORT_ADDRESS_SPACE = 2,
2626
GFXSTREAM_TRANSPORT_VIRTIO_GPU_PIPE = 3,
2727
GFXSTREAM_TRANSPORT_VIRTIO_GPU_ADDRESS_SPACE = 4,
28+
GFXSTREAM_TRANSPORT_WEBROGUE = 5,
2829
};
2930

3031
class GfxStreamConnectionManager {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "WebrogueStream.h"
2+
#include <cstdint>
3+
4+
__attribute__((import_name("commit_buffer")))
5+
__attribute__((import_module("webrogue_gfx")))
6+
void imported_webrogue_gfx_commit_buffer(const void* buf, uint32_t len);
7+
8+
9+
__attribute__((import_name("ret_buffer_read")))
10+
__attribute__((import_module("webrogue_gfx"))) void
11+
imported_webrogue_gfx_ret_buffer_read(const void* buf, uint32_t len);
12+
13+
14+
int WebrogueStream::connect(const char* serviceName = nullptr) {
15+
return 0;
16+
}
17+
18+
class WebrogueStream : public gfxstream::IOStream {
19+
public:
20+
explicit WebrogueStream(size_t bufsize):
21+
gfxstream::IOStream(bufsize) {}
22+
23+
~WebrogueStream() {};
24+
25+
virtual void* allocBuffer(size_t minSize) {
26+
size_t allocSize = (m_bufsize < minSize ? minSize : m_bufsize);
27+
if (!m_buf) {
28+
m_buf = (unsigned char *)malloc(allocSize);
29+
}
30+
else if (m_bufsize < allocSize) {
31+
unsigned char *p = (unsigned char *)realloc(m_buf, allocSize);
32+
if (p != NULL) {
33+
m_buf = p;
34+
m_bufsize = allocSize;
35+
} else {
36+
free(m_buf);
37+
m_buf = NULL;
38+
m_bufsize = 0;
39+
}
40+
}
41+
42+
return m_buf;
43+
}
44+
virtual int commitBuffer(size_t size) {
45+
if (size == 0) return 0;
46+
return writeFully(m_buf, size);
47+
}
48+
virtual const unsigned char* readFully(void* buf, size_t len) {
49+
imported_webrogue_gfx_ret_buffer_read(buf, len);
50+
return (const unsigned char*)buf;
51+
}
52+
virtual int writeFully(const void* buf, size_t len) {
53+
imported_webrogue_gfx_commit_buffer(buf, len);
54+
return len;
55+
}
56+
57+
virtual void* getDmaForReading(uint64_t guest_paddr) { return nullptr; }
58+
virtual void unlockDma(uint64_t guest_paddr) {}
59+
60+
virtual void onSave(gfxstream::guest::Stream* stream) {
61+
printf("WebrogueStream::onSave not implemented\n");
62+
abort();
63+
}
64+
virtual unsigned char* onLoad(gfxstream::guest::Stream* stream) {
65+
printf("WebrogueStream::onLoad not implemented\n");
66+
abort();
67+
}
68+
69+
virtual const unsigned char *readRaw(void *buf, size_t *inout_len) {
70+
printf("WebrogueStream::readRaw not implemented\n");
71+
abort();
72+
}
73+
};
74+
75+
gfxstream::IOStream* makeWebrogueStream(int bufferSize) {
76+
return new WebrogueStream(bufferSize);
77+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
#pragma once
3+
4+
#include <stdlib.h>
5+
6+
#include "gfxstream/guest/IOStream.h"
7+
8+
class WebrogueStream : public gfxstream::guest::IOStream {
9+
public:
10+
explicit WebrogueStream(size_t bufsize, int32_t descriptor);
11+
~WebrogueStream();
12+
13+
virtual int connect(const char* serviceName = nullptr);
14+
virtual uint64_t processPipeInit();
15+
16+
virtual void* allocBuffer(size_t minSize);
17+
virtual int commitBuffer(size_t size);
18+
virtual const unsigned char* readFully(void* buf, size_t len);
19+
virtual const unsigned char* commitBufferAndReadFully(size_t size, void* buf, size_t len);
20+
virtual const unsigned char* read(void* buf, size_t* inout_len);
21+
22+
bool valid();
23+
int getRendernodeFd();
24+
int recv(void* buf, size_t len);
25+
26+
virtual int writeFully(const void* buf, size_t len);
27+
};

src/gfxstream/guest/connection-manager/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ files_libconnection_manager = files(
88
'GfxStreamConnection.cpp',
99
'QemuPipeStreamStub.cpp',
1010
'VirtioGpuPipeStream.cpp',
11+
'WebrogueStream.cpp',
1112
)
1213

1314
libconnection_manager = static_library(

src/gfxstream/guest/vulkan-mapper/GfxStreamVulkanMapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ int32_t GfxStreamVulkanMapper::map(struct VulkanMapperData* mapData) {
245245
};
246246
#endif
247247

248+
#if DETECT_OS_WASI
249+
abort();
250+
#else
248251
mai.pNext = reinterpret_cast<void*>(&importInfo);
252+
#endif
249253

250254
VkResult result = mVk.AllocateMemory(mDevice, &mai, nullptr, &mapData->memory);
251255
if (result != VK_SUCCESS) {

0 commit comments

Comments
 (0)