forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
@ -0,0 +1,92 @@
|
||||
#include <string.h>
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
#include <emscripten/html5_webgpu.h>
|
||||
#include <webgpu/webgpu.h>
|
||||
#include <kinc/graphics5/graphics.h>
|
||||
#include <kinc/graphics5/pipeline.h>
|
||||
#include <kinc/math/core.h>
|
||||
#include <kinc/system.h>
|
||||
#include <kinc/log.h>
|
||||
|
||||
int renderTargetWidth;
|
||||
int renderTargetHeight;
|
||||
int newRenderTargetWidth;
|
||||
int newRenderTargetHeight;
|
||||
|
||||
WGPUDevice device;
|
||||
WGPUQueue queue;
|
||||
WGPUSwapChain swapChain;
|
||||
|
||||
void kinc_g5_internal_destroy_window(int windowId) {}
|
||||
|
||||
void kinc_g5_internal_destroy() {}
|
||||
|
||||
void kinc_g5_internal_init() {}
|
||||
|
||||
void kinc_g5_internal_init_window(int window, int depthBufferBits, int stencilBufferBits, bool vsync) {
|
||||
newRenderTargetWidth = renderTargetWidth = kinc_width();
|
||||
newRenderTargetHeight = renderTargetHeight = kinc_height();
|
||||
|
||||
device = emscripten_webgpu_get_device();
|
||||
queue = wgpuDeviceGetQueue(device);
|
||||
|
||||
WGPUSurfaceDescriptorFromCanvasHTMLSelector canvasDesc;
|
||||
memset(&canvasDesc, 0, sizeof(canvasDesc));
|
||||
canvasDesc.selector = "canvas";
|
||||
|
||||
WGPUSurfaceDescriptor surfDesc;
|
||||
memset(&surfDesc, 0, sizeof(surfDesc));
|
||||
surfDesc.nextInChain = &canvasDesc;
|
||||
WGPUInstance instance = 0;
|
||||
WGPUSurface surface = wgpuInstanceCreateSurface(instance, &surfDesc);
|
||||
|
||||
WGPUSwapChainDescriptor scDesc;
|
||||
memset(&scDesc, 0, sizeof(scDesc));
|
||||
scDesc.usage = WGPUTextureUsage_RenderAttachment;
|
||||
scDesc.format = WGPUTextureFormat_BGRA8Unorm;
|
||||
scDesc.width = kinc_width();
|
||||
scDesc.height = kinc_height();
|
||||
scDesc.presentMode = WGPUPresentMode_Fifo;
|
||||
swapChain = wgpuDeviceCreateSwapChain(device, surface, &scDesc);
|
||||
}
|
||||
|
||||
void kinc_g5_draw_indexed_vertices_instanced(int instanceCount) {}
|
||||
|
||||
void kinc_g5_draw_indexed_vertices_instanced_from_to(int instanceCount, int start, int count) {}
|
||||
|
||||
void kinc_g5_draw_indexed_vertices_instanced_from_to_from(int instanceCount, int start, int count, int vertex_offset) {}
|
||||
|
||||
void kinc_g5_begin(kinc_g5_render_target_t *renderTarget, int window) {}
|
||||
|
||||
void kinc_g5_end(int window) {}
|
||||
|
||||
bool kinc_g5_swap_buffers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void kinc_g5_flush() {}
|
||||
|
||||
bool kinc_g5_supports_raytracing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool kinc_g5_supports_instanced_rendering() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool kinc_g5_supports_compute_shaders() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool kinc_g5_supports_blend_constants() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool kinc_g5_supports_non_pow2_textures() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool kinc_g5_render_targets_inverted_y() {
|
||||
return false;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/graphics5/graphics.h>
|
||||
#include <kinc/math/matrix.h>
|
@ -0,0 +1,162 @@
|
||||
#include <string.h>
|
||||
#include <kinc/graphics5/commandlist.h>
|
||||
#include <kinc/graphics5/compute.h>
|
||||
#include <kinc/graphics5/indexbuffer.h>
|
||||
#include <kinc/graphics5/pipeline.h>
|
||||
#include <kinc/graphics5/vertexbuffer.h>
|
||||
#include <kinc/system.h>
|
||||
|
||||
extern WGPUDevice device;
|
||||
extern WGPUQueue queue;
|
||||
extern WGPUSwapChain swapChain;
|
||||
|
||||
void kinc_g5_command_list_init(kinc_g5_command_list_t *list) {}
|
||||
|
||||
void kinc_g5_command_list_destroy(kinc_g5_command_list_t *list) {}
|
||||
|
||||
void kinc_g5_command_list_begin(kinc_g5_command_list_t *list) {
|
||||
WGPUCommandEncoderDescriptor ceDesc;
|
||||
memset(&ceDesc, 0, sizeof(ceDesc));
|
||||
list->impl.encoder = wgpuDeviceCreateCommandEncoder(device, &ceDesc);
|
||||
|
||||
WGPURenderPassColorAttachment attachment;
|
||||
memset(&attachment, 0, sizeof(attachment));
|
||||
attachment.view = wgpuSwapChainGetCurrentTextureView(swapChain);;
|
||||
attachment.loadOp = WGPULoadOp_Clear;
|
||||
attachment.storeOp = WGPUStoreOp_Store;
|
||||
WGPUColor color = {0, 0, 0, 1};
|
||||
attachment.clearValue = color;
|
||||
|
||||
WGPURenderPassDescriptor passDesc;
|
||||
memset(&passDesc, 0, sizeof(passDesc));
|
||||
passDesc.colorAttachmentCount = 1;
|
||||
passDesc.colorAttachments = &attachment;
|
||||
|
||||
list->impl.pass = wgpuCommandEncoderBeginRenderPass(list->impl.encoder, &passDesc);
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_end(kinc_g5_command_list_t *list) {
|
||||
wgpuRenderPassEncoderEnd(list->impl.pass);
|
||||
|
||||
WGPUCommandBufferDescriptor cbDesc;
|
||||
memset(&cbDesc, 0, sizeof(cbDesc));
|
||||
WGPUCommandBuffer commands = wgpuCommandEncoderFinish(list->impl.encoder, &cbDesc);
|
||||
wgpuQueueSubmit(queue, 1, &commands);
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_clear(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget, unsigned flags, unsigned color, float depth,
|
||||
int stencil) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_render_target_to_framebuffer_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {}
|
||||
void kinc_g5_command_list_framebuffer_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {}
|
||||
void kinc_g5_command_list_texture_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {}
|
||||
void kinc_g5_command_list_render_target_to_texture_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {}
|
||||
|
||||
void kinc_g5_command_list_draw_indexed_vertices(kinc_g5_command_list_t *list) {
|
||||
wgpuRenderPassEncoderDrawIndexed(list->impl.pass, list->impl.indexCount, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_draw_indexed_vertices_from_to(kinc_g5_command_list_t *list, int start, int count) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_draw_indexed_vertices_instanced(kinc_g5_command_list_t *list, int instanceCount) {
|
||||
|
||||
}
|
||||
void kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(kinc_g5_command_list_t *list, int instanceCount, int start, int count) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_viewport(kinc_g5_command_list_t *list, int x, int y, int width, int height) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_scissor(kinc_g5_command_list_t *list, int x, int y, int width, int height) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_disable_scissor(kinc_g5_command_list_t *list) {}
|
||||
|
||||
void kinc_g5_command_list_set_pipeline(kinc_g5_command_list_t *list, struct kinc_g5_pipeline *pipeline) {
|
||||
wgpuRenderPassEncoderSetPipeline(list->impl.pass, pipeline->impl.pipeline);
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_blend_constant(kinc_g5_command_list_t *list, float r, float g, float b, float a) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_pipeline_layout(kinc_g5_command_list_t *list) {}
|
||||
|
||||
void kinc_g5_command_list_set_vertex_buffers(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer **buffers, int *offsets, int count) {
|
||||
uint64_t size = (kinc_g5_vertex_buffer_count(buffers[0]) - offsets[0]) * kinc_g5_vertex_buffer_stride(buffers[0]);
|
||||
wgpuRenderPassEncoderSetVertexBuffer(list->impl.pass, 0, buffers[0]->impl.buffer, 0, size);
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer) {
|
||||
list->impl.indexCount = kinc_g5_index_buffer_count(buffer);
|
||||
uint64_t size = kinc_g5_index_buffer_count(buffer) * sizeof(int);
|
||||
wgpuRenderPassEncoderSetIndexBuffer(list->impl.pass, buffer->impl.buffer, buffer->impl.format == KINC_G5_INDEX_BUFFER_FORMAT_16BIT ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32, 0, size);
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_upload_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer) {}
|
||||
void kinc_g5_command_list_upload_vertex_buffer(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer *buffer) {}
|
||||
void kinc_g5_command_list_upload_texture(kinc_g5_command_list_t *list, struct kinc_g5_texture *texture) {}
|
||||
void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, kinc_g5_render_target_t *render_target, uint8_t *data) {}
|
||||
|
||||
void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *list) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_vertex_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_compute_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face) {}
|
||||
|
||||
void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) {}
|
||||
|
||||
void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {}
|
||||
|
||||
bool kinc_g5_command_list_init_occlusion_query(kinc_g5_command_list_t *list, unsigned *occlusionQuery) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_delete_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery) {}
|
||||
|
||||
void kinc_g5_command_list_render_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery, int triangles) {}
|
||||
|
||||
bool kinc_g5_command_list_are_query_results_available(kinc_g5_command_list_t *list, unsigned occlusionQuery) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigned occlusionQuery, unsigned *pixelCount) {}
|
||||
|
||||
void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *renderTarget) {}
|
||||
|
||||
void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *renderTarget) {}
|
||||
|
||||
void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_g5_compute_shader *shader) {}
|
||||
|
||||
void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) {}
|
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
WGPUCommandEncoder encoder;
|
||||
WGPURenderPassEncoder pass;
|
||||
int indexCount;
|
||||
} CommandList5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,16 @@
|
||||
#include <kinc/graphics5/compute.h>
|
||||
#include <kinc/math/core.h>
|
||||
|
||||
void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *source, int length) {}
|
||||
|
||||
void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) {}
|
||||
|
||||
kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) {
|
||||
kinc_g5_constant_location_t location = {0};
|
||||
return location;
|
||||
}
|
||||
|
||||
kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) {
|
||||
kinc_g5_texture_unit_t unit = {0};
|
||||
return unit;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct kinc_g5_compute_shader_impl {
|
||||
int nothing;
|
||||
} kinc_g5_compute_shader_impl;
|
@ -0,0 +1,34 @@
|
||||
#include <kinc/graphics5/constantbuffer.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool kinc_g5_transposeMat3 = false;
|
||||
bool kinc_g5_transposeMat4 = false;
|
||||
|
||||
void kinc_g5_constant_buffer_init(kinc_g5_constant_buffer_t *buffer, int size) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_constant_buffer_destroy(kinc_g5_constant_buffer_t *buffer) {}
|
||||
|
||||
void kinc_g5_constant_buffer_lock_all(kinc_g5_constant_buffer_t *buffer) {
|
||||
kinc_g5_constant_buffer_lock(buffer, 0, kinc_g5_constant_buffer_size(buffer));
|
||||
}
|
||||
|
||||
void kinc_g5_constant_buffer_lock(kinc_g5_constant_buffer_t *buffer, int start, int count) {}
|
||||
|
||||
void kinc_g5_constant_buffer_unlock(kinc_g5_constant_buffer_t *buffer) {
|
||||
|
||||
}
|
||||
|
||||
int kinc_g5_constant_buffer_size(kinc_g5_constant_buffer_t *buffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
WGPUBuffer buffer;
|
||||
} ConstantBuffer5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/backend/graphics5/indexbuffer.h>
|
||||
#include <kinc/backend/graphics5/rendertarget.h>
|
||||
#include <kinc/backend/graphics5/texture.h>
|
||||
#include <kinc/backend/graphics5/vertexbuffer.h>
|
@ -0,0 +1,52 @@
|
||||
#include <kinc/graphics5/indexbuffer.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <kinc/graphics5/indexbuffer.h>
|
||||
|
||||
extern WGPUDevice device;
|
||||
|
||||
kinc_g5_index_buffer_t *kinc_g5_internal_current_index_buffer = NULL;
|
||||
|
||||
void kinc_g5_index_buffer_init(kinc_g5_index_buffer_t *buffer, int count, kinc_g5_index_buffer_format_t format, bool gpuMemory) {
|
||||
buffer->impl.count = count;
|
||||
buffer->impl.format = format;
|
||||
}
|
||||
|
||||
void kinc_g5_index_buffer_destroy(kinc_g5_index_buffer_t *buffer) {
|
||||
|
||||
}
|
||||
|
||||
static int kinc_g5_internal_index_buffer_stride(kinc_g5_index_buffer_t *buffer) {
|
||||
return buffer->impl.format == KINC_G5_INDEX_BUFFER_FORMAT_16BIT ? 2 : 4;
|
||||
}
|
||||
|
||||
void *kinc_g5_index_buffer_lock_all(kinc_g5_index_buffer_t *buffer) {
|
||||
kinc_g5_index_buffer_lock(buffer, 0, kinc_g5_index_buffer_count(buffer));
|
||||
}
|
||||
|
||||
void *kinc_g5_index_buffer_lock(kinc_g5_index_buffer_t *buffer, int start, int count) {
|
||||
WGPUBufferDescriptor bDesc;
|
||||
memset(&bDesc, 0, sizeof(bDesc));
|
||||
bDesc.size = count * kinc_g5_internal_index_buffer_stride(buffer);
|
||||
bDesc.usage = WGPUBufferUsage_Index | WGPUBufferUsage_CopyDst;
|
||||
bDesc.mappedAtCreation = true;
|
||||
buffer->impl.buffer = wgpuDeviceCreateBuffer(device, &bDesc);
|
||||
return wgpuBufferGetMappedRange(buffer->impl.buffer, start * kinc_g5_internal_index_buffer_stride(buffer), bDesc.size);
|
||||
}
|
||||
|
||||
void kinc_g5_index_buffer_unlock_all(kinc_g5_index_buffer_t *buffer) {
|
||||
wgpuBufferUnmap(buffer->impl.buffer);
|
||||
}
|
||||
|
||||
void kinc_g5_index_buffer_unlock(kinc_g5_index_buffer_t *buffer, int count) {
|
||||
kinc_g5_index_buffer_unlock_all(buffer);
|
||||
}
|
||||
|
||||
void kinc_g5_internal_index_buffer_set(kinc_g5_index_buffer_t *buffer) {
|
||||
|
||||
}
|
||||
|
||||
int kinc_g5_index_buffer_count(kinc_g5_index_buffer_t *buffer) {
|
||||
return buffer->impl.count;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
WGPUBuffer buffer;
|
||||
int count;
|
||||
int format;
|
||||
} IndexBuffer5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,233 @@
|
||||
#include <kinc/graphics5/pipeline.h>
|
||||
#include <kinc/graphics5/constantlocation.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
return location;
|
||||
}
|
||||
|
||||
kinc_g5_texture_unit_t kinc_g5_pipeline_get_texture_unit(kinc_g5_pipeline_t *pipe, const char *name) {
|
||||
kinc_g5_texture_unit_t unit;
|
||||
return unit;
|
||||
}
|
||||
|
||||
void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) {
|
||||
WGPUColorTargetState csDesc;
|
||||
memset(&csDesc, 0, sizeof(csDesc));
|
||||
csDesc.format = WGPUTextureFormat_BGRA8Unorm;
|
||||
csDesc.writeMask = WGPUColorWriteMask_All;
|
||||
WGPUBlendState blend;
|
||||
memset(&blend, 0, sizeof(blend));
|
||||
blend.color.operation = WGPUBlendOperation_Add;
|
||||
blend.color.srcFactor = WGPUBlendFactor_One;
|
||||
blend.color.dstFactor = WGPUBlendFactor_Zero;
|
||||
blend.alpha.operation = WGPUBlendOperation_Add;
|
||||
blend.alpha.srcFactor = WGPUBlendFactor_One;
|
||||
blend.alpha.dstFactor = WGPUBlendFactor_Zero;
|
||||
csDesc.blend = &blend;
|
||||
|
||||
WGPUPipelineLayoutDescriptor plDesc;
|
||||
memset(&plDesc, 0, sizeof(plDesc));
|
||||
plDesc.bindGroupLayoutCount = 0;
|
||||
plDesc.bindGroupLayouts = NULL;
|
||||
|
||||
WGPUVertexAttribute vaDesc[8];
|
||||
memset(&vaDesc[0], 0, sizeof(vaDesc[0]) * 8);
|
||||
uint64_t offset = 0;
|
||||
for (int i = 0; i < pipe->inputLayout[0]->size; ++i) {
|
||||
vaDesc[i].shaderLocation = i;
|
||||
vaDesc[i].offset = offset;
|
||||
offset += kinc_g4_vertex_data_size(pipe->inputLayout[0]->elements[i].data);
|
||||
switch (pipe->inputLayout[0]->elements[i].data) {
|
||||
case KINC_G4_VERTEX_DATA_NONE:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_F32_1X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Float32;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_F32_2X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Float32x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_F32_3X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Float32x3;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_F32_4X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Float32x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_F32_4X4:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I8_1X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U8_1X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I8_1X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U8_1X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I8_2X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint8x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U8_2X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint8x2 ;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I8_2X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Snorm8x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U8_2X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Unorm8x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I8_4X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint8x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U8_4X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint8x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I8_4X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Snorm8x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U8_4X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Unorm8x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I16_1X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U16_1X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I16_1X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U16_1X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Undefined;
|
||||
assert(false);
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I16_2X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint16x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U16_2X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint16x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I16_2X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Snorm16x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U16_2X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Unorm16x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I16_4X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint16x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U16_4X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint16x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I16_4X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Snorm16x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U16_4X_NORMALIZED:
|
||||
vaDesc[i].format = WGPUVertexFormat_Unorm16x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I32_1X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint32;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U32_1X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint32;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I32_2X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint32x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U32_2X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint32x2;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I32_3X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint32x3;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U32_3X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint32x3;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_I32_4X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Sint32x4;
|
||||
break;
|
||||
case KINC_G4_VERTEX_DATA_U32_4X:
|
||||
vaDesc[i].format = WGPUVertexFormat_Uint32x4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
WGPUVertexBufferLayout vbDesc;
|
||||
memset(&vbDesc, 0, sizeof(vbDesc));
|
||||
vbDesc.arrayStride = offset;
|
||||
vbDesc.attributeCount = pipe->inputLayout[0]->size;
|
||||
vbDesc.attributes = &vaDesc[0];
|
||||
|
||||
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;
|
||||
|
||||
WGPUPrimitiveState rsDesc;
|
||||
memset(&rsDesc, 0, sizeof(rsDesc));
|
||||
rsDesc.topology = WGPUPrimitiveTopology_TriangleList;
|
||||
rsDesc.stripIndexFormat = WGPUIndexFormat_Uint32;
|
||||
rsDesc.frontFace = WGPUFrontFace_CW;
|
||||
rsDesc.cullMode = WGPUCullMode_None;
|
||||
|
||||
WGPUMultisampleState multisample;
|
||||
memset(&multisample, 0, sizeof(multisample));
|
||||
multisample.count = 1;
|
||||
multisample.mask = 0xffffffff;
|
||||
multisample.alphaToCoverageEnabled = false;
|
||||
|
||||
WGPURenderPipelineDescriptor rpDesc;
|
||||
memset(&rpDesc, 0, sizeof(rpDesc));
|
||||
rpDesc.layout = wgpuDeviceCreatePipelineLayout(device, &plDesc);
|
||||
rpDesc.fragment = &fragmentDest;
|
||||
rpDesc.vertex = vsDest;
|
||||
rpDesc.multisample = multisample;
|
||||
rpDesc.primitive = rsDesc;
|
||||
pipe->impl.pipeline = wgpuDeviceCreateRenderPipeline(device, &rpDesc);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
WGPURenderPipeline pipeline;
|
||||
} PipelineState5Impl;
|
||||
|
||||
typedef struct {
|
||||
WGPUComputePipeline pipeline;
|
||||
} ComputePipelineState5Impl;
|
||||
|
||||
typedef struct {
|
||||
int vertexOffset;
|
||||
int fragmentOffset;
|
||||
int computeOffset;
|
||||
} ConstantLocation5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,21 @@
|
||||
#include <kinc/graphics5/rendertarget.h>
|
||||
#include <kinc/log.h>
|
||||
|
||||
void kinc_g5_render_target_init_with_multisampling(kinc_g5_render_target_t *target, int width, int height, kinc_g5_render_target_format_t format,
|
||||
int depthBufferBits, int stencilBufferBits, int samples_per_pixel) {
|
||||
|
||||
}
|
||||
|
||||
void kinc_g5_render_target_init_framebuffer_with_multisampling(kinc_g5_render_target_t *target, int width, int height, kinc_g5_render_target_format_t format,
|
||||
int depthBufferBits, int stencilBufferBits, int samples_per_pixel) {}
|
||||
|
||||
void kinc_g5_render_target_init_cube_with_multisampling(kinc_g5_render_target_t *render_target, int cubeMapSize, kinc_g5_render_target_format_t format,
|
||||
int depthBufferBits, int stencilBufferBits, int samples_per_pixel) {}
|
||||
|
||||
void kinc_g5_render_target_destroy(kinc_g5_render_target_t *renderTarget) {}
|
||||
|
||||
void kinc_g5_render_target_set_depth_stencil_from(kinc_g5_render_target_t *renderTarget, kinc_g5_render_target_t *source) {}
|
||||
|
||||
void kinc_g5_render_target_get_pixels(kinc_g5_render_target_t *renderTarget, uint8_t *data) {}
|
||||
|
||||
void kinc_g5_render_target_generate_mipmaps(kinc_g5_render_target_t *renderTarget, int levels) {}
|
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
WGPUTexture texture;
|
||||
} RenderTarget5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,5 @@
|
||||
#include <kinc/graphics5/sampler.h>
|
||||
|
||||
void kinc_g5_sampler_init(kinc_g5_sampler_t *sampler, const kinc_g5_sampler_options_t *options) {}
|
||||
|
||||
void kinc_g5_sampler_destroy(kinc_g5_sampler_t *sampler) {}
|
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct kinc_g5_sampler_impl {
|
||||
int a;
|
||||
} kinc_g5_sampler_impl_t;
|
@ -0,0 +1,38 @@
|
||||
#include <kinc/graphics5/shader.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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));
|
||||
smSpirvDesc.chain.sType = WGPUSType_ShaderModuleSPIRVDescriptor;
|
||||
smSpirvDesc.codeSize = length / 4;
|
||||
smSpirvDesc.code = source;
|
||||
WGPUShaderModuleDescriptor smDesc;
|
||||
memset(&smDesc, 0, sizeof(smDesc));
|
||||
smDesc.nextInChain = &smSpirvDesc;
|
||||
shader->impl.module = wgpuDeviceCreateShaderModule(device, &smDesc);
|
||||
}
|
||||
#endif
|
||||
|
||||
void kinc_g5_shader_destroy(kinc_g5_shader_t *shader) {}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct WGPUShaderModuleImpl;
|
||||
|
||||
typedef struct {
|
||||
#ifdef KINC_KONG
|
||||
char entry_name[256];
|
||||
#else
|
||||
WGPUShaderModule module;
|
||||
#endif
|
||||
} Shader5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,55 @@
|
||||
#include <kinc/graphics5/texture.h>
|
||||
|
||||
void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kinc_image_format_t format) {
|
||||
|
||||
// WGPUExtent3D size = {};
|
||||
// size.width = kinc_width();
|
||||
// size.height = kinc_height();
|
||||
// size.depth = 1;
|
||||
|
||||
// WGPUTextureDescriptor tDesc = {};
|
||||
// tDesc.sampleCount = 1;
|
||||
// tDesc.format = WGPUTextureFormat_BGRA8Unorm;
|
||||
// tDesc.usage = WGPUTextureUsage_OutputAttachment;
|
||||
// tDesc.size = size;
|
||||
// tDesc.dimension = WGPUTextureDimension_2D;
|
||||
// tDesc.mipLevelCount = 1;
|
||||
// tDesc.arrayLayerCount = 1;
|
||||
// WGPUTexture texture = wgpuDeviceCreateTexture(device, &tDesc);
|
||||
|
||||
// WGPUTextureViewDescriptor tvDesc = {};
|
||||
// tvDesc.format = WGPUTextureFormat_BGRA8Unorm;
|
||||
// tvDesc.dimension = WGPUTextureViewDimension_2D;
|
||||
// WGPUTextureView textureView = wgpuTextureCreateView(texture, &tvDesc);
|
||||
|
||||
}
|
||||
void kinc_g5_texture_init3d(kinc_g5_texture_t *texture, int width, int height, int depth, kinc_image_format_t format) {}
|
||||
void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *image) {}
|
||||
void kinc_g5_texture_init_from_encoded_data(kinc_g5_texture_t *texture, void *data, int size, const char *format, bool readable) {}
|
||||
void kinc_g5_texture_init_from_data(kinc_g5_texture_t *texture, void *data, int width, int height, int format, bool readable) {}
|
||||
void kinc_g5_texture_init_non_sampled_access(kinc_g5_texture_t *texture, int width, int height, kinc_image_format_t format) {}
|
||||
void kinc_g5_texture_destroy(kinc_g5_texture_t *texture) {}
|
||||
|
||||
// void Texture5Impl::unmipmap() {
|
||||
// mipmap = false;
|
||||
//}
|
||||
|
||||
// void Graphics5::Texture::_set(TextureUnit unit) {}
|
||||
|
||||
// void Texture5Impl::unset() {}
|
||||
|
||||
uint8_t *kinc_g5_texture_lock(kinc_g5_texture_t *texture) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void kinc_g5_texture_unlock(kinc_g5_texture_t *texture) {}
|
||||
|
||||
void kinc_g5_texture_clear(kinc_g5_texture_t *texture, int x, int y, int z, int width, int height, int depth, unsigned color) {}
|
||||
|
||||
int kinc_g5_texture_stride(kinc_g5_texture_t *texture) {
|
||||
return 32;
|
||||
}
|
||||
|
||||
void kinc_g5_texture_generate_mipmaps(kinc_g5_texture_t *texture, int levels) {}
|
||||
|
||||
void kinc_g5_texture_set_mipmap(kinc_g5_texture_t *texture, kinc_image_t *mipmap, int level) {}
|
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
WGPUTexture texture;
|
||||
} Texture5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,50 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <kinc/graphics5/vertexbuffer.h>
|
||||
#include <kinc/log.h>
|
||||
|
||||
extern WGPUDevice device;
|
||||
|
||||
kinc_g5_vertex_buffer_t *kinc_g5_internal_current_vertex_buffer = NULL;
|
||||
|
||||
void kinc_g5_vertex_buffer_init(kinc_g5_vertex_buffer_t *buffer, int count, kinc_g5_vertex_structure_t *structure, bool gpuMemory, int instanceDataStepRate) {
|
||||
buffer->impl.count = count;
|
||||
buffer->impl.stride = 0;
|
||||
for (int i = 0; i < structure->size; ++i) {
|
||||
buffer->impl.stride += kinc_g4_vertex_data_size(structure->elements[i].data);
|
||||
}
|
||||
}
|
||||
|
||||
void kinc_g5_vertex_buffer_destroy(kinc_g5_vertex_buffer_t *buffer) {
|
||||
|
||||
}
|
||||
|
||||
float *kinc_g5_vertex_buffer_lock_all(kinc_g5_vertex_buffer_t *buffer) {
|
||||
WGPUBufferDescriptor bDesc;
|
||||
memset(&bDesc, 0, sizeof(bDesc));
|
||||
bDesc.size = buffer->impl.count * buffer->impl.stride * sizeof(float);
|
||||
bDesc.usage = WGPUBufferUsage_Vertex | WGPUBufferUsage_CopyDst;
|
||||
bDesc.mappedAtCreation = true;
|
||||
buffer->impl.buffer = wgpuDeviceCreateBuffer(device, &bDesc);
|
||||
return wgpuBufferGetMappedRange(buffer->impl.buffer, 0, bDesc.size);
|
||||
}
|
||||
|
||||
float *kinc_g5_vertex_buffer_lock(kinc_g5_vertex_buffer_t *buffer, int start, int count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void kinc_g5_vertex_buffer_unlock_all(kinc_g5_vertex_buffer_t *buffer) {
|
||||
wgpuBufferUnmap(buffer->impl.buffer);
|
||||
}
|
||||
|
||||
void kinc_g5_vertex_buffer_unlock(kinc_g5_vertex_buffer_t* buffer, int count) {
|
||||
|
||||
}
|
||||
|
||||
int kinc_g5_vertex_buffer_count(kinc_g5_vertex_buffer_t *buffer) {
|
||||
return buffer->impl.count;
|
||||
}
|
||||
|
||||
int kinc_g5_vertex_buffer_stride(kinc_g5_vertex_buffer_t *buffer) {
|
||||
return buffer->impl.stride;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
WGPUBuffer buffer;
|
||||
int count;
|
||||
int stride;
|
||||
} VertexBuffer5Impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user