diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h index d4d877281..7ba75b6d6 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h @@ -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, diff --git a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp index 05e0694c0..d8083637b 100644 --- a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp +++ b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp @@ -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) {} @@ -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) {} diff --git a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.cpp b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.cpp new file mode 100644 index 000000000..b5e8a1dc3 --- /dev/null +++ b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.cpp @@ -0,0 +1,34 @@ +#ifdef KINC_KONG + +#include + +#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 diff --git a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.h b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.h new file mode 100644 index 000000000..ac7b3ace3 --- /dev/null +++ b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.h @@ -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 diff --git a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp index 391f15235..9f7ed569a 100644 --- a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp +++ b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp @@ -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; @@ -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; diff --git a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp index 02a514560..c827aa0ed 100644 --- a/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp +++ b/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp @@ -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) { diff --git a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h index 875c4f3b9..b26bfcad6 100644 --- a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h @@ -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(); } @@ -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); @@ -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); @@ -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); @@ -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(); @@ -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); } @@ -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(); } @@ -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; @@ -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; } @@ -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(); } @@ -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; } diff --git a/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h b/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h index 66abe9fce..0e7392a5a 100644 --- a/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h +++ b/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h @@ -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 diff --git a/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h b/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h index 1d14022d8..473263785 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h +++ b/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h @@ -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(); diff --git a/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h index d80f5d6de..f7b96d709 100644 --- a/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h +++ b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h @@ -34,7 +34,7 @@ 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); @@ -42,7 +42,7 @@ 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; @@ -50,7 +50,7 @@ void kinc_g5_internal_init_window(int window, int depthBufferBits, int stencilBu 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) {} @@ -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]; @@ -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; } diff --git a/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h index 863e3d16c..537012b22 100644 --- a/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h +++ b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h @@ -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; } diff --git a/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h index 97106f8a2..a495855b0 100644 --- a/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h +++ b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h @@ -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; { @@ -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); } diff --git a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c index cfe3cc960..28098eb3e 100644 --- a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c +++ b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c @@ -6,6 +6,10 @@ extern WGPUDevice device; +#ifdef KINC_KONG +extern WGPUShaderModule kinc_g5_internal_webgpu_shader_module; +#endif + void kinc_g5_pipeline_init(kinc_g5_pipeline_t *pipe) { kinc_g5_internal_pipeline_init(pipe); } @@ -183,15 +187,25 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { WGPUVertexState vsDest; memset(&vsDest, 0, sizeof(vsDest)); +#ifdef KINC_KONG + vsDest.module = kinc_g5_internal_webgpu_shader_module; + vsDest.entryPoint = pipe->vertexShader->impl.entry_name; +#else vsDest.module = pipe->vertexShader->impl.module; vsDest.entryPoint = "main"; +#endif vsDest.bufferCount = 1; vsDest.buffers = &vbDesc; WGPUFragmentState fragmentDest; memset(&fragmentDest, 0, sizeof(fragmentDest)); +#ifdef KINC_KONG + fragmentDest.module = kinc_g5_internal_webgpu_shader_module; + fragmentDest.entryPoint = pipe->fragmentShader->impl.entry_name; +#else fragmentDest.module = pipe->fragmentShader->impl.module; fragmentDest.entryPoint = "main"; +#endif fragmentDest.targetCount = 1; fragmentDest.targets = &csDesc; diff --git a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c index 4b769e518..daf79a73f 100644 --- a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c +++ b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c @@ -4,6 +4,24 @@ extern WGPUDevice device; +#ifdef KINC_KONG +WGPUShaderModule kinc_g5_internal_webgpu_shader_module; + +void kinc_g5_internal_webgpu_create_shader_module(const void *source, size_t length) { + WGPUShaderModuleWGSLDescriptor wgsl_desc = {0}; + wgsl_desc.code = (const char *)source; + wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; + + WGPUShaderModuleDescriptor desc = {0}; + desc.nextInChain = (WGPUChainedStruct *)(&wgsl_desc); + + kinc_g5_internal_webgpu_shader_module = wgpuDeviceCreateShaderModule(device, &desc); +} + +void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) { + strcpy(&shader->impl.entry_name[0], source); +} +#else void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) { WGPUShaderModuleSPIRVDescriptor smSpirvDesc; memset(&smSpirvDesc, 0, sizeof(smSpirvDesc)); @@ -15,5 +33,6 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t le smDesc.nextInChain = &smSpirvDesc; shader->impl.module = wgpuDeviceCreateShaderModule(device, &smDesc); } +#endif void kinc_g5_shader_destroy(kinc_g5_shader_t *shader) {} diff --git a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h index 8a7036e59..125e8ebe9 100644 --- a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h +++ b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h @@ -9,7 +9,11 @@ extern "C" { struct WGPUShaderModuleImpl; typedef struct { +#ifdef KINC_KONG + char entry_name[256]; +#else WGPUShaderModule module; +#endif } Shader5Impl; #ifdef __cplusplus diff --git a/Backends/System/Android/Sources/kinc/backend/system.c.h b/Backends/System/Android/Sources/kinc/backend/system.c.h index 973c62bbf..78ef8ef86 100644 --- a/Backends/System/Android/Sources/kinc/backend/system.c.h +++ b/Backends/System/Android/Sources/kinc/backend/system.c.h @@ -1175,6 +1175,10 @@ void android_main(struct android_app *application) { (*activity->vm)->DetachCurrentThread(activity->vm); } +#ifdef KINC_KONG +void kong_init(void); +#endif + int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame) { kinc_mutex_init(&unicode_mutex); @@ -1194,6 +1198,11 @@ int kinc_init(const char *name, int width, int height, struct kinc_window_option kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); + +#ifdef KINC_KONG + kong_init(); +#endif + return 0; } diff --git a/Backends/System/Emscripten/Sources/kinc/backend/system.c.h b/Backends/System/Emscripten/Sources/kinc/backend/system.c.h index 28c827779..8cb3206c1 100644 --- a/Backends/System/Emscripten/Sources/kinc/backend/system.c.h +++ b/Backends/System/Emscripten/Sources/kinc/backend/system.c.h @@ -250,6 +250,10 @@ static int with, height; extern int kinc_internal_window_width; extern int kinc_internal_window_height; +#ifdef KINC_KONG +void kong_init(void); +#endif + int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { kinc_window_options_t defaultWin; if (win == NULL) { @@ -276,6 +280,11 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi kinc_internal_window_height = height; kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); + +#ifdef KINC_KONG + kong_init(); +#endif + return 0; } diff --git a/Backends/System/Linux/Sources/kinc/backend/system.c.h b/Backends/System/Linux/Sources/kinc/backend/system.c.h index 9aa94ced4..5e2d9a385 100644 --- a/Backends/System/Linux/Sources/kinc/backend/system.c.h +++ b/Backends/System/Linux/Sources/kinc/backend/system.c.h @@ -152,6 +152,10 @@ void kinc_unlock_achievement(int id) {} void kinc_linux_init_procs(); +#ifdef KINC_KONG +void kong_init(void); +#endif + int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { #ifndef __FreeBSD__ kinc_linux_initHIDGamepads(); @@ -181,7 +185,11 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi win->title = name; } - return kinc_window_create(win, frame); + int window = kinc_window_create(win, frame); +#ifdef KINC_KONG + kong_init(); +#endif + return window; } void kinc_internal_shutdown() { diff --git a/Backends/System/Wasm/Sources/kinc/backend/system.c.h b/Backends/System/Wasm/Sources/kinc/backend/system.c.h index db299b51c..f71d3f0d6 100644 --- a/Backends/System/Wasm/Sources/kinc/backend/system.c.h +++ b/Backends/System/Wasm/Sources/kinc/backend/system.c.h @@ -13,6 +13,10 @@ __attribute__((import_module("imports"), import_name("js_time"))) int js_time(); extern int kinc_internal_window_width; extern int kinc_internal_window_height; +#ifdef KINC_KONG +void kong_init(void); +#endif + int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { kinc_window_options_t defaultWin; if (win == NULL) { @@ -32,6 +36,11 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); + +#ifdef KINC_KONG + kong_init(); +#endif + return 0; } diff --git a/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp b/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp index bc31da003..4012f9681 100644 --- a/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp +++ b/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp @@ -160,6 +160,10 @@ bool kinc_internal_handle_messages(void) { // return vec2i(mouseX, mouseY); //} +#ifdef KINC_KONG +extern "C" void kong_init(void); +#endif + #undef CreateWindow int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame) { @@ -179,6 +183,11 @@ int kinc_init(const char *name, int width, int height, struct kinc_window_option kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); + +#ifdef KINC_KONG + kong_init(); +#endif + return 0; } diff --git a/Backends/System/WindowsApp/Sources/kinc/backend/video.c b/Backends/System/WindowsApp/Sources/kinc/backend/video.c index 2b6c4c8e1..e1a511118 100644 --- a/Backends/System/WindowsApp/Sources/kinc/backend/video.c +++ b/Backends/System/WindowsApp/Sources/kinc/backend/video.c @@ -4,7 +4,7 @@ void kinc_video_init(kinc_video_t *video, const char *filename) {} void kinc_video_destroy(kinc_video_t *video) {} -void kinc_video_play(kinc_video_t *video) {} +void kinc_video_play(kinc_video_t *video, bool loop) {} void kinc_video_pause(kinc_video_t *video) {} diff --git a/Backends/System/iOS/Sources/kinc/backend/GLView.m.h b/Backends/System/iOS/Sources/kinc/backend/GLView.m.h index bdf70950c..ffd13c81c 100644 --- a/Backends/System/iOS/Sources/kinc/backend/GLView.m.h +++ b/Backends/System/iOS/Sources/kinc/backend/GLView.m.h @@ -17,7 +17,7 @@ static const int touchmaxcount = 20; static void *touches[touchmaxcount]; -static void initTouches() { +static void initTouches(void) { for (int i = 0; i < touchmaxcount; ++i) { touches[i] = NULL; } diff --git a/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h b/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h index 0f6f0e383..8bdee73c9 100644 --- a/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h +++ b/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h @@ -12,7 +12,7 @@ static GLView *glView; static bool visible; -void beginGL() { +void beginGL(void) { #ifdef KORE_METAL if (!visible) { return; @@ -21,7 +21,7 @@ void beginGL() { [glView begin]; } -void endGL() { +void endGL(void) { #ifdef KORE_METAL if (!visible) { return; @@ -30,29 +30,29 @@ void endGL() { [glView end]; } -void showKeyboard() { +void showKeyboard(void) { [glView showKeyboard]; } -void hideKeyboard() { +void hideKeyboard(void) { [glView hideKeyboard]; } #ifdef KORE_METAL -CAMetalLayer *getMetalLayer() { +CAMetalLayer *getMetalLayer(void) { return [glView metalLayer]; } -id getMetalDevice() { +id getMetalDevice(void) { return [glView metalDevice]; } -id getMetalLibrary() { +id getMetalLibrary(void) { return [glView metalLibrary]; } -id getMetalQueue() { +id getMetalQueue(void) { return [glView metalQueue]; } diff --git a/Backends/System/iOS/Sources/kinc/backend/audio.m.h b/Backends/System/iOS/Sources/kinc/backend/audio.m.h index fc19a5246..40a4392df 100644 --- a/Backends/System/iOS/Sources/kinc/backend/audio.m.h +++ b/Backends/System/iOS/Sources/kinc/backend/audio.m.h @@ -109,7 +109,7 @@ static void sampleRateListener(void *inRefCon, AudioUnit inUnit, AudioUnitProper static bool initialized = false; -void kinc_a2_init() { +void kinc_a2_init(void) { if (initialized) { return; } @@ -183,9 +183,9 @@ void kinc_a2_init() { soundPlaying = true; } -void kinc_a2_update() {} +void kinc_a2_update(void) {} -void kinc_a2_shutdown() { +void kinc_a2_shutdown(void) { if (!initialized) return; if (!soundPlaying) diff --git a/Backends/System/iOS/Sources/kinc/backend/display.m.h b/Backends/System/iOS/Sources/kinc/backend/display.m.h index 384aa57a3..bf798bdf1 100644 --- a/Backends/System/iOS/Sources/kinc/backend/display.m.h +++ b/Backends/System/iOS/Sources/kinc/backend/display.m.h @@ -3,7 +3,7 @@ #include #include -void kinc_display_init() {} +void kinc_display_init(void) {} kinc_display_mode_t kinc_display_available_mode(int display, int mode) { kinc_display_mode_t dm; @@ -35,10 +35,10 @@ kinc_display_mode_t kinc_display_current_mode(int display) { return dm; } -int kinc_count_displays() { +int kinc_count_displays(void) { return 1; } -int kinc_primary_display() { +int kinc_primary_display(void) { return 0; } diff --git a/Backends/System/iOS/Sources/kinc/backend/mouse.c.h b/Backends/System/iOS/Sources/kinc/backend/mouse.c.h index 9347296c1..7b75836d4 100644 --- a/Backends/System/iOS/Sources/kinc/backend/mouse.c.h +++ b/Backends/System/iOS/Sources/kinc/backend/mouse.c.h @@ -8,9 +8,9 @@ bool kinc_mouse_can_lock(void) { return false; } -void kinc_mouse_show() {} +void kinc_mouse_show(void) {} -void kinc_mouse_hide() {} +void kinc_mouse_hide(void) {} void kinc_mouse_set_position(int window, int x, int y) {} diff --git a/Backends/System/iOS/Sources/kinc/backend/system.m.h b/Backends/System/iOS/Sources/kinc/backend/system.m.h index 85f861326..4da9571ab 100644 --- a/Backends/System/iOS/Sources/kinc/backend/system.m.h +++ b/Backends/System/iOS/Sources/kinc/backend/system.m.h @@ -35,17 +35,17 @@ void kinc_set_keep_screen_on(bool on) {} void showKeyboard(void); void hideKeyboard(void); -void kinc_keyboard_show() { +void kinc_keyboard_show(void) { keyboardshown = true; showKeyboard(); } -void kinc_keyboard_hide() { +void kinc_keyboard_hide(void) { keyboardshown = false; hideKeyboard(); } -bool kinc_keyboard_active() { +bool kinc_keyboard_active(void) { return keyboardshown; } @@ -62,7 +62,7 @@ void kinc_vibrate(int ms) { static char language[3]; -const char *kinc_language() { +const char *kinc_language(void) { NSString *nsstr = [[NSLocale preferredLanguages] objectAtIndex:0]; const char *lang = [nsstr UTF8String]; language[0] = lang[0]; @@ -72,7 +72,7 @@ const char *kinc_language() { } // called on rotation event -void KoreUpdateKeyboard() { +void KoreUpdateKeyboard(void) { if (keyboardshown) { hideKeyboard(); showKeyboard(); @@ -82,7 +82,11 @@ void KoreUpdateKeyboard() { } } -void kinc_internal_shutdown() {} +#ifdef KINC_KONG +void kong_init(void); +#endif + +void kinc_internal_shutdown(void) {} int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame) { kinc_window_options_t defaultWin; @@ -97,6 +101,10 @@ int kinc_init(const char *name, int width, int height, struct kinc_window_option } kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); + +#ifdef KINC_KONG + kong_init(); +#endif return 0; } @@ -108,7 +116,7 @@ void swapBuffersiOS(void) { static char sysid[512]; -const char *kinc_system_id() { +const char *kinc_system_id(void) { const char *name = [[[UIDevice currentDevice] name] UTF8String]; const char *vendorId = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] UTF8String]; strcpy(sysid, name); @@ -132,30 +140,30 @@ static const char *getSavePath(void) { return [resolvedPath cStringUsingEncoding:1]; } -const char *kinc_internal_save_path() { +const char *kinc_internal_save_path(void) { return getSavePath(); } static const char *videoFormats[] = {"mp4", NULL}; -const char **kinc_video_formats() { +const char **kinc_video_formats(void) { return videoFormats; } #include -double kinc_frequency() { +double kinc_frequency(void) { mach_timebase_info_data_t info; mach_timebase_info(&info); return (double)info.denom / (double)info.numer / 1e-9; } -kinc_ticks_t kinc_timestamp() { +kinc_ticks_t kinc_timestamp(void) { kinc_ticks_t time = mach_absolute_time(); return time; } -void kinc_login() {} +void kinc_login(void) {} void kinc_unlock_achievement(int id) {} diff --git a/Backends/System/iOS/Sources/kinc/backend/window.c.h b/Backends/System/iOS/Sources/kinc/backend/window.c.h index 96159ff03..e42a899d3 100644 --- a/Backends/System/iOS/Sources/kinc/backend/window.c.h +++ b/Backends/System/iOS/Sources/kinc/backend/window.c.h @@ -13,7 +13,7 @@ int kinc_window_y(int window) { return 0; } -int kinc_count_windows() { +int kinc_count_windows(void) { return 1; } diff --git a/Backends/System/macOS/Sources/kinc/backend/system.m.h b/Backends/System/macOS/Sources/kinc/backend/system.m.h index 5dd6dce14..783169ed2 100644 --- a/Backends/System/macOS/Sources/kinc/backend/system.m.h +++ b/Backends/System/macOS/Sources/kinc/backend/system.m.h @@ -174,6 +174,10 @@ static void addMenubar(void) { [NSApp setMainMenu:menubar]; } +#ifdef KINC_KONG +void kong_init(void); +#endif + int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { @autoreleasepool { myapp = [KincApplication sharedApplication]; @@ -208,6 +212,11 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi int windowId = createWindow(win); kinc_g4_internal_init(); kinc_g4_internal_init_window(windowId, frame->depth_bits, frame->stencil_bits, true); + +#ifdef KINC_KONG + kong_init(); +#endif + return 0; } diff --git a/Sources/kinc/audio1/audio.c.h b/Sources/kinc/audio1/audio.c.h index c28225c03..28e424c37 100644 --- a/Sources/kinc/audio1/audio.c.h +++ b/Sources/kinc/audio1/audio.c.h @@ -118,7 +118,7 @@ void kinc_a1_mix(kinc_a2_buffer_t *buffer, int samples) { } } -void kinc_a1_init() { +void kinc_a1_init(void) { for (int i = 0; i < CHANNEL_COUNT; ++i) { channels[i].sound = NULL; channels[i].position = 0; diff --git a/Sources/kinc/system.h b/Sources/kinc/system.h index 893dc87e6..a5672d63e 100644 --- a/Sources/kinc/system.h +++ b/Sources/kinc/system.h @@ -2,6 +2,8 @@ #include +#include + #include #include #include diff --git a/Tools/freebsd_x64 b/Tools/freebsd_x64 index 2aca0409f..7ce2c0551 160000 --- a/Tools/freebsd_x64 +++ b/Tools/freebsd_x64 @@ -1 +1 @@ -Subproject commit 2aca0409f7529bdbcf375d3915a161419cd48696 +Subproject commit 7ce2c0551bc3d8f662abfcc089b4143a68563c47 diff --git a/Tools/linux_arm b/Tools/linux_arm index 12ca7aba5..0894e7a12 160000 --- a/Tools/linux_arm +++ b/Tools/linux_arm @@ -1 +1 @@ -Subproject commit 12ca7aba5d076a2a163b6f62fcf2148cfa8c32fc +Subproject commit 0894e7a125bfe09d34a6c5fd955aea413de56564 diff --git a/Tools/linux_arm64 b/Tools/linux_arm64 index a9c98df07..62bd42055 160000 --- a/Tools/linux_arm64 +++ b/Tools/linux_arm64 @@ -1 +1 @@ -Subproject commit a9c98df07f6cd5f17c256a1cd00af1a05072d032 +Subproject commit 62bd420550775e5f572a6af4d455878feeee46bc diff --git a/Tools/linux_x64 b/Tools/linux_x64 index 2a0d561ed..5877a1ecd 160000 --- a/Tools/linux_x64 +++ b/Tools/linux_x64 @@ -1 +1 @@ -Subproject commit 2a0d561ed29fc4ae1cb1d9df6ed4db07f53fbb59 +Subproject commit 5877a1ecd45f9baf03b6710e463378bd78d2c1fe diff --git a/Tools/macos b/Tools/macos index 5f643768a..ce6eb1894 160000 --- a/Tools/macos +++ b/Tools/macos @@ -1 +1 @@ -Subproject commit 5f643768ad1bf0626d9c876228b9bff21d4dc951 +Subproject commit ce6eb18948fab33cffecebe349660e545037314a diff --git a/Tools/windows_x64 b/Tools/windows_x64 index d992e41db..2890e0587 160000 --- a/Tools/windows_x64 +++ b/Tools/windows_x64 @@ -1 +1 @@ -Subproject commit d992e41db7ee62db7e1976fa4de4d1fe352d0603 +Subproject commit 2890e058794d7a198cc71a45e86be4c2bd50ae2d diff --git a/kfile.js b/kfile.js index b7e113970..8a79a0793 100644 --- a/kfile.js +++ b/kfile.js @@ -299,6 +299,7 @@ else if (platform === Platform.Emscripten) { project.addDefine('KORE_EMSCRIPTEN'); //project.addLib('websocket.js -sPROXY_POSIX_SOCKETS -sUSE_PTHREADS -sPROXY_TO_PTHREAD'); addBackend('System/Emscripten'); + project.addLib('USE_GLFW=2'); if (graphics === GraphicsApi.WebGPU) { g4 = true; g5 = true; @@ -311,6 +312,9 @@ else if (platform === Platform.Emscripten) { project.addExclude('Backends/Graphics4/OpenGL/Sources/GL/**'); project.addDefine('KORE_OPENGL'); project.addDefine('KORE_OPENGL_ES'); + if (Options.kong) { + project.addLib('USE_WEBGL2=1'); + } } else { throw new Error('Graphics API ' + graphics + ' is not available for Emscripten.');