44
55inline std::string HrToString (HRESULT hr)
66{
7- char s_str[64 ] = {};
8- sprintf_s (s_str, " HRESULT of 0x%08X" , static_cast <UINT>(hr));
9- return std::string (s_str);
7+ return std::format (" HRESULT of {:08X}" , static_cast <UINT>(hr));
108}
119
1210class HrException : public std ::runtime_error
@@ -22,10 +20,8 @@ D3D12Quad::D3D12Quad(UINT width, UINT height, std::wstring name) :
2220 m_width(width),
2321 m_height(height),
2422 m_title(name),
25- m_frameIndex(0 ),
2623 m_viewport(0 .0f , 0 .0f , static_cast <float >(width), static_cast<float>(height)),
27- m_scissorRect(0 , 0 , static_cast <LONG>(width), static_cast<LONG>(height)),
28- m_rtvDescriptorSize(0 )
24+ m_scissorRect(0 , 0 , static_cast <LONG>(width), static_cast<LONG>(height))
2925{
3026 m_aspectRatio = static_cast <float >(width) / static_cast <float >(height);
3127}
@@ -331,10 +327,10 @@ void D3D12Quad::LoadImageTexture() {
331327 textureData.SlicePitch = imageBytesPerRow * textureDesc.Height ; // also the size of our quad vertex data
332328
333329 // Now we copy the upload buffer contents to the default heap
334- UpdateSubresources (m_commandList.Get (), textureBuffer, textureBufferUploadHeap, 0 , 0 , 1 , &textureData);
330+ UpdateSubresources (m_commandList.Get (), textureBuffer. Get () , textureBufferUploadHeap. Get () , 0 , 0 , 1 , &textureData);
335331
336332 // transition the texture default heap to a pixel shader resource (we will be sampling from this heap in the pixel shader to get the color of pixels)
337- auto tb_transition = CD3DX12_RESOURCE_BARRIER::Transition (textureBuffer, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
333+ auto tb_transition = CD3DX12_RESOURCE_BARRIER::Transition (textureBuffer. Get () , D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
338334 m_commandList->ResourceBarrier (1 , &tb_transition);
339335
340336 // Describe and create a SRV for the texture.
@@ -343,7 +339,7 @@ void D3D12Quad::LoadImageTexture() {
343339 srvDesc.Format = textureDesc.Format ;
344340 srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
345341 srvDesc.Texture2D .MipLevels = 1 ;
346- m_device->CreateShaderResourceView (textureBuffer, &srvDesc, m_srvHeap->GetCPUDescriptorHandleForHeapStart ());
342+ m_device->CreateShaderResourceView (textureBuffer. Get () , &srvDesc, m_srvHeap->GetCPUDescriptorHandleForHeapStart ());
347343}
348344
349345// Create buffer that will hold the contents of the texture being drawn to the screen
@@ -524,7 +520,7 @@ void D3D12Quad::WaitForPreviousFrame()
524520}
525521
526522// get the dxgi format equivilent of a wic format
527- DXGI_FORMAT D3D12Quad::GetDXGIFormatFromWICFormat (WICPixelFormatGUID& wicFormatGUID)
523+ DXGI_FORMAT D3D12Quad::GetDXGIFormatFromWICFormat (WICPixelFormatGUID wicFormatGUID)
528524{
529525 if (wicFormatGUID == GUID_WICPixelFormat128bppRGBAFloat) return DXGI_FORMAT_R32G32B32A32_FLOAT;
530526 else if (wicFormatGUID == GUID_WICPixelFormat64bppRGBAHalf) return DXGI_FORMAT_R16G16B16A16_FLOAT;
@@ -533,7 +529,6 @@ DXGI_FORMAT D3D12Quad::GetDXGIFormatFromWICFormat(WICPixelFormatGUID& wicFormatG
533529 else if (wicFormatGUID == GUID_WICPixelFormat32bppBGRA) return DXGI_FORMAT_B8G8R8A8_UNORM;
534530 else if (wicFormatGUID == GUID_WICPixelFormat32bppBGR) return DXGI_FORMAT_B8G8R8X8_UNORM;
535531 else if (wicFormatGUID == GUID_WICPixelFormat32bppRGBA1010102XR) return DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM;
536-
537532 else if (wicFormatGUID == GUID_WICPixelFormat32bppRGBA1010102) return DXGI_FORMAT_R10G10B10A2_UNORM;
538533 else if (wicFormatGUID == GUID_WICPixelFormat16bppBGRA5551) return DXGI_FORMAT_B5G5R5A1_UNORM;
539534 else if (wicFormatGUID == GUID_WICPixelFormat16bppBGR565) return DXGI_FORMAT_B5G6R5_UNORM;
@@ -542,12 +537,11 @@ DXGI_FORMAT D3D12Quad::GetDXGIFormatFromWICFormat(WICPixelFormatGUID& wicFormatG
542537 else if (wicFormatGUID == GUID_WICPixelFormat16bppGray) return DXGI_FORMAT_R16_UNORM;
543538 else if (wicFormatGUID == GUID_WICPixelFormat8bppGray) return DXGI_FORMAT_R8_UNORM;
544539 else if (wicFormatGUID == GUID_WICPixelFormat8bppAlpha) return DXGI_FORMAT_A8_UNORM;
545-
546540 else return DXGI_FORMAT_UNKNOWN;
547541}
548542
549543// get a dxgi compatible wic format from another wic format
550- WICPixelFormatGUID D3D12Quad::GetConvertToWICFormat (WICPixelFormatGUID& wicFormatGUID)
544+ WICPixelFormatGUID D3D12Quad::GetConvertToWICFormat (WICPixelFormatGUID wicFormatGUID)
551545{
552546 if (wicFormatGUID == GUID_WICPixelFormatBlackWhite) return GUID_WICPixelFormat8bppGray;
553547 else if (wicFormatGUID == GUID_WICPixelFormat1bppIndexed) return GUID_WICPixelFormat32bppRGBA;
@@ -596,7 +590,7 @@ WICPixelFormatGUID D3D12Quad::GetConvertToWICFormat(WICPixelFormatGUID& wicForma
596590}
597591
598592// get the number of bits per pixel for a dxgi format
599- int D3D12Quad::GetDXGIFormatBitsPerPixel (DXGI_FORMAT& dxgiFormat)
593+ int D3D12Quad::GetDXGIFormatBitsPerPixel (DXGI_FORMAT dxgiFormat)
600594{
601595 if (dxgiFormat == DXGI_FORMAT_R32G32B32A32_FLOAT) return 128 ;
602596 else if (dxgiFormat == DXGI_FORMAT_R16G16B16A16_FLOAT) return 64 ;
@@ -616,7 +610,7 @@ int D3D12Quad::GetDXGIFormatBitsPerPixel(DXGI_FORMAT& dxgiFormat)
616610 else if (dxgiFormat == DXGI_FORMAT_A8_UNORM) return 8 ;
617611}
618612
619- // load and decode image from file
613+ // load and decode image from file, returning the number of image bytes
620614int D3D12Quad::LoadImageDataFromFile (BYTE** imageData, D3D12_RESOURCE_DESC& resourceDescription, LPCWSTR filename, int & bytesPerRow)
621615{
622616 HRESULT hr;
@@ -771,12 +765,7 @@ void D3D12Quad::GetHardwareAdapter(
771765 DXGI_ADAPTER_DESC1 desc;
772766 adapter->GetDesc1 (&desc);
773767
774- if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
775- {
776- // Don't select the Basic Render Driver adapter.
777- // If you want a software adapter, pass in "/warp" on the command line.
778- continue ;
779- }
768+ if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { continue ; }
780769
781770 // Check to see whether the adapter supports Direct3D 12, but don't create the
782771 // actual device yet.
0 commit comments