R32G32B32 texture format cannot be sampled in pixel shader?

Started by
3 comments, last by Adam Miles 5 years, 6 months ago

Hey,

I've come across some odd problem. I am using DirectX 11 and I've tested my results on 2 GPUs: Geforce GTX660M and GTX1060. The strange behaviour occurs surprisingly on the newer GPU - GTX1060.

I am loading HDR texture into DirectX and creating its shader resource view with DXGI_FORMAT_R32G32B32_FLOAT format:


	D3D11_SUBRESOURCE_DATA texData;
        texData.pSysMem = data; //hdr data in as a float array with rgb channels
        texData.SysMemPitch = width * (4 * 3);//size of texture row in bytes (4 bytes per each channel rgb)

        DXGI_FORMAT format = DXGI_FORMAT_R32G32B32_FLOAT;
	//the remaining (not set below) attributes have default DirectX values
        Texture2dConfigDX11 conf;
        conf.SetFormat(format);
        conf.SetWidth(width);
        conf.SetHeight(height);
        conf.SetBindFlags(D3D11_BIND_SHADER_RESOURCE);
        conf.SetCPUAccessFlags(0);
        conf.SetUsage(D3D11_USAGE_DEFAULT);

        D3D11_TEX2D_SRV srv;
        srv.MipLevels = 1;
        srv.MostDetailedMip = 0;
        ShaderResourceViewConfigDX11 srvConf;
        srvConf.SetFormat(format);
        srvConf.SetTexture2D(srv);

I'm sampling this texture using linear sampler with D3D11_FILTER_MIN_MAG_MIP_LINEAR and addressing mode: D3D11_TEXTURE_ADDRESS_CLAMP. This is how I sample the texture in a pixel shader:


SamplerState linearSampler : register(s0);
Texture2D tex;
...
float4 psMain(in PS_INPUT input) : SV_TARGET
{
	float3 color = tex.Sample(linearSampler, input.uv).rgb;

	return float4(color, 1);
}

First of all, I'm not getting any errors during runtime in release and my shader using this texture gives correct result on both GPUs. In debug mode I'm also getting correct results on both GPUs but I'm also getting following DX error (in output log in Visual Studio) when debugging the app and only on the GTX1060 GPU:


D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The Shader Resource View in slot 0 of the Pixel Shader unit is using the Format (R32G32B32_FLOAT). This format does not support 'Sample', 'SampleLevel', 'SampleBias' or 'SampleGrad', at least one of which may being used on the Resource by the shader. The exception is if the corresponding Sampler object is configured for point filtering (in which case this error can be ignored). This also only applies if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #371: DEVICE_DRAW_RESOURCE_FORMAT_SAMPLE_UNSUPPORTED]

Despite this error, the result of the shader is correct... This doesn't seem to make any sense... Is this possible that my graphics driver (I updated to the newest version) on GTX1060 doesn't support sampling R32G32B32 textures in pixel shader? This sounds like pretty basic functionality to support... R32G32B32A32 format works flawlessly in debug/release on both GPUs.

Advertisement

The fact that it works on your nvidia gpu while DX11 gives an error means that it is not required that a gpu vendor implements sampling from this format. I wouldn't rely on it. If you really need to use it, you can access a pixel directly with the brackets operator like this:


Texture2D<float3> myTexture;

// ...

float3 color = myTexture[uint2(128, 256)]; // load the pixel on coordinate (128, 256)

Then you can do a linear filtering in shader code.

https://msdn.microsoft.com/en-us/library/windows/desktop/ff471325(v=vs.85).aspx

R32G32B32 is only optionally supported for filtering - you need to query the driver for support before using it with a non-point sampler. 

Bit depths that are not a power of two (96-bit) are not particularly fun to support.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

This topic is closed to new replies.

Advertisement