Skip to content

Commit

Permalink
Merge branch 'main' of ssh://github.com/Kode/Kinc
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 14, 2023
2 parents ce9b943 + fbc77e4 commit a7e50d2
Show file tree
Hide file tree
Showing 38 changed files with 270 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ void kinc_g4_internal_init(void) {
#endif
HRESULT result = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION,
&dx_ctx.device, &featureLevel, &dx_ctx.context);

#ifdef _DEBUG
if (result == E_FAIL || result == DXGI_ERROR_SDK_COMPONENT_MISSING) {
kinc_log(KINC_LOG_LEVEL_WARNING, "%s", "Failed to create device with D3D11_CREATE_DEVICE_DEBUG, trying without");
flags &= ~D3D11_CREATE_DEVICE_DEBUG;
result = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION,
&dx_ctx.device, &featureLevel, &dx_ctx.context);
}
#endif

if (result != S_OK) {
kinc_log(KINC_LOG_LEVEL_WARNING, "%s", "Falling back to the WARP driver, things will be slow.");
kinc_microsoft_affirm(D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_WARP, NULL, flags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,19 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer) {
kinc_internal_g4_index_buffer_set(buffer);
}

#ifdef KINC_KONG
void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit);

void kinc_g4_set_texture(uint32_t unit, struct kinc_g4_texture *texture) {
kinc_internal_texture_set(texture, unit);
}
#else
void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit);

void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture) {
kinc_internal_texture_set(texture, unit);
}
#endif

void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture) {}

Expand Down Expand Up @@ -829,3 +837,5 @@ bool kinc_g4_supports_non_pow2_textures() {
bool kinc_g4_render_targets_inverted_y(void) {
return false;
}

void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifdef KINC_KONG

#include <kinc/graphics4/constantbuffer.h>

#include "Direct3D9.h"

void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) {
buffer->impl.size = size;
buffer->impl.last_start = 0;
buffer->impl.last_size = size;
}

void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) {}

uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) {
return NULL;
}

uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) {
buffer->impl.last_start = start;
buffer->impl.last_size = size;

return NULL;
}

void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) {}

void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) {}

size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer) {
return buffer->impl.size;
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef KINC_KONG

typedef struct kinc_g4_constant_buffer_impl {
size_t size;
size_t last_start;
size_t last_size;
} kinc_g4_constant_buffer_impl;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) {
}
}

#ifdef KINC_KONG
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit) {
if (renderTarget->impl.antialiasing) {
IDirect3DSurface9 *surface;
renderTarget->impl.colorTexture->GetSurfaceLevel(0, &surface);
kinc_microsoft_affirm(device->StretchRect(renderTarget->impl.colorSurface, nullptr, surface, nullptr, D3DTEXF_NONE));
surface->Release();
}
device->SetTexture(unit, renderTarget->isDepthAttachment ? renderTarget->impl.depthTexture : renderTarget->impl.colorTexture);
}
#else
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
if (renderTarget->impl.antialiasing) {
IDirect3DSurface9 *surface;
Expand All @@ -100,6 +111,7 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderT
device->SetTexture(unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT],
renderTarget->isDepthAttachment ? renderTarget->impl.depthTexture : renderTarget->impl.colorTexture);
}
#endif

void kinc_g4_render_target_set_depth_stencil_from(kinc_g4_render_target_t *renderTarget, kinc_g4_render_target_t *source) {
renderTarget->impl.depthTexture = source->impl.depthTexture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,19 @@ void kinc_g4_texture_destroy(kinc_g4_texture_t *texture) {
texture->impl.texture->Release();
}

#ifdef KINC_KONG
void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit) {
kinc_microsoft_affirm(device->SetTexture(unit, texture->impl.texture));
texture->impl.stage = unit;
setTextures[texture->impl.stage] = texture;
}
#else
void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) {
kinc_microsoft_affirm(device->SetTexture(unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], texture->impl.texture));
texture->impl.stage = unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT];
setTextures[texture->impl.stage] = texture;
}
#endif

