In the fragment function of a Metal Shader file, is there a way to redefine the "bounds" of the texture with respect to what the sample will consider it's normalized coordinates to be?
By default, a value of 0,0 for the sample is the top-left "pixel" and 1,1 is the bottom right "pixel" of the texture. However, I'm re-using textures for drawing and at any given render pass there's only a portion of the texture that contains the relevant data.
For example, in a texture of width: 500 and height: 500, I might have only copied data into the region of 0,0,250,250. In my fragment function, I'd like the sampler to interpret a normalized coordinate of 1.0 to be 250 and not 500. Is that possible?
I realize I can just change the sampler to use pixel addressing, but that comes with a few restrictions as noted in the Metal Shader Specification.
bytesPerRow
but a smallerwidth
andheight
? – rob mayoffCVMetalTextureCache
, which is being fed with aCVPixelBufferRef
that is backed by anIOSurface
who's width and height could be anything. TheIOSurface
is being used to shuttle data from an XPC service and the XPC service is only going to write into the IOSurface within the region it needs. So I was hoping I could easily clamp my sampler to that region of the texture rather than creating a new texture. – kennycCVMetalTextureCacheCreateTextureFromImage
too expensive? You can use the sameCVPixelBufferRef
to create multiple textures. – rob mayoffwidth
andheight
property for setting the dimensions of the buffer, but no origin.) I guess I just assumed that any textures that get created with a CVPixelBuffer backing should have the same dimensions. – kennyc