diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.c b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.c index ed4bcdec3..4deab739c 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.c +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.c @@ -22,31 +22,36 @@ static uint8_t constantsMemory[1024 * 4]; static int getMultipleOf16(int value) { int ret = 16; - while (ret < value) ret += 16; + while (ret < value) + ret += 16; return ret; } static void setInt(uint8_t *constants, uint32_t offset, uint32_t size, int value) { - if (size == 0) return; + if (size == 0) + return; int *ints = (int *)&constants[offset]; ints[0] = value; } static void setFloat(uint8_t *constants, uint32_t offset, uint32_t size, float value) { - if (size == 0) return; + if (size == 0) + return; float *floats = (float *)&constants[offset]; floats[0] = value; } static void setFloat2(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2) { - if (size == 0) return; + if (size == 0) + return; float *floats = (float *)&constants[offset]; floats[0] = value1; floats[1] = value2; } static void setFloat3(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3) { - if (size == 0) return; + if (size == 0) + return; float *floats = (float *)&constants[offset]; floats[0] = value1; floats[1] = value2; @@ -54,7 +59,8 @@ static void setFloat3(uint8_t *constants, uint32_t offset, uint32_t size, float } static void setFloat4(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3, float value4) { - if (size == 0) return; + if (size == 0) + return; float *floats = (float *)&constants[offset]; floats[0] = value1; floats[1] = value2; @@ -63,7 +69,8 @@ static void setFloat4(uint8_t *constants, uint32_t offset, uint32_t size, float } static void setFloats(uint8_t *constants, uint32_t offset, uint32_t size, uint8_t columns, uint8_t rows, float *values, int count) { - if (size == 0) return; + if (size == 0) + return; float *floats = (float *)&constants[offset]; if (columns == 4 && rows == 4) { for (int i = 0; i < count / 16 && i < (int)size / 4; ++i) { @@ -100,13 +107,15 @@ static void setFloats(uint8_t *constants, uint32_t offset, uint32_t size, uint8_ } static void setBool(uint8_t *constants, uint32_t offset, uint32_t size, bool value) { - if (size == 0) return; + if (size == 0) + return; int *ints = (int *)&constants[offset]; ints[0] = value ? 1 : 0; } static void setMatrix4(uint8_t *constants, uint32_t offset, uint32_t size, kinc_matrix4x4_t *value) { - if (size == 0) return; + if (size == 0) + return; float *floats = (float *)&constants[offset]; for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { @@ -116,7 +125,8 @@ static void setMatrix4(uint8_t *constants, uint32_t offset, uint32_t size, kinc_ } static void setMatrix3(uint8_t *constants, uint32_t offset, uint32_t size, kinc_matrix3x3_t *value) { - if (size == 0) return; + if (size == 0) + return; float *floats = (float *)&constants[offset]; for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { @@ -129,13 +139,15 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le unsigned index = 0; uint8_t *data = (uint8_t *)_data; +#ifndef KINC_KONG memset(&shader->impl.attributes, 0, sizeof(shader->impl.attributes)); int attributesCount = data[index++]; for (int i = 0; i < attributesCount; ++i) { unsigned char name[256]; for (unsigned i2 = 0; i2 < 255; ++i2) { name[i2] = data[index++]; - if (name[i2] == 0) break; + if (name[i2] == 0) + break; } shader->impl.attributes[i].hash = kinc_internal_hash_name(name); shader->impl.attributes[i].index = data[index++]; @@ -147,7 +159,8 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le unsigned char name[256]; for (unsigned i2 = 0; i2 < 255; ++i2) { name[i2] = data[index++]; - if (name[i2] == 0) break; + if (name[i2] == 0) + break; } shader->impl.textures[i].hash = kinc_internal_hash_name(name); shader->impl.textures[i].index = data[index++]; @@ -160,7 +173,8 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le unsigned char name[256]; for (unsigned i2 = 0; i2 < 255; ++i2) { name[i2] = data[index++]; - if (name[i2] == 0) break; + if (name[i2] == 0) + break; } kinc_compute_internal_shader_constant_t constant; constant.hash = kinc_internal_hash_name(name); @@ -176,6 +190,7 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le shader->impl.constants[i] = constant; shader->impl.constantsSize = constant.offset + constant.size; } +#endif shader->impl.length = (int)(length - index); shader->impl.data = (uint8_t *)malloc(shader->impl.length); @@ -190,6 +205,7 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le return; } +#ifndef KINC_KONG D3D11_BUFFER_DESC desc; desc.ByteWidth = getMultipleOf16(shader->impl.constantsSize); desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; @@ -198,6 +214,7 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le desc.MiscFlags = 0; desc.StructureByteStride = 0; kinc_microsoft_affirm(dx_ctx.device->lpVtbl->CreateBuffer(dx_ctx.device, &desc, NULL, &shader->impl.constantBuffer)); +#endif } void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) {} @@ -220,6 +237,7 @@ static kinc_internal_hash_index_t *findTextureUnit(kinc_internal_hash_index_t *u return NULL; } +#ifndef KINC_KONG kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { kinc_compute_constant_location_t location; @@ -250,7 +268,8 @@ kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_sh char unitName[64]; int unitOffset = 0; size_t len = strlen(name); - if (len > 63) len = 63; + if (len > 63) + len = 63; strncpy(unitName, name, len + 1); if (unitName[len - 1] == ']') { // Check for array - mySampler[2] unitOffset = (int)(unitName[len - 2] - '0'); // Array index is unit offset @@ -280,6 +299,7 @@ kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_sh } return unit; } +#endif void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) { setBool(constantsMemory, location.impl.offset, location.impl.size, value); @@ -350,9 +370,10 @@ void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, void kinc_compute_set_shader(kinc_compute_shader_t *shader) { dx_ctx.context->lpVtbl->CSSetShader(dx_ctx.context, (ID3D11ComputeShader *)shader->impl.shader, NULL, 0); - +#ifndef KINC_KONG dx_ctx.context->lpVtbl->UpdateSubresource(dx_ctx.context, (ID3D11Resource *)shader->impl.constantBuffer, 0, NULL, constantsMemory, 0, 0); dx_ctx.context->lpVtbl->CSSetConstantBuffers(dx_ctx.context, 0, 1, &shader->impl.constantBuffer); +#endif } void kinc_compute(int x, int y, int z) { diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.h index 3b826adb5..c263892b2 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.h @@ -28,14 +28,16 @@ typedef struct { } kinc_compute_internal_shader_constant_t; typedef struct { +#ifndef KINC_KONG kinc_compute_internal_shader_constant_t constants[64]; int constantsSize; kinc_internal_hash_index_t attributes[64]; kinc_internal_hash_index_t textures[64]; + struct ID3D11Buffer *constantBuffer; +#endif void *shader; uint8_t *data; int length; - struct ID3D11Buffer *constantBuffer; } kinc_compute_shader_impl_t; #ifdef __cplusplus diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h index f8c120a7d..78a07c681 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h @@ -91,6 +91,7 @@ static D3D11_STENCIL_OP get_stencil_action(kinc_g4_stencil_action_t action) { } void kinc_internal_set_constants(void) { +#ifndef KINC_KONG if (currentPipeline->vertex_shader->impl.constantsSize > 0) { dx_ctx.context->lpVtbl->UpdateSubresource(dx_ctx.context, (ID3D11Resource *)currentPipeline->impl.vertexConstantBuffer, 0, NULL, vertexConstants, 0, 0); dx_ctx.context->lpVtbl->VSSetConstantBuffers(dx_ctx.context, 0, 1, ¤tPipeline->impl.vertexConstantBuffer); @@ -115,6 +116,7 @@ void kinc_internal_set_constants(void) { 0); dx_ctx.context->lpVtbl->DSSetConstantBuffers(dx_ctx.context, 0, 1, ¤tPipeline->impl.tessEvalConstantBuffer); } +#endif } void kinc_g4_pipeline_init(struct kinc_g4_pipeline *state) { @@ -209,6 +211,7 @@ void kinc_internal_pipeline_rebind() { } } +#ifndef KINC_KONG static kinc_internal_shader_constant_t *findConstant(kinc_internal_shader_constant_t *constants, uint32_t hash) { for (int i = 0; i < 64; ++i) { if (constants[i].hash == hash) { @@ -368,6 +371,7 @@ kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(struct kinc_g4_pipeline return unit; } +#endif static char stringCache[1024]; static int stringCacheIndex = 0; @@ -432,6 +436,7 @@ static void createRenderTargetBlendDesc(struct kinc_g4_pipeline *pipe, D3D11_REN } void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { +#ifndef KINC_KONG if (state->vertex_shader->impl.constantsSize > 0) { D3D11_BUFFER_DESC desc; desc.ByteWidth = (UINT)get_multiple_of_16(state->vertex_shader->impl.constantsSize); @@ -482,6 +487,7 @@ void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { desc.StructureByteStride = 0; kinc_microsoft_affirm(dx_ctx.device->lpVtbl->CreateBuffer(dx_ctx.device, &desc, NULL, &state->impl.tessEvalConstantBuffer)); } +#endif int all = 0; for (int stream = 0; state->input_layout[stream] != NULL; ++stream) { @@ -495,14 +501,21 @@ void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { } } +#ifndef KINC_KONG bool used[usedCount]; for (int i = 0; i < usedCount; ++i) used[i] = false; for (int i = 0; i < 64; ++i) { used[state->vertex_shader->impl.attributes[i].index] = true; } +#endif stringCacheIndex = 0; D3D11_INPUT_ELEMENT_DESC *vertexDesc = (D3D11_INPUT_ELEMENT_DESC *)alloca(sizeof(D3D11_INPUT_ELEMENT_DESC) * all); + +#ifdef KINC_KONG +#define getAttributeLocation(a, b, c) index +#endif + int i = 0; for (int stream = 0; state->input_layout[stream] != NULL; ++stream) { for (int index = 0; index < state->input_layout[stream]->size; ++index) { diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h index e8e40f3f9..bdd5a1ef6 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h @@ -12,6 +12,7 @@ void kinc_g4_shader_init(kinc_g4_shader_t *shader, void *_data, size_t length, k uint8_t *data = (uint8_t *)_data; shader->impl.type = (int)type; +#ifndef KINC_KONG memset(&shader->impl.attributes, 0, sizeof(shader->impl.attributes)); int attributesCount = data[index++]; for (int i = 0; i < attributesCount; ++i) { @@ -62,6 +63,7 @@ void kinc_g4_shader_init(kinc_g4_shader_t *shader, void *_data, size_t length, k shader->impl.constants[i] = constant; shader->impl.constantsSize = constant.offset + constant.size; } +#endif shader->impl.length = (int)(length - index); shader->impl.data = (uint8_t *)malloc(shader->impl.length); diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h index 3eeb9dd5a..2e56b6dbe 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h @@ -18,10 +18,12 @@ typedef struct { } kinc_internal_shader_constant_t; typedef struct { +#ifndef KINC_KONG kinc_internal_shader_constant_t constants[64]; int constantsSize; kinc_internal_hash_index_t attributes[64]; kinc_internal_hash_index_t textures[64]; +#endif void *shader; uint8_t *data; int length; diff --git a/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h index dcc51c88e..291e0623d 100644 --- a/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h +++ b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h @@ -37,6 +37,7 @@ void kinc_g5_pipeline_destroy(kinc_g5_pipeline_t *pipe) { kinc_g4_pipeline_destroy(&pipe->impl.pipe); } +#ifndef KINC_KONG kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipeline_t *pipe, const char *name) { kinc_g5_constant_location_t location; location.impl.location = kinc_g4_pipeline_get_constant_location(&pipe->impl.pipe, name); @@ -52,6 +53,7 @@ kinc_g5_texture_unit_t kinc_g5_pipeline_get_texture_unit(kinc_g5_pipeline_t *pip return g5_unit; } +#endif void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { for (int i = 0; i < 16; ++i) { diff --git a/Sources/kinc/compute/compute.h b/Sources/kinc/compute/compute.h index 4833a695a..43f09e57e 100644 --- a/Sources/kinc/compute/compute.h +++ b/Sources/kinc/compute/compute.h @@ -47,6 +47,7 @@ KINC_FUNC void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *sou /// The shader-object to destroy KINC_FUNC void kinc_compute_shader_destroy(kinc_compute_shader_t *shader); +#ifndef KINC_KONG /// /// Finds the location of a constant/uniform inside of a shader. /// @@ -62,6 +63,7 @@ KINC_FUNC kinc_compute_constant_location_t kinc_compute_shader_get_constant_loca /// The texture-name to look for /// The found texture-unit KINC_FUNC kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name); +#endif #ifdef KORE_OPENGL typedef struct kinc_shader_storage_buffer { diff --git a/Sources/kinc/graphics1/graphics.c b/Sources/kinc/graphics1/graphics.c index b6256b336..809593d41 100644 --- a/Sources/kinc/graphics1/graphics.c +++ b/Sources/kinc/graphics1/graphics.c @@ -8,10 +8,16 @@ #include #include +#ifdef KINC_KONG +#include +#endif + +#ifndef KINC_KONG static kinc_g4_shader_t vertexShader; static kinc_g4_shader_t fragmentShader; static kinc_g4_pipeline_t pipeline; static kinc_g4_texture_unit_t tex; +#endif static kinc_g4_vertex_buffer_t vb; static kinc_g4_index_buffer_t ib; static kinc_g4_texture_t texture; @@ -30,8 +36,15 @@ void kinc_g1_end(void) { kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0xff000000, 0.0f, 0); +#ifdef KINC_KONG + kinc_g4_set_pipeline(&kinc_g1_pipeline); +#else kinc_g4_set_pipeline(&pipeline); +#endif + +#ifndef KINC_KONG kinc_g4_set_texture(tex, &texture); +#endif kinc_g4_set_vertex_buffer(&vb); kinc_g4_set_index_buffer(&ib); kinc_g4_draw_indexed_vertices(); @@ -44,6 +57,7 @@ void kinc_g1_init(int width, int height) { kinc_internal_g1_w = width; kinc_internal_g1_h = height; +#ifndef KINC_KONG { kinc_file_reader_t file; kinc_file_reader_open(&file, "g1.vert", KINC_FILE_TYPE_ASSET); @@ -76,6 +90,7 @@ void kinc_g1_init(int width, int height) { kinc_g4_pipeline_compile(&pipeline); tex = kinc_g4_pipeline_get_texture_unit(&pipeline, "texy"); +#endif kinc_g4_texture_init(&texture, width, height, KINC_IMAGE_FORMAT_RGBA32); kinc_internal_g1_tex_width = texture.tex_width; @@ -93,7 +108,11 @@ void kinc_g1_init(int width, int height) { float xAspect = (float)width / texture.tex_width; float yAspect = (float)height / texture.tex_height; +#ifdef KINC_KONG + kinc_g4_vertex_buffer_init(&vb, 4, &kinc_g1_vertex_in_structure, KINC_G4_USAGE_STATIC, 0); +#else kinc_g4_vertex_buffer_init(&vb, 4, &structure, KINC_G4_USAGE_STATIC, 0); +#endif float *v = kinc_g4_vertex_buffer_lock_all(&vb); { int i = 0; diff --git a/Sources/kinc/graphics4/pipeline.h b/Sources/kinc/graphics4/pipeline.h index d788a3706..b74da371a 100644 --- a/Sources/kinc/graphics4/pipeline.h +++ b/Sources/kinc/graphics4/pipeline.h @@ -135,6 +135,7 @@ KINC_FUNC void kinc_g4_pipeline_destroy(kinc_g4_pipeline_t *pipeline); /// The pipeline to compile KINC_FUNC void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *pipeline); +#ifndef KINC_KONG /// /// Searches for a constant/uniform and returns a constant-location which can be used to change the constant/uniform. /// @@ -150,6 +151,7 @@ KINC_FUNC kinc_g4_constant_location_t kinc_g4_pipeline_get_constant_location(kin /// The name of the texture-declaration to search for /// The texture-unit of the texture-declaration KINC_FUNC kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(kinc_g4_pipeline_t *pipeline, const char *name); +#endif void kinc_g4_internal_set_pipeline(kinc_g4_pipeline_t *pipeline); void kinc_g4_internal_pipeline_set_defaults(kinc_g4_pipeline_t *pipeline); diff --git a/Sources/kinc/graphics5/pipeline.h b/Sources/kinc/graphics5/pipeline.h index 3531090bd..f8a20ea2a 100644 --- a/Sources/kinc/graphics5/pipeline.h +++ b/Sources/kinc/graphics5/pipeline.h @@ -139,6 +139,7 @@ KINC_FUNC void kinc_g5_pipeline_destroy(kinc_g5_pipeline_t *pipeline); /// The pipeline to compile KINC_FUNC void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipeline); +#ifndef KINC_KONG /// /// Searches for a constant/uniform and returns a constant-location which can be used to change the constant/uniform. /// @@ -154,6 +155,7 @@ KINC_FUNC kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kin /// The name of the texture-declaration to search for /// The texture-unit of the texture-declaration KINC_FUNC kinc_g5_texture_unit_t kinc_g5_pipeline_get_texture_unit(kinc_g5_pipeline_t *pipeline, const char *name); +#endif /// /// Initializes a compute-pipeline.