@@ -63,53 +63,46 @@ void ResourceManager::LoadTexture(const uint8_t* pData, DWORD dwDataSize, std::s
6363}
6464
6565void ResourceManager::CreateTextureVec4 (float r, float g, float b, float a, ComPtr<ID3D12Resource>& resource) {
66- ComPtr<ID3D12Resource> res;
67- D3D12_RESOURCE_DESC resDesc = {};
68- resDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
69- resDesc.Width = 1 ;
70- resDesc.Height = 1 ;
71- resDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
72- resDesc.SampleDesc .Count = 1 ;
73- resDesc.MipLevels = 1 ;
74- resDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
75- resDesc.DepthOrArraySize = 1 ;
76-
77- CD3DX12_HEAP_PROPERTIES resProps (D3D12_HEAP_TYPE_DEFAULT);
78- ThrowIfFailed (this ->m_dev ->CreateCommittedResource (
79- &resProps,
66+ ResourceUploadBatch upload (m_dev.Get ());
67+ upload.Begin ();
68+
69+ D3D12_RESOURCE_DESC texDesc = {};
70+ texDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
71+ texDesc.Width = 1 ;
72+ texDesc.Height = 1 ;
73+ texDesc.DepthOrArraySize = 1 ;
74+ texDesc.MipLevels = 1 ;
75+ texDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
76+ texDesc.SampleDesc .Count = 1 ;
77+ texDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
78+ texDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
79+
80+ CD3DX12_HEAP_PROPERTIES heapProps (D3D12_HEAP_TYPE_DEFAULT);
81+ ThrowIfFailed (m_dev->CreateCommittedResource (
82+ &heapProps,
8083 D3D12_HEAP_FLAG_NONE,
81- &resDesc ,
84+ &texDesc ,
8285 D3D12_RESOURCE_STATE_COPY_DEST,
8386 nullptr ,
84- IID_PPV_ARGS (res .GetAddressOf ())));
87+ IID_PPV_ARGS (resource .GetAddressOf ())));
8588
86- ComPtr<ID3D12Resource> uploadRes;
87- CD3DX12_HEAP_PROPERTIES uploadProps (D3D12_HEAP_TYPE_UPLOAD);
88- D3D12_RESOURCE_DESC uploadResDesc = CD3DX12_RESOURCE_DESC::Buffer (1024 );
89- ThrowIfFailed (this ->m_dev ->CreateCommittedResource (
90- &uploadProps,
91- D3D12_HEAP_FLAG_NONE,
92- &uploadResDesc,
93- D3D12_RESOURCE_STATE_GENERIC_READ,
94- nullptr ,
95- IID_PPV_ARGS (uploadRes.GetAddressOf ())));
96- float colorData[4 ] = { r, g, b, a };
97-
98- D3D12_SUBRESOURCE_DATA subresourceData = {};
99- subresourceData.pData = colorData;
100- subresourceData.RowPitch = sizeof (float ) * 4 ;
101- subresourceData.SlicePitch = sizeof (float ) * 4 ;
102-
103- UpdateSubresources (this ->m_list .Get (), res.Get (), uploadRes.Get (), 0 , 0 , 1 , &subresourceData);
89+ std::array<float , 4 > color = { r, g, b, a };
90+ D3D12_SUBRESOURCE_DATA initData = {};
91+ initData.pData = color.data ();
92+ initData.RowPitch = sizeof (float ) * 4 ;
93+ initData.SlicePitch = initData.RowPitch ;
10494
95+ upload.Upload (resource.Get (), 0 , &initData, 1 );
10596 D3D12* d3d12 = reinterpret_cast <D3D12*>(this ->m_renderer );
106- d3d12->ResourceBarrier (res, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
97+ upload.Transition (resource.Get (), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
98+
10799
108- res-> SetName ( L" Vector4 Texture " );
100+ upload. End (d3d12-> m_queue . Get () );
109101
110- resource = res ;
102+ resource-> SetName ( L" Vector4 Texture " ) ;
111103}
112104
105+
113106void ResourceManager::LoadTextureFile (std::string texName, ComPtr<ID3D12Resource>& resource) {
114107 if (!this ->AddResource (texName, resource)) {
115108 resource = this ->m_resources [texName];
0 commit comments