Graphics Reference
In-Depth Information
First, the output texture needs to be created. This will be bound as an output to the
compute shader, but used later as an input to the hull shader. The underlying resource type
is a regular 2D texture, with the important detail of having a D3D11_BIND_UN0RDERED_
ACCESS as one of its bind flags, as shown in Listing 9.17.
// Assert on the input texture dimensions
D3D11_TEXTURE2D_DESC d = m_pHeightHapTexture->m_pTexture2dConfig->GetTextureDesc() ;
_ASSERT( 0 == (d. Width % 16) );
_ASSERT( 0 == (d. Height % 16) );
// Create the output texture
Texture2dConfigDXll LookupTextureConfig;
LookupTextureConfig. SetFormat( DXGI_F0RMAT_R32G32B32A32_FL0AT );
LookupTextureConfig. SetColorBuffer( TERRAIN_X_LEN, TERRAIN_Z_LEN );
LookupTextureConfig . SetBindFlags ( D3D11_BIND_UN0RDERED_ACCESS
| D3D11_BIND_SHADER_RES0URCE );
m_pLodLookupTexture = m_pRendererll->CreateTexture2D( SLookupTextureConfig, 0 );
II Create the effect
SAFE_DELETE( m_pComputeShaderEffect );
m_pComputeShaderEffect = new RenderEffectDXll( );
II Compile the compute shader
m_pComputeShaderEffect->m_iComputeShader =
m_pRendererll->LoadShader( COMPUTE_SHADER J
std :: wstring( L" ../Data/Shaders/InterlockingTerrainTilesComputeShader .
hlsl" ),
std::wstring( L"csMain" ),
std::wstring( L"cs_5_0" ) )j
_ASSERT( -1 != m_pComputeShaderEffect->m_iComputeShader );
Listing 9.17. Creating the compute shader.
At this point, the necessary resources have been created, so they simply need to be
bound to the pipeline. Also, the compute shader must be initiated, as shown in Listing 9.18.
// Bind the resources
m_pRendererll->m_pParamMgr->SetUnorderedAccessParameter
( L"bufferResults"j m_pLodLookupTexture );
m_pRendererll->m_pParamMgr->SetShaderResourceParameter
( L"texHeightMap", m_pHeightMapTexture );
// Determine number of threads
D3D11_TEXTURE2D_DESC d = m_pHeightMapTexture->m_pTexture2dConfig->GetTextureDesc();
// Run the compute shader
m_pRendererll->pImmPipeline->Dispatch
Search WWH ::




Custom Search