Unity-Technologies / HLSLcc

DirectX shader bytecode cross compiler
Other
854 stars 123 forks source link

samplerExternalOES support, "Inline" code added to shader output #38

Open Wunkolo opened 5 years ago

Wunkolo commented 5 years ago

This is a pretty popularly used feature for any shader that reads from a video/external texture and is pretty essential for mobile performance. Unity seems to have "abandoned" glsl support and those of us targeting multiple platforms are forced to pick one or the other(CG/HLSL or GLSL) or double the maintenance by maintaining both.

Since HLSLcc reads directly from DirectX bytecode, I do not think it is possible to propagate a samplerExternalOES resource type into the sampler declarations directly from shader source code, though maybe an "awkward" solution is by naming a variable a certain way to get it to emit the GLSL code or utilizing something like D3D10_SB_OPCODE_CUSTOMDATA or some other metadata structure to propagate certain text data from Unity's CG/HLSL shaders directly into the emitted GLSL code(kind of like an inline assembly of sorts so that from a unity shader I can put some text between a preprocessor of sorts which puts metadata into a CUSTOMDATA block for HLSLcc to handle and emit specialized code for metal or glsl and such).

GiantSox commented 3 years ago

I would love this. I'm struggling to figure out a way to unify our ShaderLab/CG shaders with our GLSL shaders. I'm willing to go as far as doing a build-time find-and-replace on the generated GLSL shader to insert the samplerExternalOES text but it doesn't seem like Unity provides an API for accessing the generated code.