From de51bd7fcf318820281d969ce1cea3d355fd6b1c Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Wed, 18 May 2016 13:57:56 -0700 Subject: [PATCH] Use brace initialization instead of memset 0 --- DDSTextureLoader/DDSTextureLoader.cpp | 9 +++------ DirectXTex/BCDirectCompute.cpp | 21 +++++++-------------- DirectXTex/DirectXTex.inl | 6 ++---- DirectXTex/DirectXTexD3D11.cpp | 3 +-- DirectXTex/DirectXTexMipmaps.cpp | 3 +-- WICTextureLoader/WICTextureLoader.cpp | 3 +-- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/DDSTextureLoader/DDSTextureLoader.cpp b/DDSTextureLoader/DDSTextureLoader.cpp index cea867a..c92aaa5 100644 --- a/DDSTextureLoader/DDSTextureLoader.cpp +++ b/DDSTextureLoader/DDSTextureLoader.cpp @@ -969,8 +969,7 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice, { if (textureView != 0) { - D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; - memset( &SRVDesc, 0, sizeof( SRVDesc ) ); + D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = format; if (arraySize > 1) @@ -1040,8 +1039,7 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice, { if (textureView != 0) { - D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; - memset( &SRVDesc, 0, sizeof( SRVDesc ) ); + D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = format; if ( isCubeMap ) @@ -1118,8 +1116,7 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice, { if (textureView != 0) { - D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; - memset( &SRVDesc, 0, sizeof( SRVDesc ) ); + D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = format; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; diff --git a/DirectXTex/BCDirectCompute.cpp b/DirectXTex/BCDirectCompute.cpp index ac66aa7..f57dc2a 100644 --- a/DirectXTex/BCDirectCompute.cpp +++ b/DirectXTex/BCDirectCompute.cpp @@ -232,8 +232,7 @@ HRESULT GPUCompressBC::Prepare( size_t width, size_t height, DXGI_FORMAT format, // Create structured buffers size_t bufferSize = num_blocks * sizeof( BufferBC6HBC7 ); { - D3D11_BUFFER_DESC desc; - memset( &desc, 0, sizeof(desc) ); + D3D11_BUFFER_DESC desc = {}; desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE; desc.Usage = D3D11_USAGE_DEFAULT; desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; @@ -261,8 +260,7 @@ HRESULT GPUCompressBC::Prepare( size_t width, size_t height, DXGI_FORMAT format, // Create staging output buffer { - D3D11_BUFFER_DESC desc; - memset( &desc, 0, sizeof(desc) ); + D3D11_BUFFER_DESC desc = {}; desc.Usage = D3D11_USAGE_STAGING; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.ByteWidth = static_cast( bufferSize ); @@ -276,8 +274,7 @@ HRESULT GPUCompressBC::Prepare( size_t width, size_t height, DXGI_FORMAT format, // Create constant buffer { - D3D11_BUFFER_DESC desc; - memset( &desc, 0, sizeof(desc) ); + D3D11_BUFFER_DESC desc = {}; desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.Usage = D3D11_USAGE_DYNAMIC; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; @@ -292,8 +289,7 @@ HRESULT GPUCompressBC::Prepare( size_t width, size_t height, DXGI_FORMAT format, // Create shader resource views { - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - memset( &desc, 0, sizeof(desc) ); + D3D11_SHADER_RESOURCE_VIEW_DESC desc = {}; desc.Buffer.NumElements = static_cast( num_blocks ); desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; @@ -312,8 +308,7 @@ HRESULT GPUCompressBC::Prepare( size_t width, size_t height, DXGI_FORMAT format, // Create unordered access views { - D3D11_UNORDERED_ACCESS_VIEW_DESC desc; - memset( &desc, 0, sizeof(desc) ); + D3D11_UNORDERED_ACCESS_VIEW_DESC desc = {}; desc.Buffer.NumElements = static_cast( num_blocks ); desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; @@ -367,8 +362,7 @@ HRESULT GPUCompressBC::Compress( const Image& srcImage, const Image& destImage ) ComPtr sourceTex; { - D3D11_TEXTURE2D_DESC desc; - memset( &desc, 0, sizeof(desc) ); + D3D11_TEXTURE2D_DESC desc = {}; desc.Width = static_cast( srcImage.width ); desc.Height = static_cast( srcImage.height ); desc.MipLevels = 1; @@ -392,8 +386,7 @@ HRESULT GPUCompressBC::Compress( const Image& srcImage, const Image& destImage ) ComPtr sourceSRV; { - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - memset( &desc, 0, sizeof(desc) ); + D3D11_SHADER_RESOURCE_VIEW_DESC desc = {}; desc.Texture2D.MipLevels = 1; desc.Format = inputFormat; desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; diff --git a/DirectXTex/DirectXTex.inl b/DirectXTex/DirectXTex.inl index ea0852b..30b044c 100644 --- a/DirectXTex/DirectXTex.inl +++ b/DirectXTex/DirectXTex.inl @@ -100,8 +100,7 @@ inline bool __cdecl IsSRGB(DXGI_FORMAT fmt) _Use_decl_annotations_ inline HRESULT __cdecl SaveToDDSMemory(const Image& image, DWORD flags, Blob& blob) { - TexMetadata mdata; - memset( &mdata, 0, sizeof(mdata) ); + TexMetadata mdata = {}; mdata.width = image.width; mdata.height = image.height; mdata.depth = 1; @@ -116,8 +115,7 @@ inline HRESULT __cdecl SaveToDDSMemory(const Image& image, DWORD flags, Blob& bl _Use_decl_annotations_ inline HRESULT __cdecl SaveToDDSFile(const Image& image, DWORD flags, LPCWSTR szFile) { - TexMetadata mdata; - memset( &mdata, 0, sizeof(mdata) ); + TexMetadata mdata = {}; mdata.width = image.width; mdata.height = image.height; mdata.depth = 1; diff --git a/DirectXTex/DirectXTexD3D11.cpp b/DirectXTex/DirectXTexD3D11.cpp index 824aa29..71a0b3d 100644 --- a/DirectXTex/DirectXTexD3D11.cpp +++ b/DirectXTex/DirectXTexD3D11.cpp @@ -611,8 +611,7 @@ HRESULT CreateShaderResourceViewEx( ID3D11Device* pDevice, const Image* srcImage assert( resource ); - D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; - memset( &SRVDesc, 0, sizeof(SRVDesc) ); + D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; if ( forceSRGB ) SRVDesc.Format = MakeSRGB( metadata.format ); else diff --git a/DirectXTex/DirectXTexMipmaps.cpp b/DirectXTex/DirectXTexMipmaps.cpp index 0f9e7b3..81392f3 100644 --- a/DirectXTex/DirectXTexMipmaps.cpp +++ b/DirectXTex/DirectXTexMipmaps.cpp @@ -2594,8 +2594,7 @@ HRESULT GenerateMipMaps( const Image& baseImage, DWORD filter, size_t levels, Sc else { //--- Use custom filters to generate mipmaps ---------------------------------- - TexMetadata mdata; - memset( &mdata, 0, sizeof(mdata) ); + TexMetadata mdata = {}; mdata.width = baseImage.width; if ( baseImage.height > 1 || !allow1D ) { diff --git a/WICTextureLoader/WICTextureLoader.cpp b/WICTextureLoader/WICTextureLoader.cpp index 70f3225..ec65980 100644 --- a/WICTextureLoader/WICTextureLoader.cpp +++ b/WICTextureLoader/WICTextureLoader.cpp @@ -640,8 +640,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, { if (textureView != 0) { - D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; - memset( &SRVDesc, 0, sizeof( SRVDesc ) ); + D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = desc.Format; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;