Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you clear a GPU texture using metal?

I've got a 3D texture that is only accessible to the GPU, which I'm trying to clear at the start of a frame. I've tried setting each element to zero using a computer shader, but that's taking nearly 3ms for a 64x64x64 texture, and I'd like to use something bigger than that.

It would be great if I could do something like the clear-on-load action for color attachments, but I'm don't think that's possible in this situation.

What's the fastest way to clear the texture?

like image 299
Curyous Avatar asked Nov 02 '25 17:11

Curyous


1 Answers

The easiest way to do this is by using the renderPassDesciptor's loadActions, like so:

MTLRenderPassDescriptor *rpdesc = [MTLRenderPassDescriptor renderPassDescriptor];
rpdesc.colorAttachments[0].clearColor = MTLClearColorMake(0,0,0,0);
rpdesc.colorAttachments[0].loadAction = MTLLoadActionClear;
like image 149
WrinkleFree Avatar answered Nov 04 '25 08:11

WrinkleFree