Skip to content

Commit

Permalink
Add some validation for copy_texture_to_texture
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 17, 2024
1 parent 663d43d commit 10a89e8
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 159 deletions.
5 changes: 5 additions & 0 deletions Sources/kope/graphics5/commandlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <kope/vulkan/commandlist_functions.h>
#endif

#include <assert.h>

void kope_g5_command_list_copy_buffer_to_texture(kope_g5_command_list *list, const kope_g5_image_copy_buffer *source,
const kope_g5_image_copy_texture *destination, uint32_t width, uint32_t height,
uint32_t depth_or_array_layers) {
Expand All @@ -17,6 +19,9 @@ void kope_g5_command_list_copy_buffer_to_texture(kope_g5_command_list *list, con
void kope_g5_command_list_copy_texture_to_texture(kope_g5_command_list *list, const kope_g5_image_copy_texture *source,
const kope_g5_image_copy_texture *destination, uint32_t width, uint32_t height,
uint32_t depth_or_array_layers) {
#ifdef KOPE_G5_VALIDATION
assert(source->texture->validation_format == destination->texture->validation_format);
#endif
KOPE_G5_CALL6(command_list_copy_texture_to_texture, list, source, destination, width, height, depth_or_array_layers);
}

Expand Down
110 changes: 2 additions & 108 deletions Sources/kope/graphics5/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void kope_g5_device_create_texture(kope_g5_device *device, const kope_g5_texture
if (kope_g5_texture_format_is_depth(parameters->format)) {
assert(parameters->dimension != KOPE_G5_TEXTURE_DIMENSION_3D);
}

texture->validation_format = parameters->format;
#endif
KOPE_G5_CALL3(device_create_texture, device, parameters, texture);
}
Expand All @@ -47,114 +49,6 @@ void kope_g5_device_execute_command_list(kope_g5_device *device, kope_g5_command
KOPE_G5_CALL2(device_execute_command_list, device, list);
}

uint32_t kope_g5_texture_format_byte_size(kope_g5_texture_format format) {
switch (format) {
case KOPE_G5_TEXTURE_FORMAT_R8_UNORM:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R8_SNORM:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R8_UINT:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R8_SINT:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R16_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R16_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R16_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG8_UNORM:
return 2;
case KOPE_G5_TEXTURE_FORMAT_RG8_SNORM:
return 2;
case KOPE_G5_TEXTURE_FORMAT_RG8_UINT:
return 2;
case KOPE_G5_TEXTURE_FORMAT_RG8_SINT:
return 2;
case KOPE_G5_TEXTURE_FORMAT_R32_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R32_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R32_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG16_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG16_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG16_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM_SRGB:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_SNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_BGRA8_UNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_BGRA8_UNORM_SRGB:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGB9E5U_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGB10A2_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGB10A2_UNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG11B10U_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG32_UINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RG32_SINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RG32_FLOAT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA16_UINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA16_SINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA16_FLOAT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA32_UINT:
return 16;
case KOPE_G5_TEXTURE_FORMAT_RGBA32_SINT:
return 16;
case KOPE_G5_TEXTURE_FORMAT_RGBA32_FLOAT:
return 16;
// case KOPE_G5_TEXTURE_FORMAT_STENCIL8:
// return 1;
case KOPE_G5_TEXTURE_FORMAT_DEPTH16_UNORM:
return 2;
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_NOTHING8:
return 4;
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_STENCIL8:
return 4;
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT_STENCIL8_NOTHING24:
return 8;
}

assert(false);
return 4;
}

bool kope_g5_texture_format_is_depth(kope_g5_texture_format format) {
switch (format) {
// case KOPE_G5_TEXTURE_FORMAT_STENCIL8:
// return 1;
case KOPE_G5_TEXTURE_FORMAT_DEPTH16_UNORM:
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_NOTHING8:
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_STENCIL8:
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT:
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT_STENCIL8_NOTHING24:
return true;
}
return false;
}

void kope_g5_device_create_sampler(kope_g5_device *device, const kope_g5_sampler_parameters *parameters, kope_g5_sampler *sampler) {
KOPE_G5_CALL3(device_create_sampler, device, parameters, sampler);
}
Expand Down
52 changes: 1 addition & 51 deletions Sources/kope/graphics5/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "buffer.h"
#include "commandlist.h"
#include "sampler.h"
#include "textureformat.h"

#ifdef KOPE_DIRECT3D12
#include <kope/direct3d12/device_structs.h>
Expand Down Expand Up @@ -57,57 +58,6 @@ KOPE_FUNC void kope_g5_device_create_buffer(kope_g5_device *device, const kope_g

typedef enum kope_g5_texture_dimension { KOPE_G5_TEXTURE_DIMENSION_1D, KOPE_G5_TEXTURE_DIMENSION_2D, KOPE_G5_TEXTURE_DIMENSION_3D } kope_g5_texture_dimension;

typedef enum kope_g5_texture_format {
KOPE_G5_TEXTURE_FORMAT_R8_UNORM,
KOPE_G5_TEXTURE_FORMAT_R8_SNORM,
KOPE_G5_TEXTURE_FORMAT_R8_UINT,
KOPE_G5_TEXTURE_FORMAT_R8_SINT,
KOPE_G5_TEXTURE_FORMAT_R16_UINT,
KOPE_G5_TEXTURE_FORMAT_R16_SINT,
KOPE_G5_TEXTURE_FORMAT_R16_FLOAT,
KOPE_G5_TEXTURE_FORMAT_RG8_UNORM,
KOPE_G5_TEXTURE_FORMAT_RG8_SNORM,
KOPE_G5_TEXTURE_FORMAT_RG8_UINT,
KOPE_G5_TEXTURE_FORMAT_RG8_SINT,
KOPE_G5_TEXTURE_FORMAT_R32_UINT,
KOPE_G5_TEXTURE_FORMAT_R32_SINT,
KOPE_G5_TEXTURE_FORMAT_R32_FLOAT,
KOPE_G5_TEXTURE_FORMAT_RG16_UINT,
KOPE_G5_TEXTURE_FORMAT_RG16_SINT,
KOPE_G5_TEXTURE_FORMAT_RG16_FLOAT,
KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM,
KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM_SRGB,
KOPE_G5_TEXTURE_FORMAT_RGBA8_SNORM,
KOPE_G5_TEXTURE_FORMAT_RGBA8_UINT,
KOPE_G5_TEXTURE_FORMAT_RGBA8_SINT,
KOPE_G5_TEXTURE_FORMAT_BGRA8_UNORM,
KOPE_G5_TEXTURE_FORMAT_BGRA8_UNORM_SRGB,
KOPE_G5_TEXTURE_FORMAT_RGB9E5U_FLOAT,
KOPE_G5_TEXTURE_FORMAT_RGB10A2_UINT,
KOPE_G5_TEXTURE_FORMAT_RGB10A2_UNORM,
KOPE_G5_TEXTURE_FORMAT_RG11B10U_FLOAT,
KOPE_G5_TEXTURE_FORMAT_RG32_UINT,
KOPE_G5_TEXTURE_FORMAT_RG32_SINT,
KOPE_G5_TEXTURE_FORMAT_RG32_FLOAT,
KOPE_G5_TEXTURE_FORMAT_RGBA16_UINT,
KOPE_G5_TEXTURE_FORMAT_RGBA16_SINT,
KOPE_G5_TEXTURE_FORMAT_RGBA16_FLOAT,
KOPE_G5_TEXTURE_FORMAT_RGBA32_UINT,
KOPE_G5_TEXTURE_FORMAT_RGBA32_SINT,
KOPE_G5_TEXTURE_FORMAT_RGBA32_FLOAT,
// KOPE_G5_TEXTURE_FORMAT_STENCIL8, // not available in d3d12
KOPE_G5_TEXTURE_FORMAT_DEPTH16_UNORM,
KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_NOTHING8,
KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_STENCIL8,
KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT,
KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT_STENCIL8_NOTHING24,
// TODO: compressed formats
} kope_g5_texture_format;

uint32_t kope_g5_texture_format_byte_size(kope_g5_texture_format format);

bool kope_g5_texture_format_is_depth(kope_g5_texture_format format);

typedef enum kope_g5_texture_usage {
KONG_G5_TEXTURE_USAGE_COPY_SRC = 0x01,
KONG_G5_TEXTURE_USAGE_COPY_DST = 0x02,
Expand Down
1 change: 1 addition & 0 deletions Sources/kope/graphics5/g5unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
#include "graphics.c"
#include "sampler.c"
#include "texture.c"
#include "textureformat.c"
4 changes: 4 additions & 0 deletions Sources/kope/graphics5/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <kope/global.h>

#include "api.h"
#include "textureformat.h"

#ifdef KOPE_DIRECT3D12
#include <kope/direct3d12/texture_structs.h>
Expand All @@ -18,6 +19,9 @@ extern "C" {
#endif

typedef struct kope_g5_texture {
#ifdef KOPE_G5_VALIDATION
kope_g5_texture_format validation_format;
#endif
KOPE_G5_IMPL(texture);
} kope_g5_texture;

Expand Down
111 changes: 111 additions & 0 deletions Sources/kope/graphics5/textureformat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "textureformat.h"

#include <assert.h>

uint32_t kope_g5_texture_format_byte_size(kope_g5_texture_format format) {
switch (format) {
case KOPE_G5_TEXTURE_FORMAT_R8_UNORM:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R8_SNORM:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R8_UINT:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R8_SINT:
return 1;
case KOPE_G5_TEXTURE_FORMAT_R16_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R16_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R16_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG8_UNORM:
return 2;
case KOPE_G5_TEXTURE_FORMAT_RG8_SNORM:
return 2;
case KOPE_G5_TEXTURE_FORMAT_RG8_UINT:
return 2;
case KOPE_G5_TEXTURE_FORMAT_RG8_SINT:
return 2;
case KOPE_G5_TEXTURE_FORMAT_R32_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R32_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_R32_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG16_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG16_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG16_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM_SRGB:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_SNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGBA8_SINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_BGRA8_UNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_BGRA8_UNORM_SRGB:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGB9E5U_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGB10A2_UINT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RGB10A2_UNORM:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG11B10U_FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_RG32_UINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RG32_SINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RG32_FLOAT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA16_UINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA16_SINT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA16_FLOAT:
return 8;
case KOPE_G5_TEXTURE_FORMAT_RGBA32_UINT:
return 16;
case KOPE_G5_TEXTURE_FORMAT_RGBA32_SINT:
return 16;
case KOPE_G5_TEXTURE_FORMAT_RGBA32_FLOAT:
return 16;
// case KOPE_G5_TEXTURE_FORMAT_STENCIL8:
// return 1;
case KOPE_G5_TEXTURE_FORMAT_DEPTH16_UNORM:
return 2;
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_NOTHING8:
return 4;
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_STENCIL8:
return 4;
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT:
return 4;
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT_STENCIL8_NOTHING24:
return 8;
}

assert(false);
return 4;
}

bool kope_g5_texture_format_is_depth(kope_g5_texture_format format) {
switch (format) {
// case KOPE_G5_TEXTURE_FORMAT_STENCIL8:
// return 1;
case KOPE_G5_TEXTURE_FORMAT_DEPTH16_UNORM:
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_NOTHING8:
case KOPE_G5_TEXTURE_FORMAT_DEPTH24PLUS_STENCIL8:
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT:
case KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT_STENCIL8_NOTHING24:
return true;
}
return false;
}
Loading

0 comments on commit 10a89e8

Please sign in to comment.