Friday, 15 July 2011

ios - Manually set a 1D Texture in Metal -



ios - Manually set a 1D Texture in Metal -

i'm trying fill 1d texture values manually , pass texture compute shader (these 2 pixels want set via code, don't represent image).

due current little amount of metal examples, examples find deal 2d textures load texture converting loaded uiimage raw bytes data, creating dummy uiimage felt hack me.

this "naive" way started -

... var manualtexturedata: [float] = [ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0 ]; allow region: mtlregion = mtlregionmake1d(0, texturedescriptor.width); mytexture.replaceregion(region, mipmaplevel: 0, withbytes: &manualtexturedata, bytesperrow: 0);

but metal doesn't recognize values in shader (it gets empty texture, except first value).

i realized float array has converted bytes array (e.g uint8), couldn't find way convert [float] [uint8] either.

another possible alternative consider using cvpixelbuffer object, felt workaround problem.

so whats right way tackle that?

thanks in advance.

please note i'm not familiar objective-c, hence i'm not sure whether using cvpixelbuffer / uiimage exaggerated should straight-forward.

i don't see reason pass info using 1d texture. instead go passing buffer. this:

var databuffer:mtlbuffer? = device.newbufferwithbytes(&manualtexturedata, length: sizeof(manualtexturedata), options: mtlresourceoptions.optioncpucachemodedefault)

then hook rendercommandencoder this:

rendercommandencoder.setfragmentbuffer(databuffer, offset: 0, atindex: 1)//note if want buffer passed vertex shader should utilize setvertexbuffer

then in shader, should add together parameter const device float* bufferpassed [[ buffer(1) ]]

and utilize this, within shader implementation:

float firstfloat = bufferpassed[0];

this job done.

ios swift gpgpu metal

No comments:

Post a Comment