2013-06-24 14:03:25 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2020-10-04 08:10:55 +00:00
|
|
|
#include "Common/System/Display.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/OpenGL/GLFeatures.h"
|
2019-10-22 20:07:34 +00:00
|
|
|
|
2013-08-17 17:20:19 +00:00
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/ge_constants.h"
|
2013-10-05 18:37:14 +00:00
|
|
|
#include "GPU/Common/TextureDecoder.h"
|
2021-05-01 14:15:04 +00:00
|
|
|
#include "Common/Data/Convert/ColorConv.h"
|
2016-02-13 20:22:27 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2013-12-15 22:01:46 +00:00
|
|
|
#include "Core/Config.h"
|
2018-06-17 01:42:31 +00:00
|
|
|
#include "Core/ConfigValues.h"
|
2021-01-02 17:23:25 +00:00
|
|
|
#include "Core/Core.h"
|
2021-02-02 08:08:05 +00:00
|
|
|
#include "Core/Debugger/MemBlockInfo.h"
|
2013-08-17 17:20:19 +00:00
|
|
|
#include "Core/MemMap.h"
|
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
|
|
|
#include "Core/HLE/sceGe.h"
|
2014-03-15 18:44:02 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-08-17 17:20:19 +00:00
|
|
|
#include "Core/Reporting.h"
|
2021-01-02 17:23:25 +00:00
|
|
|
#include "Core/Util/PPGeDraw.h"
|
2020-10-04 08:04:01 +00:00
|
|
|
#include "Common/Profiler/Profiler.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/thin3d.h"
|
2013-06-24 17:05:43 +00:00
|
|
|
|
2021-11-21 15:20:19 +00:00
|
|
|
#include "GPU/Software/DrawPixel.h"
|
2017-05-11 00:31:34 +00:00
|
|
|
#include "GPU/Software/Rasterizer.h"
|
|
|
|
#include "GPU/Software/Sampler.h"
|
2013-08-17 17:20:19 +00:00
|
|
|
#include "GPU/Software/SoftGpu.h"
|
|
|
|
#include "GPU/Software/TransformUnit.h"
|
2017-04-16 02:53:56 +00:00
|
|
|
#include "GPU/Common/DrawEngineCommon.h"
|
2020-05-10 05:06:22 +00:00
|
|
|
#include "GPU/Common/PresentationCommon.h"
|
2020-11-09 08:00:06 +00:00
|
|
|
#include "Common/GPU/ShaderTranslation.h"
|
2018-11-13 08:12:41 +00:00
|
|
|
#include "GPU/Common/SplineCommon.h"
|
2018-09-01 15:32:03 +00:00
|
|
|
#include "GPU/Debugger/Debugger.h"
|
2017-06-03 07:09:58 +00:00
|
|
|
#include "GPU/Debugger/Record.h"
|
2013-06-25 09:53:45 +00:00
|
|
|
|
2013-08-17 17:20:19 +00:00
|
|
|
const int FB_WIDTH = 480;
|
2013-06-25 13:58:59 +00:00
|
|
|
const int FB_HEIGHT = 272;
|
2017-02-07 17:42:32 +00:00
|
|
|
|
2017-05-24 08:20:10 +00:00
|
|
|
u32 clut[4096];
|
2013-10-20 11:51:54 +00:00
|
|
|
FormatBuffer fb;
|
|
|
|
FormatBuffer depthbuf;
|
2016-12-25 17:18:19 +00:00
|
|
|
|
2017-01-30 15:50:35 +00:00
|
|
|
SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
|
|
|
|
: GPUCommon(gfxCtx, draw)
|
2013-06-24 14:03:25 +00:00
|
|
|
{
|
2013-09-14 18:36:56 +00:00
|
|
|
fb.data = Memory::GetPointer(0x44000000); // TODO: correct default address?
|
|
|
|
depthbuf.data = Memory::GetPointer(0x44000000); // TODO: correct default address?
|
2013-12-15 16:55:19 +00:00
|
|
|
|
2013-12-15 22:01:46 +00:00
|
|
|
framebufferDirty_ = true;
|
2013-12-15 16:55:19 +00:00
|
|
|
// TODO: Is there a default?
|
|
|
|
displayFramebuf_ = 0;
|
|
|
|
displayStride_ = 512;
|
|
|
|
displayFormat_ = GE_FORMAT_8888;
|
2017-04-16 02:53:56 +00:00
|
|
|
|
2021-11-21 15:20:19 +00:00
|
|
|
Rasterizer::Init();
|
2017-05-11 00:31:34 +00:00
|
|
|
Sampler::Init();
|
2017-05-21 03:19:08 +00:00
|
|
|
drawEngine_ = new SoftwareDrawEngine();
|
2021-05-08 16:10:23 +00:00
|
|
|
drawEngine_->Init();
|
2017-05-21 03:19:08 +00:00
|
|
|
drawEngineCommon_ = drawEngine_;
|
2020-05-11 01:19:35 +00:00
|
|
|
|
2021-01-02 17:25:41 +00:00
|
|
|
if (gfxCtx && draw) {
|
|
|
|
presentation_ = new PresentationCommon(draw_);
|
2021-05-08 16:12:22 +00:00
|
|
|
presentation_->SetLanguage(draw_->GetShaderLanguageDesc().shaderLanguage);
|
2020-05-11 01:19:35 +00:00
|
|
|
}
|
|
|
|
Resized();
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 01:56:19 +00:00
|
|
|
void SoftGPU::DeviceLost() {
|
2021-01-02 17:25:41 +00:00
|
|
|
if (presentation_)
|
|
|
|
presentation_->DeviceLost();
|
2020-05-10 05:06:22 +00:00
|
|
|
draw_ = nullptr;
|
|
|
|
if (fbTex) {
|
|
|
|
fbTex->Release();
|
|
|
|
fbTex = nullptr;
|
|
|
|
}
|
2016-01-18 01:56:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 03:29:58 +00:00
|
|
|
void SoftGPU::DeviceRestore() {
|
2021-01-02 17:25:41 +00:00
|
|
|
if (PSP_CoreParameter().graphicsContext)
|
|
|
|
draw_ = (Draw::DrawContext *)PSP_CoreParameter().graphicsContext->GetDrawContext();
|
|
|
|
if (presentation_)
|
|
|
|
presentation_->DeviceRestore(draw_);
|
2021-01-02 17:23:25 +00:00
|
|
|
PPGeSetDrawContext(draw_);
|
2016-09-11 03:29:58 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 20:22:27 +00:00
|
|
|
SoftGPU::~SoftGPU() {
|
2017-02-19 10:02:24 +00:00
|
|
|
if (fbTex) {
|
|
|
|
fbTex->Release();
|
|
|
|
fbTex = nullptr;
|
|
|
|
}
|
2020-05-10 05:06:22 +00:00
|
|
|
|
2021-01-02 17:25:41 +00:00
|
|
|
if (presentation_) {
|
|
|
|
delete presentation_;
|
2020-05-11 01:19:35 +00:00
|
|
|
}
|
2017-05-11 00:31:34 +00:00
|
|
|
|
|
|
|
Sampler::Shutdown();
|
2021-11-21 15:20:19 +00:00
|
|
|
Rasterizer::Shutdown();
|
2013-06-24 17:05:43 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 22:44:35 +00:00
|
|
|
void SoftGPU::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) {
|
2014-01-11 17:51:32 +00:00
|
|
|
// Seems like this can point into RAM, but should be VRAM if not in RAM.
|
|
|
|
displayFramebuf_ = (framebuf & 0xFF000000) == 0 ? 0x44000000 | framebuf : framebuf;
|
2013-12-29 22:44:35 +00:00
|
|
|
displayStride_ = stride;
|
|
|
|
displayFormat_ = format;
|
2018-09-01 15:32:03 +00:00
|
|
|
GPUDebug::NotifyDisplay(framebuf, stride, format);
|
2018-11-17 17:21:51 +00:00
|
|
|
GPURecord::NotifyDisplay(framebuf, stride, format);
|
2013-12-29 22:44:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 14:51:37 +00:00
|
|
|
DSStretch g_DarkStalkerStretch;
|
2019-10-23 22:10:39 +00:00
|
|
|
|
2020-05-14 21:28:37 +00:00
|
|
|
void SoftGPU::ConvertTextureDescFrom16(Draw::TextureDesc &desc, int srcwidth, int srcheight, u8 *overrideData) {
|
2019-12-24 19:05:15 +00:00
|
|
|
// TODO: This should probably be converted in a shader instead..
|
|
|
|
fbTexBuffer_.resize(srcwidth * srcheight);
|
|
|
|
FormatBuffer displayBuffer;
|
2020-05-14 21:28:37 +00:00
|
|
|
displayBuffer.data = overrideData ? overrideData : Memory::GetPointer(displayFramebuf_);
|
2019-12-24 19:05:15 +00:00
|
|
|
for (int y = 0; y < srcheight; ++y) {
|
|
|
|
u32 *buf_line = &fbTexBuffer_[y * srcwidth];
|
|
|
|
const u16 *fb_line = &displayBuffer.as16[y * displayStride_];
|
|
|
|
|
|
|
|
switch (displayFormat_) {
|
|
|
|
case GE_FORMAT_565:
|
2020-05-14 01:17:58 +00:00
|
|
|
ConvertRGB565ToRGBA8888(buf_line, fb_line, srcwidth);
|
2019-12-24 19:05:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_FORMAT_5551:
|
|
|
|
ConvertRGBA5551ToRGBA8888(buf_line, fb_line, srcwidth);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_FORMAT_4444:
|
|
|
|
ConvertRGBA4444ToRGBA8888(buf_line, fb_line, srcwidth);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERROR_LOG_REPORT(G3D, "Software: Unexpected framebuffer format: %d", displayFormat_);
|
2020-05-14 21:28:37 +00:00
|
|
|
break;
|
2019-12-24 19:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
desc.width = srcwidth;
|
|
|
|
desc.height = srcheight;
|
|
|
|
desc.initData.push_back((uint8_t *)fbTexBuffer_.data());
|
|
|
|
}
|
|
|
|
|
2013-06-24 17:05:43 +00:00
|
|
|
// Copies RGBA8 data from RAM to the currently bound render target.
|
2016-12-24 10:50:42 +00:00
|
|
|
void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
|
2021-01-02 17:25:41 +00:00
|
|
|
if (!draw_ || !presentation_)
|
2016-04-09 15:38:33 +00:00
|
|
|
return;
|
2016-02-13 20:22:27 +00:00
|
|
|
float u0 = 0.0f;
|
|
|
|
float u1;
|
2020-05-12 06:28:50 +00:00
|
|
|
float v0 = 0.0f;
|
|
|
|
float v1 = 1.0f;
|
2017-02-19 10:02:24 +00:00
|
|
|
|
|
|
|
if (fbTex) {
|
|
|
|
fbTex->Release();
|
|
|
|
fbTex = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-12 01:45:47 +00:00
|
|
|
// For accuracy, try to handle 0 stride - sometimes used.
|
|
|
|
if (displayStride_ == 0) {
|
|
|
|
srcheight = 1;
|
2019-10-22 21:14:27 +00:00
|
|
|
u1 = 1.0f;
|
|
|
|
} else {
|
|
|
|
u1 = (float)srcwidth / displayStride_;
|
2017-11-12 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 10:02:24 +00:00
|
|
|
Draw::TextureDesc desc{};
|
|
|
|
desc.type = Draw::TextureType::LINEAR2D;
|
|
|
|
desc.format = Draw::DataFormat::R8G8B8A8_UNORM;
|
|
|
|
desc.depth = 1;
|
|
|
|
desc.mipLevels = 1;
|
2018-04-07 04:32:33 +00:00
|
|
|
desc.tag = "SoftGPU";
|
2017-01-28 15:41:17 +00:00
|
|
|
bool hasImage = true;
|
2019-10-23 22:51:55 +00:00
|
|
|
|
2020-05-10 05:06:22 +00:00
|
|
|
OutputFlags outputFlags = g_Config.iBufFilter == SCALE_NEAREST ? OutputFlags::NEAREST : OutputFlags::LINEAR;
|
2021-01-02 17:25:41 +00:00
|
|
|
bool hasPostShader = presentation_ && presentation_->HasPostShader();
|
2020-05-10 05:06:22 +00:00
|
|
|
|
2020-05-24 14:51:37 +00:00
|
|
|
if (PSP_CoreParameter().compat.flags().DarkStalkersPresentHack && displayFormat_ == GE_FORMAT_5551 && g_DarkStalkerStretch != DSStretch::Off) {
|
2019-10-23 22:10:39 +00:00
|
|
|
u8 *data = Memory::GetPointer(0x04088000);
|
2019-12-24 19:05:15 +00:00
|
|
|
bool fillDesc = true;
|
2019-10-23 23:29:24 +00:00
|
|
|
if (draw_->GetDataFormatSupport(Draw::DataFormat::A1B5G5R5_UNORM_PACK16) & Draw::FMT_TEXTURE) {
|
|
|
|
// The perfect one.
|
|
|
|
desc.format = Draw::DataFormat::A1B5G5R5_UNORM_PACK16;
|
2020-05-11 04:21:41 +00:00
|
|
|
} else if (!hasPostShader && (draw_->GetDataFormatSupport(Draw::DataFormat::A1R5G5B5_UNORM_PACK16) & Draw::FMT_TEXTURE)) {
|
2019-10-23 23:29:24 +00:00
|
|
|
// RB swapped, compensate with a shader.
|
|
|
|
desc.format = Draw::DataFormat::A1R5G5B5_UNORM_PACK16;
|
2020-05-10 05:06:22 +00:00
|
|
|
outputFlags |= OutputFlags::RB_SWIZZLE;
|
2019-12-24 19:05:15 +00:00
|
|
|
} else {
|
2020-05-14 21:28:37 +00:00
|
|
|
ConvertTextureDescFrom16(desc, srcwidth, srcheight, data);
|
2019-12-24 19:05:15 +00:00
|
|
|
fillDesc = false;
|
|
|
|
}
|
|
|
|
if (fillDesc) {
|
|
|
|
desc.width = displayStride_ == 0 ? srcwidth : displayStride_;
|
|
|
|
desc.height = srcheight;
|
|
|
|
desc.initData.push_back(data);
|
2019-10-23 23:29:24 +00:00
|
|
|
}
|
2020-05-12 01:01:48 +00:00
|
|
|
u0 = 64.5f / (float)desc.width;
|
|
|
|
u1 = 447.5f / (float)desc.width;
|
2020-05-12 06:28:50 +00:00
|
|
|
v0 = 16.0f / (float)desc.height;
|
|
|
|
v1 = 240.0f / (float)desc.height;
|
2020-05-24 14:51:37 +00:00
|
|
|
if (g_DarkStalkerStretch == DSStretch::Normal) {
|
|
|
|
outputFlags |= OutputFlags::PILLARBOX;
|
|
|
|
}
|
2019-10-23 22:10:39 +00:00
|
|
|
} else if (!Memory::IsValidAddress(displayFramebuf_) || srcwidth == 0 || srcheight == 0) {
|
2017-01-28 15:41:17 +00:00
|
|
|
hasImage = false;
|
2016-02-13 20:22:27 +00:00
|
|
|
u1 = 1.0f;
|
2013-12-15 16:55:19 +00:00
|
|
|
} else if (displayFormat_ == GE_FORMAT_8888) {
|
|
|
|
u8 *data = Memory::GetPointer(displayFramebuf_);
|
2017-11-12 01:45:47 +00:00
|
|
|
desc.width = displayStride_ == 0 ? srcwidth : displayStride_;
|
2017-02-19 10:02:24 +00:00
|
|
|
desc.height = srcheight;
|
|
|
|
desc.initData.push_back(data);
|
|
|
|
desc.format = Draw::DataFormat::R8G8B8A8_UNORM;
|
2019-10-25 22:46:56 +00:00
|
|
|
} else if (displayFormat_ == GE_FORMAT_5551) {
|
2019-10-22 21:14:27 +00:00
|
|
|
u8 *data = Memory::GetPointer(displayFramebuf_);
|
2019-12-24 19:05:15 +00:00
|
|
|
bool fillDesc = true;
|
2019-10-25 22:46:56 +00:00
|
|
|
if (draw_->GetDataFormatSupport(Draw::DataFormat::A1B5G5R5_UNORM_PACK16) & Draw::FMT_TEXTURE) {
|
|
|
|
// The perfect one.
|
|
|
|
desc.format = Draw::DataFormat::A1B5G5R5_UNORM_PACK16;
|
2020-05-11 04:21:41 +00:00
|
|
|
} else if (!hasPostShader && (draw_->GetDataFormatSupport(Draw::DataFormat::A1R5G5B5_UNORM_PACK16) & Draw::FMT_TEXTURE)) {
|
2019-10-25 22:46:56 +00:00
|
|
|
// RB swapped, compensate with a shader.
|
|
|
|
desc.format = Draw::DataFormat::A1R5G5B5_UNORM_PACK16;
|
2020-05-10 05:06:22 +00:00
|
|
|
outputFlags |= OutputFlags::RB_SWIZZLE;
|
2019-12-24 19:05:15 +00:00
|
|
|
} else {
|
|
|
|
ConvertTextureDescFrom16(desc, srcwidth, srcheight);
|
2020-05-12 01:01:48 +00:00
|
|
|
u1 = 1.0f;
|
2019-12-24 19:05:15 +00:00
|
|
|
fillDesc = false;
|
2019-10-25 22:46:56 +00:00
|
|
|
}
|
2019-12-24 19:05:15 +00:00
|
|
|
if (fillDesc) {
|
|
|
|
desc.width = displayStride_ == 0 ? srcwidth : displayStride_;
|
|
|
|
desc.height = srcheight;
|
|
|
|
desc.initData.push_back(data);
|
2013-07-21 17:15:28 +00:00
|
|
|
}
|
2019-12-24 19:05:15 +00:00
|
|
|
} else {
|
|
|
|
ConvertTextureDescFrom16(desc, srcwidth, srcheight);
|
2016-02-13 20:22:27 +00:00
|
|
|
u1 = 1.0f;
|
2013-07-21 17:15:28 +00:00
|
|
|
}
|
2017-02-19 10:02:24 +00:00
|
|
|
if (!hasImage) {
|
2020-05-21 09:24:05 +00:00
|
|
|
draw_->BindFramebufferAsRenderTarget(nullptr, { Draw::RPAction::CLEAR, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "CopyToCurrentFboFromDisplayRam");
|
2017-02-19 10:02:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fbTex = draw_->CreateTexture(desc);
|
2013-06-24 17:05:43 +00:00
|
|
|
|
2020-05-12 06:28:50 +00:00
|
|
|
switch (GetGPUBackend()) {
|
|
|
|
case GPUBackend::OPENGL:
|
2020-05-11 01:19:35 +00:00
|
|
|
outputFlags |= OutputFlags::BACKBUFFER_FLIPPED;
|
2020-05-12 06:28:50 +00:00
|
|
|
break;
|
|
|
|
case GPUBackend::DIRECT3D9:
|
|
|
|
case GPUBackend::DIRECT3D11:
|
|
|
|
outputFlags |= OutputFlags::POSITION_FLIPPED;
|
|
|
|
break;
|
|
|
|
case GPUBackend::VULKAN:
|
|
|
|
break;
|
2020-05-11 01:19:35 +00:00
|
|
|
}
|
2019-10-23 22:10:39 +00:00
|
|
|
|
2020-05-16 06:41:13 +00:00
|
|
|
presentation_->SourceTexture(fbTex, desc.width, desc.height);
|
|
|
|
presentation_->CopyToOutput(outputFlags, g_Config.iInternalScreenRotation, u0, v0, u1, v1);
|
2013-06-24 17:05:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 21:55:28 +00:00
|
|
|
void SoftGPU::CopyDisplayToOutput(bool reallyDirty) {
|
2013-08-17 17:20:19 +00:00
|
|
|
// The display always shows 480x272.
|
2013-12-17 08:02:54 +00:00
|
|
|
CopyToCurrentFboFromDisplayRam(FB_WIDTH, FB_HEIGHT);
|
2013-12-15 22:01:46 +00:00
|
|
|
framebufferDirty_ = false;
|
2020-05-11 01:19:35 +00:00
|
|
|
}
|
2017-04-16 02:54:42 +00:00
|
|
|
|
2020-05-11 01:19:35 +00:00
|
|
|
void SoftGPU::Resized() {
|
2017-04-16 02:54:42 +00:00
|
|
|
// Force the render params to 480x272 so other things work.
|
|
|
|
if (g_Config.IsPortrait()) {
|
|
|
|
PSP_CoreParameter().renderWidth = 272;
|
|
|
|
PSP_CoreParameter().renderHeight = 480;
|
|
|
|
} else {
|
|
|
|
PSP_CoreParameter().renderWidth = 480;
|
|
|
|
PSP_CoreParameter().renderHeight = 272;
|
|
|
|
}
|
2020-05-11 01:19:35 +00:00
|
|
|
|
2021-01-02 17:25:41 +00:00
|
|
|
if (presentation_) {
|
|
|
|
presentation_->UpdateSize(PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight);
|
|
|
|
presentation_->UpdatePostShader();
|
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoftGPU::FastRunLoop(DisplayList &list) {
|
2015-06-11 10:29:14 +00:00
|
|
|
PROFILE_THIS_SCOPE("soft_runloop");
|
2013-06-24 14:03:25 +00:00
|
|
|
for (; downcount > 0; --downcount) {
|
|
|
|
u32 op = Memory::ReadUnchecked_U32(list.pc);
|
|
|
|
u32 cmd = op >> 24;
|
|
|
|
|
|
|
|
u32 diff = op ^ gstate.cmdmem[cmd];
|
|
|
|
gstate.cmdmem[cmd] = op;
|
|
|
|
ExecuteOp(op, diff);
|
|
|
|
|
|
|
|
list.pc += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 20:00:44 +00:00
|
|
|
void SoftGPU::ExecuteOp(u32 op, u32 diff) {
|
2013-06-24 14:03:25 +00:00
|
|
|
u32 cmd = op >> 24;
|
|
|
|
u32 data = op & 0xFFFFFF;
|
|
|
|
|
|
|
|
// Handle control and drawing commands here directly. The others we delegate.
|
2017-01-23 20:00:44 +00:00
|
|
|
switch (cmd) {
|
2013-06-24 14:03:25 +00:00
|
|
|
case GE_CMD_BASE:
|
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_VADDR:
|
|
|
|
gstate_c.vertexAddr = gstate_c.getRelativeAddress(data);
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_IADDR:
|
2013-09-14 21:28:37 +00:00
|
|
|
gstate_c.indexAddr = gstate_c.getRelativeAddress(data);
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PRIM:
|
|
|
|
{
|
|
|
|
u32 count = data & 0xFFFF;
|
2017-04-30 03:36:36 +00:00
|
|
|
// Upper bits are ignored.
|
2017-05-24 08:20:10 +00:00
|
|
|
GEPrimitiveType prim = static_cast<GEPrimitiveType>((data >> 16) & 7);
|
2013-06-25 09:07:14 +00:00
|
|
|
|
2013-07-24 14:34:08 +00:00
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
2013-09-01 08:10:12 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "Software: Bad vertex address %08x!", gstate_c.vertexAddr);
|
2013-07-24 14:34:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-25 09:07:14 +00:00
|
|
|
void *verts = Memory::GetPointer(gstate_c.vertexAddr);
|
2013-06-28 21:34:56 +00:00
|
|
|
void *indices = NULL;
|
2013-06-25 09:07:14 +00:00
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
2013-07-24 14:34:08 +00:00
|
|
|
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
|
2013-09-01 08:10:12 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "Software: Bad index address %08x!", gstate_c.indexAddr);
|
2013-07-24 14:34:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-28 21:34:56 +00:00
|
|
|
indices = Memory::GetPointer(gstate_c.indexAddr);
|
2013-06-25 09:07:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-27 22:05:57 +00:00
|
|
|
cyclesExecuted += EstimatePerVertexCost() * count;
|
2013-11-21 05:59:45 +00:00
|
|
|
int bytesRead;
|
2017-05-24 08:20:10 +00:00
|
|
|
drawEngine_->transformUnit.SubmitPrimitive(verts, indices, prim, count, gstate.vertType, &bytesRead, drawEngine_);
|
2013-12-15 22:01:46 +00:00
|
|
|
framebufferDirty_ = true;
|
2013-11-21 05:59:45 +00:00
|
|
|
|
|
|
|
// After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed).
|
|
|
|
// Some games rely on this, they don't bother reloading VADDR and IADDR.
|
2014-05-05 01:24:49 +00:00
|
|
|
// The VADDR/IADDR registers are NOT updated.
|
2016-04-10 20:07:08 +00:00
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BEZIER:
|
|
|
|
{
|
2017-04-16 03:08:37 +00:00
|
|
|
// We don't dirty on normal changes anymore as we prescale, but it's needed for splines/bezier.
|
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
|
|
|
|
|
|
|
// This also make skipping drawing very effective.
|
|
|
|
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
|
|
|
|
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
|
|
|
|
void *indices = NULL;
|
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
indices = Memory::GetPointerUnchecked(gstate_c.indexAddr);
|
|
|
|
}
|
|
|
|
|
2018-04-10 10:22:02 +00:00
|
|
|
if ((gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) || vertTypeIsSkinningEnabled(gstate.vertType)) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", gstate.vertType, (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(gstate.vertType));
|
|
|
|
}
|
|
|
|
|
2018-11-13 08:12:41 +00:00
|
|
|
Spline::BezierSurface surface;
|
|
|
|
surface.tess_u = gstate.getPatchDivisionU();
|
|
|
|
surface.tess_v = gstate.getPatchDivisionV();
|
|
|
|
surface.num_points_u = op & 0xFF;
|
|
|
|
surface.num_points_v = (op >> 8) & 0xFF;
|
|
|
|
surface.num_patches_u = (surface.num_points_u - 1) / 3;
|
|
|
|
surface.num_patches_v = (surface.num_points_v - 1) / 3;
|
|
|
|
surface.primType = gstate.getPatchPrimitiveType();
|
|
|
|
surface.patchFacing = gstate.patchfacing & 1;
|
2017-04-16 03:08:37 +00:00
|
|
|
|
2018-11-13 08:12:41 +00:00
|
|
|
SetDrawType(DRAW_BEZIER, PatchPrimToPrim(surface.primType));
|
2017-04-16 03:08:37 +00:00
|
|
|
|
|
|
|
int bytesRead = 0;
|
2018-11-13 08:12:41 +00:00
|
|
|
drawEngineCommon_->SubmitCurve(control_points, indices, surface, gstate.vertType, &bytesRead, "bezier");
|
2017-04-16 03:08:37 +00:00
|
|
|
framebufferDirty_ = true;
|
|
|
|
|
|
|
|
// After drawing, we advance pointers - see SubmitPrim which does the same.
|
2018-11-13 08:12:41 +00:00
|
|
|
int count = surface.num_points_u * surface.num_points_v;
|
2017-04-16 03:08:37 +00:00
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_SPLINE:
|
|
|
|
{
|
2017-04-16 03:08:37 +00:00
|
|
|
// We don't dirty on normal changes anymore as we prescale, but it's needed for splines/bezier.
|
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
|
|
|
|
|
|
|
// This also make skipping drawing very effective.
|
|
|
|
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
|
|
|
|
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
|
|
|
|
return;
|
|
|
|
}
|
2013-07-24 15:59:21 +00:00
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
2017-04-16 03:08:37 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
|
|
|
|
return;
|
2013-07-24 15:59:21 +00:00
|
|
|
}
|
|
|
|
|
2017-04-16 03:08:37 +00:00
|
|
|
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
|
|
|
|
void *indices = NULL;
|
2013-07-24 15:59:21 +00:00
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
|
2017-04-16 03:08:37 +00:00
|
|
|
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
|
|
|
|
return;
|
2013-07-24 15:59:21 +00:00
|
|
|
}
|
2017-04-16 03:08:37 +00:00
|
|
|
indices = Memory::GetPointerUnchecked(gstate_c.indexAddr);
|
2013-07-24 15:59:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 10:22:02 +00:00
|
|
|
if ((gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) || vertTypeIsSkinningEnabled(gstate.vertType)) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", gstate.vertType, (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(gstate.vertType));
|
|
|
|
}
|
|
|
|
|
2018-11-13 08:12:41 +00:00
|
|
|
Spline::SplineSurface surface;
|
|
|
|
surface.tess_u = gstate.getPatchDivisionU();
|
|
|
|
surface.tess_v = gstate.getPatchDivisionV();
|
|
|
|
surface.type_u = (op >> 16) & 0x3;
|
|
|
|
surface.type_v = (op >> 18) & 0x3;
|
|
|
|
surface.num_points_u = op & 0xFF;
|
|
|
|
surface.num_points_v = (op >> 8) & 0xFF;
|
|
|
|
surface.num_patches_u = surface.num_points_u - 3;
|
|
|
|
surface.num_patches_v = surface.num_points_v - 3;
|
|
|
|
surface.primType = gstate.getPatchPrimitiveType();
|
|
|
|
surface.patchFacing = gstate.patchfacing & 1;
|
|
|
|
|
|
|
|
SetDrawType(DRAW_SPLINE, PatchPrimToPrim(surface.primType));
|
2017-04-16 03:08:37 +00:00
|
|
|
|
|
|
|
int bytesRead = 0;
|
2018-11-13 08:12:41 +00:00
|
|
|
drawEngineCommon_->SubmitCurve(control_points, indices, surface, gstate.vertType, &bytesRead, "spline");
|
2013-12-15 22:01:46 +00:00
|
|
|
framebufferDirty_ = true;
|
2017-04-16 03:08:37 +00:00
|
|
|
|
|
|
|
// After drawing, we advance pointers - see SubmitPrim which does the same.
|
2018-11-13 08:12:41 +00:00
|
|
|
int count = surface.num_points_u * surface.num_points_v;
|
2017-04-16 03:08:37 +00:00
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BOUNDINGBOX:
|
2017-12-24 19:05:52 +00:00
|
|
|
if (data == 0) {
|
|
|
|
currentList->bboxResult = false;
|
|
|
|
} else if (((data & 7) == 0) && data <= 64) { // Sanity check
|
2013-09-24 10:59:34 +00:00
|
|
|
DEBUG_LOG(G3D, "Unsupported bounding box: %06x", data);
|
2017-12-24 19:05:52 +00:00
|
|
|
void *control_points = Memory::GetPointer(gstate_c.vertexAddr);
|
|
|
|
if (!control_points) {
|
|
|
|
ERROR_LOG_REPORT_ONCE(boundingbox, G3D, "Invalid verts in bounding box check");
|
|
|
|
currentList->bboxResult = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.vertType & GE_VTYPE_IDX_MASK) {
|
|
|
|
ERROR_LOG_REPORT_ONCE(boundingbox, G3D, "Indexed bounding box data not supported.");
|
|
|
|
// Data seems invalid. Let's assume the box test passed.
|
|
|
|
currentList->bboxResult = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if the bounding box is within the drawing region.
|
|
|
|
int bytesRead;
|
|
|
|
currentList->bboxResult = drawEngineCommon_->TestBoundingBox(control_points, data, gstate.vertType, &bytesRead);
|
|
|
|
AdvanceVerts(gstate.vertType, data, bytesRead);
|
|
|
|
} else {
|
|
|
|
ERROR_LOG_REPORT_ONCE(boundingbox, G3D, "Bad bounding box data: %06x", data);
|
|
|
|
// Data seems invalid. Let's assume the box test passed.
|
|
|
|
currentList->bboxResult = true;
|
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VERTEXTYPE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_REGION1:
|
|
|
|
case GE_CMD_REGION2:
|
|
|
|
break;
|
|
|
|
|
2018-08-11 23:33:39 +00:00
|
|
|
case GE_CMD_DEPTHCLAMPENABLE:
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_CULLFACEENABLE:
|
|
|
|
case GE_CMD_CULL:
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TEXTUREMAPENABLE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LIGHTINGENABLE:
|
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_FOGCOLOR:
|
|
|
|
case GE_CMD_FOG1:
|
|
|
|
case GE_CMD_FOG2:
|
|
|
|
case GE_CMD_FOGENABLE:
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_DITHERENABLE:
|
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_OFFSETX:
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_OFFSETY:
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_TEXSCALEU:
|
|
|
|
gstate_c.uv.uScale = getFloat24(data);
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_TEXSCALEV:
|
|
|
|
gstate_c.uv.vScale = getFloat24(data);
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_TEXOFFSETU:
|
|
|
|
gstate_c.uv.uOff = getFloat24(data);
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_TEXOFFSETV:
|
|
|
|
gstate_c.uv.vOff = getFloat24(data);
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_SCISSOR1:
|
|
|
|
case GE_CMD_SCISSOR2:
|
|
|
|
break;
|
|
|
|
|
2013-09-14 21:28:37 +00:00
|
|
|
case GE_CMD_MINZ:
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FRAMEBUFPTR:
|
2013-10-06 22:51:31 +00:00
|
|
|
fb.data = Memory::GetPointer(gstate.getFrameBufAddress());
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FRAMEBUFWIDTH:
|
2013-10-06 22:51:31 +00:00
|
|
|
fb.data = Memory::GetPointer(gstate.getFrameBufAddress());
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_FRAMEBUFPIXFORMAT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TEXADDR0:
|
|
|
|
case GE_CMD_TEXADDR1:
|
|
|
|
case GE_CMD_TEXADDR2:
|
|
|
|
case GE_CMD_TEXADDR3:
|
|
|
|
case GE_CMD_TEXADDR4:
|
|
|
|
case GE_CMD_TEXADDR5:
|
|
|
|
case GE_CMD_TEXADDR6:
|
|
|
|
case GE_CMD_TEXADDR7:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TEXBUFWIDTH0:
|
|
|
|
case GE_CMD_TEXBUFWIDTH1:
|
|
|
|
case GE_CMD_TEXBUFWIDTH2:
|
|
|
|
case GE_CMD_TEXBUFWIDTH3:
|
|
|
|
case GE_CMD_TEXBUFWIDTH4:
|
|
|
|
case GE_CMD_TEXBUFWIDTH5:
|
|
|
|
case GE_CMD_TEXBUFWIDTH6:
|
|
|
|
case GE_CMD_TEXBUFWIDTH7:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_CLUTADDR:
|
|
|
|
case GE_CMD_CLUTADDRUPPER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LOADCLUT:
|
|
|
|
{
|
2013-08-24 18:10:56 +00:00
|
|
|
u32 clutAddr = gstate.getClutAddress();
|
|
|
|
u32 clutTotalBytes = gstate.getClutLoadBytes();
|
2013-07-11 20:43:02 +00:00
|
|
|
|
|
|
|
if (Memory::IsValidAddress(clutAddr)) {
|
2015-04-13 05:38:17 +00:00
|
|
|
u32 validSize = Memory::ValidSize(clutAddr, clutTotalBytes);
|
|
|
|
Memory::MemcpyUnchecked(clut, clutAddr, validSize);
|
|
|
|
if (validSize < clutTotalBytes) {
|
|
|
|
// Zero out the parts that were outside valid memory.
|
|
|
|
memset((u8 *)clut + validSize, 0x00, clutTotalBytes - validSize);
|
|
|
|
}
|
2013-10-05 21:24:05 +00:00
|
|
|
} else if (clutAddr != 0) {
|
2015-04-13 05:38:17 +00:00
|
|
|
// Some invalid addresses trigger a crash, others fill with zero. We always fill zero.
|
2015-06-21 19:25:38 +00:00
|
|
|
DEBUG_LOG(G3D, "Software: Invalid CLUT address, filling with garbage instead of crashing");
|
2015-04-13 05:38:17 +00:00
|
|
|
memset(clut, 0x00, clutTotalBytes);
|
2013-07-11 20:43:02 +00:00
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-08-24 17:41:45 +00:00
|
|
|
// Don't need to do anything, just state for transferstart.
|
|
|
|
case GE_CMD_TRANSFERSRC:
|
2013-06-24 14:03:25 +00:00
|
|
|
case GE_CMD_TRANSFERSRCW:
|
2013-08-24 17:41:45 +00:00
|
|
|
case GE_CMD_TRANSFERDST:
|
2013-06-24 14:03:25 +00:00
|
|
|
case GE_CMD_TRANSFERDSTW:
|
|
|
|
case GE_CMD_TRANSFERSRCPOS:
|
|
|
|
case GE_CMD_TRANSFERDSTPOS:
|
|
|
|
case GE_CMD_TRANSFERSIZE:
|
2013-08-24 17:41:45 +00:00
|
|
|
break;
|
2013-06-24 14:03:25 +00:00
|
|
|
|
|
|
|
case GE_CMD_TRANSFERSTART:
|
|
|
|
{
|
2013-08-24 17:41:45 +00:00
|
|
|
u32 srcBasePtr = gstate.getTransferSrcAddress();
|
|
|
|
u32 srcStride = gstate.getTransferSrcStride();
|
|
|
|
|
|
|
|
u32 dstBasePtr = gstate.getTransferDstAddress();
|
|
|
|
u32 dstStride = gstate.getTransferDstStride();
|
2013-07-26 08:38:02 +00:00
|
|
|
|
2013-08-24 17:41:45 +00:00
|
|
|
int srcX = gstate.getTransferSrcX();
|
|
|
|
int srcY = gstate.getTransferSrcY();
|
2013-07-26 08:38:02 +00:00
|
|
|
|
2013-08-24 17:41:45 +00:00
|
|
|
int dstX = gstate.getTransferDstX();
|
|
|
|
int dstY = gstate.getTransferDstY();
|
2013-07-26 08:38:02 +00:00
|
|
|
|
2013-08-24 17:41:45 +00:00
|
|
|
int width = gstate.getTransferWidth();
|
|
|
|
int height = gstate.getTransferHeight();
|
2013-07-26 08:38:02 +00:00
|
|
|
|
2013-08-24 17:41:45 +00:00
|
|
|
int bpp = gstate.getTransferBpp();
|
2013-07-26 08:38:02 +00:00
|
|
|
|
2013-08-24 17:41:45 +00:00
|
|
|
DEBUG_LOG(G3D, "Block transfer: %08x/%x -> %08x/%x, %ix%ix%i (%i,%i)->(%i,%i)", srcBasePtr, srcStride, dstBasePtr, dstStride, width, height, bpp, srcX, srcY, dstX, dstY);
|
2013-07-26 08:38:02 +00:00
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
const u8 *src = Memory::GetPointer(srcBasePtr + ((y + srcY) * srcStride + srcX) * bpp);
|
|
|
|
u8 *dst = Memory::GetPointer(dstBasePtr + ((y + dstY) * dstStride + dstX) * bpp);
|
|
|
|
memcpy(dst, src, width * bpp);
|
|
|
|
}
|
|
|
|
|
2021-04-04 00:04:35 +00:00
|
|
|
const uint32_t src = srcBasePtr + (srcY * srcStride + srcX) * bpp;
|
|
|
|
const uint32_t srcSize = height * srcStride * bpp;
|
|
|
|
const std::string tag = "GPUBlockTransfer/" + GetMemWriteTagAt(src, srcSize);
|
|
|
|
NotifyMemInfo(MemBlockFlags::READ, src, srcSize, tag.c_str(), tag.size());
|
|
|
|
NotifyMemInfo(MemBlockFlags::WRITE, dstBasePtr + (dstY * dstStride + dstX) * bpp, height * dstStride * bpp, tag.c_str(), tag.size());
|
2013-12-14 22:54:05 +00:00
|
|
|
|
2014-08-31 05:02:28 +00:00
|
|
|
// TODO: Correct timing appears to be 1.9, but erring a bit low since some of our other timing is inaccurate.
|
|
|
|
cyclesExecuted += ((height * width * bpp) * 16) / 10;
|
|
|
|
|
2013-12-15 22:01:46 +00:00
|
|
|
// Could theoretically dirty the framebuffer.
|
|
|
|
framebufferDirty_ = true;
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GE_CMD_TEXSIZE0:
|
|
|
|
case GE_CMD_TEXSIZE1:
|
|
|
|
case GE_CMD_TEXSIZE2:
|
|
|
|
case GE_CMD_TEXSIZE3:
|
|
|
|
case GE_CMD_TEXSIZE4:
|
|
|
|
case GE_CMD_TEXSIZE5:
|
|
|
|
case GE_CMD_TEXSIZE6:
|
|
|
|
case GE_CMD_TEXSIZE7:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ZBUFPTR:
|
2013-10-06 22:51:31 +00:00
|
|
|
depthbuf.data = Memory::GetPointer(gstate.getDepthBufAddress());
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ZBUFWIDTH:
|
2013-10-06 22:51:31 +00:00
|
|
|
depthbuf.data = Memory::GetPointer(gstate.getDepthBufAddress());
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_AMBIENTCOLOR:
|
|
|
|
case GE_CMD_AMBIENTALPHA:
|
|
|
|
case GE_CMD_MATERIALAMBIENT:
|
|
|
|
case GE_CMD_MATERIALDIFFUSE:
|
|
|
|
case GE_CMD_MATERIALEMISSIVE:
|
|
|
|
case GE_CMD_MATERIALSPECULAR:
|
|
|
|
case GE_CMD_MATERIALALPHA:
|
|
|
|
case GE_CMD_MATERIALSPECULARCOEF:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LIGHTTYPE0:
|
|
|
|
case GE_CMD_LIGHTTYPE1:
|
|
|
|
case GE_CMD_LIGHTTYPE2:
|
|
|
|
case GE_CMD_LIGHTTYPE3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LX0:case GE_CMD_LY0:case GE_CMD_LZ0:
|
|
|
|
case GE_CMD_LX1:case GE_CMD_LY1:case GE_CMD_LZ1:
|
|
|
|
case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2:
|
|
|
|
case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LDX0:case GE_CMD_LDY0:case GE_CMD_LDZ0:
|
|
|
|
case GE_CMD_LDX1:case GE_CMD_LDY1:case GE_CMD_LDZ1:
|
|
|
|
case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2:
|
|
|
|
case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LKA0:case GE_CMD_LKB0:case GE_CMD_LKC0:
|
|
|
|
case GE_CMD_LKA1:case GE_CMD_LKB1:case GE_CMD_LKC1:
|
|
|
|
case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2:
|
|
|
|
case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LAC0:case GE_CMD_LAC1:case GE_CMD_LAC2:case GE_CMD_LAC3:
|
|
|
|
case GE_CMD_LDC0:case GE_CMD_LDC1:case GE_CMD_LDC2:case GE_CMD_LDC3:
|
|
|
|
case GE_CMD_LSC0:case GE_CMD_LSC1:case GE_CMD_LSC2:case GE_CMD_LSC3:
|
|
|
|
break;
|
|
|
|
|
2015-11-04 21:03:29 +00:00
|
|
|
case GE_CMD_VIEWPORTXSCALE:
|
|
|
|
case GE_CMD_VIEWPORTYSCALE:
|
|
|
|
case GE_CMD_VIEWPORTZSCALE:
|
|
|
|
case GE_CMD_VIEWPORTXCENTER:
|
|
|
|
case GE_CMD_VIEWPORTYCENTER:
|
|
|
|
case GE_CMD_VIEWPORTZCENTER:
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
2013-09-14 21:28:37 +00:00
|
|
|
|
2013-06-24 14:03:25 +00:00
|
|
|
case GE_CMD_LIGHTENABLE0:
|
|
|
|
case GE_CMD_LIGHTENABLE1:
|
|
|
|
case GE_CMD_LIGHTENABLE2:
|
|
|
|
case GE_CMD_LIGHTENABLE3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_LIGHTMODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PATCHDIVISION:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MATERIALUPDATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// CLEARING
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
case GE_CMD_CLEARMODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// ALPHA BLENDING
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
case GE_CMD_ALPHABLENDENABLE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BLENDMODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BLENDFIXEDA:
|
|
|
|
case GE_CMD_BLENDFIXEDB:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ALPHATESTENABLE:
|
|
|
|
case GE_CMD_ALPHATEST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TEXFUNC:
|
|
|
|
case GE_CMD_TEXFILTER:
|
|
|
|
break;
|
2013-09-14 21:28:37 +00:00
|
|
|
|
2013-06-24 14:03:25 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Z/STENCIL TESTING
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
case GE_CMD_ZTESTENABLE:
|
|
|
|
case GE_CMD_STENCILTESTENABLE:
|
|
|
|
case GE_CMD_ZTEST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_MORPHWEIGHT0:
|
|
|
|
case GE_CMD_MORPHWEIGHT1:
|
|
|
|
case GE_CMD_MORPHWEIGHT2:
|
|
|
|
case GE_CMD_MORPHWEIGHT3:
|
|
|
|
case GE_CMD_MORPHWEIGHT4:
|
|
|
|
case GE_CMD_MORPHWEIGHT5:
|
|
|
|
case GE_CMD_MORPHWEIGHT6:
|
|
|
|
case GE_CMD_MORPHWEIGHT7:
|
2013-09-14 21:28:37 +00:00
|
|
|
gstate_c.morphWeights[cmd - GE_CMD_MORPHWEIGHT0] = getFloat24(data);
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_DITH0:
|
|
|
|
case GE_CMD_DITH1:
|
|
|
|
case GE_CMD_DITH2:
|
|
|
|
case GE_CMD_DITH3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_WORLDMATRIXNUMBER:
|
2015-06-11 15:00:44 +00:00
|
|
|
gstate.worldmtxnum = data & 0xF;
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_WORLDMATRIXDATA:
|
2013-09-14 21:28:37 +00:00
|
|
|
{
|
|
|
|
int num = gstate.worldmtxnum & 0xF;
|
|
|
|
if (num < 12) {
|
|
|
|
gstate.worldMatrix[num] = getFloat24(data);
|
|
|
|
}
|
|
|
|
gstate.worldmtxnum = (++num) & 0xF;
|
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VIEWMATRIXNUMBER:
|
2015-06-11 15:00:44 +00:00
|
|
|
gstate.viewmtxnum = data & 0xF;
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_VIEWMATRIXDATA:
|
2013-09-14 21:28:37 +00:00
|
|
|
{
|
|
|
|
int num = gstate.viewmtxnum & 0xF;
|
|
|
|
if (num < 12) {
|
|
|
|
gstate.viewMatrix[num] = getFloat24(data);
|
|
|
|
}
|
|
|
|
gstate.viewmtxnum = (++num) & 0xF;
|
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PROJMATRIXNUMBER:
|
2016-12-01 22:14:41 +00:00
|
|
|
gstate.projmtxnum = data & 0x1F;
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_PROJMATRIXDATA:
|
2013-09-14 21:28:37 +00:00
|
|
|
{
|
2016-12-01 22:14:41 +00:00
|
|
|
int num = gstate.projmtxnum & 0x1F; // NOTE: Changed from 0xF to catch overflows
|
2013-09-14 21:28:37 +00:00
|
|
|
gstate.projMatrix[num] = getFloat24(data);
|
2016-12-01 22:14:41 +00:00
|
|
|
if (num <= 16)
|
|
|
|
gstate.projmtxnum = (++num) & 0x1F;
|
2013-09-14 21:28:37 +00:00
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TGENMATRIXNUMBER:
|
|
|
|
gstate.texmtxnum = data&0xF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_TGENMATRIXDATA:
|
2013-09-14 21:07:53 +00:00
|
|
|
{
|
|
|
|
int num = gstate.texmtxnum & 0xF;
|
|
|
|
if (num < 12) {
|
|
|
|
gstate.tgenMatrix[num] = getFloat24(data);
|
|
|
|
}
|
|
|
|
gstate.texmtxnum = (++num) & 0xF;
|
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BONEMATRIXNUMBER:
|
2013-09-14 21:07:53 +00:00
|
|
|
gstate.boneMatrixNumber = data & 0x7F;
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_BONEMATRIXDATA:
|
2013-09-14 21:07:53 +00:00
|
|
|
{
|
|
|
|
int num = gstate.boneMatrixNumber & 0x7F;
|
|
|
|
if (num < 96) {
|
|
|
|
gstate.boneMatrix[num] = getFloat24(data);
|
|
|
|
}
|
|
|
|
gstate.boneMatrixNumber = (++num) & 0x7F;
|
|
|
|
}
|
2013-06-24 14:03:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GPUCommon::ExecuteOp(op, diff);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 08:17:02 +00:00
|
|
|
void SoftGPU::GetStats(char *buffer, size_t bufsize) {
|
|
|
|
snprintf(buffer, bufsize, "SoftGPU: (N/A)");
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoftGPU::InvalidateCache(u32 addr, int size, GPUInvalidationType type)
|
|
|
|
{
|
|
|
|
// Nothing to invalidate.
|
|
|
|
}
|
|
|
|
|
2016-01-17 20:43:13 +00:00
|
|
|
void SoftGPU::NotifyVideoUpload(u32 addr, int size, int width, int format)
|
|
|
|
{
|
|
|
|
// Ignore.
|
|
|
|
}
|
|
|
|
|
2014-05-27 08:14:29 +00:00
|
|
|
bool SoftGPU::PerformMemoryCopy(u32 dest, u32 src, int size)
|
|
|
|
{
|
|
|
|
// Nothing to update.
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
2017-06-03 07:09:58 +00:00
|
|
|
GPURecord::NotifyMemcpy(dest, src, size);
|
2014-05-27 08:14:29 +00:00
|
|
|
// Let's just be safe.
|
|
|
|
framebufferDirty_ = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoftGPU::PerformMemorySet(u32 dest, u8 v, int size)
|
2013-06-24 14:03:25 +00:00
|
|
|
{
|
|
|
|
// Nothing to update.
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
2017-06-03 07:09:58 +00:00
|
|
|
GPURecord::NotifyMemset(dest, v, size);
|
2013-12-15 22:01:46 +00:00
|
|
|
// Let's just be safe.
|
|
|
|
framebufferDirty_ = true;
|
2014-05-26 03:05:28 +00:00
|
|
|
return false;
|
2013-12-15 22:01:46 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 06:33:50 +00:00
|
|
|
bool SoftGPU::PerformMemoryDownload(u32 dest, int size)
|
|
|
|
{
|
|
|
|
// Nothing to update.
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
|
|
|
return false;
|
2014-06-10 07:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SoftGPU::PerformMemoryUpload(u32 dest, int size)
|
|
|
|
{
|
|
|
|
// Nothing to update.
|
|
|
|
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
|
2017-06-03 07:09:58 +00:00
|
|
|
GPURecord::NotifyUpload(dest, size);
|
2014-06-10 07:45:03 +00:00
|
|
|
return false;
|
2014-05-31 06:33:50 +00:00
|
|
|
}
|
|
|
|
|
2014-06-01 01:24:35 +00:00
|
|
|
bool SoftGPU::PerformStencilUpload(u32 dest, int size)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-15 22:01:46 +00:00
|
|
|
bool SoftGPU::FramebufferDirty() {
|
|
|
|
if (g_Config.iFrameSkip != 0) {
|
|
|
|
bool dirty = framebufferDirty_;
|
|
|
|
framebufferDirty_ = false;
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
return true;
|
2013-06-24 14:03:25 +00:00
|
|
|
}
|
2013-09-23 02:03:31 +00:00
|
|
|
|
2017-02-14 11:42:35 +00:00
|
|
|
bool SoftGPU::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) {
|
2016-09-25 23:31:38 +00:00
|
|
|
int x1 = gstate.getRegionX1();
|
|
|
|
int y1 = gstate.getRegionY1();
|
|
|
|
int x2 = gstate.getRegionX2() + 1;
|
|
|
|
int y2 = gstate.getRegionY2() + 1;
|
|
|
|
int stride = gstate.FrameBufStride();
|
|
|
|
GEBufferFormat fmt = gstate.FrameBufFormat();
|
|
|
|
|
|
|
|
if (type == GPU_DBG_FRAMEBUF_DISPLAY) {
|
|
|
|
x1 = 0;
|
|
|
|
y1 = 0;
|
|
|
|
x2 = 480;
|
|
|
|
y2 = 272;
|
|
|
|
stride = displayStride_;
|
|
|
|
fmt = displayFormat_;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.Allocate(x2 - x1, y2 - y1, fmt);
|
2013-12-29 21:02:04 +00:00
|
|
|
|
2016-09-25 23:31:38 +00:00
|
|
|
const int depth = fmt == GE_FORMAT_8888 ? 4 : 2;
|
|
|
|
const u8 *src = fb.data + stride * depth * y1;
|
2013-12-29 21:02:04 +00:00
|
|
|
u8 *dst = buffer.GetData();
|
2016-09-25 23:31:38 +00:00
|
|
|
const int byteWidth = (x2 - x1) * depth;
|
|
|
|
for (int y = y1; y < y2; ++y) {
|
|
|
|
memcpy(dst, src + x1, byteWidth);
|
|
|
|
dst += byteWidth;
|
|
|
|
src += stride * depth;
|
2013-12-29 21:02:04 +00:00
|
|
|
}
|
2013-09-23 02:03:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-28 09:38:05 +00:00
|
|
|
|
2017-06-02 03:40:45 +00:00
|
|
|
bool SoftGPU::GetOutputFramebuffer(GPUDebugBuffer &buffer) {
|
|
|
|
return GetCurrentFramebuffer(buffer, GPU_DBG_FRAMEBUF_DISPLAY, 1);
|
|
|
|
}
|
|
|
|
|
2013-09-28 09:38:05 +00:00
|
|
|
bool SoftGPU::GetCurrentDepthbuffer(GPUDebugBuffer &buffer)
|
|
|
|
{
|
2013-12-29 21:43:13 +00:00
|
|
|
const int w = gstate.getRegionX2() - gstate.getRegionX1() + 1;
|
|
|
|
const int h = gstate.getRegionY2() - gstate.getRegionY1() + 1;
|
2013-12-29 21:02:04 +00:00
|
|
|
buffer.Allocate(w, h, GPU_DBG_FORMAT_16BIT);
|
|
|
|
|
2013-12-29 21:43:13 +00:00
|
|
|
const int depth = 2;
|
|
|
|
const u8 *src = depthbuf.data + gstate.DepthBufStride() * depth * gstate.getRegionY1();
|
2013-12-29 21:02:04 +00:00
|
|
|
u8 *dst = buffer.GetData();
|
|
|
|
for (int y = gstate.getRegionY1(); y <= gstate.getRegionY2(); ++y) {
|
2013-12-29 21:43:13 +00:00
|
|
|
memcpy(dst, src + gstate.getRegionX1(), (gstate.getRegionX2() + 1) * depth);
|
|
|
|
dst += w * depth;
|
|
|
|
src += gstate.DepthBufStride() * depth;
|
2013-12-29 21:02:04 +00:00
|
|
|
}
|
2013-09-28 09:38:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoftGPU::GetCurrentStencilbuffer(GPUDebugBuffer &buffer)
|
|
|
|
{
|
2013-10-07 08:02:58 +00:00
|
|
|
return Rasterizer::GetCurrentStencilbuffer(buffer);
|
2013-09-28 09:38:05 +00:00
|
|
|
}
|
2013-10-05 18:37:14 +00:00
|
|
|
|
2014-06-15 16:30:37 +00:00
|
|
|
bool SoftGPU::GetCurrentTexture(GPUDebugBuffer &buffer, int level)
|
2013-10-05 18:37:14 +00:00
|
|
|
{
|
2014-06-15 16:30:37 +00:00
|
|
|
return Rasterizer::GetCurrentTexture(buffer, level);
|
2013-10-05 18:37:14 +00:00
|
|
|
}
|
2013-12-29 21:32:55 +00:00
|
|
|
|
2016-01-10 17:25:19 +00:00
|
|
|
bool SoftGPU::GetCurrentClut(GPUDebugBuffer &buffer)
|
|
|
|
{
|
|
|
|
const u32 bpp = gstate.getClutPaletteFormat() == GE_CMODE_32BIT_ABGR8888 ? 4 : 2;
|
|
|
|
const u32 pixels = 1024 / bpp;
|
|
|
|
|
|
|
|
buffer.Allocate(pixels, 1, (GEBufferFormat)gstate.getClutPaletteFormat());
|
|
|
|
memcpy(buffer.GetData(), clut, 1024);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-29 21:32:55 +00:00
|
|
|
bool SoftGPU::GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices)
|
|
|
|
{
|
2017-05-24 08:20:10 +00:00
|
|
|
return drawEngine_->transformUnit.GetCurrentSimpleVertices(count, vertices, indices);
|
2013-12-29 21:32:55 +00:00
|
|
|
}
|
2017-05-11 03:36:09 +00:00
|
|
|
|
|
|
|
bool SoftGPU::DescribeCodePtr(const u8 *ptr, std::string &name) {
|
|
|
|
std::string subname;
|
|
|
|
if (Sampler::DescribeCodePtr(ptr, subname)) {
|
|
|
|
name = "SamplerJit:" + subname;
|
|
|
|
return true;
|
|
|
|
}
|
2021-11-21 15:20:19 +00:00
|
|
|
if (Rasterizer::DescribeCodePtr(ptr, subname)) {
|
|
|
|
name = "RasterizerJit:" + subname;
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-11 03:36:09 +00:00
|
|
|
return false;
|
|
|
|
}
|