示例#1
0
TextureCacheBase::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntryConfig& config)
{
	if (config.rendertarget)
	{
		D3DTexture2D* texture = D3DTexture2D::Create(config.width, config.height,
			static_cast<D3D11_BIND_FLAG>((static_cast<int>(D3D11_BIND_RENDER_TARGET) | static_cast<int>(D3D11_BIND_SHADER_RESOURCE))),
			D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM, 1, config.layers);

		TCacheEntry* entry = new TCacheEntry(config, texture);

		entry->m_texture_srv_cpu_handle = texture->GetSRV12CPU();
		entry->m_texture_srv_gpu_handle = texture->GetSRV12GPU();
		entry->m_texture_srv_gpu_handle_cpu_shadow = texture->GetSRV12GPUCPUShadow();

		return entry;
	}
	else
	{
		ID3D12Resource* texture_resource = nullptr;

		D3D12_RESOURCE_DESC texture_resource_desc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM,
			config.width, config.height, 1, config.levels);

		CheckHR(
			D3D::device12->CreateCommittedResource(
			&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
			D3D12_HEAP_FLAG_NONE,
			&CD3DX12_RESOURCE_DESC(texture_resource_desc),
			D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
			nullptr,
			IID_PPV_ARGS(&texture_resource)
			)
			);

		D3DTexture2D* texture = new D3DTexture2D(
			texture_resource,
			D3D11_BIND_SHADER_RESOURCE,
			DXGI_FORMAT_UNKNOWN,
			DXGI_FORMAT_UNKNOWN,
			DXGI_FORMAT_UNKNOWN,
			false,
			D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE
			);

		TCacheEntry* const entry = new TCacheEntry(
			config, texture
			);

		entry->m_texture_srv_cpu_handle = texture->GetSRV12CPU();
		entry->m_texture_srv_gpu_handle = texture->GetSRV12GPU();
		entry->m_texture_srv_gpu_handle_cpu_shadow = texture->GetSRV12GPUCPUShadow();

		// EXISTINGD3D11TODO: better debug names
		D3D::SetDebugObjectName12(entry->m_texture->GetTex12(), "a texture of the TextureCache");

		SAFE_RELEASE(texture_resource);

		return entry;
	}
}
示例#2
0
D3DTexture2D* D3DTexture2D::Create(unsigned int width, unsigned int height, D3D11_BIND_FLAG bind, D3D11_USAGE usage, DXGI_FORMAT fmt, unsigned int levels, unsigned int slices, D3D12_SUBRESOURCE_DATA* data)
{
	ID3D12Resource* texture12 = nullptr;

	D3D12_RESOURCE_DESC texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(
		fmt,
		width,
		height,
		slices,
		levels
		);

	D3D12_CLEAR_VALUE optimized_clear_value = {};
	optimized_clear_value.Format = fmt;

	if (bind & D3D11_BIND_RENDER_TARGET)
	{
		texdesc12.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
		optimized_clear_value.Color[0] = 0.0f;
		optimized_clear_value.Color[1] = 0.0f;
		optimized_clear_value.Color[2] = 0.0f;
		optimized_clear_value.Color[3] = 1.0f;
	}

	if (bind & D3D11_BIND_DEPTH_STENCIL)
	{
		texdesc12.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
		optimized_clear_value.DepthStencil.Depth = 0.0f;
		optimized_clear_value.DepthStencil.Stencil = 0;
	}

	CheckHR(
		D3D::device12->CreateCommittedResource(
			&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
			D3D12_HEAP_FLAG_NONE,
			&CD3DX12_RESOURCE_DESC(texdesc12),
			D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
			&optimized_clear_value,
			IID_PPV_ARGS(&texture12)
			)
		);

	D3D::SetDebugObjectName12(texture12, "Texture created via D3DTexture2D::Create");
	D3DTexture2D* ret = new D3DTexture2D(texture12, bind, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, false, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);

	if (data)
	{
		DX12::D3D::ReplaceRGBATexture2D(texture12, reinterpret_cast<const u8*>(data->pData), width, height, static_cast<unsigned int>(data->RowPitch), 0, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
	}

	SAFE_RELEASE(texture12);
	return ret;
}
示例#3
0
TextureCacheBase::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntryConfig& config)
{
	if (config.rendertarget)
	{
		D3DTexture2D* texture = D3DTexture2D::Create(config.width, config.height,
			(D3D11_BIND_FLAG)((int)D3D11_BIND_RENDER_TARGET | (int)D3D11_BIND_SHADER_RESOURCE),
			D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM, 1, config.layers);

		TCacheEntry* entry = new TCacheEntry(config, texture);

		entry->m_texture_srv_cpu_handle = texture->GetSRV12CPU();
		entry->m_texture_srv_gpu_handle = texture->GetSRV12GPU();
		entry->m_texture_srv_gpu_handle_cpu_shadow = texture->GetSRV12GPUCPUShadow();

		return entry;
	}
	else
	{
		static const DXGI_FORMAT PC_TexFormat_To_DXGIFORMAT[11]
		{
			DXGI_FORMAT_UNKNOWN,//PC_TEX_FMT_NONE
			DXGI_FORMAT_R8G8B8A8_UNORM,//PC_TEX_FMT_BGRA32
			DXGI_FORMAT_R8G8B8A8_UNORM,//PC_TEX_FMT_RGBA32
			DXGI_FORMAT_R8G8B8A8_UNORM,//PC_TEX_FMT_I4_AS_I8
			DXGI_FORMAT_R8G8B8A8_UNORM,//PC_TEX_FMT_IA4_AS_IA8
			DXGI_FORMAT_R8G8B8A8_UNORM,//PC_TEX_FMT_I8
			DXGI_FORMAT_R8G8B8A8_UNORM,//PC_TEX_FMT_IA8
			DXGI_FORMAT_R8G8B8A8_UNORM,//PC_TEX_FMT_RGB565
			DXGI_FORMAT_BC1_UNORM,//PC_TEX_FMT_DXT1
			DXGI_FORMAT_BC2_UNORM,//PC_TEX_FMT_DXT3
			DXGI_FORMAT_BC3_UNORM,//PC_TEX_FMT_DXT5
		};
		DXGI_FORMAT format = PC_TexFormat_To_DXGIFORMAT[config.pcformat];
		ID3D12Resource* pTexture12 = nullptr;

		D3D12_RESOURCE_DESC texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(format,
			config.width, config.height, 1, config.levels);

		CheckHR(
			D3D::device12->CreateCommittedResource(
			&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
			D3D12_HEAP_FLAG_NONE,
			&CD3DX12_RESOURCE_DESC(texdesc12),
			D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
			nullptr,
			IID_PPV_ARGS(&pTexture12)
			)
			);

		D3DTexture2D* texture = new D3DTexture2D(
			pTexture12,
			D3D11_BIND_SHADER_RESOURCE,
			DXGI_FORMAT_UNKNOWN,
			DXGI_FORMAT_UNKNOWN,
			DXGI_FORMAT_UNKNOWN,
			false,
			D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE
			);

		TCacheEntry* const entry = new TCacheEntry(
			config, texture
			);

		entry->m_texture_srv_cpu_handle = texture->GetSRV12CPU();
		entry->m_texture_srv_gpu_handle = texture->GetSRV12GPU();
		entry->m_texture_srv_gpu_handle_cpu_shadow = texture->GetSRV12GPUCPUShadow();
		entry->DXGI_format = format;
		if (format != DXGI_FORMAT_R8G8B8A8_UNORM)
		{
			entry->compressed = true;
		}
		// EXISTINGD3D11TODO: better debug names
		D3D::SetDebugObjectName12(entry->m_texture->GetTex12(), "a texture of the TextureCache");

		SAFE_RELEASE(pTexture12);
		if (config.materialmap)
		{
			pTexture12 = nullptr;
			CheckHR(
				D3D::device12->CreateCommittedResource(
					&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
					D3D12_HEAP_FLAG_NONE,
					&CD3DX12_RESOURCE_DESC(texdesc12),
					D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
					nullptr,
					IID_PPV_ARGS(&pTexture12)
					)
				);
			entry->m_nrm_texture = new D3DTexture2D(
				pTexture12,
				D3D11_BIND_SHADER_RESOURCE,
				DXGI_FORMAT_UNKNOWN,
				DXGI_FORMAT_UNKNOWN,
				DXGI_FORMAT_UNKNOWN,
				false,
				D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE
				);
			entry->m_nrm_texture_srv_cpu_handle = entry->m_nrm_texture->GetSRV12CPU();
			entry->m_nrm_texture_srv_gpu_handle = entry->m_nrm_texture->GetSRV12GPU();
			entry->m_nrm_texture_srv_gpu_handle_cpu_shadow = entry->m_nrm_texture->GetSRV12GPUCPUShadow();
			SAFE_RELEASE(pTexture12);
		}
		return entry;
	}
}