void kinc_internal_texture_unset(struct kinc_g4_texture *texture) {
if (setTextures[texture->impl.stage] == texture) {
Expand Down
32 changes: 16 additions & 16 deletions Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ static kinc_g5_constant_buffer_t fragmentConstantBuffer;
#define constantBufferMultiply 100
static int constantBufferIndex = 0;

void kinc_g4_internal_init() {
void kinc_g4_internal_init(void) {
kinc_g5_internal_init();
}

void kinc_g4_internal_destroy() {
void kinc_g4_internal_destroy(void) {
kinc_g5_internal_destroy();
}

Expand Down Expand Up @@ -117,7 +117,7 @@ void kinc_g4_on_g5_internal_resize(int window, int width, int height) {
windows[window].resized = true;
}

void kinc_g4_on_g5_internal_restore_render_target() {
void kinc_g4_on_g5_internal_restore_render_target(void) {
windows[current_window].current_render_targets[0] = NULL;
kinc_g5_render_target_t *render_target = &windows[current_window].framebuffers[windows[current_window].currentBuffer];
kinc_g5_command_list_set_render_targets(&commandList, &render_target, 1);
Expand Down Expand Up @@ -156,7 +156,7 @@ void kinc_g4_on_g5_internal_set_samplers(int count, kinc_g5_texture_unit_t *text
}
}

static void startDraw() {
static void startDraw(void) {
if ((constantBufferIndex + 1) >= constantBufferMultiply || waitAfterNextDraw) {
memcpy(current_state.vertex_constant_data, vertexConstantBuffer.data, constantBufferSize);
memcpy(current_state.fragment_constant_data, fragmentConstantBuffer.data, constantBufferSize);
Expand All @@ -172,7 +172,7 @@ static void startDraw() {
kinc_g5_command_list_set_fragment_constant_buffer(&commandList, &fragmentConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize);
}

static void endDraw() {
static void endDraw(void) {
++constantBufferIndex;
if (constantBufferIndex >= constantBufferMultiply || waitAfterNextDraw) {
kinc_g5_command_list_end(&commandList);
Expand Down Expand Up @@ -238,7 +238,7 @@ static void endDraw() {
}
}

void kinc_g4_draw_indexed_vertices() {
void kinc_g4_draw_indexed_vertices(void) {
startDraw();
kinc_g5_command_list_draw_indexed_vertices(&commandList);
endDraw();
Expand Down Expand Up @@ -365,7 +365,7 @@ void kinc_g4_scissor(int x, int y, int width, int height) {
kinc_g5_command_list_scissor(&commandList, x, y, width, height);
}

void kinc_g4_disable_scissor() {
void kinc_g4_disable_scissor(void) {
current_state.scissor_set = false;
kinc_g5_command_list_disable_scissor(&commandList);
}
Expand All @@ -390,11 +390,11 @@ void kinc_g4_end(int window) {
}*/

bool kinc_g4_swap_buffers() {
bool kinc_g4_swap_buffers(void) {
return kinc_g5_swap_buffers();
}

void kinc_g4_flush() {
void kinc_g4_flush(void) {
kinc_g5_flush();
}

Expand Down Expand Up @@ -567,7 +567,7 @@ void kinc_g4_set_texture_lod(kinc_g4_texture_unit_t unit, float lod_min_clamp, f

void kinc_g4_set_cubemap_lod(kinc_g4_texture_unit_t unit, float lod_min_clamp, float lod_max_clamp) {}

void kinc_g4_restore_render_target() {
void kinc_g4_restore_render_target(void) {
kinc_g4_on_g5_internal_restore_render_target();
current_state.viewport_set = false;
current_state.scissor_set = false;
Expand Down Expand Up @@ -630,7 +630,7 @@ void kinc_g4_set_texture(uint32_t unit, kinc_g4_texture_t *texture) {
}

assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT);
kinc_g5_texture_unit_t g5_unit;
kinc_g5_texture_unit_t g5_unit = {0};
for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) {
g5_unit.stages[i] = unit;
}
Expand Down Expand Up @@ -723,19 +723,19 @@ void kinc_g4_set_blend_constant(float r, float g, float b, float a) {

void kinc_g4_set_texture_array(kinc_g4_texture_unit_t unit, struct kinc_g4_texture_array *array) {}

bool kinc_g4_supports_instanced_rendering() {
bool kinc_g4_supports_instanced_rendering(void) {
return kinc_g5_supports_instanced_rendering();
}

bool kinc_g4_supports_compute_shaders() {
bool kinc_g4_supports_compute_shaders(void) {
return kinc_g5_supports_compute_shaders();
}

bool kinc_g4_supports_blend_constants() {
bool kinc_g4_supports_blend_constants(void) {
return kinc_g5_supports_blend_constants();
}

bool kinc_g4_supports_non_pow2_textures() {
bool kinc_g4_supports_non_pow2_textures(void) {
return kinc_g5_supports_non_pow2_textures();
}

Expand All @@ -751,7 +751,7 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_
}

assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT);
kinc_g5_texture_unit_t g5_unit;
kinc_g5_texture_unit_t g5_unit = {0};
for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) {
g5_unit.stages[i] = unit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1269,4 +1269,9 @@ bool kinc_g4_render_targets_inverted_y(void) {
void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer) {
glBindBufferBase(GL_UNIFORM_BUFFER, id, buffer->impl.buffer);
}

void kinc_g4_internal_opengl_setup_uniform_block(unsigned program, const char *name, unsigned binding) {
unsigned index = glGetUniformBlockIndex(program, name);
glUniformBlockBinding(program, index, binding);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,11 @@ void kinc_g5_internal_init() {
#ifdef KORE_WINDOWS
#ifdef _DEBUG
ID3D12Debug *debugController = NULL;
D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
debugController->EnableDebugLayer();
if (D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)) == S_OK) {
debugController->EnableDebugLayer();
}
#endif
D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));
kinc_microsoft_affirm(D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)));

createRootSignature();
createComputeRootSignature();
Expand Down
20 changes: 10 additions & 10 deletions Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ id getMetalEncoder(void) {

void kinc_g5_internal_destroy_window(int window) {}

void kinc_g5_internal_destroy() {}
void kinc_g5_internal_destroy(void) {}

extern void kinc_g4_on_g5_internal_resize(int, int, int);

void kinc_internal_resize(int window, int width, int height) {
kinc_g4_on_g5_internal_resize(window, width, height);
}

void kinc_g5_internal_init() {}
void kinc_g5_internal_init(void) {}

void kinc_g5_internal_init_window(int window, int depthBufferBits, int stencilBufferBits, bool vsync) {
depthBits = depthBufferBits;
stencilBits = stencilBufferBits;
kinc_g5_render_target_init(&fallback_render_target, 32, 32, KINC_G5_RENDER_TARGET_FORMAT_32BIT, 0, 0);
}

void kinc_g5_flush() {}
void kinc_g5_flush(void) {}

void kinc_g5_draw_indexed_vertices_instanced(int instanceCount) {}

Expand Down Expand Up @@ -112,7 +112,7 @@ void kinc_g5_begin(kinc_g5_render_target_t *renderTarget, int window) {

void kinc_g5_end(int window) {}

bool kinc_g5_swap_buffers() {
bool kinc_g5_swap_buffers(void) {
if (commandBuffer != nil && commandEncoder != nil) {
[commandEncoder endEncoding];
[commandBuffer presentDrawable:drawable];
Expand Down Expand Up @@ -202,27 +202,27 @@ void kinc_g5_internal_new_render_pass(kinc_g5_render_target_t **renderTargets, i
commandEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
}

bool kinc_g5_supports_raytracing() {
bool kinc_g5_supports_raytracing(void) {
return false;
}

bool kinc_g5_supports_instanced_rendering() {
bool kinc_g5_supports_instanced_rendering(void) {
return true;
}

bool kinc_g5_supports_compute_shaders() {
bool kinc_g5_supports_compute_shaders(void) {
return true;
}

bool kinc_g5_supports_blend_constants() {
bool kinc_g5_supports_blend_constants(void) {
return true;
}

bool kinc_g5_supports_non_pow2_textures() {
bool kinc_g5_supports_non_pow2_textures(void) {
return true;
}

bool kinc_g5_render_targets_inverted_y() {
bool kinc_g5_render_targets_inverted_y(void) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipel
}

kinc_g5_texture_unit_t kinc_g5_pipeline_get_texture_unit(kinc_g5_pipeline_t *pipeline, const char *name) {
kinc_g5_texture_unit_t unit;
kinc_g5_texture_unit_t unit = {0};
for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) {
unit.stages[i] = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ void kinc_g5_shader_destroy(kinc_g5_shader_t *shader) {
}

void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) {
#ifdef KINC_KONG
strcpy(shader->impl.name, (const char *)source);
shader->impl.mtlFunction = (__bridge_retained void *)[getMetalLibrary() newFunctionWithName:[NSString stringWithCString:shader->impl.name
encoding:NSUTF8StringEncoding]];
#else
shader->impl.name[0] = 0;

{
Expand Down Expand Up @@ -51,5 +56,6 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t le
}
shader->impl.mtlFunction = (__bridge_retained void *)[library newFunctionWithName:[NSString stringWithCString:shader->impl.name
encoding:NSUTF8StringEncoding]];
#endif
assert(shader->impl.mtlFunction);
}
Loading

0 comments on commit a7e50d2

Please sign in to comment.