Skip to content

Commit

Permalink
Merge pull request KhronosGroup#2123 from piegfx/main
Browse files Browse the repository at this point in the history
Implement set_scalar functions in the specialization constants C API
  • Loading branch information
HansKristian-Work authored Mar 29, 2023
2 parents 09e60d7 + a3b5cdc commit 8e64f8e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ if (SPIRV_CROSS_STATIC)
endif()

set(spirv-cross-abi-major 0)
set(spirv-cross-abi-minor 55)
set(spirv-cross-abi-minor 56)
set(spirv-cross-abi-patch 0)

if (SPIRV_CROSS_SHARED)
Expand Down
45 changes: 45 additions & 0 deletions spirv_cross_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,51 @@ spvc_type_id spvc_constant_get_type(spvc_constant constant)
return constant->constant_type;
}

void spvc_constant_set_scalar_fp16(spvc_constant constant, unsigned column, unsigned row, unsigned short value)
{
constant->m.c[column].r[row].u32 = value;
}

void spvc_constant_set_scalar_fp32(spvc_constant constant, unsigned column, unsigned row, float value)
{
constant->m.c[column].r[row].f32 = value;
}

void spvc_constant_set_scalar_fp64(spvc_constant constant, unsigned column, unsigned row, double value)
{
constant->m.c[column].r[row].f64 = value;
}

void spvc_constant_set_scalar_u32(spvc_constant constant, unsigned column, unsigned row, unsigned value)
{
constant->m.c[column].r[row].u32 = value;
}

void spvc_constant_set_scalar_i32(spvc_constant constant, unsigned column, unsigned row, int value)
{
constant->m.c[column].r[row].i32 = value;
}

void spvc_constant_set_scalar_u16(spvc_constant constant, unsigned column, unsigned row, unsigned short value)
{
constant->m.c[column].r[row].u32 = uint32_t(value);
}

void spvc_constant_set_scalar_i16(spvc_constant constant, unsigned column, unsigned row, signed short value)
{
constant->m.c[column].r[row].u32 = uint32_t(value);
}

void spvc_constant_set_scalar_u8(spvc_constant constant, unsigned column, unsigned row, unsigned char value)
{
constant->m.c[column].r[row].u32 = uint32_t(value);
}

void spvc_constant_set_scalar_i8(spvc_constant constant, unsigned column, unsigned row, signed char value)
{
constant->m.c[column].r[row].u32 = uint32_t(value);
}

spvc_bool spvc_compiler_get_binary_offset_for_decoration(spvc_compiler compiler, spvc_variable_id id,
SpvDecoration decoration,
unsigned *word_offset)
Expand Down
15 changes: 14 additions & 1 deletion spirv_cross_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" {
/* Bumped if ABI or API breaks backwards compatibility. */
#define SPVC_C_API_VERSION_MAJOR 0
/* Bumped if APIs or enumerations are added in a backwards compatible way. */
#define SPVC_C_API_VERSION_MINOR 55
#define SPVC_C_API_VERSION_MINOR 56
/* Bumped if internal implementation details change. */
#define SPVC_C_API_VERSION_PATCH 0

Expand Down Expand Up @@ -1049,6 +1049,19 @@ SPVC_PUBLIC_API int spvc_constant_get_scalar_i8(spvc_constant constant, unsigned
SPVC_PUBLIC_API void spvc_constant_get_subconstants(spvc_constant constant, const spvc_constant_id **constituents, size_t *count);
SPVC_PUBLIC_API spvc_type_id spvc_constant_get_type(spvc_constant constant);

/*
* C implementation of the C++ api.
*/
SPVC_PUBLIC_API void spvc_constant_set_scalar_fp16(spvc_constant constant, unsigned column, unsigned row, unsigned short value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_fp32(spvc_constant constant, unsigned column, unsigned row, float value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_fp64(spvc_constant constant, unsigned column, unsigned row, double value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_u32(spvc_constant constant, unsigned column, unsigned row, unsigned value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_i32(spvc_constant constant, unsigned column, unsigned row, int value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_u16(spvc_constant constant, unsigned column, unsigned row, unsigned short value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_i16(spvc_constant constant, unsigned column, unsigned row, signed short value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_u8(spvc_constant constant, unsigned column, unsigned row, unsigned char value);
SPVC_PUBLIC_API void spvc_constant_set_scalar_i8(spvc_constant constant, unsigned column, unsigned row, signed char value);

/*
* Misc reflection
* Maps to C++ API.
Expand Down

0 comments on commit 8e64f8e

Please sign in to comment.