mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-10 15:03:34 +00:00
adding command list to metal backend
This commit is contained in:
@@ -50,6 +50,12 @@ int main(void)
|
||||
info.num_readwrite_storage_buffers = 1;
|
||||
PulseComputePipeline pipeline = PulseCreateComputePipeline(device, &info);
|
||||
|
||||
PulseFence fence = PulseCreateFence(device);
|
||||
PulseCommandList cmd = PulseRequestCommandList(device, PULSE_COMMAND_LIST_GENERAL);
|
||||
|
||||
PulseReleaseCommandList(device, cmd);
|
||||
PulseDestroyFence(device, fence);
|
||||
|
||||
PulseDestroyComputePipeline(device, pipeline);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
#ifndef PULSE_TEMPLATE_COMMAND_LIST_H_
|
||||
#define PULSE_TEMPLATE_COMMAND_LIST_H_
|
||||
|
||||
#include <stdatomic.h>
|
||||
#include <tinycthread.h>
|
||||
|
||||
#include "Template.h"
|
||||
#include "TemplateFence.h"
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
|
||||
#include "Template.h"
|
||||
|
||||
typedef struct MetalComputePass
|
||||
{
|
||||
int dummy;
|
||||
} MetalComputePass;
|
||||
|
||||
PulseComputePass TemplateNameCreateComputePass(PulseDevice device, PulseCommandList cmd);
|
||||
void TemplateNameDestroyComputePass(PulseDevice device, PulseComputePass pass);
|
||||
|
||||
|
||||
@@ -66,8 +66,11 @@ bool MetalCopyBufferToImage(PulseCommandList cmd, const PulseBufferRegion* src,
|
||||
|
||||
void MetalDestroyBuffer(PulseDevice device, PulseBuffer buffer)
|
||||
{
|
||||
MetalBuffer* metal_buffer = METAL_RETRIEVE_DRIVER_DATA_AS(buffer, MetalBuffer*);
|
||||
metal_buffer->buffer = nil;
|
||||
free(metal_buffer);
|
||||
free(buffer);
|
||||
@autoreleasepool
|
||||
{
|
||||
MetalBuffer* metal_buffer = METAL_RETRIEVE_DRIVER_DATA_AS(buffer, MetalBuffer*);
|
||||
metal_buffer->buffer = nil;
|
||||
free(metal_buffer);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,14 @@
|
||||
#ifndef PULSE_METAL_COMMAND_LIST_H_
|
||||
#define PULSE_METAL_COMMAND_LIST_H_
|
||||
|
||||
#include <stdatomic.h>
|
||||
#include <tinycthread.h>
|
||||
|
||||
#include <Metal/Metal.h>
|
||||
#include "Metal.h"
|
||||
#include "MetalFence.h"
|
||||
|
||||
typedef struct MetalCommandList
|
||||
{
|
||||
int dummy;
|
||||
id<MTLCommandBuffer> cmd;
|
||||
id<MTLBlitCommandEncoder> copy_encoder;
|
||||
} MetalCommandList;
|
||||
|
||||
PulseCommandList MetalRequestCommandList(PulseDevice device, PulseCommandListUsage usage);
|
||||
|
||||
@@ -14,10 +14,23 @@
|
||||
|
||||
PulseCommandList MetalRequestCommandList(PulseDevice device, PulseCommandListUsage usage)
|
||||
{
|
||||
PULSE_CHECK_HANDLE_RETVAL(device, PULSE_NULL_HANDLE);
|
||||
PulseCommandList cmd = (PulseCommandList)calloc(1, sizeof(PulseCommandListHandler));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(cmd, PULSE_NULL_HANDLE);
|
||||
return cmd;
|
||||
@autoreleasepool
|
||||
{
|
||||
PULSE_UNUSED(usage);
|
||||
|
||||
MetalDevice* metal_device = (MetalDevice*)METAL_RETRIEVE_DRIVER_DATA_AS(device, MetalDevice*);
|
||||
|
||||
PulseCommandList cmd = (PulseCommandList)calloc(1, sizeof(PulseCommandListHandler));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(cmd, PULSE_NULL_HANDLE);
|
||||
|
||||
MetalCommandList* metal_cmd = (MetalCommandList*)calloc(1, sizeof(MetalCommandList));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(metal_cmd, PULSE_NULL_HANDLE);
|
||||
|
||||
metal_cmd->cmd = [metal_device->queue commandBuffer];
|
||||
|
||||
cmd->driver_data = metal_cmd;
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
bool MetalSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence fence)
|
||||
@@ -26,4 +39,12 @@ bool MetalSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence
|
||||
|
||||
void MetalReleaseCommandList(PulseDevice device, PulseCommandList cmd)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
PULSE_UNUSED(device);
|
||||
MetalCommandList* metal_cmd = METAL_RETRIEVE_DRIVER_DATA_AS(cmd, MetalCommandList*);
|
||||
metal_cmd->cmd = nil;
|
||||
free(metal_cmd);
|
||||
free(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,14 @@
|
||||
#ifndef PULSE_METAL_COMPUTE_PASS_H_
|
||||
#define PULSE_METAL_COMPUTE_PASS_H_
|
||||
|
||||
#include <Metal/Metal.h>
|
||||
#include "Metal.h"
|
||||
|
||||
typedef struct MetalComputePass
|
||||
{
|
||||
id<MTLComputeCommandEncoder> encoder;
|
||||
} MetalComputePass;
|
||||
|
||||
PulseComputePass MetalCreateComputePass(PulseDevice device, PulseCommandList cmd);
|
||||
void MetalDestroyComputePass(PulseDevice device, PulseComputePass pass);
|
||||
|
||||
|
||||
@@ -75,12 +75,16 @@ PulseComputePipeline MetalCreateComputePipeline(PulseDevice device, const PulseC
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
MetalDevice* metal_device = (MetalDevice*)METAL_RETRIEVE_DRIVER_DATA_AS(device, MetalDevice*);
|
||||
|
||||
PulseComputePipelineHandler* pipeline = (PulseComputePipelineHandler*)calloc(1, sizeof(PulseComputePipelineHandler));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(pipeline, PULSE_NULL_HANDLE);
|
||||
|
||||
MetalComputePipeline* metal_pipeline = (MetalComputePipeline*)calloc(1, sizeof(MetalComputePipeline));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(metal_pipeline, PULSE_NULL_HANDLE);
|
||||
|
||||
pipeline->driver_data = metal_pipeline;
|
||||
|
||||
MetalLibraryFunction library_function = MetalCompileShader(device, info);
|
||||
if(library_function.library == nil || library_function.function == nil)
|
||||
{
|
||||
@@ -90,7 +94,18 @@ PulseComputePipeline MetalCreateComputePipeline(PulseDevice device, const PulseC
|
||||
return PULSE_NULL_HANDLE;
|
||||
}
|
||||
|
||||
pipeline->driver_data = metal_pipeline;
|
||||
MTLComputePipelineDescriptor* descriptor = [MTLComputePipelineDescriptor new];
|
||||
descriptor.computeFunction = library_function.function;
|
||||
|
||||
NSError* error;
|
||||
metal_pipeline->pipeline = [metal_device->device newComputePipelineStateWithDescriptor:descriptor options:MTLPipelineOptionNone reflection: nil error:&error];
|
||||
if(error)
|
||||
{
|
||||
if(PULSE_IS_BACKEND_LOW_LEVEL_DEBUG(device->backend))
|
||||
PulseLogErrorFmt(device->backend, "(Metal) failed to create compute compute pipeline; %s", [[error description] UTF8String]);
|
||||
PulseSetInternalError(PULSE_ERROR_INITIALIZATION_FAILED);
|
||||
return PULSE_NULL_HANDLE;
|
||||
}
|
||||
|
||||
if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(device->backend))
|
||||
PulseLogInfoFmt(device->backend, "(Metal) created new compute pipeline %p", pipeline);
|
||||
@@ -100,10 +115,13 @@ PulseComputePipeline MetalCreateComputePipeline(PulseDevice device, const PulseC
|
||||
|
||||
void MetalDestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline)
|
||||
{
|
||||
MetalComputePipeline* metal_pipeline = METAL_RETRIEVE_DRIVER_DATA_AS(pipeline, MetalComputePipeline*);
|
||||
metal_pipeline->pipeline = nil;
|
||||
free(metal_pipeline);
|
||||
if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(device->backend))
|
||||
PulseLogInfoFmt(device->backend, "(Metal) destroyed compute pipeline %p", pipeline);
|
||||
free(pipeline);
|
||||
@autoreleasepool
|
||||
{
|
||||
MetalComputePipeline* metal_pipeline = METAL_RETRIEVE_DRIVER_DATA_AS(pipeline, MetalComputePipeline*);
|
||||
metal_pipeline->pipeline = nil;
|
||||
free(metal_pipeline);
|
||||
if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(device->backend))
|
||||
PulseLogInfoFmt(device->backend, "(Metal) destroyed compute pipeline %p", pipeline);
|
||||
free(pipeline);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "../../PulseInternal.h"
|
||||
#include "WebGPU.h"
|
||||
#include "WebGPUDevice.h"
|
||||
#include "webgpu.h"
|
||||
#include "WebGPUComputePipeline.h"
|
||||
|
||||
typedef struct WebGPUBindGroupLayoutEntryInfo
|
||||
|
||||
Reference in New Issue
Block a user