diff --git a/base/project.js b/base/project.js index 758dbda6..c1ef8ff9 100644 --- a/base/project.js +++ b/base/project.js @@ -157,6 +157,8 @@ if (!flags.lite) { if (platform === "windows") { add_sys_backend("windows"); + add_net_backend("windows"); + add_thread_backend("windows"); project.add_lib("dxguid"); project.add_lib("dsound"); project.add_lib("dinput8"); @@ -203,6 +205,7 @@ if (!flags.lite) { add_sys_backend("apple"); add_sys_backend("ios"); add_sys_backend("posix"); + add_thread_backend("posix"); if (graphics === "metal" || graphics === "default") { add_gpu_backend("metal"); project.add_define("KINC_METAL"); @@ -227,6 +230,7 @@ if (!flags.lite) { project.add_define("KINC_ANDROID"); add_sys_backend("android"); add_sys_backend("posix"); + add_thread_backend("posix"); if (graphics === "vulkan" || graphics === "default") { add_gpu_backend("vulkan"); project.add_define("KINC_VULKAN"); @@ -247,6 +251,7 @@ if (!flags.lite) { else if (platform === "wasm") { project.add_define("KINC_WASM"); add_sys_backend("wasm"); + add_thread_backend("wasm"); project.add_include_dir("miniclib"); project.add_cfiles("sources/libs/miniclib/**"); if (graphics === "webgpu" || graphics === "default") { diff --git a/base/sources/backends/android_video.c b/base/sources/backends/android_video.c index 3f0d7fd8..2712a306 100644 --- a/base/sources/backends/android_video.c +++ b/base/sources/backends/android_video.c @@ -11,7 +11,7 @@ // #include // #include // #include -// #include +// #include // #include // void kinc_video_sound_stream_impl_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency) { diff --git a/base/sources/backends/direct3d12_gpu.c b/base/sources/backends/direct3d12_gpu.c index 65f894b9..29fedfbd 100644 --- a/base/sources/backends/direct3d12_gpu.c +++ b/base/sources/backends/direct3d12_gpu.c @@ -48,32 +48,24 @@ #include #include -#include "d3d12mini.h" #include #include #include #include #include -#include "g5_commandlist.h" -#include "g5_pipeline.h" -#include "g5_buffer.h" #include #include #undef CreateWindow -#include -#include -#include "g5_pipeline.h" +#include #include -#include #include -#include "g5_texture.h" #include -#include ID3D12Device *device = NULL; static ID3D12RootSignature *globalRootSignature = NULL; static ID3D12RootSignature *globalComputeRootSignature = NULL; // extern ID3D12GraphicsCommandList* commandList; +static int framebuffer_count = 0; #define MAXIMUM_WINDOWS 1 @@ -239,7 +231,7 @@ static void createRootSignature() { samplers[i].AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplers[i].MipLODBias = 0; samplers[i].MaxAnisotropy = 16; - samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL; + samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; samplers[i].BorderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE; samplers[i].MinLOD = 0.0f; samplers[i].MaxLOD = D3D12_FLOAT32_MAX; @@ -254,7 +246,7 @@ static void createRootSignature() { samplers[i].AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplers[i].MipLODBias = 0; samplers[i].MaxAnisotropy = 16; - samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL; + samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; samplers[i].BorderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE; samplers[i].MinLOD = 0.0f; samplers[i].MaxLOD = D3D12_FLOAT32_MAX; @@ -327,7 +319,7 @@ static void createComputeRootSignature() { samplers[i].AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplers[i].MipLODBias = 0; samplers[i].MaxAnisotropy = 16; - samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL; + samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; samplers[i].BorderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE; samplers[i].MinLOD = 0.0f; samplers[i].MaxLOD = D3D12_FLOAT32_MAX; @@ -342,7 +334,7 @@ static void createComputeRootSignature() { samplers[i].AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplers[i].MipLODBias = 0; samplers[i].MaxAnisotropy = 16; - samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL; + samplers[i].ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; samplers[i].BorderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE; samplers[i].MinLOD = 0.0f; samplers[i].MaxLOD = D3D12_FLOAT32_MAX; @@ -952,7 +944,7 @@ void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE; - device->lpVtbl->CreateCommittedResource(device , &heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, NULL, + device->lpVtbl->CreateCommittedResource(device , &heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_COMMON, NULL, &IID_ID3D12Resource, &render_target->impl.renderTargetReadback); } @@ -1566,7 +1558,7 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.DepthStencilState.StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK; psoDesc.DepthStencilState.StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK; - const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp = {D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS}; + const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp = {D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_NEVER}; psoDesc.DepthStencilState.FrontFace = defaultStencilOp; psoDesc.DepthStencilState.BackFace = defaultStencilOp; @@ -1670,7 +1662,7 @@ void kinc_g5_sampler_init(kinc_g5_sampler_t *sampler, const kinc_g5_sampler_opti samplerDesc.MaxLOD = 32; samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 1; - samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL; + samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; D3D12_CPU_DESCRIPTOR_HANDLE handle; sampler->impl.sampler_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(sampler->impl.sampler_heap, &handle); device->lpVtbl->CreateSampler(device, &samplerDesc, handle); @@ -1885,12 +1877,16 @@ void kinc_memory_emergency(); void kinc_g5_texture_init_from_bytes(kinc_g5_texture_t *texture, void *data, int width, int height, kinc_image_format_t format) { memset(&texture->impl, 0, sizeof(texture->impl)); texture->impl.stage = 0; + texture->impl.stage_depth = -1; texture->impl.mipmap = true; texture->width = width; texture->height = height; texture->_uploaded = false; texture->format = format; texture->data = data; + texture->state = KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE; + texture->framebuffer_index = -1; + texture->impl.renderTarget = NULL; DXGI_FORMAT d3dformat = convertImageFormat(format); int formatSize = formatByteSize(format); @@ -2002,10 +1998,13 @@ void kinc_g5_texture_init_from_bytes(kinc_g5_texture_t *texture, void *data, int void create_texture(struct kinc_g5_texture *texture, int width, int height, kinc_image_format_t format, D3D12_RESOURCE_FLAGS flags) { memset(&texture->impl, 0, sizeof(texture->impl)); texture->impl.stage = 0; + texture->impl.stage_depth = -1; texture->impl.mipmap = true; texture->width = width; texture->height = height; texture->data = NULL; + texture->framebuffer_index = -1; + texture->impl.renderTarget = NULL; DXGI_FORMAT d3dformat = convertImageFormat(format); @@ -2109,11 +2108,14 @@ void create_texture(struct kinc_g5_texture *texture, int width, int height, kinc void kinc_g5_texture_init(struct kinc_g5_texture *texture, int width, int height, kinc_image_format_t format) { create_texture(texture, width, height, format, D3D12_RESOURCE_FLAG_NONE); texture->_uploaded = true; + texture->state = KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE; texture->format = format; } void kinc_g5_texture_init_non_sampled_access(struct kinc_g5_texture *texture, int width, int height, kinc_image_format_t format) { create_texture(texture, width, height, format, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); + texture->_uploaded = true; + texture->state = KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE; } void kinc_g5_texture_destroy(kinc_g5_texture_t *render_target) { @@ -2121,21 +2123,25 @@ void kinc_g5_texture_destroy(kinc_g5_texture_t *render_target) { framebuffer_count -= 1; } - render_target->impl.renderTarget->lpVtbl->Release(render_target->impl.renderTarget); - render_target->impl.renderTargetDescriptorHeap->lpVtbl->Release(render_target->impl.renderTargetDescriptorHeap); - render_target->impl.srvDescriptorHeap->lpVtbl->Release(render_target->impl.srvDescriptorHeap); - if (render_target->impl.depthStencilTexture != NULL) { - render_target->impl.depthStencilTexture->lpVtbl->Release(render_target->impl.depthStencilTexture); - render_target->impl.depthStencilDescriptorHeap->lpVtbl->Release(render_target->impl.depthStencilDescriptorHeap); - render_target->impl.srvDepthDescriptorHeap->lpVtbl->Release(render_target->impl.srvDepthDescriptorHeap); - } - if (render_target->impl.renderTargetReadback != NULL) { - render_target->impl.renderTargetReadback->lpVtbl->Release(render_target->impl.renderTargetReadback); + if (render_target->impl.renderTarget != NULL) { + render_target->impl.renderTarget->lpVtbl->Release(render_target->impl.renderTarget); + render_target->impl.renderTargetDescriptorHeap->lpVtbl->Release(render_target->impl.renderTargetDescriptorHeap); + render_target->impl.srvDescriptorHeap->lpVtbl->Release(render_target->impl.srvDescriptorHeap); + if (render_target->impl.depthStencilTexture != NULL) { + render_target->impl.depthStencilTexture->lpVtbl->Release(render_target->impl.depthStencilTexture); + render_target->impl.depthStencilDescriptorHeap->lpVtbl->Release(render_target->impl.depthStencilDescriptorHeap); + render_target->impl.srvDepthDescriptorHeap->lpVtbl->Release(render_target->impl.srvDepthDescriptorHeap); + } + if (render_target->impl.renderTargetReadback != NULL) { + render_target->impl.renderTargetReadback->lpVtbl->Release(render_target->impl.renderTargetReadback); + } } - texture->impl.image->lpVtbl->Release(texture->impl.image); - texture->impl.uploadImage->lpVtbl->Release(texture->impl.uploadImage); - // texture->impl.srvDescriptorHeap->lpVtbl->Release(texture->impl.srvDescriptorHeap); + if (render_target->impl.image != NULL) { + render_target->impl.image->lpVtbl->Release(render_target->impl.image); + render_target->impl.uploadImage->lpVtbl->Release(render_target->impl.uploadImage); + // render_target->impl.srvDescriptorHeap->lpVtbl->Release(render_target->impl.srvDescriptorHeap); + } } void kinc_g5_internal_texture_unmipmap(struct kinc_g5_texture *texture) { @@ -2204,6 +2210,8 @@ static void render_target_init(kinc_g5_texture_t *render_target, int width, int render_target->impl.stage_depth = -1; render_target->impl.renderTargetReadback = NULL; render_target->impl.framebuffer_index = framebuffer_index; + render_target->impl.image = NULL; + render_target->impl.uploadImage = NULL; render_target->data = NULL; DXGI_FORMAT dxgiFormat = convertFormat(format); @@ -2395,13 +2403,15 @@ static void render_target_init(kinc_g5_texture_t *render_target, int width, int void kinc_g5_render_target_init(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits) { render_target_init(target, width, height, format, depthBufferBits, -1); + target->_uploaded = true; + target->state = KINC_INTERNAL_RENDER_TARGET_STATE_RENDER_TARGET; } -static int framebuffer_count = 0; - void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits) { render_target_init(target, width, height, format, depthBufferBits, framebuffer_count); framebuffer_count += 1; + target->_uploaded = true; + target->state = KINC_INTERNAL_RENDER_TARGET_STATE_RENDER_TARGET; } void kinc_g5_render_target_set_depth_from(kinc_g5_texture_t *render_target, kinc_g5_texture_t *source) { @@ -2610,7 +2620,7 @@ void kinc_g5_index_buffer_init(kinc_g5_index_buffer_t *buffer, int count, bool g heapProperties.VisibleNodeMask = 1; kinc_microsoft_affirm(device->lpVtbl->CreateCommittedResource(device , &heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, - D3D12_RESOURCE_STATE_COPY_DEST, NULL, + D3D12_RESOURCE_STATE_COMMON, NULL, &IID_ID3D12Resource, &buffer->impl.index_buffer)); buffer->impl.index_buffer_view.BufferLocation = buffer->impl.index_buffer->lpVtbl->GetGPUVirtualAddress(buffer->impl.index_buffer); diff --git a/base/sources/backends/direct3d12_gpu.h b/base/sources/backends/direct3d12_gpu.h index 511a5bda..042ba5cd 100644 --- a/base/sources/backends/direct3d12_gpu.h +++ b/base/sources/backends/direct3d12_gpu.h @@ -2,7 +2,6 @@ #include #include -#include "d3d12mini.h" struct ID3D12CommandAllocator; struct ID3D12GraphicsCommandList; @@ -81,6 +80,11 @@ typedef struct { uint8_t rows; } kinc_compute_internal_shader_constant_t; +typedef struct { + uint32_t hash; + uint32_t index; +} kinc_internal_hash_index_t; + typedef struct kinc_g5_compute_shader_impl { kinc_compute_internal_shader_constant_t constants[64]; int constantsSize; @@ -164,11 +168,6 @@ typedef struct { int length; } Shader5Impl; -typedef struct { - uint32_t hash; - uint32_t index; -} kinc_internal_hash_index_t; - uint32_t kinc_internal_hash_name(unsigned char *str); struct ID3D12Resource; diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index 0d40441d..47410ae1 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -7,8 +7,6 @@ #include #include #include -#include - static id command_buffer = nil; static id render_command_encoder = nil; @@ -1588,6 +1586,7 @@ void kinc_g5_render_target_init(kinc_g5_texture_t *target, int width, int height target->width = target->width = width; target->height = target->height = height; target->state = KINC_INTERNAL_RENDER_TARGET_STATE_RENDER_TARGET; + target->_uploaded = true; } static int framebuffer_count = 0; diff --git a/base/sources/backends/vulkan_gpu.c b/base/sources/backends/vulkan_gpu.c index d366c131..58e79c87 100644 --- a/base/sources/backends/vulkan_gpu.c +++ b/base/sources/backends/vulkan_gpu.c @@ -4060,6 +4060,7 @@ void kinc_g5_render_target_init(kinc_g5_texture_t *target, int width, int height target->width = width; target->height = height; target->state = KINC_INTERNAL_RENDER_TARGET_STATE_RENDER_TARGET; + target->_uploaded = true; } void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits) { diff --git a/base/sources/backends/webgpu_gpu.c b/base/sources/backends/webgpu_gpu.c index 241a927a..074a38a0 100644 --- a/base/sources/backends/webgpu_gpu.c +++ b/base/sources/backends/webgpu_gpu.c @@ -222,6 +222,7 @@ void kinc_g5_render_target_init(kinc_g5_texture_t *target, int width, int height target->height = target->height = height; target->state = KINC_INTERNAL_RENDER_TARGET_STATE_RENDER_TARGET; target->data = NULL; + target->_uploaded = true; } void kinc_g5_render_target_init_framebuffer(kinc_g5_texture_t *target, int width, int height, kinc_image_format_t format, int depthBufferBits) {} diff --git a/base/sources/backends/windows_audio.c b/base/sources/backends/windows_audio.c index 5bc178ed..25d968bc 100644 --- a/base/sources/backends/windows_audio.c +++ b/base/sources/backends/windows_audio.c @@ -1,9 +1,9 @@ #ifdef KINC_A2 -#include -#include +#include #include +#include // Windows 7 #define WINVER 0x0601 diff --git a/base/sources/backends/windows_net.c b/base/sources/backends/windows_net.c index e2d915cd..a07ff202 100644 --- a/base/sources/backends/windows_net.c +++ b/base/sources/backends/windows_net.c @@ -2,6 +2,7 @@ #include #include #include +#include #include static const wchar_t *convert(int method) { diff --git a/base/sources/backends/windows_system.c b/base/sources/backends/windows_system.c index a9da8946..8739f748 100644 --- a/base/sources/backends/windows_system.c +++ b/base/sources/backends/windows_system.c @@ -1713,7 +1713,7 @@ void kinc_init(const char *name, int width, int height, kinc_window_options_t *w kinc_g5_internal_init(); - kinc_window_create(win, frame); + kinc_window_create(win); loadXInput(); initializeDirectInput(); } diff --git a/base/sources/backends/windows_thread.c b/base/sources/backends/windows_thread.c index ac7fdd32..f3d14450 100644 --- a/base/sources/backends/windows_thread.c +++ b/base/sources/backends/windows_thread.c @@ -1,4 +1,5 @@ #include +#include void kinc_threads_init() {} @@ -30,7 +31,6 @@ void kinc_thread_init(kinc_thread_t *thread, void (*func)(void *param), void *pa starts[start_index].thread = func; starts[start_index].param = param; thread->impl.handle = CreateThread(0, 65536, ThreadProc, (LPVOID)start_index, 0, 0); - assert(thread->impl.handle != NULL); } void kinc_thread_wait_and_destroy(kinc_thread_t *thread) { @@ -71,7 +71,6 @@ void kinc_thread_sleep(int milliseconds) { } void kinc_mutex_init(kinc_mutex_t *mutex) { - assert(sizeof(RTL_CRITICAL_SECTION) == sizeof(kinc_microsoft_critical_section_t)); InitializeCriticalSection((LPCRITICAL_SECTION)&mutex->impl.criticalSection); } diff --git a/base/sources/iron.h b/base/sources/iron.h index 4866fedc..70ffb93b 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -1495,12 +1495,12 @@ buffer_t *iron_g4_get_texture_pixels(kinc_g5_texture_t *image) { // Release staging texture immediately to save memory #ifdef KINC_DIRECT3D12 - rt->impl.renderTargetReadback->lpVtbl->Release(rt->impl.renderTargetReadback); - rt->impl.renderTargetReadback = NULL; + image->impl.renderTargetReadback->lpVtbl->Release(image->impl.renderTargetReadback); + image->impl.renderTargetReadback = NULL; #elif defined(KINC_METAL) - // id texReadback = (__bridge_transfer id)rt->impl._texReadback; + // id texReadback = (__bridge_transfer id)image->impl._texReadback; // texReadback = nil; - // rt->impl._texReadback = NULL; + // image->impl._texReadback = NULL; #endif } else { diff --git a/base/sources/iron_file.c b/base/sources/iron_file.c index 9bc0bb33..b774e0a4 100644 --- a/base/sources/iron_file.c +++ b/base/sources/iron_file.c @@ -2,7 +2,7 @@ #include "iron_file.h" #include #ifdef KINC_ANDROID -#include +#include #endif #include #include @@ -52,7 +52,7 @@ const char *macgetresourcepath(void); #endif #ifdef KINC_WINDOWS -#include +#include #endif static char *fileslocation = NULL; diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index b245cb26..66a1a35e 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -498,7 +498,6 @@ void kinc_g4_set_render_targets(kinc_g5_texture_t **targets, int count) { } windows[0].current_render_target_count = count; kinc_g5_texture_t *render_targets[16]; - assert(count <= 16); for (int i = 0; i < count; ++i) { render_targets[i] = targets[i]; } diff --git a/base/sources/iron_system.c b/base/sources/iron_system.c index b241b590..18fc1f36 100644 --- a/base/sources/iron_system.c +++ b/base/sources/iron_system.c @@ -5,8 +5,8 @@ #include #include #ifdef KINC_WINDOWS -#include -#include +#include +#include #endif #ifdef KINC_ANDROID #include