Skip to content

Commit

Permalink
Make the bindless sample compile
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 20, 2024
1 parent 96cc866 commit 5093359
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
Binary file modified Bindless/Deployment/numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 33 additions & 25 deletions Bindless/Sources/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#ifdef SCREENSHOT
#include "../../screenshot.h"
Expand All @@ -18,7 +19,7 @@ static kope_g5_command_list list;
static vertex_in_buffer vertices;
static kope_g5_buffer indices;
static kope_g5_buffer image_buffer;
static kope_g5_texture texture;
static kope_g5_texture textures[9];
static kope_g5_sampler sampler;
static kope_g5_buffer constants;
static everything_set everything;
Expand All @@ -45,15 +46,17 @@ static void update(void *data) {
constants_type_buffer_unlock(&constants);

if (first_update) {
kope_g5_image_copy_buffer source = {0};
source.buffer = &image_buffer;
source.bytes_per_row = kope_g5_device_align_texture_row_bytes(&device, 250 * 4);
for (int i = 0; i < 9; ++i) {
kope_g5_image_copy_buffer source = {0};
source.buffer = &image_buffer;
source.bytes_per_row = kope_g5_device_align_texture_row_bytes(&device, 250 * 4);

kope_g5_image_copy_texture destination = {0};
destination.texture = &texture;
destination.mip_level = 0;
kope_g5_image_copy_texture destination = {0};
destination.texture = &textures[i];
destination.mip_level = 0;

kope_g5_command_list_copy_buffer_to_texture(&list, &source, &destination, 250, 250, 1);
kope_g5_command_list_copy_buffer_to_texture(&list, &source, &destination, 639 / 3, 642 / 3, 1);
}
first_update = false;
}

Expand Down Expand Up @@ -106,26 +109,28 @@ int kickstart(int argc, char **argv) {
kope_g5_device_create_command_list(&device, &list);

kope_g5_buffer_parameters buffer_parameters = {0};
buffer_parameters.size = kope_g5_device_align_texture_row_bytes(&device, 250 * 4) * 250;
buffer_parameters.size = kope_g5_device_align_texture_row_bytes(&device, 639 * 4) * 642;
buffer_parameters.usage_flags = KOPE_G5_BUFFER_USAGE_CPU_WRITE;
kope_g5_device_create_buffer(&device, &buffer_parameters, &image_buffer);

kinc_image_t image;
kinc_image_init_from_file_with_stride(&image, kope_g5_buffer_lock_all(&image_buffer), "parrot.png",
kope_g5_device_align_texture_row_bytes(&device, 250 * 4));
kinc_image_init_from_file_with_stride(&image, kope_g5_buffer_lock_all(&image_buffer), "numbers.png",
kope_g5_device_align_texture_row_bytes(&device, 639 * 4));
kinc_image_destroy(&image);
kope_g5_buffer_unlock(&image_buffer);

kope_g5_texture_parameters texture_parameters = {0};
texture_parameters.width = 250;
texture_parameters.height = 250;
texture_parameters.depth_or_array_layers = 1;
texture_parameters.mip_level_count = 1;
texture_parameters.sample_count = 1;
texture_parameters.dimension = KOPE_G5_TEXTURE_DIMENSION_2D;
texture_parameters.format = KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM;
texture_parameters.usage = KONG_G5_TEXTURE_USAGE_SAMPLE | KONG_G5_TEXTURE_USAGE_COPY_DST;
kope_g5_device_create_texture(&device, &texture_parameters, &texture);
for (int i = 0; i < 9; ++i) {
kope_g5_texture_parameters texture_parameters = {0};
texture_parameters.width = 639 / 3;
texture_parameters.height = 642 / 3;
texture_parameters.depth_or_array_layers = 1;
texture_parameters.mip_level_count = 1;
texture_parameters.sample_count = 1;
texture_parameters.dimension = KOPE_G5_TEXTURE_DIMENSION_2D;
texture_parameters.format = KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM;
texture_parameters.usage = KONG_G5_TEXTURE_USAGE_SAMPLE | KONG_G5_TEXTURE_USAGE_COPY_DST;
kope_g5_device_create_texture(&device, &texture_parameters, &textures[i]);
}

kope_g5_sampler_parameters sampler_parameters = {0};
sampler_parameters.address_mode_u = KOPE_G5_ADDRESS_MODE_REPEAT;
Expand Down Expand Up @@ -183,10 +188,13 @@ int kickstart(int argc, char **argv) {
{
everything_parameters parameters = {0};
parameters.constants = &constants;
parameters.tex.texture = &texture;
parameters.tex.base_mip_level = 0;
parameters.tex.mip_level_count = 1;
parameters.tex.array_layer_count = 1;
parameters.textures = calloc(9, sizeof(kope_g5_texture_view));
for (int i = 0; i < 9; ++i) {
parameters.textures[i].texture = &textures[i];
parameters.textures[i].base_mip_level = 0;
parameters.textures[i].mip_level_count = 1;
parameters.textures[i].array_layer_count = 1;
}
parameters.sam = &sampler;
kong_create_everything_set(&device, &parameters, &everything);
}
Expand Down

0 comments on commit 5093359

Please sign in to comment.