Unity-Technologies / barracuda-release

Other
561 stars 76 forks source link

RenderTexture.Create failed: requested size is too large. #278

Open aaronvdbrugge opened 2 years ago

aaronvdbrugge commented 2 years ago

I am using Barracuda for Motion Tracking. I have tried several different models (ResNet, MobileNet, different versions, etc.)

They all give me the same error in WebGL:

Texture with ID 263 and with size 16384x16 was too large for graphics device maximum supported texture size (8192x8192). Falling back to a dummy texture. Generate mip maps to provide lower size fallback. 2 barracuda.framework.js.gz:3:34456 RenderTexture.Create failed: requested size is too large.

On this piece of code:

yield return _worker.StartManualSchedule(inputs);

I have changed size of input image, tried tiny raw texture, it doesn't matter. I keep getting these huge image references in the console of web browser. Chrome can handle it but not FIreFox.

Where are these huge image sizes coming from & how do I decrease it?

image

aaronvdbrugge commented 2 years ago

I pinpointed the issue to be coming from here.

Why is the texture on this line so huge? How to fix it?

image

MaxTextureSize is way too big for FIrefox.

Why is it so large? Can it be decreased?

aaronvdbrugge commented 2 years ago

If I divide it by 4, I now get this error:

image

Any advice on this whole issue please? I don't know where this error is coming from now...

Aurimasp commented 2 years ago

Hi @aaronvdbrugge , could you share your script/project with us?

aaronvdbrugge commented 2 years ago

@Aurimasp How can I best share the project with you?

Thank you.

aaronvdbrugge commented 2 years ago

@Aurimasp Oh, actually, it is this project:

https://github.com/digital-standard/ThreeDPoseUnityBarracuda

But I upgraded Barracuda to 3.0 and turned on PixelShader mode

image

But I need to decrease MaxTextureSize or it crashes in FireFox:

image

Is that allowed?

aaronvdbrugge commented 2 years ago

Hmm, no... I don't know what MaxTextureSize does, but if I change it in BarracudaPixelShader.cs, then the pose tracking stops working correctly.

Here it is with MaxTextureSize = 16384 (not great, because I put resolution low and I'm not on screen, but you can tell it's working)

Screen Shot 2022-05-16 at 2 30 23 PM

And here it is with MaxTextureSize = 16384 / 2

image

You can see it's all messed up.

But if I leave MaxTextureSize on 16384, it crashes on FireFox (see posts above).

Please advise.

aaronvdbrugge commented 2 years ago

@Aurimasp

I looked more into this issue. At the point of public virtual float[] Download(TensorShape shape), the TensorShape length is 60000+ pixels. So it gets reduced down to MaxTextureSize, but that size is too big. It's not allowed to create a RenderTexture in Firefox larger than about 8000 pixels.

I am creating a Tensor from a Texture2D image that is only 448x448, but the width is made flat, so the result is a length of 602112x1 pixels. That gets reduced to MaxTextureSize of 16384, but it's still too big for Firefox. Maximum allowed RenderTexture is size 8192.

This is Barracuda related, not my project. Barracuda processes it this way when I create a TensorShape from a 448x448 image.

And I can't simply decrease MaxTextureSize because the Tensor stops working as intended, my output is all wrong. So it seems it needs a deeper fix or change.

So please tell me how to fix this. I need to use Barracuda PixelShader in Firefox, but it seems not possible.

aaronvdbrugge commented 2 years ago

I have another update,

This issue exists on MacOS but not on my Windows.