Texture1D_D3D11 :: Texture1D_D3D11(IReferenceCounters *pRefCounters, FixedBlockMemoryAllocator &TexViewObjAllocator, RenderDeviceD3D11Impl *pRenderDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData /*= TextureData()*/) : TextureBaseD3D11(pRefCounters, TexViewObjAllocator, pRenderDeviceD3D11, TexDesc, InitData) { auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags); auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags); auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage); UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags); auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); D3D11_TEXTURE1D_DESC Tex1DDesc = { m_Desc.Width, m_Desc.MipLevels, m_Desc.ArraySize, D3D11TexFormat, D3D11Usage, D3D11BindFlags, D3D11CPUAccessFlags, MiscFlags }; std::vector<D3D11_SUBRESOURCE_DATA, STDAllocatorRawMem<D3D11_SUBRESOURCE_DATA>> D3D11InitData( STD_ALLOCATOR_RAW_MEM(D3D11_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector<D3D11_SUBRESOURCE_DATA>") ); PrepareD3D11InitData(InitData, Tex1DDesc.ArraySize * Tex1DDesc.MipLevels, D3D11InitData); ID3D11Texture1D *ptex1D = nullptr; HRESULT hr = pDeviceD3D11->CreateTexture1D(&Tex1DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex1D); m_pd3d11Texture.Attach(ptex1D); CHECK_D3D_RESULT_THROW( hr, "Failed to create the Direct3D11 Texture1D" ); }
void RenderDeviceD3D11Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) { auto &TexFormatInfo = m_TextureFormatsInfo[TexFormat]; VERIFY( TexFormatInfo.Supported, "Texture format is not supported" ); auto DXGIFormat = TexFormatToDXGI_Format(TexFormat); UINT DefaultBind = 0; if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) DefaultBind = D3D11_BIND_DEPTH_STENCIL; else DefaultBind = D3D11_BIND_SHADER_RESOURCE; const int TestTextureDim = 32; const int TestTextureDepth = 8; // Create test texture 1D TexFormatInfo.Tex1DFmt = false; if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED ) { D3D11_TEXTURE1D_DESC Tex1DDesc = { TestTextureDim, // UINT Width; 1, // UINT MipLevels; 1, // UINT ArraySize; DXGIFormat, // DXGI_FORMAT Format; D3D11_USAGE_DEFAULT, // D3D11_USAGE Usage; DefaultBind, // UINT BindFlags; 0, // UINT CPUAccessFlags; 0 // UINT MiscFlags; }; TexFormatInfo.Tex1DFmt = CreateTestTexture1D(m_pd3d11Device, Tex1DDesc ); } // Create test texture 2D TexFormatInfo.Tex2DFmt = false; TexFormatInfo.TexCubeFmt = false; TexFormatInfo.ColorRenderable = false; TexFormatInfo.DepthRenderable = false; TexFormatInfo.SupportsMS = false; { D3D11_TEXTURE2D_DESC Tex2DDesc = { TestTextureDim, // UINT Width; TestTextureDim, // UINT Height; 1, // UINT MipLevels; 1, // UINT ArraySize; DXGIFormat, // DXGI_FORMAT Format; { 1, 0 }, // DXGI_SAMPLE_DESC SampleDesc; D3D11_USAGE_DEFAULT, // D3D11_USAGE Usage; DefaultBind, // UINT BindFlags; 0, // UINT CPUAccessFlags; 0, // UINT MiscFlags; }; TexFormatInfo.Tex2DFmt = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); if( TexFormatInfo.Tex2DFmt ) { { D3D11_TEXTURE2D_DESC CubeTexDesc = Tex2DDesc; CubeTexDesc.ArraySize = 6; CubeTexDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; TexFormatInfo.TexCubeFmt = CreateTestTexture2D( m_pd3d11Device, CubeTexDesc ); } if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) { Tex2DDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; TexFormatInfo.DepthRenderable = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); if( TexFormatInfo.DepthRenderable ) { Tex2DDesc.SampleDesc.Count = 4; TexFormatInfo.SupportsMS = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); } } else if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED && TexFormatInfo.Format != DXGI_FORMAT_R9G9B9E5_SHAREDEXP) { Tex2DDesc.BindFlags = D3D11_BIND_RENDER_TARGET; TexFormatInfo.ColorRenderable = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); if( TexFormatInfo.ColorRenderable ) { Tex2DDesc.SampleDesc.Count = 4; TexFormatInfo.SupportsMS = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); } } } } // Create test texture 3D TexFormatInfo.Tex3DFmt = false; // 3D textures do not support depth formats if( !(TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) ) { D3D11_TEXTURE3D_DESC Tex3DDesc = { TestTextureDim, // UINT Width; TestTextureDim, // UINT Height; TestTextureDepth, // UINT Depth; 1, // UINT MipLevels; DXGIFormat, // DXGI_FORMAT Format; D3D11_USAGE_DEFAULT,// D3D11_USAGE Usage; DefaultBind, // UINT BindFlags; 0, // UINT CPUAccessFlags; 0 // UINT MiscFlags; }; TexFormatInfo.Tex3DFmt = CreateTestTexture3D( m_pd3d11Device, Tex3DDesc ); } }
void RenderDeviceD3D12Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) { auto &TexFormatInfo = m_TextureFormatsInfo[TexFormat]; VERIFY( TexFormatInfo.Supported, "Texture format is not supported" ); auto DXGIFormat = TexFormatToDXGI_Format(TexFormat); D3D12_RESOURCE_FLAGS DefaultResourceFlags = D3D12_RESOURCE_FLAG_NONE; if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) DefaultResourceFlags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; const int TestTextureDim = 32; const int TestTextureDepth = 8; D3D12_RESOURCE_DESC ResDesc = { D3D12_RESOURCE_DIMENSION_TEXTURE1D, 0, // Alignment TestTextureDim, 1, // Height 1, // DepthOrArraySize 1, // MipLevels DXGIFormat, {1, 0}, D3D12_TEXTURE_LAYOUT_UNKNOWN, DefaultResourceFlags }; // Create test texture 1D TexFormatInfo.Tex1DFmt = false; if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED ) { TexFormatInfo.Tex1DFmt = CreateTestResource(m_pd3d12Device, ResDesc ); } // Create test texture 2D TexFormatInfo.Tex2DFmt = false; TexFormatInfo.TexCubeFmt = false; TexFormatInfo.ColorRenderable = false; TexFormatInfo.DepthRenderable = false; TexFormatInfo.SupportsMS = false; { ResDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; ResDesc.Height = TestTextureDim; TexFormatInfo.Tex2DFmt = CreateTestResource( m_pd3d12Device, ResDesc ); if( TexFormatInfo.Tex2DFmt ) { { // D3D12_TEXTURE2D_DESC CubeTexDesc = Tex2DDesc; ResDesc.DepthOrArraySize = 6; // CubeTexDesc.MiscFlags = D3D12_RESOURCE_MISC_TEXTURECUBE; TexFormatInfo.TexCubeFmt = CreateTestResource( m_pd3d12Device, ResDesc ); ResDesc.DepthOrArraySize = 1; } if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) { ResDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; ResDesc.SampleDesc.Count = 1; TexFormatInfo.DepthRenderable = CreateTestResource( m_pd3d12Device, ResDesc ); if( TexFormatInfo.DepthRenderable ) { ResDesc.SampleDesc.Count = 4; TexFormatInfo.SupportsMS = CreateTestResource( m_pd3d12Device, ResDesc ); } } else if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED && TexFormatInfo.Format != DXGI_FORMAT_R9G9B9E5_SHAREDEXP ) { ResDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; ResDesc.SampleDesc.Count = 1; TexFormatInfo.ColorRenderable = CreateTestResource( m_pd3d12Device, ResDesc ); if( TexFormatInfo.ColorRenderable ) { ResDesc.SampleDesc.Count = 4; TexFormatInfo.SupportsMS = CreateTestResource( m_pd3d12Device, ResDesc ); } } } } // Create test texture 3D TexFormatInfo.Tex3DFmt = false; // 3D textures do not support depth formats if( !(TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) ) { ResDesc.SampleDesc.Count = 1; ResDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; ResDesc.Flags = DefaultResourceFlags; ResDesc.DepthOrArraySize = TestTextureDepth; TexFormatInfo.Tex3DFmt = CreateTestResource( m_pd3d12Device, ResDesc ); } }