Skip to content

Commit

Permalink
Add missing G5 constant buffer functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jan 31, 2024
1 parent bee05c3 commit b4d0aed
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 65 deletions.
36 changes: 32 additions & 4 deletions Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,41 @@ void kinc_g4_set_int(kinc_g4_constant_location_t location, int value) {
kinc_g5_constant_buffer_set_int(&computeConstantBuffer, location.impl._location.impl.computeOffset, value);
}

void kinc_g4_set_int2(kinc_g4_constant_location_t location, int value1, int value2) {}
void kinc_g4_set_int2(kinc_g4_constant_location_t location, int value1, int value2) {
if (location.impl._location.impl.vertexOffset >= 0)
kinc_g5_constant_buffer_set_int2(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2);
if (location.impl._location.impl.fragmentOffset >= 0)
kinc_g5_constant_buffer_set_int2(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2);
if (location.impl._location.impl.computeOffset >= 0)
kinc_g5_constant_buffer_set_int2(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2);
}

void kinc_g4_set_int3(kinc_g4_constant_location_t location, int value1, int value2, int value3) {}
void kinc_g4_set_int3(kinc_g4_constant_location_t location, int value1, int value2, int value3) {
if (location.impl._location.impl.vertexOffset >= 0)
kinc_g5_constant_buffer_set_int3(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2, value3);
if (location.impl._location.impl.fragmentOffset >= 0)
kinc_g5_constant_buffer_set_int3(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2, value3);
if (location.impl._location.impl.computeOffset >= 0)
kinc_g5_constant_buffer_set_int3(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2, value3);
}

void kinc_g4_set_int4(kinc_g4_constant_location_t location, int value1, int value2, int value3, int value4) {}
void kinc_g4_set_int4(kinc_g4_constant_location_t location, int value1, int value2, int value3, int value4) {
if (location.impl._location.impl.vertexOffset >= 0)
kinc_g5_constant_buffer_set_int4(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2, value3, value4);
if (location.impl._location.impl.fragmentOffset >= 0)
kinc_g5_constant_buffer_set_int4(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2, value3, value4);
if (location.impl._location.impl.computeOffset >= 0)
kinc_g5_constant_buffer_set_int4(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2, value3, value4);
}

void kinc_g4_set_ints(kinc_g4_constant_location_t location, int *values, int count) {}
void kinc_g4_set_ints(kinc_g4_constant_location_t location, int *values, int count) {
if (location.impl._location.impl.vertexOffset >= 0)
kinc_g5_constant_buffer_set_ints(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, values, count);
if (location.impl._location.impl.fragmentOffset >= 0)
kinc_g5_constant_buffer_set_ints(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, values, count);
if (location.impl._location.impl.computeOffset >= 0)
kinc_g5_constant_buffer_set_ints(&computeConstantBuffer, location.impl._location.impl.computeOffset, values, count);
}

