図0005a
void SquareSprite::CreateRootSignature() {
//ルートシグネチャ
m_RootSignature = RootSignature::CreateSrvSmpCbv();
}
//シェーダリソースとサンプラーとコンスタントバッファ static inline ComPtr<ID3D12RootSignature> CreateSrvSmpCbv() { auto Dev = App::GetApp()->GetDeviceResources(); ComPtr<ID3D12RootSignature> Ret = Dev->GetRootSignature(L"SrvSmpCbv"); if (Ret != nullptr) { return Ret; } CD3DX12_DESCRIPTOR_RANGE ranges[3]; ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0); ranges[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0); ranges[2].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0); CD3DX12_ROOT_PARAMETER rootParameters[3]; rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_PIXEL); rootParameters[1].InitAsDescriptorTable(1, &ranges[1], D3D12_SHADER_VISIBILITY_PIXEL); rootParameters[2].InitAsDescriptorTable(1, &ranges[2], D3D12_SHADER_VISIBILITY_ALL); CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); Ret = CreateDirect(rootSignatureDesc); Dev->SetRootSignature(L"SrvSmpCbv", Ret); return Ret; }
void SquareSprite::CreateDescriptorHeap() { auto Dev = App::GetApp()->GetDeviceResources(); m_CbvSrvDescriptorHandleIncrementSize = Dev->GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); //CbvSrvデスクプリタヒープ m_CbvSrvUavDescriptorHeap = DescriptorHeap::CreateCbvSrvUavHeap(1 + 1); //サンプラーデスクプリタヒープ m_SamplerDescriptorHeap = DescriptorHeap::CreateSamplerHeap(1); //GPU側デスクプリタヒープのハンドルの配列の作成 m_GPUDescriptorHandleVec.clear(); CD3DX12_GPU_DESCRIPTOR_HANDLE SrvHandle( m_CbvSrvUavDescriptorHeap->GetGPUDescriptorHandleForHeapStart(), 0, 0 ); m_GPUDescriptorHandleVec.push_back(SrvHandle); CD3DX12_GPU_DESCRIPTOR_HANDLE SamplerHandle( m_SamplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart(), 0, 0 ); m_GPUDescriptorHandleVec.push_back(SamplerHandle); CD3DX12_GPU_DESCRIPTOR_HANDLE CbvHandle( m_CbvSrvUavDescriptorHeap->GetGPUDescriptorHandleForHeapStart(), 1, m_CbvSrvDescriptorHandleIncrementSize ); m_GPUDescriptorHandleVec.push_back(CbvHandle); }
void SquareSprite::CreateShaderResourceView() { auto Dev = App::GetApp()->GetDeviceResources(); //テクスチャハンドルを作成 CD3DX12_CPU_DESCRIPTOR_HANDLE Handle( m_CbvSrvUavDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), 0, 0 ); //テクスチャのシェーダリソースビューを作成 D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; //フォーマット srvDesc.Format = m_TextureResource->GetTextureResDesc().Format; srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = m_TextureResource->GetTextureResDesc().MipLevels; //シェーダリソースビュー Dev->GetDevice()->CreateShaderResourceView( m_TextureResource->GetTexture().Get(), &srvDesc, Handle); }
void SquareSprite::CreatePipelineState() {
D3D12_GRAPHICS_PIPELINE_STATE_DESC PineLineDesc;
m_PipelineState
= PipelineState::CreateDefault2D<VertexPositionTexture,
VSPTSprite, PSPTSprite>(m_RootSignature,PineLineDesc);
//透明の場合はブレンドステート差し替え
if (m_Trace) {
D3D12_BLEND_DESC blend_desc;
D3D12_RENDER_TARGET_BLEND_DESC Target;
ZeroMemory(&blend_desc, sizeof(blend_desc));
blend_desc.AlphaToCoverageEnable = false;
blend_desc.IndependentBlendEnable = false;
ZeroMemory(&Target, sizeof(Target));
Target.BlendEnable = true;
Target.SrcBlend = D3D12_BLEND_SRC_ALPHA;
Target.DestBlend = D3D12_BLEND_INV_SRC_ALPHA;
Target.BlendOp = D3D12_BLEND_OP_ADD;
Target.SrcBlendAlpha = D3D12_BLEND_ONE;
Target.DestBlendAlpha = D3D12_BLEND_ZERO;
Target.BlendOpAlpha = D3D12_BLEND_OP_ADD;
Target.RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; i++) {
blend_desc.RenderTarget[i] = Target;
}
PineLineDesc.BlendState = blend_desc;
m_PipelineState = PipelineState::CreateDirect(PineLineDesc);
}
}
void SquareSprite::DrawObject() {
//中略
ID3D12DescriptorHeap* ppHeaps[] =
{ m_CbvSrvUavDescriptorHeap.Get(), m_SamplerDescriptorHeap.Get() };
m_CommandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
for (size_t i = 0; i < m_GPUDescriptorHandleVec.size(); i++) {
m_CommandList->SetGraphicsRootDescriptorTable(i, m_GPUDescriptorHandleVec[i]);
}
//中略
}