#Looking for a well supported GraphicsFormat to store 2 uint16 s / 1 uint32 (packed)

1 messages · Page 1 of 1 (latest)

halcyon creek
#

Hi, I'm trying to render some mesh data to a texture
The data consists of two indices, both are ushorts on the c# side
Since hlsl support for 16 bit integers is a bit weird, I'm sending that data packed as a single uint which has worked out so far

The issue I'm facing now is that I haven't found a well suited GraphicsFormat to render to
I made a small helper script, to check whether the obvious choices like R32_Uint or R16G16_Uint support both rendering and sampling, but none of the ones I thought would be a great fit are supported according to SystemInfo.IsFormatSupported
This is especially concerning since I'm targeting mobile and I expect support for stuff like that will be worse on phones

tldr

I need a well supported GraphicsFormat (should work on mobile) to store 2 uint16s (packing them as a uint32 is fine)
It's important that it at least supports rendering and sampling
I might actually need support for more than that, but those two are the onlyGraphicsFormatUsages that are obvious to me

halcyon creek
#

I think I might actually be looking for ones with support for Render and LoadStore
That would mean the formats I previously mentioned would actually be supported, which is weird because the frame debugger shows them as completely black, even if I write values to them

halcyon creek
#

I've gotten it to work, but the solution is rather unsatisfying

I'm using GraphicsFormat.R32_UInt with this code:

float Frag(Varyings IN, uint primitiveId : SV_PrimitiveID) : SV_Target
{
    uint packedData = _TriangleData[primitiveId];

    return packedData;
}

This code doesn't work:

uint Frag(Varyings IN, uint primitiveId : SV_PrimitiveID) : SV_Target
{
    uint packedData = _TriangleData[primitiveId];

    return packedData;
}

The only difference is that the second one uses uint as return type, which breaks it completely

#

even though that's what the texture should be storing

#

Doesn't work on mobile tho

#

According to SystemInfo.IsFormatSupported , R32_Uint is supported with GraphicsFormatUsage.Render and GraphicsFormatUsage.LoadStore so that shouldn't be causing issues

#

And using uint instead of float as return type doesn't help either

halcyon creek
#

I got it to work on my phone using R32_Sfloat instead of R32_Uint, and with some adjustments

// writing data
float Frag(Varyings IN, uint primitiveId : SV_PrimitiveID) : SV_Target
{
    uint packedData = _TriangleData[primitiveId];
    return asfloat(packedData);
}

// reading data
half3 Frag(Varyings input) : SV_Target
{
    int2 pixelCoord = int2(input.uv * _ScreenParams.xy);
    uint packedData = asuint(LOAD_TEXTURE2D(_MapData, pixelCoord).r);

    uint regionId, polygonId;
    UnpackMapData(packedData, regionId, polygonId);

    return half3(regionId / 200., 0, polygonId / 200.);
}
crisp dagger
#

i have no clue what's this about but care to explain? render mesh data to texture.. what does that even mean?