Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBenS1

Posted 04 November 2012 - 02:29 PM

Somehow I seem to have missed a couple of the simpler subjects despite reading every DirectX 11 book I can find. Todays subject is Texture Samplers.

I've successfully created Samplers in code in the past using code like this:

	// Create the sample state
	D3D11_SAMPLER_DESC sampDesc;
	ZeroMemory( &sampDesc, sizeof(sampDesc) );
	sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	sampDesc.MinLOD = 0;
	sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
	DXCall(g_pd3dDevice->CreateSamplerState( &sampDesc, &m_pSamplerLinear));

However, its my understanding that you can define samplers in your HLSL code instead of your C++ code. So for example I could have the following in my HLSL:

SamplerState permSampler2d
{
Filter  = MIN_MAG_MIP_POINT;
AddressU = WRAP;
AddressV = WRAP;
};

The problem is, when I define the sampler in my HLSL code I always get the following Debug messages in Visual Studio:
449 : ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.
449 : ID3D11DeviceContext::DrawIndexed: The resource return type for component 0 declared in the shader code (FLOAT) is not compatible with the Shader Resource View format bound to slot 0 of the Pixel Shader unit (UINT).  This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching).

And any attempt to use the sampler in my Pixel Shader always returns black:

float4 PS(VertexOut pin) : SV_Target
{
float4 colour = permTexture2d.SampleLevel(permSampler2d, pin.TextureUV, 0);
return colour;
}

I've confirmed from the Visual Studio 2012 Graphics Debugger that the texture is correct at this point, and the TextureUV co-ords are correct so I can only guess I'm doing something wrong with the sampler.

I feel that I'm missing something obvious here, but I don't know what.

Any help would be appreciated.

Thanks
Ben
P.S. Note that I'm not using the Effects framework. I presume defining Samplers in HLSL isn't something that only possible through Effects?

#2BenS1

Posted 04 November 2012 - 02:28 PM

Somehow I seem to have missed a couple of the simpler subjects despite reading every DirectX 11 book I can find. Todays subject is Texture Samplers.

I've successfully created Samplers in code in the past using code like this:

	// Create the sample state
	D3D11_SAMPLER_DESC sampDesc;
	ZeroMemory( &sampDesc, sizeof(sampDesc) );
	sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	sampDesc.MinLOD = 0;
	sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
	DXCall(g_pd3dDevice->CreateSamplerState( &sampDesc, &m_pSamplerLinear));

However, its my understanding that you can define samplers in your HLSL code instead of your C++ code. So for example I could have the following in my HLSL:

SamplerState permSampler2d
{
Filter  = MIN_MAG_MIP_POINT;
AddressU = WRAP;
AddressV = WRAP;
};

The problem is, when I define the sampler in my HLSL code I always get the following Debug messages in Visual Studio:
449 : ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.
449 : ID3D11DeviceContext::DrawIndexed: The resource return type for component 0 declared in the shader code (FLOAT) is not compatible with the Shader Resource View format bound to slot 0 of the Pixel Shader unit (UINT).  This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching).

And any attempt to use the sampler in my Pixel Shader always returns black:

float4 PS(VertexOut pin) : SV_Target
{
float4 colour = permTexture2d.SampleLevel(permSampler2d, pin.TextureUV, 0);
return colour;
}

I've confirmed from the Visual Studio 2012 Graphics Debugger that the texture is correct at this point, and the TextureUV co-ords are correct so I can only guess I'm doing something wrong with the sampler.

I feel that I'm missing something obvious here, but I don't know what.

Any help would be appreciated.

Thanks
Ben

#1BenS1

Posted 04 November 2012 - 02:27 PM

Somehow I seem to have missed a couple of the simpler subjects despite reading every DirectX 11 book I can find. Todays subject is Texture Samplers.

I've successfully created Samplers in code in the past using code like this:

    // Create the sample state
    D3D11_SAMPLER_DESC sampDesc;
    ZeroMemory( &sampDesc, sizeof(sampDesc) );
    sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
    sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
    sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
    sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    sampDesc.MinLOD = 0;
    sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
    DXCall(g_pd3dDevice->CreateSamplerState( &sampDesc, &m_pSamplerLinear));

However, its my understanding that you can define samplers in your HLSL code instead of your C++ code. So for example I could have the following in my HLSL:

SamplerState permSampler2d
{
Filter  = MIN_MAG_MIP_POINT;
AddressU = WRAP;
AddressV = WRAP;
};

The problem is, when I define the sampler in my HLSL code I always get the following Debug messages in Visual Studio:
449 : ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.
449 : ID3D11DeviceContext::DrawIndexed: The resource return type for component 0 declared in the shader code (FLOAT) is not compatible with the Shader Resource View format bound to slot 0 of the Pixel Shader unit (UINT).  This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching).

And any attempt to use the sampler in my Pixel Shader always returns black:

float4 PS(VertexOut pin) : SV_Target
{
float4 colour = permTexture2d.SampleLevel(permSampler2d, pin.TextureUV, 0);
return colour;
}

I've confirmed from the Visual Studio 2012 Graphics Debugger that the texture is correct at this point, and the TextureUV co-ords are correct so I can only guess I'm doing something wrong with the sampler.

I feel that I'm missing something obvious here, but I don't know what.

Any help would be appreciated.

Thanks
Ben

PARTNERS