mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-02 10:43:44 +01:00
Vulkan: Directly decode simple palette textures.
This commit is contained in:
1 parent
9cd0544137
commit
9a4b74cd09
2 files changed
+54
-73
No files matched your search
@@ -402,95 +402,76 @@ bool TextureCacheVulkan::AttachFramebuffer(TexCacheEntry *entry, u32 address, Vi
|
||||
return false;
|
||||
}
|
||||
|
||||
void *TextureCacheVulkan::ReadIndexedTex(int level, const u8 *texptr, int bytesPerIndex, VkFormat dstFmt, int bufw) {
|
||||
void *TextureCacheVulkan::ReadIndexedTex(u8 *out, int outPitch, int level, const u8 *texptr, int bytesPerIndex, VkFormat dstFmt, int bufw) {
|
||||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
int length = bufw * h;
|
||||
void *buf = NULL;
|
||||
|
||||
void *buf = nullptr;
|
||||
switch (gstate.getClutPaletteFormat()) {
|
||||
case GE_CMODE_16BIT_BGR5650:
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
{
|
||||
tmpTexBuf16.resize(std::max(bufw, w) * h);
|
||||
const u16 *clut = GetCurrentClut<u16>();
|
||||
if (!gstate.isTextureSwizzled()) {
|
||||
switch (bytesPerIndex) {
|
||||
case 1:
|
||||
DeIndexTexture(tmpTexBuf16.data(), (const u8 *)texptr, length, clut);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
DeIndexTexture(tmpTexBuf16.data(), (const u16_le *)texptr, length, clut);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
DeIndexTexture(tmpTexBuf16.data(), (const u32_le *)texptr, length, clut);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (gstate.isTextureSwizzled()) {
|
||||
tmpTexBuf32.resize(std::max(bufw, w) * h);
|
||||
UnswizzleFromMem(tmpTexBuf32.data(), texptr, bufw, h, bytesPerIndex);
|
||||
switch (bytesPerIndex) {
|
||||
case 1:
|
||||
DeIndexTexture(tmpTexBuf16.data(), (u8 *)tmpTexBuf32.data(), length, clut);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
DeIndexTexture(tmpTexBuf16.data(), (u16 *)tmpTexBuf32.data(), length, clut);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
DeIndexTexture(tmpTexBuf16.data(), (u32 *)tmpTexBuf32.data(), length, clut);
|
||||
break;
|
||||
}
|
||||
texptr = (u8 *)tmpTexBuf32.data();
|
||||
}
|
||||
buf = tmpTexBuf16.data();
|
||||
|
||||
switch (bytesPerIndex) {
|
||||
case 1:
|
||||
for (int y = 0; y < h; ++y) {
|
||||
DeIndexTexture((u16 *)(out + outPitch * y), (const u8 *)texptr + bufw * y, w, clut);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (int y = 0; y < h; ++y) {
|
||||
DeIndexTexture((u16 *)(out + outPitch * y), (const u16_le *)texptr + bufw * y, w, clut);
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
for (int y = 0; y < h; ++y) {
|
||||
DeIndexTexture((u16 *)(out + outPitch * y), (const u32_le *)texptr + bufw * y, w, clut);
|
||||
}
|
||||
break;
|
||||
}
|
||||
buf = out;
|
||||
}
|
||||
break;
|
||||
|
||||
case GE_CMODE_32BIT_ABGR8888:
|
||||
{
|
||||
tmpTexBuf32.resize(std::max(bufw, w) * h);
|
||||
const u32 *clut = GetCurrentClut<u32>();
|
||||
if (!gstate.isTextureSwizzled()) {
|
||||
switch (bytesPerIndex) {
|
||||
case 1:
|
||||
DeIndexTexture(tmpTexBuf32.data(), (const u8 *)texptr, length, clut);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
DeIndexTexture(tmpTexBuf32.data(), (const u16_le *)texptr, length, clut);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
DeIndexTexture(tmpTexBuf32.data(), (const u32_le *)texptr, length, clut);
|
||||
break;
|
||||
}
|
||||
buf = tmpTexBuf32.data();
|
||||
} else {
|
||||
if (gstate.isTextureSwizzled()) {
|
||||
tmpTexBuf32.resize(std::max(bufw, w) * h);
|
||||
UnswizzleFromMem(tmpTexBuf32.data(), texptr, bufw, h, bytesPerIndex);
|
||||
// Since we had to unswizzle to tmpTexBuf32, let's output to tmpTexBuf16.
|
||||
tmpTexBuf16.resize(std::max(bufw, w) * h * 2);
|
||||
u32 *dest32 = (u32 *)tmpTexBuf16.data();
|
||||
switch (bytesPerIndex) {
|
||||
case 1:
|
||||
DeIndexTexture(dest32, (u8 *)tmpTexBuf32.data(), length, clut);
|
||||
buf = dest32;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
DeIndexTexture(dest32, (u16 *)tmpTexBuf32.data(), length, clut);
|
||||
buf = dest32;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// TODO: If a game actually uses this mode, check if using dest32 or tmpTexBuf32 is faster.
|
||||
DeIndexTexture(tmpTexBuf32.data(), tmpTexBuf32.data(), length, clut);
|
||||
buf = tmpTexBuf32.data();
|
||||
break;
|
||||
}
|
||||
texptr = (u8 *)tmpTexBuf32.data();
|
||||
}
|
||||
|
||||
switch (bytesPerIndex) {
|
||||
case 1:
|
||||
for (int y = 0; y < h; ++y) {
|
||||
DeIndexTexture((u32 *)(out + outPitch * y), (const u8 *)texptr + bufw * y, w, clut);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (int y = 0; y < h; ++y) {
|
||||
DeIndexTexture((u32 *)(out + outPitch * y), (const u16_le *)texptr + bufw * y, w, clut);
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
for (int y = 0; y < h; ++y) {
|
||||
DeIndexTexture((u32 *)(out + outPitch * y), (const u32_le *)texptr + bufw * y, w, clut);
|
||||
}
|
||||
break;
|
||||
}
|
||||
buf = out;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1490,15 +1471,15 @@ void *TextureCacheVulkan::DecodeTextureLevel(u8 *out, int outPitch, GETextureFor
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT8:
|
||||
finalBuf = ReadIndexedTex(level, texptr, 1, dstFmt, bufw);
|
||||
finalBuf = ReadIndexedTex(out, outPitch, level, texptr, 1, dstFmt, bufw);
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT16:
|
||||
finalBuf = ReadIndexedTex(level, texptr, 2, dstFmt, bufw);
|
||||
finalBuf = ReadIndexedTex(out, outPitch, level, texptr, 2, dstFmt, bufw);
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT32:
|
||||
finalBuf = ReadIndexedTex(level, texptr, 4, dstFmt, bufw);
|
||||
finalBuf = ReadIndexedTex(out, outPitch, level, texptr, 4, dstFmt, bufw);
|
||||
break;
|
||||
|
||||
case GE_TFMT_4444:
|
||||
|
||||
Reference in new issue
Block a user