Skip to content

Commit

Permalink
Fix 06 to 15
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 27, 2024
1 parent cba81c8 commit 41b1ee5
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 59 deletions.
4 changes: 2 additions & 2 deletions 06_render_targets/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ static vertex_in_buffer vertices;
static kope_g5_buffer indices;
static kope_g5_texture render_target;

static const uint32_t width = 1024;
static const uint32_t height = 768;
static const uint32_t width = 800;
static const uint32_t height = 600;

static void update(void *data) {
kope_g5_render_pass_parameters parameters = {0};
Expand Down
Binary file added 06_render_targets/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 14 additions & 11 deletions 07_multiple_render_targets/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ static vertex_in_buffer vertices;
static kope_g5_buffer indices;
static kope_g5_texture render_targets[4];

static const int width = 800;
static const int height = 600;

static void update(void *data) {
kope_g5_render_pass_parameters parameters = {0};
for (uint32_t i = 0; i < 4; ++i) {
Expand Down Expand Up @@ -66,25 +69,25 @@ static void update(void *data) {
source.origin_y = 0;
source.origin_z = 0;

kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, 512, 384, 1);
kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, width / 2, height / 2, 1);

destination.origin_x = 512;
destination.origin_x = width / 2;
destination.origin_y = 0;
source.texture = &render_targets[1];

kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, 512, 384, 1);
kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, width / 2, height / 2, 1);

destination.origin_x = 0;
destination.origin_y = 384;
destination.origin_y = height / 2;
source.texture = &render_targets[2];

kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, 512, 384, 1);
kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, width / 2, height / 2, 1);

destination.origin_x = 512;
destination.origin_y = 384;
destination.origin_x = width / 2;
destination.origin_y = height / 2;
source.texture = &render_targets[3];

kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, 512, 384, 1);
kope_g5_command_list_copy_texture_to_texture(&list, &source, &destination, width / 2, height / 2, 1);

kope_g5_command_list_present(&list);

Expand All @@ -96,7 +99,7 @@ static void update(void *data) {
}

