Sign in to follow this  
16bit_port

sampler index in d3d10?

Recommended Posts

In D3D9, I was able to set the sample states from my C++ app to a specific sampler in a shader by a sampler index, but I don't see where I can do that in any of the D3D10 device interfaces.

d3d9 samplers :

////////////.fx

sampler ColorSampler = sampler_state
{
Texture = <ColorTexture>;
};
sampler DecalSampler = sampler_state
{
Texture = <DecalTexture>;
};

///////////.cpp

//set ColorSampler
SamplerIndex = 0;
m_pd3dDevice->SetSamplerState( SamplerIndex, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
m_pd3dDevice->SetSamplerState( SamplerIndex, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);

//set DecalSampler
SamplerIndex = 1
m_pd3dDevice->SetSamplerState( SamplerIndex, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
m_pd3dDevice->SetSamplerState( SamplerIndex, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);





d3d10 samplers :

///////////.fx
SamplerState ColorSampler{
//Filter = MIN_MAG_MIP_LINEAR;
};

SamplerState DecalSampler{
//Filter = MIN_MAG_MIP_LINEAR;
};

/////////// .cpp
D3D10_SAMPLER_DESC desc;
ZeroMemory( &desc, sizeof(D3D10_SAMPLER_DESC) );
desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
desc.MinLOD = 0.f;
desc.MaxLOD = D3D10_FLOAT32_MAX;
desc.MipLODBias = 0.f;
desc.MaxAnisotropy = 16;
desc.ComparisonFunc = D3D10_COMPARISON_NEVER;

ID3D10SamplerState *SamplerState = NULL;
m_pd3dDevice->CreateSamplerState( &desc, &SamplerState );

m_pd3dDevice->PSSetSamplers( 0, 1, &SamplerState );

// WHERE DO I SPECIFY THE SAMPLER INDEX? Or say that I want DecalSampler to use this sampler state?





[Edited by - 16bit_port on September 28, 2010 3:32:05 PM]

Share this post


Link to post
Share on other sites
The index is the first parameter to PSSetSamplers. If you specify more than one they will be bound to subsequent slots.

If you want to explicitly bind a sampler state to an index you do it the same way as in previous versions:


SamplerState ColorSampler : register(s0);
SamplerState DecalSampler : register(s1);



Share this post


Link to post
Share on other sites
Is it possible to iteratively set sample states to different sample indices and then render?

i.e.

void SetSampleStates()
{
for( ... )
{
int SamplerIndex = ...

D3D10_SAMPLER_DESC samplerDesc;
...
ID3D10SamplerState *S;
m_pd3dDevice->CreateSamplerState( &samplerDesc, &S );
m_pd3dDevice->PSSetSamplers( SamplerIndex, 1, &S );
}
}

void Render()
{
SetSampleStates();

m_pd3dDevice->IASetPrimitiveTopology( ... );

D3D10_TECHNIQUE_DESC techDesc;
Shader->Technique->GetDesc( &techDesc );
for( unsigned i = 0; i < techDesc.Passes; i++ )
{
...
}

}



I tried doing it that way but I don't see any visual changes. HOWEVER, I do see one of my desired effects when I take one of states' creation and setting and paste it into the Passes loop.

i.e.

void Render()
{
m_pd3dDevice->IASetPrimitiveTopology( ... );

D3D10_TECHNIQUE_DESC techDesc;
Shader->Technique->GetDesc( &techDesc );
for( unsigned i = 0; i < techDesc.Passes; i++ )
{
D3D10_SAMPLER_DESC samplerDesc;
...
ID3D10SamplerState *S;
m_pd3dDevice->CreateSamplerState( &samplerDesc, &S );
m_pd3dDevice->PSSetSamplers( SamplerIndex, 1, &S );

...
}

}



Basically what I'm asking is should my first approach work or does it not work like that and I need to queue the sampler states and then call PSSetSamplers with that array of states?

Share this post


Link to post
Share on other sites
You can set single or multiple states in different slots without affecting slots that are untouched.

Your code is fine, accept for the fact that Effects makes changes to the pipeline. Effects is geared towards completely controlling the rendering pipeline, including states for each pass. It'll override anything you've done when you call Apply();

You could override the states after Apply(), though there is a potential for bugs since Effects tries to keep track of the pipeline in order to minimize state changes. Effects11 provides a way for you to indicate that you want to take control over some particular state yourself.

[Edited by - DieterVW on October 5, 2010 4:54:14 PM]

Share this post


Link to post
Share on other sites
So then my options are : either don't work with Effects or set the states after the apply and hope that there aren't any bugs? =(

Also, if I do something like this :

ID3D10SamplerState *samplerState = NULL;
m_pd3dDevice->CreateSamplerState( &samplerDesc1, &samplerState );
m_pd3dDevice->CreateSamplerState( &samplerDesc2, &samplerState );



do I need to do samplerState->Release() in between those CreateSamplerState calls?

[Edited by - 16bit_port on October 5, 2010 2:58:33 PM]

Share this post


Link to post
Share on other sites
If you're going to use effects, then you may as well let effects manage all of the sampler state changes for you and just not do it in the API.

Yes, any object returned by a create call will need an explicit release.

Share this post


Link to post
Share on other sites
Quote:

then you may as well let effects manage all of the sampler state changes for you


Can you elaborate? Do you mean hardcode the sampler states into the .fx file?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this