Skip to content

Commit

Permalink
Also format .c files in format.js
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Dec 7, 2024
1 parent 8b40695 commit e61c280
Show file tree
Hide file tree
Showing 45 changed files with 623 additions and 676 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ static void endDraw(bool compute) {
#endif
if (
#ifndef KINC_KONG
constantBufferIndex >= constantBufferMultiply ||
constantBufferIndex >= constantBufferMultiply ||
#endif
waitAfterNextDraw) {
waitAfterNextDraw) {
kinc_g5_command_list_end(&commandList);
kinc_g5_command_list_execute(&commandList);
kinc_g5_command_list_wait_for_execution_to_finish(&commandList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void kinc_g5_internal_set_compute_constants(kinc_g5_command_list_t *commandList)

commandList->impl._commandList->SetComputeRootSignature(globalComputeRootSignature);

//if (pipeline->impl.textures > 0) {
kinc_g5_internal_set_textures(commandList);
// if (pipeline->impl.textures > 0) {
kinc_g5_internal_set_textures(commandList);
//}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "rendertarget.h"

#include <kinc/backend/SystemMicrosoft.h>
#include <kinc/graphics5/rendertarget.h>
#include <kinc/graphics5/texture.h>
#include <kinc/backend/SystemMicrosoft.h>

#ifdef KINC_WINDOWS
#include <dxgi1_4.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ void kinc_g5_internal_set_textures(kinc_g5_command_list_t *list) {
shaderResourceViewDesc.Texture2D.MipLevels = 1;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.ResourceMinLODClamp = 0.0f;
device->CreateShaderResourceView(NULL, &shaderResourceViewDesc,
srvCpu);
device->CreateShaderResourceView(NULL, &shaderResourceViewDesc, srvCpu);

D3D12_SAMPLER_DESC samplerDesc;
ZeroMemory(&samplerDesc, sizeof(D3D12_SAMPLER_DESC));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void start_render_pass(void) {
renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionDontCare;
renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionDontCare;
renderPassDescriptor.stencilAttachment.texture = depthTexture;

render_command_encoder = [command_buffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_
end_render_pass();
compute_command_encoder = [command_buffer computeCommandEncoder];
}

id<MTLComputePipelineState> pipeline = (__bridge id<MTLComputePipelineState>)shader->impl._pipeline;
[compute_command_encoder setComputePipelineState:pipeline];
}

void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) {
assert(compute_command_encoder != nil);

MTLSize perGrid;
perGrid.width = x;
perGrid.height = y;
Expand All @@ -386,7 +386,7 @@ void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, in
[compute_command_encoder dispatchThreadgroups:perGrid threadsPerThreadgroup:perGroup];

[compute_command_encoder endEncoding];

compute_command_encoder = nil;

start_render_pass();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <kinc/graphics5/compute.h>
#include <kinc/graphics4/texture.h>
#include <kinc/graphics5/compute.h>
#include <kinc/math/core.h>

#include <Metal/Metal.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipel
location.impl.vertexOffset = -1;
location.impl.fragmentOffset = -1;
location.impl.computeOffset = -1;

MTLRenderPipelineReflection *reflection = (__bridge MTLRenderPipelineReflection *)pipeline->impl._reflection;

for (MTLArgument *arg in reflection.vertexArguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,59 +46,59 @@ API_AVAILABLE(macos(11.0), ios(14.0))
id<MTLAccelerationStructure> create_acceleration_sctructure(MTLAccelerationStructureDescriptor *descriptor) {
id<MTLDevice> device = getMetalDevice();
id<MTLCommandQueue> queue = getMetalQueue();

MTLAccelerationStructureSizes accel_sizes = [device accelerationStructureSizesWithDescriptor:descriptor];
id<MTLAccelerationStructure> acceleration_structure = [device newAccelerationStructureWithSize:accel_sizes.accelerationStructureSize];

id<MTLBuffer> scratch_buffer = [device newBufferWithLength:accel_sizes.buildScratchBufferSize options:MTLResourceStorageModePrivate];
id<MTLCommandBuffer> command_buffer = [queue commandBuffer];
id<MTLAccelerationStructureCommandEncoder> command_encoder = [command_buffer accelerationStructureCommandEncoder];
id<MTLBuffer> compacteds_size_buffer = [device newBufferWithLength:sizeof(uint32_t) options:MTLResourceStorageModeShared];

[command_encoder buildAccelerationStructure:acceleration_structure descriptor:descriptor scratchBuffer:scratch_buffer scratchBufferOffset:0];

[command_encoder writeCompactedAccelerationStructureSize:acceleration_structure toBuffer:compacteds_size_buffer offset:0];

[command_encoder endEncoding];
[command_buffer commit];
[command_buffer waitUntilCompleted];

uint32_t compacted_size = *(uint32_t *)compacteds_size_buffer.contents;
id<MTLAccelerationStructure> compacted_acceleration_structure = [device newAccelerationStructureWithSize:compacted_size];
command_buffer = [queue commandBuffer];
command_encoder = [command_buffer accelerationStructureCommandEncoder];
[command_encoder copyAndCompactAccelerationStructure:acceleration_structure toAccelerationStructure:compacted_acceleration_structure];
[command_encoder endEncoding];
[command_buffer commit];

return compacted_acceleration_structure;
}

API_AVAILABLE(macos(11.0), ios(14.0))
void kinc_raytrace_acceleration_structure_init(kinc_raytrace_acceleration_structure_t *accel, kinc_g5_command_list_t *command_list, kinc_g5_vertex_buffer_t *vb,
kinc_g5_index_buffer_t *ib) {
kinc_g5_index_buffer_t *ib) {
#if !TARGET_OS_IPHONE
MTLResourceOptions options = MTLResourceStorageModeManaged;
#else
MTLResourceOptions options = MTLResourceStorageModeShared;
#endif

MTLAccelerationStructureTriangleGeometryDescriptor *descriptor = [MTLAccelerationStructureTriangleGeometryDescriptor descriptor];
descriptor.indexType = MTLIndexTypeUInt32;
descriptor.indexBuffer = (__bridge id<MTLBuffer>)ib->impl.metal_buffer;
descriptor.vertexBuffer = (__bridge id<MTLBuffer>)vb->impl.mtlBuffer;
descriptor.vertexStride = vb->impl.myStride;
descriptor.triangleCount = ib->impl.count / 3;

MTLPrimitiveAccelerationStructureDescriptor *accel_descriptor = [MTLPrimitiveAccelerationStructureDescriptor descriptor];
accel_descriptor.geometryDescriptors = @[ descriptor ];
id<MTLAccelerationStructure> acceleration_structure = create_acceleration_sctructure(accel_descriptor);
_primitive_accels = [[NSMutableArray alloc] init];
[_primitive_accels addObject:acceleration_structure];

id<MTLDevice> device = getMetalDevice();
id<MTLBuffer> instance_buffer = [device newBufferWithLength:sizeof(MTLAccelerationStructureInstanceDescriptor) * 1 options:options];

MTLAccelerationStructureInstanceDescriptor *instance_descriptors = (MTLAccelerationStructureInstanceDescriptor *)instance_buffer.contents;
instance_descriptors[0].accelerationStructureIndex = 0;
instance_descriptors[0].options = MTLAccelerationStructureInstanceOptionOpaque;
Expand All @@ -107,11 +107,11 @@ void kinc_raytrace_acceleration_structure_init(kinc_raytrace_acceleration_struct
instance_descriptors[0].transformationMatrix.columns[1] = MTLPackedFloat3Make(0, 1, 0);
instance_descriptors[0].transformationMatrix.columns[2] = MTLPackedFloat3Make(0, 0, 1);
instance_descriptors[0].transformationMatrix.columns[3] = MTLPackedFloat3Make(0, 0, 0);

#if !TARGET_OS_IPHONE
[instance_buffer didModifyRange:NSMakeRange(0, instance_buffer.length)];
#endif

MTLInstanceAccelerationStructureDescriptor *inst_accel_descriptor = [MTLInstanceAccelerationStructureDescriptor descriptor];
inst_accel_descriptor.instancedAccelerationStructures = _primitive_accels;
inst_accel_descriptor.instanceCount = 1;
Expand All @@ -136,29 +136,29 @@ void kinc_raytrace_set_target(kinc_g5_texture_t *_output) {
API_AVAILABLE(macos(11.0), ios(14.0))
void kinc_raytrace_dispatch_rays(kinc_g5_command_list_t *command_list) {
dispatch_semaphore_wait(_sem, DISPATCH_TIME_FOREVER);

id<MTLCommandQueue> queue = getMetalQueue();
id<MTLCommandBuffer> command_buffer = [queue commandBuffer];
__block dispatch_semaphore_t sem = _sem;
[command_buffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
dispatch_semaphore_signal(sem);
}];

NSUInteger width = output->texWidth;
NSUInteger height = output->texHeight;
MTLSize threads_per_threadgroup = MTLSizeMake(8, 8, 1);
MTLSize threadgroups = MTLSizeMake((width + threads_per_threadgroup.width - 1) / threads_per_threadgroup.width,
(height + threads_per_threadgroup.height - 1) / threads_per_threadgroup.height, 1);
(height + threads_per_threadgroup.height - 1) / threads_per_threadgroup.height, 1);

id<MTLComputeCommandEncoder> compute_encoder = [command_buffer computeCommandEncoder];
[compute_encoder setBuffer:(__bridge id<MTLBuffer>)constant_buf->impl._buffer offset:0 atIndex:0];
[compute_encoder setAccelerationStructure:_instance_accel atBufferIndex:1];
[compute_encoder setTexture:(__bridge id<MTLTexture>)output->impl._tex atIndex:0];

for (id<MTLAccelerationStructure> primitive_accel in _primitive_accels) {
[compute_encoder useResource:primitive_accel usage:MTLResourceUsageRead];
}

[compute_encoder setComputePipelineState:_raytracing_pipeline];
[compute_encoder dispatchThreadgroups:threadgroups threadsPerThreadgroup:threads_per_threadgroup];
[compute_encoder endEncoding];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ static MTLSamplerAddressMode convert_addressing(kinc_g5_texture_addressing_t mod
case KINC_G5_TEXTURE_ADDRESSING_REPEAT:
return MTLSamplerAddressModeRepeat;
case KINC_G5_TEXTURE_ADDRESSING_BORDER:
if (@available(iOS 14.0, *)) {
return MTLSamplerAddressModeClampToBorderColor;
}
else {
return MTLSamplerAddressModeClampToEdge;
}
if (@available(iOS 14.0, *)) {
return MTLSamplerAddressModeClampToBorderColor;
}
else {
return MTLSamplerAddressModeClampToEdge;
}
case KINC_G5_TEXTURE_ADDRESSING_CLAMP:
return MTLSamplerAddressModeClampToEdge;
case KINC_G5_TEXTURE_ADDRESSING_MIRROR:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#pragma once

#define KINC_INTERNAL_NAMED_NUMBER_COUNT 32

typedef struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#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/log.h>
#include <kinc/math/core.h>
#include <kinc/system.h>
#include <kinc/log.h>
#include <string.h>
#include <webgpu/webgpu.h>

int renderTargetWidth;
int renderTargetHeight;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#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>
#include <string.h>

extern WGPUDevice device;
extern WGPUQueue queue;
Expand All @@ -21,7 +21,8 @@ void kinc_g5_command_list_begin(kinc_g5_command_list_t *list) {

WGPURenderPassColorAttachment attachment;
memset(&attachment, 0, sizeof(attachment));
attachment.view = wgpuSwapChainGetCurrentTextureView(swapChain);;
attachment.view = wgpuSwapChainGetCurrentTextureView(swapChain);
;
attachment.loadOp = WGPULoadOp_Clear;
attachment.storeOp = WGPUStoreOp_Store;
WGPUColor color = {0, 0, 0, 1};
Expand All @@ -45,9 +46,7 @@ void kinc_g5_command_list_end(kinc_g5_command_list_t *list) {
}

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) {

}
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) {}
Expand All @@ -58,24 +57,14 @@ 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_from_to(kinc_g5_command_list_t *list, int start, int count) {}

}
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_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_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_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) {}

Expand All @@ -97,43 +86,30 @@ void kinc_g5_command_list_set_vertex_buffers(kinc_g5_command_list_t *list, struc
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);
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_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_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_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_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_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_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) {}

Expand All @@ -155,7 +131,8 @@ void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigne

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_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) {}

Expand Down
Loading

0 comments on commit e61c280

Please sign in to comment.