当前位置: 首页>>代码示例>>C++>>正文


C++ TCacheEntryBase类代码示例

本文整理汇总了C++中TCacheEntryBase的典型用法代码示例。如果您正苦于以下问题:C++ TCacheEntryBase类的具体用法?C++ TCacheEntryBase怎么用?C++ TCacheEntryBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TCacheEntryBase类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch


//.........这里部分代码省略.........
			dstFormat,
			tex_w,
			bytes_per_row,
			num_blocks_y,
			dstStride,
			srcFormat,
			srcRect,
			isIntensity,
			scaleByHalf);
	}
	else
	{
		// Hack: Most games don't actually need the correct texture data in RAM
		//       and we can just keep a copy in VRAM. We zero the memory so we
		//       can check it hasn't changed before using our copy in VRAM.
		u8* ptr = dst;
		for (u32 i = 0; i < num_blocks_y; i++)
		{
			memset(ptr, 0, bytes_per_row);
			ptr += dstStride;
		}
	}

	if (g_bRecordFifoData)
	{
		// Mark the memory behind this efb copy as dynamicly generated for the Fifo log
		u32 address = dstAddr;
		for (u32 i = 0; i < num_blocks_y; i++)
		{
			FifoRecorder::GetInstance().UseMemory(address, bytes_per_row, MemoryUpdate::TEXTURE_MAP, true);
			address += dstStride;
		}
	}

	if (dstStride < bytes_per_row)
	{
		// This kind of efb copy results in a scrambled image.
		// I'm pretty sure no game actually wants to do this, it might be caused by a
		// programming bug in the game, or a CPU/Bounding box emulation issue with dolphin.
		// The copy_to_ram code path above handles this "correctly" and scrambles the image
		// but the copy_to_vram code path just saves and uses unscrambled texture instead.

		// To avoid a "incorrect" result, we simply skip doing the copy_to_vram code path
		// so if the game does try to use the scrambled texture, dolphin will grab the scrambled
		// texture (or black if copy_to_ram is also disabled) out of ram.
		ERROR_LOG(VIDEO, "Memory stride too small (%i < %i)", dstStride, bytes_per_row);
		copy_to_vram = false;
	}

	// Invalidate all textures that overlap the range of our efb copy.
	// Unless our efb copy has a weird stride, then we want avoid invalidating textures which
	// we might be able to do a partial texture update on.
	if (dstStride == bytes_per_row || !copy_to_vram)
	{
		TexCache::iterator iter = textures_by_address.begin();
		while (iter != textures_by_address.end())
		{
			if (iter->second->addr + iter->second->size_in_bytes <= dstAddr || iter->second->addr >= dstAddr + num_blocks_y * dstStride)
				++iter;
			else
				iter = FreeTexture(iter);
		}
	}

	if (copy_to_vram)
	{
		// create the texture
		TCacheEntryConfig config;
		config.rendertarget = true;
		config.width = scaled_tex_w;
		config.height = scaled_tex_h;
		config.layers = FramebufferManagerBase::GetEFBLayers();

		TCacheEntryBase* entry = AllocateTexture(config);

		if (entry)
		{
			entry->SetGeneralParameters(dstAddr, 0, baseFormat);
			entry->SetDimensions(tex_w, tex_h, 1);

			entry->frameCount = FRAMECOUNT_INVALID;
			entry->SetEfbCopy(dstStride);
			entry->is_custom_tex = false;

			entry->FromRenderTarget(dst, srcFormat, srcRect, scaleByHalf, cbufid, colmat);

			u64 hash = entry->CalculateHash();
			entry->SetHashes(hash, hash);

			if (g_ActiveConfig.bDumpEFBTarget)
			{
				static int count = 0;
				entry->Save(StringFromFormat("%sefb_frame_%i.png", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
					count++), 0);
			}

			textures_by_address.emplace((u64)dstAddr, entry);
		}
	}
}
开发者ID:MarioManTAW,项目名称:dolphin,代码行数:101,代码来源:TextureCacheBase.cpp

示例2: TexDecoder_GetBlockWidthInTexels

