0

I want to store image float data in an unformatted memory location from within my shader, and MTLBuffer seems to be the answer. Firstly, is this possible? I saw within the apple docs of MTLBuffer that one can access the pointer pointing to the buffer. Is it possible to use that pointer from within the shader to fill up allocated memory? Secondly, I wish to get some idea how fast this operation will be; will it be fast and efficient as operating with Textures?

I ask this as I need to re-engineer a lot of my code if it is confirmed that MTLBuffer's speed of access is comparable to operating with MTLTexture.

CaladanBrood
  • 192
  • 3
  • 17

1 Answers1

1

First, it's important to be aware of several restrictions:

  • Fragment shaders neither support writing to textures nor to buffers. You're only option is rendering to textures.
  • Vertex shaders support support writes to buffers but not to textures.

So if you're using either of these shader types, you don't have a choice between texture writes and buffer writes, regardless of performance.
If you're using a compute shader and your write pattern is relatively simple (i.e. a 1-to-1 thread id to pixel correspondence), I'd expected buffer writes to be faster. That said, there is no good general advice, so the best solution is to try both and profile.

bronxbomber92
  • 280
  • 2
  • 5
  • Hi. It appears my only option is to just profile and see, as you suggested. I'm using a compute shader, by the way. I'll see what happens, then, and be back with my findings. – CaladanBrood Apr 23 '15 at 07:57
  • This has changed! Fragment shaders can now write to buffers: https://stackoverflow.com/a/46943707/74975 – Pat Niemeyer May 27 '20 at 18:47