Skip to content

Commit 887f226

Browse files
committed
[Kompjuta] Start implementing the command list
1 parent 8046294 commit 887f226

6 files changed

Lines changed: 96 additions & 20 deletions

File tree

backends/gpu/kompjuta/includes/kore3/kompjuta/commandlist_structs.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#ifndef KORE_KOMPJUTA_COMMANDLIST_STRUCTS_HEADER
22
#define KORE_KOMPJUTA_COMMANDLIST_STRUCTS_HEADER
33

4+
#include <stdint.h>
5+
46
#ifdef __cplusplus
57
extern "C" {
68
#endif
79

8-
typedef struct kore_kompjuta_compute_bind_group {
9-
int nothing;
10-
} kore_kompjuta_compute_bind_group;
10+
#include <kore3/backend/mmio.h>
1111

1212
typedef struct kore_kompjuta_command_list {
13-
int nothing;
13+
kompjuta_gpu_command *commands;
14+
uint32_t commands_count;
15+
uint32_t current_command;
1416
} kore_kompjuta_command_list;
1517

1618
#ifdef __cplusplus

backends/gpu/kompjuta/sources/commandlist.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@
99

1010
#include <kore3/util/align.h>
1111

12+
#include <assert.h>
13+
1214
void kore_kompjuta_command_list_destroy(kore_gpu_command_list *list) {}
1315

14-
void kore_kompjuta_command_list_begin_render_pass(kore_gpu_command_list *list, const kore_gpu_render_pass_parameters *parameters) {}
16+
void kore_kompjuta_command_list_begin_render_pass(kore_gpu_command_list *list, const kore_gpu_render_pass_parameters *parameters) {
17+
assert(list->kompjuta.current_command < list->kompjuta.commands_count);
18+
kompjuta_gpu_command *command = &list->kompjuta.commands[list->kompjuta.current_command];
19+
command->kind = KOMPJUTA_GPU_COMMAND_CLEAR;
20+
command->data.clear.r = parameters->color_attachments[0].clear_value.r;
21+
command->data.clear.g = parameters->color_attachments[0].clear_value.g;
22+
command->data.clear.b = parameters->color_attachments[0].clear_value.b;
23+
command->data.clear.a = parameters->color_attachments[0].clear_value.a;
24+
++list->kompjuta.current_command;
25+
}
1526

1627
void kore_kompjuta_command_list_end_render_pass(kore_gpu_command_list *list) {}
1728

18-
void kore_kompjuta_command_list_present(kore_gpu_command_list *list) {}
29+
void kore_kompjuta_command_list_present(kore_gpu_command_list *list) {
30+
assert(list->kompjuta.current_command < list->kompjuta.commands_count);
31+
kompjuta_gpu_command *command = &list->kompjuta.commands[list->kompjuta.current_command];
32+
command->kind = KOMPJUTA_GPU_COMMAND_PRESENT;
33+
++list->kompjuta.current_command;
34+
}
1935

2036
void kore_kompjuta_command_list_set_index_buffer(kore_gpu_command_list *list, kore_gpu_buffer *buffer, kore_gpu_index_format index_format, uint64_t offset) {}
2137

backends/gpu/kompjuta/sources/device.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#include <kore3/kompjuta/device_functions.h>
22

3+
#include <kore3/gpu/commandlist.h>
34
#include <kore3/gpu/device.h>
45
#include <kore3/util/align.h>
56

67
#include <kore3/log.h>
78
#include <kore3/window.h>
89

10+
#include <stdlib.h>
11+
12+
#include <kore3/backend/mmio.h>
13+
914
void kore_kompjuta_device_create(kore_gpu_device *device, const kore_gpu_device_wishlist *wishlist) {}
1015

1116
void kore_kompjuta_device_destroy(kore_gpu_device *device) {}
@@ -14,7 +19,11 @@ void kore_kompjuta_device_set_name(kore_gpu_device *device, const char *name) {}
1419

1520
void kore_kompjuta_device_create_buffer(kore_gpu_device *device, const kore_gpu_buffer_parameters *parameters, kore_gpu_buffer *buffer) {}
1621

17-
void kore_kompjuta_device_create_command_list(kore_gpu_device *device, kore_gpu_command_list_type type, kore_gpu_command_list *list) {}
22+
void kore_kompjuta_device_create_command_list(kore_gpu_device *device, kore_gpu_command_list_type type, kore_gpu_command_list *list) {
23+
list->kompjuta.commands_count = 1024;
24+
list->kompjuta.commands = malloc(sizeof(kompjuta_gpu_command) * list->kompjuta.commands_count);
25+
list->kompjuta.current_command = 0;
26+
}
1827

1928
void kore_kompjuta_device_create_texture(kore_gpu_device *device, const kore_gpu_texture_parameters *parameters, kore_gpu_texture *texture) {}
2029

@@ -26,7 +35,20 @@ kore_gpu_texture_format kore_kompjuta_device_framebuffer_format(kore_gpu_device
2635
return KORE_GPU_TEXTURE_FORMAT_RGBA8_UNORM;
2736
}
2837

29-
void kore_kompjuta_device_execute_command_list(kore_gpu_device *device, kore_gpu_command_list *list) {}
38+
void kore_kompjuta_device_execute_command_list(kore_gpu_device *device, kore_gpu_command_list *list) {
39+
uint8_t *mmio = (uint8_t *)MMIO_BASE;
40+
41+
uint64_t *list_address = (uint64_t *)&mmio[COMMAND_LIST_ADDR];
42+
*list_address = (uint64_t)list->kompjuta.commands;
43+
44+
uint32_t *list_size = (uint32_t *)&mmio[COMMAND_LIST_SIZE];
45+
*list_size = list->kompjuta.commands_count;
46+
47+
uint8_t *execute = &mmio[EXECUTE_COMMAND_LIST];
48+
*execute = 1;
49+
50+
list->kompjuta.current_command = 0;
51+
}
3052

3153
void kore_kompjuta_device_wait_until_idle(kore_gpu_device *device) {}
3254

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef KOMPJUTA_MMIO_HEADER
2+
#define KOMPJUTA_MMIO_HEADER
3+
4+
#include <stdint.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
#define MMIO_BASE 0xffffffff00000000
11+
12+
#define FB_ADDR 0x0
13+
#define FB_STRIDE 0x08
14+
#define FB_WIDTH 0x0c
15+
#define FB_HEIGHT 0x10
16+
#define FB_FORMAT 0x14
17+
#define PRESENT 0x18
18+
#define COMMAND_LIST_ADDR 0x20
19+
#define COMMAND_LIST_SIZE 0x28
20+
#define EXECUTE_COMMAND_LIST 0x32
21+
22+
typedef enum kompjuta_gpu_command_kind {
23+
KOMPJUTA_GPU_COMMAND_CLEAR,
24+
KOMPJUTA_GPU_COMMAND_PRESENT,
25+
} kompjuta_gpu_command_kind;
26+
27+
typedef struct kompjuta_gpu_command {
28+
kompjuta_gpu_command_kind kind;
29+
union {
30+
struct {
31+
float r;
32+
float g;
33+
float b;
34+
float a;
35+
} clear;
36+
} data;
37+
} kompjuta_gpu_command;
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#endif

includes/kore3/gpu/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ typedef enum kore_gpu_api {
150150

151151
#elif defined(KORE_KOMPJUTA)
152152

153-
#define KORE_GPU_IMPL(name) kore_kompjuta_##name webgpu
153+
#define KORE_GPU_IMPL(name) kore_kompjuta_##name kompjuta
154154
#define KORE_GPU_CALL(name) kore_kompjuta_##name()
155155
#define KORE_GPU_CALL1(name, arg0) kore_kompjuta_##name(arg0)
156156
#define KORE_GPU_CALL2(name, arg0, arg1) kore_kompjuta_##name(arg0, arg1)

sources/framebuffer/framebuffer.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,10 @@ uint8_t *kore_framebuffer_pixels;
1616

1717
#ifdef KORE_KOMPJUTA
1818

19-
#define MMIO_BASE 0xffffffff00000000
20-
21-
#define FB_ADDR 0x0
22-
#define FB_STRIDE 0x08
23-
#define FB_WIDTH 0x0c
24-
#define FB_HEIGHT 0x10
25-
#define FB_FORMAT 0x14
26-
#define PRESENT 0x18
27-
28-
static uint8_t *mmio;
19+
#include <kore3/backend/mmio.h>
2920

3021
void kore_fb_init() {
31-
mmio = (uint8_t *)MMIO_BASE;
22+
uint8_t *mmio = (uint8_t *)MMIO_BASE;
3223

3324
kore_framebuffer_width = *(uint32_t *)&mmio[FB_WIDTH];
3425
kore_framebuffer_height = *(uint32_t *)&mmio[FB_HEIGHT];
@@ -43,6 +34,8 @@ void kore_fb_init() {
4334
void kore_fb_begin(void) {}
4435

4536
void kore_fb_end(void) {
37+
uint8_t *mmio = (uint8_t *)MMIO_BASE;
38+
4639
uint8_t *present = &mmio[PRESENT];
4740
*present = 1;
4841
}

0 commit comments

Comments
 (0)