TextureCacheBase::TCacheEntryBase* TextureCacheBase::Load(const u32 stage)
{
	const FourTexUnits &tex = bpmem.tex[stage >> 2];
	const u32 id = stage & 3;
	const u32 address = (tex.texImage3[id].image_base/* & 0x1FFFFF*/) << 5;
	u32 width = tex.texImage0[id].width + 1;
	u32 height = tex.texImage0[id].height + 1;
	const int texformat = tex.texImage0[id].format;
	const u32 tlutaddr = tex.texTlut[id].tmem_offset << 9;
	const u32 tlutfmt = tex.texTlut[id].tlut_format;
	const bool use_mipmaps = SamplerCommon::AreBpTexMode0MipmapsEnabled(tex.texMode0[id]);
	u32 tex_levels = use_mipmaps ? ((tex.texMode1[id].max_lod + 0xf) / 0x10 + 1) : 1;
	const bool from_tmem = tex.texImage1[id].image_type != 0;

	if (0 == address)
		return nullptr;

	// TexelSizeInNibbles(format) * width * height / 16;
	const unsigned int bsw = TexDecoder_GetBlockWidthInTexels(texformat);
	const unsigned int bsh = TexDecoder_GetBlockHeightInTexels(texformat);

	unsigned int expandedWidth = ROUND_UP(width, bsw);
	unsigned int expandedHeight = ROUND_UP(height, bsh);
	const unsigned int nativeW = width;
	const unsigned int nativeH = height;

	// Hash assigned to texcache entry (also used to generate filenames used for texture dumping and custom texture lookup)
	u64 base_hash = TEXHASH_INVALID;
	u64 full_hash = TEXHASH_INVALID;

	u32 full_format = texformat;

	const bool isPaletteTexture = (texformat == GX_TF_C4 || texformat == GX_TF_C8 || texformat == GX_TF_C14X2);

	// Reject invalid tlut format.
	if (isPaletteTexture && tlutfmt > GX_TL_RGB5A3)
		return nullptr;

	if (isPaletteTexture)
		full_format = texformat | (tlutfmt << 16);

	const u32 texture_size = TexDecoder_GetTextureSizeInBytes(expandedWidth, expandedHeight, texformat);
	u32 additional_mips_size = 0; // not including level 0, which is texture_size

	// GPUs don't like when the specified mipmap count would require more than one 1x1-sized LOD in the mipmap chain
	// e.g. 64x64 with 7 LODs would have the mipmap chain 64x64,32x32,16x16,8x8,4x4,2x2,1x1,0x0, so we limit the mipmap count to 6 there
	tex_levels = std::min<u32>(IntLog2(std::max(width, height)) + 1, tex_levels);

	for (u32 level = 1; level != tex_levels; ++level)
	{
		// We still need to calculate the original size of the mips
		const u32 expanded_mip_width = ROUND_UP(CalculateLevelSize(width, level), bsw);
		const u32 expanded_mip_height = ROUND_UP(CalculateLevelSize(height, level), bsh);

		additional_mips_size += TexDecoder_GetTextureSizeInBytes(expanded_mip_width, expanded_mip_height, texformat);
	}

	const u8* src_data;
	if (from_tmem)
		src_data = &texMem[bpmem.tex[stage / 4].texImage1[stage % 4].tmem_even * TMEM_LINE_SIZE];
	else
		src_data = Memory::GetPointer(address);

	if (!src_data)
	{
		ERROR_LOG(VIDEO, "Trying to use an invalid texture address 0x%8x", address);
		return nullptr;
	}

	// If we are recording a FifoLog, keep track of what memory we read.
	// FifiRecorder does it's own memory modification tracking independant of the texture hashing below.
	if (g_bRecordFifoData && !from_tmem)
		FifoRecorder::GetInstance().UseMemory(address, texture_size + additional_mips_size, MemoryUpdate::TEXTURE_MAP);

	// TODO: This doesn't hash GB tiles for preloaded RGBA8 textures (instead, it's hashing more data from the low tmem bank than it should)
	base_hash = GetHash64(src_data, texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
	u32 palette_size = 0;
	if (isPaletteTexture)
	{
		palette_size = TexDecoder_GetPaletteSize(texformat);
		full_hash = base_hash ^ GetHash64(&texMem[tlutaddr], palette_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
	}
	else
	{
		full_hash = base_hash;
	}

	// Search the texture cache for textures by address
	//
	// Find all texture cache entries for the current texture address, and decide whether to use one of
	// them, or to create a new one
	//
	// In most cases, the fastest way is to use only one texture cache entry for the same address. Usually,
	// when a texture changes, the old version of the texture is unlikely to be used again. If there were
	// new cache entries created for normal texture updates, there would be a slowdown due to a huge amount
	// of unused cache entries. Also thanks to texture pooling, overwriting an existing cache entry is
	// faster than creating a new one from scratch.
	//
	// Some games use the same address for different textures though. If the same cache entry was used in
	// this case, it would be constantly overwritten, and effectively there wouldn't be any caching for
//.........这里部分代码省略.........
开发者ID:MarioManTAW,项目名称:dolphin,代码行数:101,代码来源:TextureCacheBase.cpp

示例3: ERROR_LOG

void TextureCacheBase::ScaleTextureCacheEntryTo(TextureCacheBase::TCacheEntryBase** entry, u32 new_width, u32 new_height)
{
	if ((*entry)->config.width == new_width && (*entry)->config.height == new_height)
	{
		return;
	}

	u32 max = g_renderer->GetMaxTextureSize();
	if (max < new_width || max < new_height)
	{
		ERROR_LOG(VIDEO, "Texture too big, width = %d, height = %d", new_width, new_height);
		return;
	}

	TextureCacheBase::TCacheEntryConfig newconfig;
	newconfig.width = new_width;
	newconfig.height = new_height;
	newconfig.layers = (*entry)->config.layers;
	newconfig.rendertarget = true;

	TCacheEntryBase* newentry = AllocateTexture(newconfig);
	if (newentry)
	{
		newentry->SetGeneralParameters((*entry)->addr, (*entry)->size_in_bytes, (*entry)->format);
		newentry->SetDimensions((*entry)->native_width, (*entry)->native_height, 1);
		newentry->SetHashes((*entry)->base_hash, (*entry)->hash);
		newentry->frameCount = frameCount;
		newentry->is_efb_copy = (*entry)->is_efb_copy;
		MathUtil::Rectangle<int> srcrect, dstrect;
		srcrect.left = 0;
		srcrect.top = 0;
		srcrect.right = (*entry)->config.width;
		srcrect.bottom = (*entry)->config.height;
		dstrect.left = 0;
		dstrect.top = 0;
		dstrect.right = new_width;
		dstrect.bottom = new_height;
		newentry->CopyRectangleFromTexture(*entry, srcrect, dstrect);

		// Keep track of the pointer for textures_by_hash
		if ((*entry)->textures_by_hash_iter != textures_by_hash.end())
		{
			newentry->textures_by_hash_iter = textures_by_hash.emplace((*entry)->hash, newentry);
		}

		// Remove the old texture
		std::pair<TexCache::iterator, TexCache::iterator>iter_range = textures_by_address.equal_range((*entry)->addr);
		TexCache::iterator iter = iter_range.first;
		while (iter != iter_range.second)
		{
			if (iter->second == *entry)
			{
				FreeTexture(iter);
				iter = iter_range.second;
			}
			else
			{
				iter++;
			}
		}

		*entry = newentry;
		textures_by_address.emplace((*entry)->addr, *entry);
	}
	else
	{
		ERROR_LOG(VIDEO, "Scaling failed");
	}
}
开发者ID:MarioManTAW,项目名称:dolphin,代码行数:69,代码来源:TextureCacheBase.cpp

示例4: TexDecoder_GetBlockWidthInTexels

TextureCacheBase::TCacheEntryBase* TextureCacheBase::DoPartialTextureUpdates(TexCache::iterator iter_t)
{
	TCacheEntryBase* entry_to_update = iter_t->second;
	const bool isPaletteTexture = (entry_to_update->format == GX_TF_C4
		|| entry_to_update->format == GX_TF_C8
		|| entry_to_update->format == GX_TF_C14X2
		|| entry_to_update->format >= 0x10000);

	// Efb copies and paletted textures are excluded from these updates, until there's an example where a game would
	// benefit from this. Both would require more work to be done.
	// TODO: Implement upscaling support for normal textures, and then remove the efb to ram and the scaled efb restrictions
	if (entry_to_update->IsEfbCopy()
		|| isPaletteTexture)
		return entry_to_update;

	u32 block_width = TexDecoder_GetBlockWidthInTexels(entry_to_update->format & 0xf);
	u32 block_height = TexDecoder_GetBlockHeightInTexels(entry_to_update->format & 0xf);
	u32 block_size = block_width * block_height * TexDecoder_GetTexelSizeInNibbles(entry_to_update->format & 0xf) / 2;

	u32 numBlocksX = (entry_to_update->native_width + block_width - 1) / block_width;

	TexCache::iterator iter = textures_by_address.lower_bound(entry_to_update->addr);
	TexCache::iterator iterend = textures_by_address.upper_bound(entry_to_update->addr + entry_to_update->size_in_bytes);
	bool entry_need_scaling = g_ActiveConfig.bCopyEFBScaled;
	while (iter != iterend)
	{
		TCacheEntryBase* entry = iter->second;
		if (entry != entry_to_update
			&& entry->IsEfbCopy()
			&& entry->OverlapsMemoryRange(entry_to_update->addr, entry_to_update->size_in_bytes)
			&& entry->frameCount == FRAMECOUNT_INVALID
			&& entry->memory_stride == numBlocksX * block_size)
		{
			u32 src_x, src_y, dst_x, dst_y;
			MathUtil::Rectangle<s32> srcrect, dstrect;

			u32 block_offset = std::abs((s32)((entry->addr - entry_to_update->addr) / block_size));
			u32 block_x = block_offset % numBlocksX;
			u32 block_y = block_offset / numBlocksX;

			if (entry->addr >= entry_to_update->addr)
			{
				dst_x = block_x * block_width;
				dst_y = block_y * block_height;
				src_x = 0;
				src_y = 0;
			}
			else
			{
				src_x = block_x * block_width;
				src_y = block_y * block_height;
				dst_x = 0;
				dst_y = 0;
			}
			u32 copy_width = std::min(entry->native_width - src_x, entry_to_update->native_width - dst_x);
			u32 copy_height = std::min(entry->native_height - src_y, entry_to_update->native_height - dst_y);

			if (g_ActiveConfig.bCopyEFBScaled)
			{
				src_x = Renderer::EFBToScaledX(src_x);
				src_y = Renderer::EFBToScaledY(src_y);
				dst_x = Renderer::EFBToScaledX(dst_x);
				dst_y = Renderer::EFBToScaledY(dst_y);
				copy_width = Renderer::EFBToScaledX(copy_width);
				copy_height = Renderer::EFBToScaledY(copy_height);
			}
			if (entry_need_scaling)
			{
				entry_need_scaling = false;
				u32 w = Renderer::EFBToScaledX(entry_to_update->native_width);
				u32 h = Renderer::EFBToScaledX(entry_to_update->native_height);
				u32 max = g_renderer->GetMaxTextureSize();
				if (max < w || max < h)
				{
					iter++;
					continue;
				}
				if (entry_to_update->config.width != w || entry_to_update->config.height != h)
				{
					TextureCacheBase::TCacheEntryConfig newconfig;
					newconfig.width = w;
					newconfig.height = h;
					newconfig.rendertarget = true;
					TCacheEntryBase* newentry = AllocateTexture(newconfig);
					newentry->SetGeneralParameters(entry_to_update->addr, entry_to_update->size_in_bytes, entry_to_update->format);
					newentry->SetDimensions(entry_to_update->native_width, entry_to_update->native_height, 1);
					newentry->SetHashes(entry_to_update->hash, entry_to_update->base_hash);
					newentry->frameCount = frameCount;
					newentry->is_efb_copy = false;
					srcrect.left = 0;
					srcrect.top = 0;
					srcrect.right = entry_to_update->config.width;
					srcrect.bottom = entry_to_update->config.height;
					dstrect.left = 0;
					dstrect.top = 0;
					dstrect.right = w;
					dstrect.bottom = h;
					newentry->CopyRectangleFromTexture(entry_to_update, srcrect, dstrect);
					entry_to_update = newentry;
					u64 key = iter_t->first;
//.........这里部分代码省略.........
开发者ID:gamax92,项目名称:Ishiiruka,代码行数:101,代码来源:TextureCacheBase.cpp


注:本文中的TCacheEntryBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。