This commit is contained in:
2025-03-04 17:42:10 +01:00
parent 211700b955
commit 8fd62b365b
16 changed files with 173 additions and 46 deletions

View File

@@ -5,6 +5,7 @@
#include <string.h>
#include <stdatomic.h>
#include <tinycthread.h>
#include <spvm/ext/GLSL450.h>
#include <Pulse.h>
#include "../../PulseInternal.h"
@@ -13,8 +14,11 @@
#include "SoftDevice.h"
#include "SoftCommandList.h"
#include "SoftComputePass.h"
#include "SoftComputePipeline.h"
#include "SoftBuffer.h"
#include <stdio.h>
static void SoftCommandCopyBufferToBuffer(SoftCommand* cmd)
{
const PulseBufferRegion* src = cmd->CopyBufferToBuffer.src;
@@ -22,8 +26,59 @@ static void SoftCommandCopyBufferToBuffer(SoftCommand* cmd)
SoftBuffer* src_buffer = SOFT_RETRIEVE_DRIVER_DATA_AS(src->buffer, SoftBuffer*);
SoftBuffer* dst_buffer = SOFT_RETRIEVE_DRIVER_DATA_AS(dst->buffer, SoftBuffer*);
memcpy(dst_buffer->buffer + dst->offset, src_buffer->buffer + src->offset, (src->size < dst->size ? src->size : dst->size));
//free((void*)src);
//free((void*)dst);
free((void*)src);
free((void*)dst);
}
static int SoftCommandDispatchCore(void* arg)
{
SoftComputePipeline* soft_pipeline = (SoftComputePipeline*)arg;
spvm_state_t state = spvm_state_create(soft_pipeline->program);
spvm_ext_opcode_func* glsl_ext_data = spvm_build_glsl450_ext();
spvm_result_t glsl_std_450 = spvm_state_get_result(state, "GLSL.std.450");
if(glsl_std_450)
glsl_std_450->extension = glsl_ext_data;
spvm_word main = spvm_state_get_result_location(state, (spvm_string)soft_pipeline->entry_point);
spvm_state_prepare(state, main);
spvm_state_call_function(state);
spvm_state_delete(state);
return 0;
}
static void SoftCommandDispatch(SoftCommand* cmd)
{
SoftComputePipeline* soft_pipeline = SOFT_RETRIEVE_DRIVER_DATA_AS(cmd->Dispatch.pipeline, SoftComputePipeline*);
uint32_t local_size = soft_pipeline->program->local_size_x * soft_pipeline->program->local_size_y * soft_pipeline->program->local_size_z;
uint32_t invocations_count = cmd->Dispatch.groupcount_x * cmd->Dispatch.groupcount_y * cmd->Dispatch.groupcount_z * local_size;
thrd_t* invocations = (thrd_t*)malloc(invocations_count * sizeof(thrd_t));
PULSE_CHECK_PTR(invocations);
printf("test2 %d %d\n", invocations_count, local_size);
uint32_t invocation_index = 0;
for(uint32_t z = 0; z < cmd->Dispatch.groupcount_z; z++)
{
for(uint32_t y = 0; y < cmd->Dispatch.groupcount_y; y++)
{
for(uint32_t x = 0; x < cmd->Dispatch.groupcount_x; x++)
{
for(uint32_t i = 0; i < local_size; i++)
{
printf("\r%d", invocation_index);
thrd_create(&invocations[invocation_index], SoftCommandDispatchCore, soft_pipeline);
invocation_index++;
}
}
}
}
printf("\ntest %d %d %d\n", invocation_index, invocations_count, local_size);
for(uint32_t i = 0; i < invocations_count; i++)
{
printf("test %d\n", i);
int res;
thrd_join(invocations[i], &res);
PULSE_UNUSED(res);
}
free(invocations);
}
static int SoftCommandsRunner(void* arg)
@@ -39,15 +94,10 @@ static int SoftCommandsRunner(void* arg)
SoftCommand* command = &soft_cmd->commands[i];
switch(command->type)
{
case SOFT_COMMAND_BIND_COMPUTE_PIPELINE: break;
case SOFT_COMMAND_BIND_STORAGE_BUFFERS: break;
case SOFT_COMMAND_BIND_STORAGE_IMAGES: break;
case SOFT_COMMAND_BIND_UNIFORM_BUFFERS: break;
case SOFT_COMMAND_BLIT_IMAGES: break;
case SOFT_COMMAND_COPY_BUFFER_TO_BUFFER: SoftCommandCopyBufferToBuffer(command); break;
case SOFT_COMMAND_COPY_BUFFER_TO_IMAGE: break;
case SOFT_COMMAND_COPY_IMAGE_TO_BUFFER: break;
case SOFT_COMMAND_DISPATCH: break;
case SOFT_COMMAND_DISPATCH: SoftCommandDispatch(command); break;
case SOFT_COMMAND_DISPATCH_INDIRECT: break;
default: break;
@@ -100,15 +150,19 @@ bool SoftSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence
PULSE_UNUSED(device);
SoftCommandList* soft_cmd = SOFT_RETRIEVE_DRIVER_DATA_AS(cmd, SoftCommandList*);
cmd->state = PULSE_COMMAND_LIST_STATE_SENT;
soft_cmd->fence = fence;
if(fence != PULSE_NULL_HANDLE)
{
SoftFence* soft_fence = SOFT_RETRIEVE_DRIVER_DATA_AS(fence, SoftFence*);
soft_cmd->fence = fence;
fence->cmd = cmd;
atomic_store(&soft_fence->signal, false);
}
return thrd_create(&soft_cmd->thread, SoftCommandsRunner, cmd) == thrd_success;
}
#include <stdio.h>
void SoftReleaseCommandList(PulseDevice device, PulseCommandList cmd)
{
SoftCommandList* soft_cmd = SOFT_RETRIEVE_DRIVER_DATA_AS(cmd, SoftCommandList*);
printf("%p, %p, %p\n", cmd, soft_cmd, cmd->pass);
SoftDestroyComputePass(device, cmd->pass);
free(soft_cmd);
free(cmd);