diff --git a/tests/shader_runner_metal.m b/tests/shader_runner_metal.m index 38731e93..41d77c27 100644 --- a/tests/shader_runner_metal.m +++ b/tests/shader_runner_metal.m @@ -318,7 +318,42 @@ static bool metal_runner_dispatch(struct shader_runner *r, unsigned int x, unsig static void metal_runner_clear(struct shader_runner *r, struct resource *res, const struct vec4 *clear_value) { - return; + struct metal_resource *resource = metal_resource(res); + struct metal_runner *runner = metal_runner(r); + id encoder; + id command_buffer; + MTLRenderPassDescriptor *descriptor; + + @autoreleasepool + { + descriptor = [MTLRenderPassDescriptor renderPassDescriptor]; + command_buffer = [runner->queue commandBuffer]; + + switch (resource->r.desc.type) + { + case RESOURCE_TYPE_RENDER_TARGET: + descriptor.colorAttachments[0].texture = resource->texture; + descriptor.colorAttachments[0].loadAction = MTLLoadActionClear; + descriptor.colorAttachments[0].storeAction = MTLStoreActionStore; + descriptor.colorAttachments[0].clearColor = + MTLClearColorMake(clear_value->x, clear_value->y, clear_value->z, clear_value->w); + break; + case RESOURCE_TYPE_DEPTH_STENCIL: + descriptor.depthAttachment.texture = resource->texture; + descriptor.depthAttachment.loadAction = MTLLoadActionClear; + descriptor.depthAttachment.storeAction = MTLStoreActionStore; + descriptor.depthAttachment.clearDepth = clear_value->x; + break; + default: + fatal_error("Clears are not implemented for resource type %#x.\n", resource->r.desc.type); + } + + encoder = [command_buffer renderCommandEncoderWithDescriptor:descriptor]; + [encoder endEncoding]; + + [command_buffer commit]; + [command_buffer waitUntilCompleted]; + } } static bool metal_runner_draw(struct shader_runner *r, D3D_PRIMITIVE_TOPOLOGY topology,