gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.69k stars 930 forks source link

Last 16-bits of u32 cant be used on certain Qualcomm Adreno GPUs #5318

Open oscrim opened 8 months ago

oscrim commented 8 months ago

Description The last 16-bits of a u32 cannot be used on certain Qualcomm Adreno devices

Repro steps I encountered this in Bevy and steps for reproducing it can be found in this issue in the Bevy repo. https://github.com/bevyengine/bevy/issues/10066

Expected vs observed behavior Expected behavior is that the WGSL shader works the same when ran on non Adreno devices as when its ran on Adreno devices

Observed behavior is that when I ran the Bevy example on a phone that uses an Adreno 660 and a tablet that uses an Adreno 619 transparency was broken, which I managed to find out was caused by a u32 bitflag where the bits for transparency was in the last 16-bits

Extra materials Issue in Bevy: https://github.com/bevyengine/bevy/issues/10066 My PR in Bevy: https://github.com/bevyengine/bevy/pull/11525

Platform Tested on:

WGPU version: 0.18

Shader lang: WGSL

cwfitzgerald commented 8 months ago

Is this only on WebGL? Does vulkan/native gl show the issue?

oscrim commented 8 months ago

Ive never tested it and Im not quite sure how I would go about testing that, Ive never compiled anything to Android but Ill give it a go

oscrim commented 8 months ago

Alright, I managed to compile an example to an apk and it works as it should! I found this AdrenoGLES-0: OpenGL ES Shader Compiler Version: EV031.35.01.09 while scanning through the logs.

It kept throwing these errors however, not sure if its related

02-28 20:35:33.064 25047 26158 E qdgralloc: GetGpuPixelFormat: No map for format: 0x38
02-28 20:35:33.064 25047 26158 E AdrenoUtils: <validate_memory_layout_input_parmas:2097>: Unknown Format 0
02-28 20:35:33.064 25047 26158 E AdrenoUtils: <adreno_init_memory_layout:4847>: Memory Layout input parameter validation failed!
02-28 20:35:33.064 25047 26158 E qdgralloc: GetGpuResourceSizeAndDimensions Graphics metadata init failed
02-28 20:35:33.064 25047 26158 E Gralloc4: isSupported(1, 1, 56, 1, ...) failed with 1
02-28 20:35:33.068 25047 26158 E GraphicBufferAllocator: Failed to allocate (4 x 4) layerCount 1 format 56 usage b00: 1
02-28 20:35:33.068 25047 26158 E AHardwareBuffer: GraphicBuffer(w=4, h=4, lc=1) failed (Unknown error -1), handle=0x0
oscrim commented 8 months ago

Ive also tried it now on bevy main which uses wgpu version 0.19.1 with the same results as before

cwfitzgerald commented 8 months ago

Thanks for testing this! Could you test verify from the AdapterInfo is running on OpenGL? We always initialize the GL backend, so just want to be sure.

Not sure what those errors are about

cwfitzgerald commented 8 months ago

This smells exactly like https://github.com/KhronosGroup/WebGL/issues/3351

oscrim commented 8 months ago

Oh, yeah it absolutely looks like that is it. I opened the testwebsite linked in that issue and also had 16-bits for Uints in FS Structs. Ill verify it asap, should be before the end of the week.

oscrim commented 8 months ago

Do you think a work around for this could be implemented into wgpu?

teoxoy commented 8 months ago

The workaround would be quite involved. I think these GPUs support Vulkan which doesn't have this issue.