Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Common/GPU/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,12 @@ VkResult VulkanContext::CreateDevice(int physical_device) {
// This is as good a place as any to do this. Though, we don't use this much anymore after we added
// support for VMA.
vkGetPhysicalDeviceMemoryProperties(physical_devices_[physical_device_], &memory_properties_);
INFO_LOG(Log::G3D, "Memory Types (%d):", memory_properties_.memoryTypeCount);
DEBUG_LOG(Log::G3D, "Memory Types (%d):", memory_properties_.memoryTypeCount);
for (int i = 0; i < (int)memory_properties_.memoryTypeCount; i++) {
// Don't bother printing dummy memory types.
if (!memory_properties_.memoryTypes[i].propertyFlags)
continue;
INFO_LOG(Log::G3D, " %d: Heap %d; Flags: %s%s%s%s ", i, memory_properties_.memoryTypes[i].heapIndex,
DEBUG_LOG(Log::G3D, " %d: Heap %d; Flags: %s%s%s%s ", i, memory_properties_.memoryTypes[i].heapIndex,
(memory_properties_.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) ? "DEVICE_LOCAL " : "",
(memory_properties_.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) ? "HOST_VISIBLE " : "",
(memory_properties_.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) ? "HOST_CACHED " : "",
Expand Down Expand Up @@ -1349,15 +1349,15 @@ bool VulkanContext::InitSwapchain() {
res = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_devices_[physical_device_], surface_, &presentModeCount, presentModes);
_dbg_assert_(res == VK_SUCCESS);

VkExtent2D currentExtent { surfCapabilities_.currentExtent };
VkExtent2D currentExtent{ surfCapabilities_.currentExtent };
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSurfaceCapabilitiesKHR.html
// currentExtent is the current width and height of the surface, or the special value (0xFFFFFFFF, 0xFFFFFFFF) indicating that the surface size will be determined by the extent of a swapchain targeting the surface.
if (currentExtent.width == 0xFFFFFFFFu || currentExtent.height == 0xFFFFFFFFu
#if PPSSPP_PLATFORM(IOS)
|| currentExtent.width == 0 || currentExtent.height == 0
#endif
) {
_dbg_assert_((bool)cbGetDrawSize_)
_dbg_assert_((bool)cbGetDrawSize_);
if (cbGetDrawSize_) {
currentExtent = cbGetDrawSize_();
}
Expand Down Expand Up @@ -1407,8 +1407,7 @@ bool VulkanContext::InitSwapchain() {
// queued for display):
uint32_t desiredNumberOfSwapChainImages = surfCapabilities_.minImageCount + 1;
if ((surfCapabilities_.maxImageCount > 0) &&
(desiredNumberOfSwapChainImages > surfCapabilities_.maxImageCount))
{
(desiredNumberOfSwapChainImages > surfCapabilities_.maxImageCount)) {
// Application must settle for fewer images than desired:
desiredNumberOfSwapChainImages = surfCapabilities_.maxImageCount;
}
Expand Down Expand Up @@ -1459,8 +1458,11 @@ bool VulkanContext::InitSwapchain() {
preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
}

std::string preTransformStr = surface_transforms_to_string(preTransform);
INFO_LOG(Log::G3D, "Transform supported: %s current: %s chosen: %s", supportedTransforms.c_str(), currentTransform.c_str(), preTransformStr.c_str());
// Only log transforms if relevant.
if (surfCapabilities_.supportedTransforms != VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
std::string preTransformStr = surface_transforms_to_string(preTransform);
INFO_LOG(Log::G3D, "Transform supported: %s current: %s chosen: %s", supportedTransforms.c_str(), currentTransform.c_str(), preTransformStr.c_str());
}

if (physicalDeviceProperties_[physical_device_].properties.vendorID == VULKAN_VENDOR_IMGTEC) {
u32 driverVersion = physicalDeviceProperties_[physical_device_].properties.driverVersion;
Expand Down
36 changes: 0 additions & 36 deletions Core/HLE/sceAtrac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,42 +1023,6 @@ static u32 _sceAtracGetContextAddress(int atracID) {
return hleLogDebug(Log::ME, atrac->context_.ptr);
}

struct At3HeaderMap {
u16 bytes;
u16 channels;
u8 jointStereo;

bool Matches(int bytesPerFrame, int encodedChannels) const {
return this->bytes == bytesPerFrame && this->channels == encodedChannels;
}
};

// These should represent all possible supported bitrates (66, 104, and 132 for stereo.)
static const At3HeaderMap at3HeaderMap[] = {
{ 0x00C0, 1, 0 }, // 132/2 (66) kbps mono
{ 0x0098, 1, 0 }, // 105/2 (52.5) kbps mono
{ 0x0180, 2, 0 }, // 132 kbps stereo
{ 0x0130, 2, 0 }, // 105 kbps stereo
// At this size, stereo can only use joint stereo.
{ 0x00C0, 2, 1 }, // 66 kbps stereo
};

bool IsAtrac3StreamJointStereo(int codecType, int bytesPerFrame, int channels) {
if (codecType != PSP_CODEC_AT3) {
// Well, might actually be, but it's not used in codec setup.
return false;
}

for (size_t i = 0; i < ARRAY_SIZE(at3HeaderMap); ++i) {
if (at3HeaderMap[i].Matches(bytesPerFrame, channels)) {
return at3HeaderMap[i].jointStereo;
}
}

// Not found? Should we log?
return false;
}

static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) {
AtracBase *atrac = getAtrac(atracID);
if (!atrac) {
Expand Down
2 changes: 0 additions & 2 deletions Core/HLE/sceAtrac.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ class AtracBase;
// For debugger use ONLY.
const AtracBase *__AtracGetCtx(int i, u32 *type);

bool IsAtrac3StreamJointStereo(int codecType, int bytesPerFrame, int channels);

// External interface used by sceSas, see ATRAC_STATUS_FOR_SCESAS.
u32 AtracSasAddStreamData(int atracID, u32 bufPtr, u32 bytesToAdd);
void AtracSasDecodeData(int atracID, u8* outbuf, int *SamplesNum, int *finish);
Expand Down
99 changes: 88 additions & 11 deletions Core/HLE/sceAudiocodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ static_assert(sizeof(SceAudiocodecCodec) == 128);
//
// Known byte values.

// Atrac3 (0x1001)
// ------------------------------------------------

// AAC (0x1003)
// ------------------------------------------------
// Sample rate is at offset 0x28.
// srcBytesConsumed can be very small the first frames.
// 0x1000 is always the frame size.

// MP3 (0x1002)
// ------------------------------------------------


void CalculateInputBytesAndChannelsAt3Plus(const SceAudiocodecCodec *ctx, int *inputBytes, int *channels) {
*inputBytes = 0;
*channels = 2;
Expand Down Expand Up @@ -125,9 +138,12 @@ static int __AudioCodecInitCommon(u32 ctxPtr, int codec, bool mono) {
ctx->unk_init = 0x5100601; // Firmware version indicator?
ctx->err = 0;

int inFrameBytes = 0;
int bytesPerFrame = 0;
int channels = 2;

uint8_t extraData[14]{};

SceAudiocodecCodec *ptr = ctx;
// Special actions for some codecs.
switch (audioType) {
case PSP_CODEC_MP3:
Expand All @@ -140,15 +156,31 @@ static int __AudioCodecInitCommon(u32 ctxPtr, int codec, bool mono) {
// neededMem has been set to 0x18f20.
break;
case PSP_CODEC_AT3PLUS:
CalculateInputBytesAndChannelsAt3Plus(ctx, &inFrameBytes, &channels);
CalculateInputBytesAndChannelsAt3Plus(ctx, &bytesPerFrame, &channels);
break;
case PSP_CODEC_AT3:
{
// See AtracBase::CreateDecoder. Need to properly understand this one day..
//
// TODO: How do we get the bytesPerFrame?
bytesPerFrame = 384; // TODO: Calculate from params.
bool jointStereo = IsAtrac3StreamJointStereo(PSP_CODEC_AT3, bytesPerFrame, channels);
// The only thing that changes are the jointStereo_ values.
extraData[0] = 1;
extraData[3] = channels << 3;
extraData[6] = jointStereo;
extraData[8] = jointStereo;
extraData[10] = 1;
break;
}
default:
break;
}

// Create audio decoder for given audio codec and push it into AudioList
INFO_LOG(Log::ME, "sceAudioDecoder: Creating codec with %04x frame size and %d channels, codec %04x", inFrameBytes, channels, codec);
AudioDecoder *decoder = CreateAudioDecoder(audioType, 44100, channels, inFrameBytes);
INFO_LOG(Log::ME, "sceAudioDecoder: Creating codec with %04x frame size and %d channels, codec %04x", bytesPerFrame, channels, codec);
// We send in extra data with all codec, most ignore it.
AudioDecoder *decoder = CreateAudioDecoder(audioType, 44100, channels, bytesPerFrame, extraData, sizeof(extraData));
decoder->SetCtxPtr(ctxPtr);
g_audioDecoderContexts[ctxPtr] = decoder;
return hleLogDebug(Log::ME, 0);
Expand Down Expand Up @@ -177,15 +209,23 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) {

auto ctx = PSPPointer<SceAudiocodecCodec>::Create(ctxPtr); // On game-owned heap, no need to allocate.

int inFrameBytes = 0;
int bytesPerFrame = 0;
int channels = 2;
int sampleRate = 0;

switch (codec) {
case PSP_CODEC_AT3PLUS:
CalculateInputBytesAndChannelsAt3Plus(ctx, &inFrameBytes, &channels);
CalculateInputBytesAndChannelsAt3Plus(ctx, &bytesPerFrame, &channels);
break;
case PSP_CODEC_MP3:
inFrameBytes = ctx->srcBytesRead;
bytesPerFrame = ctx->srcBytesRead;
break;
case PSP_CODEC_AAC:
bytesPerFrame = ctx->srcBytesRead;
sampleRate = ctx->formatOutSamples;
break;
case PSP_CODEC_AT3:
bytesPerFrame = 384;
break;
}

Expand All @@ -195,7 +235,7 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) {
if (!decoder && oldStateLoaded) {
// We must have loaded an old state that did not have sceAudiocodec information.
// Fake it by creating the desired context.
decoder = CreateAudioDecoder(audioType, 44100, channels, inFrameBytes);
decoder = CreateAudioDecoder(audioType, 44100, channels, bytesPerFrame);
decoder->SetCtxPtr(ctxPtr);
g_audioDecoderContexts[ctxPtr] = decoder;
}
Expand All @@ -206,11 +246,11 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) {
int inDataConsumed = 0;
int outSamples = 0;

INFO_LOG(Log::ME, "decoder. in: %08x out: %08x unk40: %d unk41: %d", ctx->inBuf, ctx->outBuf, ctx->unk40, ctx->unk41);
DEBUG_LOG(Log::ME, "decoder. in: %08x out: %08x unk40: %02x unk41: %02x", ctx->inBuf, ctx->outBuf, ctx->unk40, ctx->unk41);

int16_t *outBuf = (int16_t *)Memory::GetPointerWrite(ctx->outBuf);

bool result = decoder->Decode(Memory::GetPointer(ctx->inBuf), inFrameBytes, &inDataConsumed, 2, outBuf, &outSamples);
bool result = decoder->Decode(Memory::GetPointer(ctx->inBuf), bytesPerFrame, &inDataConsumed, 2, outBuf, &outSamples);
if (!result) {
ctx->err = 0x20b;
ERROR_LOG(Log::ME, "AudioCodec decode failed. Setting error to %08x", ctx->err);
Expand All @@ -219,7 +259,7 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) {
ctx->srcBytesRead = inDataConsumed;
ctx->dstSamplesWritten = outSamples;
}
return hleLogInfo(Log::ME, 0, "codec %s", GetCodecName(codec));
return hleLogDebug(Log::ME, 0, "codec %s", GetCodecName(codec));
}

// This is used by sceMp3, in Beats.
Expand Down Expand Up @@ -331,6 +371,43 @@ static int sceAudiocodecGetOutputBytes(u32 ctxPtr, int codec, u32 outBytesAddr)
return hleLogInfo(Log::ME, 0);
}

struct At3HeaderMap {
u16 bytes;
u16 channels;
u8 jointStereo;

bool Matches(int bytesPerFrame, int encodedChannels) const {
return this->bytes == bytesPerFrame && this->channels == encodedChannels;
}
};

// These should represent all possible supported bitrates (66, 104, and 132 for stereo.)
static const At3HeaderMap at3HeaderMap[] = {
{ 0x00C0, 1, 0 }, // 132/2 (66) kbps mono
{ 0x0098, 1, 0 }, // 105/2 (52.5) kbps mono
{ 0x0180, 2, 0 }, // 132 kbps stereo
{ 0x0130, 2, 0 }, // 105 kbps stereo
// At this size, stereo can only use joint stereo.
{ 0x00C0, 2, 1 }, // 66 kbps stereo
};

bool IsAtrac3StreamJointStereo(int codecType, int bytesPerFrame, int channels) {
if (codecType != PSP_CODEC_AT3) {
// Well, might actually be, but it's not used in codec setup.
return false;
}

for (size_t i = 0; i < ARRAY_SIZE(at3HeaderMap); ++i) {
if (at3HeaderMap[i].Matches(bytesPerFrame, channels)) {
return at3HeaderMap[i].jointStereo;
}
}

// Not found? Should we log?
return false;
}


const HLEFunction sceAudiocodec[] = {
{0X70A703F8, &WrapI_UI<sceAudiocodecDecode>, "sceAudiocodecDecode", 'i', "xx"},
{0X5B37EB1D, &WrapI_UI<sceAudiocodecInit>, "sceAudiocodecInit", 'i', "xx"},
Expand Down
2 changes: 2 additions & 0 deletions Core/HLE/sceAudiocodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ void __sceAudiocodecDoState(PointerWrap &p);

class AudioDecoder;
extern std::map<u32, AudioDecoder *> g_audioDecoderContexts;

bool IsAtrac3StreamJointStereo(int codecType, int bytesPerFrame, int channels);
24 changes: 14 additions & 10 deletions Core/HLE/sceMpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static int mpegLibVersion = 0;
static u32 mpegLibCrc = 0;
static u32 streamIdGen;
static int actionPostPut;
static std::map<u32, MpegContext *> mpegMap;
std::map<u32, MpegContext *> g_mpegCtxs;

MpegContext::MpegContext() {
memcpy(mpegheader, defaultMpegheader, 2048);
Expand Down Expand Up @@ -215,8 +215,8 @@ static MpegContext *getMpegCtx(u32 mpegAddr) {
return nullptr;

u32 mpeg = Memory::Read_U32(mpegAddr);
auto found = mpegMap.find(mpeg);
if (found == mpegMap.end())
auto found = g_mpegCtxs.find(mpeg);
if (found == g_mpegCtxs.end())
return nullptr;

MpegContext *res = found->second;
Expand All @@ -229,6 +229,10 @@ static MpegContext *getMpegCtx(u32 mpegAddr) {
return res;
}

const std::map<u32, MpegContext *> &__MpegGetContexts() {
return g_mpegCtxs;
}

static u32 convertTimestampToDate(u32 ts) {
return ts; // TODO
}
Expand Down Expand Up @@ -366,15 +370,15 @@ void __MpegDoState(PointerWrap &p) {
Do(p, actionPostPut);
__KernelRestoreActionType(actionPostPut, PostPutAction::Create);

Do(p, mpegMap);
Do(p, g_mpegCtxs);
}

void __MpegShutdown() {
std::map<u32, MpegContext *>::iterator it, end;
for (it = mpegMap.begin(), end = mpegMap.end(); it != end; ++it) {
for (it = g_mpegCtxs.begin(), end = g_mpegCtxs.end(); it != end; ++it) {
delete it->second;
}
mpegMap.clear();
g_mpegCtxs.clear();
}

void __MpegLoadModule(int version,u32 crc) {
Expand Down Expand Up @@ -486,12 +490,12 @@ static u32 sceMpegCreate(u32 mpegAddr, u32 dataPtr, u32 size, u32 ringbufferAddr
Memory::Write_U32(ringbuffer->dataUpperBound, mpegHandle + 20);
}
MpegContext *ctx = new MpegContext();
if (mpegMap.find(mpegHandle) != mpegMap.end()) {
if (g_mpegCtxs.find(mpegHandle) != g_mpegCtxs.end()) {
WARN_LOG_REPORT(Log::HLE, "Replacing existing mpeg context at %08x", mpegAddr);
// Otherwise, it would leak.
delete mpegMap[mpegHandle];
delete g_mpegCtxs[mpegHandle];
}
mpegMap[mpegHandle] = ctx;
g_mpegCtxs[mpegHandle] = ctx;

// Initialize mpeg values.
ctx->mpegRingbufferAddr = ringbufferAddr;
Expand Down Expand Up @@ -526,7 +530,7 @@ static int sceMpegDelete(u32 mpeg) {
}

delete ctx;
mpegMap.erase(Memory::Read_U32(mpeg));
g_mpegCtxs.erase(Memory::Read_U32(mpeg));

return hleDelayResult(hleLogDebug(Log::ME, 0), "mpeg delete", 40000);
}
Expand Down
5 changes: 5 additions & 0 deletions Core/HLE/sceMpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ struct MpegContext {
MpegContext();
~MpegContext();

MpegContext(const MpegContext &) = delete;
void operator=(const MpegContext &) = delete;

void DoState(PointerWrap &p);

u8 mpegheader[2048];
Expand Down Expand Up @@ -140,3 +143,5 @@ void Register_sceMpegbase();
void __VideoPmpInit();
void __VideoPmpDoState(PointerWrap &p);
void __VideoPmpShutdown();

const std::map<u32, MpegContext *> &__MpegGetContexts();
8 changes: 7 additions & 1 deletion Core/HW/MediaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "Common/Serialize/SerializeFuncs.h"
#include "Common/Math/SIMDHeaders.h"
#include "Common/StringUtils.h"
#include "Core/System.h"
#include "Core/Debugger/MemBlockInfo.h"
#include "Core/HW/MediaEngine.h"
Expand Down Expand Up @@ -86,7 +87,12 @@ void ffmpeg_logger(void *, int level, const char *format, va_list va_args) {
} else if (level >= AV_LOG_VERBOSE) {
DEBUG_LOG(Log::ME, "FF: %s", tmp);
} else {
INFO_LOG(Log::ME, "FF: %s", tmp);
// Downgrade some log messages we don't care about
if (startsWith(tmp, "No accelerated colorspace") || startsWith(tmp, "SEI type 1 size 40 truncated at 36")) {
VERBOSE_LOG(Log::ME, "FF: %s", tmp);
} else {
INFO_LOG(Log::ME, "FF: %s", tmp);
}
}
}

Expand Down
Loading
Loading