void kinc_g4_set_float(kinc_g4_constant_location_t location, float value) {
if (location.impl._location.impl.vertexOffset >= 0)
Expand Down
122 changes: 61 additions & 61 deletions Sources/kinc/graphics5/constantbuffer.c.h
Original file line number Diff line number Diff line change
@@ -1,58 +1,77 @@
#include "constantbuffer.h"

static void setInt(uint8_t *constants, int offset, int value) {
int *ints = (int *)(&constants[offset]);
void kinc_g5_constant_buffer_set_int(kinc_g5_constant_buffer_t *buffer, int offset, int value) {
int *ints = (int *)(&buffer->data[offset]);
ints[0] = value;
}

static void setFloat(uint8_t *constants, int offset, float value) {
float *floats = (float *)(&constants[offset]);
void kinc_g5_constant_buffer_set_int2(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2) {
int *ints = (int *)(&buffer->data[offset]);
ints[0] = value1;
ints[1] = value2;
}

void kinc_g5_constant_buffer_set_int3(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3) {
int *ints = (int *)(&buffer->data[offset]);
ints[0] = value1;
ints[1] = value2;
ints[2] = value3;
}

void kinc_g5_constant_buffer_set_int4(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3, int value4) {
int *ints = (int *)(&buffer->data[offset]);
ints[0] = value1;
ints[1] = value2;
ints[2] = value3;
ints[3] = value4;
}

void kinc_g5_constant_buffer_set_ints(kinc_g5_constant_buffer_t *buffer, int offset, int *values, int count) {
int *ints = (int *)(&buffer->data[offset]);
for (int i = 0; i < count; ++i) {
ints[i] = values[i];
}
}

void kinc_g5_constant_buffer_set_float(kinc_g5_constant_buffer_t *buffer, int offset, float value) {
float *floats = (float *)(&buffer->data[offset]);
floats[0] = value;
}

static void setFloat2(uint8_t *constants, int offset, float value1, float value2) {
float *floats = (float *)(&constants[offset]);
void kinc_g5_constant_buffer_set_float2(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2) {
float *floats = (float *)(&buffer->data[offset]);
floats[0] = value1;
floats[1] = value2;
}

static void setFloat3(uint8_t *constants, int offset, float value1, float value2, float value3) {
float *floats = (float *)(&constants[offset]);
void kinc_g5_constant_buffer_set_float3(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3) {
float *floats = (float *)(&buffer->data[offset]);
floats[0] = value1;
floats[1] = value2;
floats[2] = value3;
}

static void setFloat4(uint8_t *constants, int offset, float value1, float value2, float value3, float value4) {
float *floats = (float *)(&constants[offset]);
void kinc_g5_constant_buffer_set_float4(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3, float value4) {
float *floats = (float *)(&buffer->data[offset]);
floats[0] = value1;
floats[1] = value2;
floats[2] = value3;
floats[3] = value4;
}

static void setFloats(uint8_t *constants, int offset, float *values, int count) {
float *floats = (float *)(&constants[offset]);
void kinc_g5_constant_buffer_set_floats(kinc_g5_constant_buffer_t *buffer, int offset, float *values, int count) {
float *floats = (float *)(&buffer->data[offset]);
for (int i = 0; i < count; ++i) {
floats[i] = values[i];
}
}

static void setBool(uint8_t *constants, int offset, bool value) {
int *ints = (int *)(&constants[offset]);
void kinc_g5_constant_buffer_set_bool(kinc_g5_constant_buffer_t *buffer, int offset, bool value) {
int *ints = (int *)(&buffer->data[offset]);
ints[0] = value ? 1 : 0;
}

static void setMatrix4(uint8_t *constants, int offset, kinc_matrix4x4_t *value) {
float *floats = (float *)(&constants[offset]);
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
floats[x + y * 4] = kinc_matrix4x4_get(value, x, y);
}
}
}

static void setMatrix3(uint8_t *constants, int offset, kinc_matrix3x3_t *value) {
static void set_matrix3(uint8_t *constants, int offset, kinc_matrix3x3_t *value) {
float *floats = (float *)(&constants[offset]);
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 3; ++x) {
Expand All @@ -61,52 +80,33 @@ static void setMatrix3(uint8_t *constants, int offset, kinc_matrix3x3_t *value)
}
}

void kinc_g5_constant_buffer_set_int(kinc_g5_constant_buffer_t *buffer, int offset, int value) {
setInt(buffer->data, offset, value);
}

void kinc_g5_constant_buffer_set_float(kinc_g5_constant_buffer_t *buffer, int offset, float value) {
setFloat(buffer->data, offset, value);
}

void kinc_g5_constant_buffer_set_float2(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2) {
setFloat2(buffer->data, offset, value1, value2);
}

void kinc_g5_constant_buffer_set_float3(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3) {
setFloat3(buffer->data, offset, value1, value2, value3);
}

void kinc_g5_constant_buffer_set_float4(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3, float value4) {
setFloat4(buffer->data, offset, value1, value2, value3, value4);
}

void kinc_g5_constant_buffer_set_floats(kinc_g5_constant_buffer_t *buffer, int offset, float *values, int count) {
setFloats(buffer->data, offset, values, count);
void kinc_g5_constant_buffer_set_matrix3(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix3x3_t *value) {
if (kinc_g5_transposeMat3) {
kinc_matrix3x3_t m = *value;
kinc_matrix3x3_transpose(&m);
set_matrix3(buffer->data, offset, &m);
}
else {
set_matrix3(buffer->data, offset, value);
}
}

void kinc_g5_constant_buffer_set_bool(kinc_g5_constant_buffer_t *buffer, int offset, bool value) {
setBool(buffer->data, offset, value);
static void set_matrix4(uint8_t *constants, int offset, kinc_matrix4x4_t *value) {
float *floats = (float *)(&constants[offset]);
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
floats[x + y * 4] = kinc_matrix4x4_get(value, x, y);
}
}
}

void kinc_g5_constant_buffer_set_matrix4(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix4x4_t *value) {
if (kinc_g5_transposeMat4) {
kinc_matrix4x4_t m = *value;
kinc_matrix4x4_transpose(&m);
setMatrix4(buffer->data, offset, &m);
}
else {
setMatrix4(buffer->data, offset, value);
}
}

void kinc_g5_constant_buffer_set_matrix3(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix3x3_t *value) {
if (kinc_g5_transposeMat3) {
kinc_matrix3x3_t m = *value;
kinc_matrix3x3_transpose(&m);
setMatrix3(buffer->data, offset, &m);
set_matrix4(buffer->data, offset, &m);
}
else {
setMatrix3(buffer->data, offset, value);
set_matrix4(buffer->data, offset, value);
}
}
35 changes: 35 additions & 0 deletions Sources/kinc/graphics5/constantbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,41 @@ KINC_FUNC void kinc_g5_constant_buffer_set_bool(kinc_g5_constant_buffer_t *buffe
/// <param name="value">The value to assign to the constant/uniform</param>
KINC_FUNC void kinc_g5_constant_buffer_set_int(kinc_g5_constant_buffer_t *buffer, int offset, int value);

/// <summary>
/// Assigns two integers at an offset in a constant-buffer.
/// </summary>
/// <param name="offset">The offset at which to write the data</param>
/// <param name="value1">The first value to write into the buffer</param>
/// <param name="value2">The second value to write into the buffer</param>
KINC_FUNC void kinc_g5_constant_buffer_set_int2(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2);

/// <summary>
/// Assigns three integers at an offset in a constant-buffer.
/// </summary>
/// <param name="offset">The offset at which to write the data</param>
/// <param name="value1">The first value to write into the buffer</param>
/// <param name="value2">The second value to write into the buffer</param>
/// <param name="value3">The third value to write into the buffer/param>
KINC_FUNC void kinc_g5_constant_buffer_set_int3(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3);

/// <summary>
/// Assigns four integers at an offset in a constant-buffer.
/// </summary>
/// <param name="offset">The offset at which to write the data</param>
/// <param name="value1">The first value to write into the buffer</param>
/// <param name="value2">The second value to write into the buffer</param>
/// <param name="value3">The third value to write into the buffer/param>
/// <param name="value4">The fourth value to write into the buffer</param>
KINC_FUNC void kinc_g5_constant_buffer_set_int4(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3, int value4);

/// <summary>
/// Assigns a bunch of integers at an offset in a constant-buffer.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value">The values to write into the buffer</param>
/// <param name="value">The number of values to write into the buffer</param>
KINC_FUNC void kinc_g5_constant_buffer_set_ints(kinc_g5_constant_buffer_t *buffer, int offset, int *values, int count);

/// <summary>
/// Assigns a float at an offset in a constant-buffer.
/// </summary>
Expand Down

0 comments on commit b4d0aed

Please sign in to comment.