int kickstart(int argc, char **argv) {
kinc_init("Example", 1024, 768, NULL, NULL);
kinc_init("Example", width, height, NULL, NULL);
kinc_set_update_callback(update, NULL);

kope_g5_device_wishlist wishlist = {0};
Expand All @@ -108,8 +111,8 @@ int kickstart(int argc, char **argv) {

for (uint32_t i = 0; i < 4; ++i) {
kope_g5_texture_parameters texture_parameters;
texture_parameters.width = 512;
texture_parameters.height = 384;
texture_parameters.width = width / 2;
texture_parameters.height = height / 2;
texture_parameters.depth_or_array_layers = 1;
texture_parameters.mip_level_count = 1;
texture_parameters.sample_count = 1;
Expand Down
Binary file added 07_multiple_render_targets/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions 08_float_render_targets/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ static kope_g5_texture float_render_target;
static kope_g5_texture render_target; // intermediate target because D3D12 doesn't seem to like uav framebuffer access
static compute_set set;

const static int width = 1024;
const static int height = 768;
const static int width = 800;
const static int height = 600;

static void update(void *data) {
kope_g5_render_pass_parameters parameters = {0};
Expand Down Expand Up @@ -143,11 +143,16 @@ int kickstart(int argc, char **argv) {
}

compute_parameters cparams = {0};
cparams.copy_source_texture = &float_render_target;
cparams.copy_source_texture_highest_mip_level = 0;
cparams.copy_source_texture_mip_count = 1;
cparams.copy_destination_texture = &render_target;
cparams.copy_destination_texture_mip_level = 0;
cparams.copy_source_texture.texture = &float_render_target;
cparams.copy_source_texture.base_mip_level = 0;
cparams.copy_source_texture.mip_level_count = 1;
cparams.copy_source_texture.base_array_layer = 0;
cparams.copy_source_texture.array_layer_count = 1;
cparams.copy_destination_texture.texture = &render_target;
cparams.copy_destination_texture.base_mip_level = 0;
cparams.copy_destination_texture.mip_level_count = 1;
cparams.copy_destination_texture.base_array_layer = 0;
cparams.copy_destination_texture.array_layer_count = 1;
kong_create_compute_set(&device, &cparams, &set);

kinc_start();
Expand Down
Binary file added 08_float_render_targets/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions 09_depth_render_targets/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static kope_g5_texture render_target;
static kope_g5_sampler sampler;
static fs_set set;

static const uint32_t width = 1024;
static const uint32_t height = 768;
static const uint32_t width = 800;
static const uint32_t height = 600;

static void update(void *data) {
{
Expand Down Expand Up @@ -151,9 +151,11 @@ int kickstart(int argc, char **argv) {
kope_g5_device_create_sampler(&device, &sampler_params, &sampler);

fs_parameters fs_params = {0};
fs_params.fs_texture = &render_target;
fs_params.fs_texture_highest_mip_level = 0;
fs_params.fs_texture_mip_count = 1;
fs_params.fs_texture.texture = &render_target;
fs_params.fs_texture.base_mip_level = 0;
fs_params.fs_texture.mip_level_count = 1;
fs_params.fs_texture.base_array_layer = 0;
fs_params.fs_texture.array_layer_count = 1;
fs_params.fs_sampler = &sampler;
kong_create_fs_set(&device, &fs_params, &set);

Expand Down
Binary file added 09_depth_render_targets/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions 10_cubemap/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static kope_g5_texture render_target;
static kope_g5_sampler sampler;
static fs_set set;

static const uint32_t width = 1024;
static const uint32_t height = 768;
static const uint32_t width = 800;
static const uint32_t height = 600;

static void update(void *data) {
{
Expand Down Expand Up @@ -160,9 +160,11 @@ int kickstart(int argc, char **argv) {
kope_g5_device_create_sampler(&device, &sampler_params, &sampler);

fs_parameters fs_params = {0};
fs_params.fs_texture = &render_target;
fs_params.fs_texture_highest_mip_level = 0;
fs_params.fs_texture_mip_count = 1;
fs_params.fs_texture.texture = &render_target;
fs_params.fs_texture.base_mip_level = 0;
fs_params.fs_texture.mip_level_count = 1;
fs_params.fs_texture.base_array_layer = 0;
fs_params.fs_texture.array_layer_count = 1;
fs_params.fs_sampler = &sampler;
kong_create_fs_set(&device, &fs_params, &set);

Expand Down
Binary file added 10_cubemap/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion 11_instanced_rendering/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ static vertex_in_buffer vertices;
static vertex_offset_in_buffer vertices_inst;
static kope_g5_buffer indices;

static const int width = 800;
static const int height = 600;

static void update(void *data) {
kope_g5_texture *framebuffer = kope_g5_device_get_framebuffer(&device);

Expand Down Expand Up @@ -54,7 +57,7 @@ static void update(void *data) {
}

int kickstart(int argc, char **argv) {
kinc_init("Example", 1024, 768, NULL, NULL);
kinc_init("Example", width, height, NULL, NULL);
kinc_set_update_callback(update, NULL);

kope_g5_device_wishlist wishlist = {0};
Expand Down
Binary file added 11_instanced_rendering/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions 12_set_render_target_depth/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ static kope_g5_texture target_depth;
static kope_g5_sampler sampler;
static fs_set set;

static const int width = 1024;
static const int height = 768;
static const int width = 800;
static const int height = 600;

static void update(void *data) {
{
Expand Down Expand Up @@ -106,9 +106,11 @@ int kickstart(int argc, char **argv) {
kope_g5_device_create_sampler(&device, &sampler_params, &sampler);

fs_parameters set_parameters = {0};
set_parameters.fs_texture = &target_depth;
set_parameters.fs_texture_highest_mip_level = 0;
set_parameters.fs_texture_mip_count = 1;
set_parameters.fs_texture.texture = &target_depth;
set_parameters.fs_texture.base_mip_level = 0;
set_parameters.fs_texture.mip_level_count = 1;
set_parameters.fs_texture.base_array_layer = 0;
set_parameters.fs_texture.array_layer_count = 1;
set_parameters.fs_sampler = &sampler;
kong_create_fs_set(&device, &set_parameters, &set);

Expand Down
Binary file added 12_set_render_target_depth/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 19 additions & 9 deletions 13_generate_mipmaps/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ static kope_g5_sampler sampler;
static fs_set set;
static mip_set mip_sets[4];

static const int width = 800;
static const int height = 600;

static void update(void *data) {
{
kope_g5_render_pass_parameters parameters = {0};
Expand Down Expand Up @@ -100,7 +103,7 @@ static void update(void *data) {
}

int kickstart(int argc, char **argv) {
kinc_init("Example", 1024, 768, NULL, NULL);
kinc_init("Example", width, height, NULL, NULL);
kinc_set_update_callback(update, NULL);

kope_g5_device_wishlist wishlist = {0};
Expand Down Expand Up @@ -176,19 +179,26 @@ int kickstart(int argc, char **argv) {
}

fs_parameters fsparams = {0};
fsparams.fs_texture = &render_target;
fsparams.fs_texture_highest_mip_level = 0;
fsparams.fs_texture_mip_count = 5;
fsparams.fs_texture.texture = &render_target;
fsparams.fs_texture.base_mip_level = 0;
fsparams.fs_texture.mip_level_count = 5;
fsparams.fs_texture.base_array_layer = 0;
fsparams.fs_texture.array_layer_count = 1;
fsparams.fs_sampler = &sampler;
kong_create_fs_set(&device, &fsparams, &set);

for (int i = 0; i < 4; ++i) {
mip_parameters cparams = {0};
cparams.mip_source_texture = &render_target;
cparams.mip_source_texture_highest_mip_level = i;
cparams.mip_source_texture_mip_count = 1;
cparams.mip_destination_texture = &render_target;
cparams.mip_destination_texture_mip_level = i + 1;
cparams.mip_source_texture.texture = &render_target;
cparams.mip_source_texture.base_mip_level = i;
cparams.mip_source_texture.mip_level_count = 1;
cparams.mip_source_texture.base_array_layer = 0;
cparams.mip_source_texture.array_layer_count = 1;
cparams.mip_destination_texture.texture = &render_target;
cparams.mip_destination_texture.base_mip_level = i + 1;
cparams.mip_destination_texture.mip_level_count = 1;
cparams.mip_destination_texture.base_array_layer = 0;
cparams.mip_destination_texture.array_layer_count = 1;
kong_create_mip_set(&device, &cparams, &mip_sets[i]);
}

Expand Down
Binary file added 13_generate_mipmaps/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 39 additions & 10 deletions 14_set_mipmap/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ static fs_set set;
static kope_g5_buffer image_buffer0;
static kope_g5_buffer image_buffer1;

static const int width = 800;
static const int height = 600;

static bool first = true;

static void update(void *data) {
if (first) {
{
kope_g5_image_copy_buffer source = {0};
source.bytes_per_row = 512 * 4;
source.bytes_per_row = kope_g5_device_align_texture_row_bytes(&device, 512 * 4);
source.buffer = &image_buffer0;

kope_g5_image_copy_texture destination = {0};
Expand All @@ -39,7 +42,7 @@ static void update(void *data) {

{
kope_g5_image_copy_buffer source = {0};
source.bytes_per_row = 256 * 4;
source.bytes_per_row = kope_g5_device_align_texture_row_bytes(&device, 256 * 4);
source.buffer = &image_buffer1;

kope_g5_image_copy_texture destination = {0};
Expand Down Expand Up @@ -90,7 +93,7 @@ static void update(void *data) {
}

int kickstart(int argc, char **argv) {
kinc_init("Example", 1024, 768, NULL, NULL);
kinc_init("Example", width, height, NULL, NULL);
kinc_set_update_callback(update, NULL);

kope_g5_device_wishlist wishlist = {0};
Expand All @@ -102,25 +105,49 @@ int kickstart(int argc, char **argv) {

{
kope_g5_buffer_parameters buffer_parameters;
buffer_parameters.size = 512 * 512 * 4;
buffer_parameters.size = kope_g5_device_align_texture_row_bytes(&device, 512 * 4) * 512;
buffer_parameters.usage_flags = KOPE_G5_BUFFER_USAGE_CPU_WRITE;
kope_g5_device_create_buffer(&device, &buffer_parameters, &image_buffer0);

// kinc_image can not load images with row-alignment directly because stb_image doesn't support that :-(
uint32_t *image_data = (uint32_t *)malloc(512 * 4 * 512);
assert(image_data != NULL);

kinc_image_t image;
kinc_image_init_from_file(&image, kope_g5_buffer_lock(&image_buffer0), "uvtemplate.png");
kinc_image_init_from_file(&image, image_data, "uvtemplate.png");
kinc_image_destroy(&image);

uint32_t stride = kope_g5_device_align_texture_row_bytes(&device, 512 * 4) / 4;
uint32_t *gpu_image_data = (uint32_t *)kope_g5_buffer_lock(&image_buffer0);
for (int y = 0; y < 512; ++y) {
for (int x = 0; x < 512; ++x) {
gpu_image_data[y * stride + x] = image_data[y * 512 + x];
}
}
kope_g5_buffer_unlock(&image_buffer0);
}

{
kope_g5_buffer_parameters buffer_parameters;
buffer_parameters.size = 256 * 256 * 4;
buffer_parameters.size = kope_g5_device_align_texture_row_bytes(&device, 256 * 4) * 256;
buffer_parameters.usage_flags = KOPE_G5_BUFFER_USAGE_CPU_WRITE;
kope_g5_device_create_buffer(&device, &buffer_parameters, &image_buffer1);

// kinc_image can not load images with row-alignment directly because stb_image doesn't support that :-(
uint32_t *image_data = (uint32_t *)malloc(256 * 4 * 256);
assert(image_data != NULL);

kinc_image_t image;
kinc_image_init_from_file(&image, kope_g5_buffer_lock(&image_buffer1), "uvtemplate2.png");
kinc_image_init_from_file(&image, image_data, "uvtemplate2.png");
kinc_image_destroy(&image);

uint32_t stride = kope_g5_device_align_texture_row_bytes(&device, 256 * 4) / 4;
uint32_t *gpu_image_data = (uint32_t *)kope_g5_buffer_lock(&image_buffer1);
for (int y = 0; y < 256; ++y) {
for (int x = 0; x < 256; ++x) {
gpu_image_data[y * stride + x] = image_data[y * 256 + x];
}
}
kope_g5_buffer_unlock(&image_buffer1);
}

Expand Down Expand Up @@ -171,9 +198,11 @@ int kickstart(int argc, char **argv) {
}

fs_parameters fsparams = {0};
fsparams.fs_texture = &texture;
fsparams.fs_texture_highest_mip_level = 0;
fsparams.fs_texture_mip_count = 2;
fsparams.fs_texture.texture = &texture;
fsparams.fs_texture.base_mip_level = 0;
fsparams.fs_texture.mip_level_count = 2;
fsparams.fs_texture.base_array_layer = 0;
fsparams.fs_texture.array_layer_count = 1;
fsparams.fs_sampler = &sampler;
kong_create_fs_set(&device, &fsparams, &set);

Expand Down
Binary file added 14_set_mipmap/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions 15_deinterleaved_buffers/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ static kope_g5_buffer constants;
static kope_g5_sampler sampler;
static everything_set everything;

static const int width = 800;
static const int height = 600;

/* clang-format off */
static float vertices_data[] = {
-1.0,-1.0,-1.0,
Expand Down Expand Up @@ -252,7 +255,7 @@ static void update(void *data) {
}

int kickstart(int argc, char **argv) {
kinc_init("Example", 1024, 768, NULL, NULL);
kinc_init("Example", width, height, NULL, NULL);
kinc_set_update_callback(update, NULL);

kope_g5_device_wishlist wishlist = {0};
Expand Down Expand Up @@ -334,9 +337,11 @@ int kickstart(int argc, char **argv) {
{
everything_parameters parameters;
parameters.constants = &constants;
parameters.tex = &texture;
parameters.tex_highest_mip_level = 0;
parameters.tex_mip_count = 1;
parameters.tex.texture = &texture;
parameters.tex.base_mip_level = 0;
parameters.tex.mip_level_count = 1;
parameters.tex.base_array_layer = 0;
parameters.tex.array_layer_count = 1;
parameters.sam = &sampler;
kong_create_everything_set(&device, &parameters, &everything);
}
Expand Down
Binary file added 15_deinterleaved_buffers/reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 41b1ee5

Please sign in to comment.