2017-02-19 21:02:30 +00:00
|
|
|
|
2015-10-10 14:41:19 +00:00
|
|
|
// Copyright (c) 2015- 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/.
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "profiler/profiler.h"
|
|
|
|
|
|
|
|
#include "Common/ChunkFile.h"
|
|
|
|
#include "Common/GraphicsContext.h"
|
|
|
|
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
|
|
|
#include "Core/MemMapHelpers.h"
|
|
|
|
#include "Core/Host.h"
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/Reporting.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
|
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/ge_constants.h"
|
|
|
|
#include "GPU/GeDisasm.h"
|
|
|
|
#include "GPU/Common/FramebufferCommon.h"
|
|
|
|
|
|
|
|
#include "GPU/Vulkan/ShaderManagerVulkan.h"
|
2015-10-10 14:41:19 +00:00
|
|
|
#include "GPU/Vulkan/GPU_Vulkan.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
#include "GPU/Vulkan/FramebufferVulkan.h"
|
|
|
|
#include "GPU/Vulkan/DrawEngineVulkan.h"
|
|
|
|
#include "GPU/Vulkan/TextureCacheVulkan.h"
|
|
|
|
|
|
|
|
#include "Core/MIPS/MIPS.h"
|
|
|
|
#include "Core/HLE/sceKernelThread.h"
|
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
|
|
|
#include "Core/HLE/sceGe.h"
|
|
|
|
|
2017-03-14 12:21:24 +00:00
|
|
|
struct VulkanCommandTableEntry {
|
2017-01-23 22:15:54 +00:00
|
|
|
uint8_t cmd;
|
|
|
|
uint8_t flags;
|
2017-01-24 11:53:42 +00:00
|
|
|
uint64_t dirty;
|
2016-01-05 20:18:43 +00:00
|
|
|
GPU_Vulkan::CmdFunc func;
|
|
|
|
};
|
|
|
|
|
|
|
|
GPU_Vulkan::CommandInfo GPU_Vulkan::cmdInfo_[256];
|
|
|
|
|
|
|
|
// This table gets crunched into a faster form by init.
|
2017-03-14 12:21:24 +00:00
|
|
|
static const VulkanCommandTableEntry commandTable[] = {
|
2017-01-24 12:13:09 +00:00
|
|
|
// Changes that dirty the current texture.
|
2016-01-05 20:18:43 +00:00
|
|
|
{ GE_CMD_TEXSIZE0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, 0, &GPU_Vulkan::Execute_TexSize0 },
|
|
|
|
|
2017-01-30 11:02:14 +00:00
|
|
|
{ GE_CMD_STENCILTEST, FLAG_FLUSHBEFOREONCHANGE, DIRTY_STENCILREPLACEVALUE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE },
|
2016-01-05 20:18:43 +00:00
|
|
|
|
2017-01-23 21:06:30 +00:00
|
|
|
// Changing the vertex type requires us to flush.
|
2016-01-24 16:30:26 +00:00
|
|
|
{ GE_CMD_VERTEXTYPE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPU_Vulkan::Execute_VertexType },
|
2016-01-05 20:18:43 +00:00
|
|
|
|
2017-03-14 12:32:56 +00:00
|
|
|
{ GE_CMD_PRIM, FLAG_EXECUTE, 0, &GPU_Vulkan::Execute_Prim },
|
2016-01-05 20:18:43 +00:00
|
|
|
{ GE_CMD_BEZIER, FLAG_FLUSHBEFORE | FLAG_EXECUTE, 0, &GPU_Vulkan::Execute_Bezier },
|
|
|
|
{ GE_CMD_SPLINE, FLAG_FLUSHBEFORE | FLAG_EXECUTE, 0, &GPU_Vulkan::Execute_Spline },
|
|
|
|
|
|
|
|
// Changes that trigger data copies. Only flushing on change for LOADCLUT must be a bit of a hack...
|
|
|
|
{ GE_CMD_LOADCLUT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, 0, &GPU_Vulkan::Execute_LoadClut },
|
|
|
|
};
|
|
|
|
|
2017-01-30 15:50:35 +00:00
|
|
|
GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
|
|
|
|
: GPUCommon(gfxCtx, draw),
|
|
|
|
vulkan_((VulkanContext *)gfxCtx->GetAPIContext()),
|
2017-10-30 11:05:08 +00:00
|
|
|
drawEngine_(vulkan_, draw),
|
|
|
|
depalShaderCache_(draw, vulkan_),
|
|
|
|
vulkan2D_(vulkan_) {
|
2016-01-05 20:18:43 +00:00
|
|
|
UpdateVsyncInterval(true);
|
|
|
|
CheckGPUFeatures();
|
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_ = new ShaderManagerVulkan(vulkan_);
|
2016-01-09 00:23:32 +00:00
|
|
|
pipelineManager_ = new PipelineManagerVulkan(vulkan_);
|
2017-02-05 18:51:50 +00:00
|
|
|
framebufferManagerVulkan_ = new FramebufferManagerVulkan(draw, vulkan_);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManager_ = framebufferManagerVulkan_;
|
2017-02-05 18:51:50 +00:00
|
|
|
textureCacheVulkan_ = new TextureCacheVulkan(draw, vulkan_);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCache_ = textureCacheVulkan_;
|
2017-01-21 19:42:40 +00:00
|
|
|
drawEngineCommon_ = &drawEngine_;
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManager_ = shaderManagerVulkan_;
|
2016-12-21 17:07:17 +00:00
|
|
|
|
|
|
|
drawEngine_.SetTextureCache(textureCacheVulkan_);
|
|
|
|
drawEngine_.SetFramebufferManager(framebufferManagerVulkan_);
|
2017-01-23 19:48:23 +00:00
|
|
|
drawEngine_.SetShaderManager(shaderManagerVulkan_);
|
2016-01-09 00:23:32 +00:00
|
|
|
drawEngine_.SetPipelineManager(pipelineManager_);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerVulkan_->Init();
|
|
|
|
framebufferManagerVulkan_->SetTextureCache(textureCacheVulkan_);
|
|
|
|
framebufferManagerVulkan_->SetDrawEngine(&drawEngine_);
|
2017-02-19 21:02:30 +00:00
|
|
|
framebufferManagerVulkan_->SetShaderManager(shaderManagerVulkan_);
|
2017-10-30 11:05:08 +00:00
|
|
|
framebufferManagerVulkan_->SetVulkan2D(&vulkan2D_);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->SetDepalShaderCache(&depalShaderCache_);
|
2017-10-30 11:05:08 +00:00
|
|
|
textureCacheVulkan_->SetFramebufferManager(framebufferManagerVulkan_);
|
2017-01-23 19:48:23 +00:00
|
|
|
textureCacheVulkan_->SetShaderManager(shaderManagerVulkan_);
|
2017-02-04 10:47:19 +00:00
|
|
|
textureCacheVulkan_->SetDrawEngine(&drawEngine_);
|
2017-10-30 11:05:08 +00:00
|
|
|
textureCacheVulkan_->SetVulkan2D(&vulkan2D_);
|
|
|
|
|
|
|
|
InitDeviceObjects();
|
2016-01-05 20:18:43 +00:00
|
|
|
|
|
|
|
// Sanity check gstate
|
|
|
|
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
|
|
|
|
ERROR_LOG(G3D, "gstate has drifted out of sync!");
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(cmdInfo_, 0, sizeof(cmdInfo_));
|
2017-03-14 12:21:24 +00:00
|
|
|
|
|
|
|
// Import both the global and local command tables, and check for dupes
|
|
|
|
std::set<u8> dupeCheck;
|
|
|
|
for (size_t i = 0; i < commonCommandTableSize; i++) {
|
|
|
|
const u8 cmd = commonCommandTable[i].cmd;
|
|
|
|
if (dupeCheck.find(cmd) != dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command table Dupe: %02x (%i)", (int)cmd, (int)cmd);
|
|
|
|
} else {
|
|
|
|
dupeCheck.insert(cmd);
|
|
|
|
}
|
|
|
|
cmdInfo_[cmd].flags |= (uint64_t)commonCommandTable[i].flags | (commonCommandTable[i].dirty << 8);
|
|
|
|
cmdInfo_[cmd].func = commonCommandTable[i].func;
|
|
|
|
if ((cmdInfo_[cmd].flags & (FLAG_EXECUTE | FLAG_EXECUTEONCHANGE)) && !cmdInfo_[cmd].func) {
|
|
|
|
Crash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(commandTable); i++) {
|
|
|
|
const u8 cmd = commandTable[i].cmd;
|
|
|
|
if (dupeCheck.find(cmd) != dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command table Dupe: %02x (%i)", (int)cmd, (int)cmd);
|
|
|
|
} else {
|
|
|
|
dupeCheck.insert(cmd);
|
|
|
|
}
|
2017-01-24 11:53:42 +00:00
|
|
|
cmdInfo_[cmd].flags |= (uint64_t)commandTable[i].flags | (commandTable[i].dirty << 8);
|
2016-01-05 20:18:43 +00:00
|
|
|
cmdInfo_[cmd].func = commandTable[i].func;
|
2017-01-24 09:56:30 +00:00
|
|
|
if ((cmdInfo_[cmd].flags & (FLAG_EXECUTE | FLAG_EXECUTEONCHANGE)) && !cmdInfo_[cmd].func) {
|
|
|
|
Crash();
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Find commands missing from the table.
|
|
|
|
for (int i = 0; i < 0xEF; i++) {
|
|
|
|
if (dupeCheck.find((u8)i) == dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command missing from table: %02x (%i)", i, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateCmdInfo();
|
|
|
|
|
|
|
|
BuildReportingInfo();
|
|
|
|
// Update again after init to be sure of any silly driver problems.
|
|
|
|
UpdateVsyncInterval(true);
|
2016-03-26 18:44:22 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->NotifyConfigChanged();
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GPU_Vulkan::~GPU_Vulkan() {
|
2017-10-30 11:05:08 +00:00
|
|
|
DestroyDeviceObjects();
|
2017-04-14 06:07:21 +00:00
|
|
|
framebufferManagerVulkan_->DestroyAllFBOs();
|
2017-10-30 11:05:08 +00:00
|
|
|
vulkan2D_.Shutdown();
|
2016-01-05 20:18:43 +00:00
|
|
|
depalShaderCache_.Clear();
|
2017-05-07 08:53:04 +00:00
|
|
|
delete textureCacheVulkan_;
|
2016-03-13 23:53:57 +00:00
|
|
|
delete pipelineManager_;
|
2017-01-23 19:48:23 +00:00
|
|
|
delete shaderManagerVulkan_;
|
2017-05-07 09:08:09 +00:00
|
|
|
delete framebufferManagerVulkan_;
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::CheckGPUFeatures() {
|
2017-02-22 15:23:04 +00:00
|
|
|
uint32_t features = 0;
|
2016-01-05 20:18:43 +00:00
|
|
|
if (vulkan_->GetFeaturesEnabled().wideLines) {
|
2017-02-22 15:23:04 +00:00
|
|
|
features |= GPU_SUPPORTS_WIDE_LINES;
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
if (vulkan_->GetFeaturesEnabled().dualSrcBlend) {
|
2017-11-09 12:16:06 +00:00
|
|
|
// Work around for Intel driver bug. See issue #10074.
|
|
|
|
if (vulkan_->GetPhysicalDeviceProperties().vendorID != VULKAN_VENDOR_INTEL)
|
|
|
|
features |= GPU_SUPPORTS_DUALSOURCE_BLEND;
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
if (vulkan_->GetFeaturesEnabled().logicOp) {
|
2017-02-22 15:23:04 +00:00
|
|
|
features |= GPU_SUPPORTS_LOGIC_OP;
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
2016-03-18 04:59:16 +00:00
|
|
|
if (vulkan_->GetFeaturesEnabled().samplerAnisotropy) {
|
2017-02-22 15:23:04 +00:00
|
|
|
features |= GPU_SUPPORTS_ANISOTROPY;
|
2016-03-18 04:59:16 +00:00
|
|
|
}
|
2017-01-28 09:04:50 +00:00
|
|
|
|
|
|
|
if (PSP_CoreParameter().compat.flags().ClearToRAM) {
|
2017-02-22 15:23:04 +00:00
|
|
|
features |= GPU_USE_CLEAR_RAM_HACK;
|
2017-01-28 09:04:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-09 20:19:18 +00:00
|
|
|
// Mandatory features on Vulkan, which may be checked in "centralized" code
|
2017-02-22 15:23:04 +00:00
|
|
|
features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL;
|
|
|
|
features |= GPU_SUPPORTS_FBO;
|
|
|
|
features |= GPU_SUPPORTS_BLEND_MINMAX;
|
|
|
|
features |= GPU_SUPPORTS_ANY_COPY_IMAGE;
|
|
|
|
features |= GPU_SUPPORTS_OES_TEXTURE_NPOT;
|
|
|
|
features |= GPU_SUPPORTS_LARGE_VIEWPORTS;
|
|
|
|
features |= GPU_SUPPORTS_16BIT_FORMATS;
|
|
|
|
gstate_c.featureFlags = features;
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 00:05:52 +00:00
|
|
|
void GPU_Vulkan::BeginHostFrame() {
|
|
|
|
drawEngine_.BeginFrame();
|
2017-06-02 09:47:14 +00:00
|
|
|
UpdateCmdInfo();
|
2016-01-08 00:05:52 +00:00
|
|
|
|
|
|
|
if (resized_) {
|
|
|
|
CheckGPUFeatures();
|
2016-10-08 21:52:53 +00:00
|
|
|
// In case the GPU changed.
|
|
|
|
BuildReportingInfo();
|
2017-04-24 18:58:16 +00:00
|
|
|
framebufferManager_->Resized();
|
2016-01-08 00:05:52 +00:00
|
|
|
drawEngine_.Resized();
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->NotifyConfigChanged();
|
2016-01-08 00:05:52 +00:00
|
|
|
}
|
|
|
|
resized_ = false;
|
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->StartFrame();
|
2017-10-30 11:05:08 +00:00
|
|
|
|
2017-10-31 22:49:47 +00:00
|
|
|
int curFrame = vulkan_->GetCurFrame();
|
|
|
|
FrameData &frame = frameData_[curFrame];
|
2017-10-30 11:05:08 +00:00
|
|
|
|
|
|
|
frame.push_->Reset();
|
|
|
|
frame.push_->Begin(vulkan_);
|
2016-01-08 00:05:52 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerVulkan_->BeginFrameVulkan();
|
2017-10-31 22:49:47 +00:00
|
|
|
framebufferManagerVulkan_->SetPushBuffer(frameData_[curFrame].push_);
|
|
|
|
depalShaderCache_.SetPushBuffer(frameData_[curFrame].push_);
|
|
|
|
textureCacheVulkan_->SetPushBuffer(frameData_[curFrame].push_);
|
2017-10-30 11:05:08 +00:00
|
|
|
|
|
|
|
vulkan2D_.BeginFrame();
|
2016-03-21 23:12:41 +00:00
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_->DirtyShader();
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_ALL);
|
2016-03-21 23:12:41 +00:00
|
|
|
|
2016-01-08 00:05:52 +00:00
|
|
|
if (dumpNextFrame_) {
|
|
|
|
NOTICE_LOG(G3D, "DUMPING THIS FRAME");
|
|
|
|
dumpThisFrame_ = true;
|
|
|
|
dumpNextFrame_ = false;
|
|
|
|
} else if (dumpThisFrame_) {
|
|
|
|
dumpThisFrame_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::EndHostFrame() {
|
2017-10-31 22:49:47 +00:00
|
|
|
int curFrame = vulkan_->GetCurFrame();
|
|
|
|
FrameData &frame = frameData_[curFrame];
|
2017-10-30 11:05:08 +00:00
|
|
|
frame.push_->End();
|
|
|
|
|
|
|
|
vulkan2D_.EndFrame();
|
|
|
|
|
2016-01-08 00:05:52 +00:00
|
|
|
drawEngine_.EndFrame();
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerVulkan_->EndFrame();
|
|
|
|
textureCacheVulkan_->EndFrame();
|
2016-01-08 00:05:52 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
// Needs to be called on GPU thread, not reporting thread.
|
|
|
|
void GPU_Vulkan::BuildReportingInfo() {
|
2016-03-27 15:52:55 +00:00
|
|
|
const auto &props = vulkan_->GetPhysicalDeviceProperties();
|
|
|
|
const auto &features = vulkan_->GetFeaturesAvailable();
|
|
|
|
|
2016-03-27 16:25:25 +00:00
|
|
|
#define CHECK_BOOL_FEATURE(n) do { if (features.n) { featureNames += ", " #n; } } while (false)
|
2016-03-27 15:52:55 +00:00
|
|
|
|
|
|
|
std::string featureNames = "";
|
|
|
|
CHECK_BOOL_FEATURE(robustBufferAccess);
|
|
|
|
CHECK_BOOL_FEATURE(fullDrawIndexUint32);
|
|
|
|
CHECK_BOOL_FEATURE(imageCubeArray);
|
|
|
|
CHECK_BOOL_FEATURE(independentBlend);
|
|
|
|
CHECK_BOOL_FEATURE(geometryShader);
|
|
|
|
CHECK_BOOL_FEATURE(tessellationShader);
|
|
|
|
CHECK_BOOL_FEATURE(sampleRateShading);
|
|
|
|
CHECK_BOOL_FEATURE(dualSrcBlend);
|
|
|
|
CHECK_BOOL_FEATURE(logicOp);
|
|
|
|
CHECK_BOOL_FEATURE(multiDrawIndirect);
|
|
|
|
CHECK_BOOL_FEATURE(drawIndirectFirstInstance);
|
|
|
|
CHECK_BOOL_FEATURE(depthClamp);
|
|
|
|
CHECK_BOOL_FEATURE(depthBiasClamp);
|
|
|
|
CHECK_BOOL_FEATURE(fillModeNonSolid);
|
|
|
|
CHECK_BOOL_FEATURE(depthBounds);
|
|
|
|
CHECK_BOOL_FEATURE(wideLines);
|
|
|
|
CHECK_BOOL_FEATURE(largePoints);
|
|
|
|
CHECK_BOOL_FEATURE(alphaToOne);
|
|
|
|
CHECK_BOOL_FEATURE(multiViewport);
|
|
|
|
CHECK_BOOL_FEATURE(samplerAnisotropy);
|
|
|
|
CHECK_BOOL_FEATURE(textureCompressionETC2);
|
|
|
|
CHECK_BOOL_FEATURE(textureCompressionASTC_LDR);
|
|
|
|
CHECK_BOOL_FEATURE(textureCompressionBC);
|
|
|
|
CHECK_BOOL_FEATURE(occlusionQueryPrecise);
|
|
|
|
CHECK_BOOL_FEATURE(pipelineStatisticsQuery);
|
|
|
|
CHECK_BOOL_FEATURE(vertexPipelineStoresAndAtomics);
|
|
|
|
CHECK_BOOL_FEATURE(fragmentStoresAndAtomics);
|
|
|
|
CHECK_BOOL_FEATURE(shaderTessellationAndGeometryPointSize);
|
|
|
|
CHECK_BOOL_FEATURE(shaderImageGatherExtended);
|
|
|
|
CHECK_BOOL_FEATURE(shaderStorageImageExtendedFormats);
|
|
|
|
CHECK_BOOL_FEATURE(shaderStorageImageMultisample);
|
|
|
|
CHECK_BOOL_FEATURE(shaderStorageImageReadWithoutFormat);
|
|
|
|
CHECK_BOOL_FEATURE(shaderStorageImageWriteWithoutFormat);
|
|
|
|
CHECK_BOOL_FEATURE(shaderUniformBufferArrayDynamicIndexing);
|
|
|
|
CHECK_BOOL_FEATURE(shaderSampledImageArrayDynamicIndexing);
|
|
|
|
CHECK_BOOL_FEATURE(shaderStorageBufferArrayDynamicIndexing);
|
|
|
|
CHECK_BOOL_FEATURE(shaderStorageImageArrayDynamicIndexing);
|
|
|
|
CHECK_BOOL_FEATURE(shaderClipDistance);
|
|
|
|
CHECK_BOOL_FEATURE(shaderCullDistance);
|
|
|
|
CHECK_BOOL_FEATURE(shaderFloat64);
|
|
|
|
CHECK_BOOL_FEATURE(shaderInt64);
|
|
|
|
CHECK_BOOL_FEATURE(shaderInt16);
|
|
|
|
CHECK_BOOL_FEATURE(shaderResourceResidency);
|
|
|
|
CHECK_BOOL_FEATURE(shaderResourceMinLod);
|
|
|
|
CHECK_BOOL_FEATURE(sparseBinding);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidencyBuffer);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidencyImage2D);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidencyImage3D);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidency2Samples);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidency4Samples);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidency8Samples);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidency16Samples);
|
|
|
|
CHECK_BOOL_FEATURE(sparseResidencyAliased);
|
|
|
|
CHECK_BOOL_FEATURE(variableMultisampleRate);
|
|
|
|
CHECK_BOOL_FEATURE(inheritedQueries);
|
|
|
|
|
2016-03-27 16:26:34 +00:00
|
|
|
#undef CHECK_BOOL_FEATURE
|
|
|
|
|
2016-03-27 15:52:55 +00:00
|
|
|
if (!featureNames.empty()) {
|
|
|
|
featureNames = featureNames.substr(2);
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
char temp[16384];
|
2016-03-27 15:52:55 +00:00
|
|
|
snprintf(temp, sizeof(temp), "v%08x driver v%08x (%s), vendorID=%d, deviceID=%d (features: %s)", props.apiVersion, props.driverVersion, props.deviceName, props.vendorID, props.deviceID, featureNames.c_str());
|
|
|
|
reportingPrimaryInfo_ = props.deviceName;
|
2016-01-05 20:18:43 +00:00
|
|
|
reportingFullInfo_ = temp;
|
|
|
|
|
|
|
|
Reporting::UpdateConfig();
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_Vulkan::Reinitialize() {
|
|
|
|
GPUCommon::Reinitialize();
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->Clear(true);
|
2016-01-05 20:18:43 +00:00
|
|
|
depalShaderCache_.Clear();
|
2017-04-14 06:07:21 +00:00
|
|
|
framebufferManagerVulkan_->DestroyAllFBOs();
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_Vulkan::InitClear() {
|
2016-01-05 20:18:43 +00:00
|
|
|
bool useNonBufferedRendering = g_Config.iRenderingMode == FB_NON_BUFFERED_MODE;
|
|
|
|
if (useNonBufferedRendering) {
|
2017-11-05 19:33:28 +00:00
|
|
|
// TODO?
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::UpdateVsyncInterval(bool force) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::UpdateCmdInfo() {
|
2016-12-20 12:27:44 +00:00
|
|
|
if (g_Config.bSoftwareSkinning) {
|
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].flags &= ~FLAG_FLUSHBEFOREONCHANGE;
|
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].func = &GPU_Vulkan::Execute_VertexTypeSkinning;
|
2017-06-02 09:47:14 +00:00
|
|
|
} else {
|
2016-12-20 12:27:44 +00:00
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].flags |= FLAG_FLUSHBEFOREONCHANGE;
|
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].func = &GPU_Vulkan::Execute_VertexType;
|
2017-06-02 09:47:14 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) {
|
|
|
|
host->GPUNotifyDisplay(framebuf, stride, format);
|
2016-01-10 13:24:10 +00:00
|
|
|
framebufferManager_->SetDisplayFramebuffer(framebuf, stride, format);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GPU_Vulkan::FramebufferDirty() {
|
2016-01-10 13:24:10 +00:00
|
|
|
VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB();
|
2016-01-05 20:18:43 +00:00
|
|
|
if (vfb) {
|
|
|
|
bool dirty = vfb->dirtyAfterDisplay;
|
|
|
|
vfb->dirtyAfterDisplay = false;
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPU_Vulkan::FramebufferReallyDirty() {
|
2016-01-10 13:24:10 +00:00
|
|
|
VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB();
|
2016-01-05 20:18:43 +00:00
|
|
|
if (vfb) {
|
|
|
|
bool dirty = vfb->reallyDirtyAfterDisplay;
|
|
|
|
vfb->reallyDirtyAfterDisplay = false;
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_Vulkan::CopyDisplayToOutput() {
|
2016-01-05 20:18:43 +00:00
|
|
|
// Flush anything left over.
|
2017-05-19 15:21:08 +00:00
|
|
|
drawEngine_.Flush();
|
2016-01-05 20:18:43 +00:00
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_->DirtyLastShader();
|
2016-01-05 20:18:43 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerVulkan_->CopyDisplayToOutput();
|
2016-01-06 22:08:26 +00:00
|
|
|
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Maybe should write this in ASM...
|
2015-10-10 14:41:19 +00:00
|
|
|
void GPU_Vulkan::FastRunLoop(DisplayList &list) {
|
2016-01-05 20:18:43 +00:00
|
|
|
PROFILE_THIS_SCOPE("gpuloop");
|
|
|
|
const CommandInfo *cmdInfo = cmdInfo_;
|
|
|
|
int dc = downcount;
|
|
|
|
for (; dc > 0; --dc) {
|
|
|
|
// We know that display list PCs have the upper nibble == 0 - no need to mask the pointer
|
|
|
|
const u32 op = *(const u32 *)(Memory::base + list.pc);
|
|
|
|
const u32 cmd = op >> 24;
|
2017-08-17 11:53:13 +00:00
|
|
|
const CommandInfo &info = cmdInfo[cmd];
|
2016-01-05 20:18:43 +00:00
|
|
|
const u32 diff = op ^ gstate.cmdmem[cmd];
|
2017-08-17 11:53:13 +00:00
|
|
|
if (diff == 0) {
|
|
|
|
if (info.flags & FLAG_EXECUTE) {
|
|
|
|
downcount = dc;
|
|
|
|
(this->*info.func)(op, diff);
|
|
|
|
dc = downcount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint64_t flags = info.flags;
|
|
|
|
if (flags & FLAG_FLUSHBEFOREONCHANGE) {
|
|
|
|
drawEngine_.Flush();
|
|
|
|
}
|
2017-08-17 12:26:52 +00:00
|
|
|
gstate.cmdmem[cmd] = op;
|
2017-08-17 11:53:13 +00:00
|
|
|
if (flags & (FLAG_EXECUTE | FLAG_EXECUTEONCHANGE)) {
|
|
|
|
downcount = dc;
|
|
|
|
(this->*info.func)(op, diff);
|
|
|
|
dc = downcount;
|
|
|
|
} else {
|
|
|
|
uint64_t dirty = flags >> 8;
|
|
|
|
if (dirty)
|
|
|
|
gstate_c.Dirty(dirty);
|
|
|
|
}
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
list.pc += 4;
|
|
|
|
}
|
|
|
|
downcount = 0;
|
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::FinishDeferred() {
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
inline void GPU_Vulkan::CheckFlushOp(int cmd, u32 diff) {
|
|
|
|
const u8 cmdFlags = cmdInfo_[cmd].flags;
|
2017-02-13 21:02:26 +00:00
|
|
|
if ((cmdFlags & FLAG_FLUSHBEFORE) || (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE))) {
|
2016-01-05 20:18:43 +00:00
|
|
|
if (dumpThisFrame_) {
|
|
|
|
NOTICE_LOG(G3D, "================ FLUSH ================");
|
|
|
|
}
|
2017-05-19 15:21:08 +00:00
|
|
|
drawEngine_.Flush();
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::PreExecuteOp(u32 op, u32 diff) {
|
|
|
|
CheckFlushOp(op >> 24, diff);
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::ExecuteOp(u32 op, u32 diff) {
|
|
|
|
const u8 cmd = op >> 24;
|
|
|
|
const CommandInfo info = cmdInfo_[cmd];
|
|
|
|
const u8 cmdFlags = info.flags;
|
|
|
|
if ((cmdFlags & FLAG_EXECUTE) || (diff && (cmdFlags & FLAG_EXECUTEONCHANGE))) {
|
|
|
|
(this->*info.func)(op, diff);
|
2017-01-24 11:45:50 +00:00
|
|
|
} else if (diff) {
|
|
|
|
uint64_t dirty = info.flags >> 8;
|
|
|
|
if (dirty)
|
|
|
|
gstate_c.Dirty(dirty);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::Execute_Prim(u32 op, u32 diff) {
|
|
|
|
// This drives all drawing. All other state we just buffer up, then we apply it only
|
|
|
|
// when it's time to draw. As most PSP games set state redundantly ALL THE TIME, this is a huge optimization.
|
|
|
|
|
2017-08-18 11:39:42 +00:00
|
|
|
PROFILE_THIS_SCOPE("execprim");
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
u32 data = op & 0xFFFFFF;
|
|
|
|
u32 count = data & 0xFFFF;
|
|
|
|
if (count == 0)
|
|
|
|
return;
|
|
|
|
|
2017-01-30 13:04:20 +00:00
|
|
|
// Upper bits are ignored.
|
|
|
|
GEPrimitiveType prim = static_cast<GEPrimitiveType>((data >> 16) & 7);
|
2017-04-03 14:45:58 +00:00
|
|
|
SetDrawType(DRAW_PRIM, prim);
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
// Discard AA lines as we can't do anything that makes sense with these anyway. The SW plugin might, though.
|
|
|
|
if (gstate.isAntiAliasEnabled()) {
|
|
|
|
// Discard AA lines in DOA
|
|
|
|
if (prim == GE_PRIM_LINE_STRIP)
|
|
|
|
return;
|
|
|
|
// Discard AA lines in Summon Night 5
|
|
|
|
if ((prim == GE_PRIM_LINES) && gstate.isSkinningEnabled())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This also makes skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManager_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2016-03-21 23:12:41 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
|
2017-08-15 14:01:50 +00:00
|
|
|
drawEngine_.SetupVertexDecoder(gstate.vertType); // Do we still need to do this?
|
2016-01-05 20:18:43 +00:00
|
|
|
// Rough estimate, not sure what's correct.
|
2017-01-23 20:00:44 +00:00
|
|
|
cyclesExecuted += EstimatePerVertexCost() * count;
|
2016-01-05 20:18:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
|
|
|
|
void *inds = 0;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
inds = Memory::GetPointerUnchecked(gstate_c.indexAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MOBILE_DEVICE
|
|
|
|
if (prim > GE_PRIM_RECTANGLES) {
|
|
|
|
ERROR_LOG_REPORT_ONCE(reportPrim, G3D, "Unexpected prim type: %d", prim);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-20 17:03:16 +00:00
|
|
|
if (gstate_c.dirty & DIRTY_VERTEXSHADER_STATE) {
|
|
|
|
vertexCost_ = EstimatePerVertexCost();
|
|
|
|
}
|
|
|
|
gpuStats.vertexGPUCycles += vertexCost_ * count;
|
|
|
|
cyclesExecuted += vertexCost_* count;
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
int bytesRead = 0;
|
2017-08-17 11:53:13 +00:00
|
|
|
UpdateUVScaleOffset();
|
2016-01-05 20:18:43 +00:00
|
|
|
drawEngine_.SubmitPrim(verts, inds, prim, count, gstate.vertType, &bytesRead);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// The VADDR/IADDR registers are NOT updated.
|
2016-04-10 20:07:08 +00:00
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::Execute_VertexType(u32 op, u32 diff) {
|
2017-01-30 13:04:20 +00:00
|
|
|
if (diff)
|
|
|
|
gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE);
|
2016-01-05 20:18:43 +00:00
|
|
|
if (diff & (GE_VTYPE_TC_MASK | GE_VTYPE_THROUGH_MASK)) {
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
2017-01-30 13:04:20 +00:00
|
|
|
if (diff & GE_VTYPE_THROUGH_MASK)
|
2017-08-15 08:38:20 +00:00
|
|
|
gstate_c.Dirty(DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_FRAGMENTSHADER_STATE);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2017-06-02 09:47:14 +00:00
|
|
|
void GPU_Vulkan::Execute_VertexTypeSkinning(u32 op, u32 diff) {
|
|
|
|
// Don't flush when weight count changes, unless morph is enabled.
|
|
|
|
if ((diff & ~GE_VTYPE_WEIGHTCOUNT_MASK) || (op & GE_VTYPE_MORPHCOUNT_MASK) != 0) {
|
|
|
|
// Restore and flush
|
|
|
|
gstate.vertType ^= diff;
|
|
|
|
Flush();
|
|
|
|
gstate.vertType ^= diff;
|
|
|
|
if (diff & (GE_VTYPE_TC_MASK | GE_VTYPE_THROUGH_MASK))
|
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
|
|
|
// In this case, we may be doing weights and morphs.
|
|
|
|
// Update any bone matrix uniforms so it uses them correctly.
|
|
|
|
if ((op & GE_VTYPE_MORPHCOUNT_MASK) != 0) {
|
|
|
|
gstate_c.Dirty(gstate_c.deferredVertTypeDirty);
|
|
|
|
gstate_c.deferredVertTypeDirty = 0;
|
|
|
|
}
|
2017-08-15 12:21:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE);
|
2017-06-02 09:47:14 +00:00
|
|
|
}
|
2017-08-15 08:38:20 +00:00
|
|
|
if (diff & GE_VTYPE_THROUGH_MASK)
|
|
|
|
gstate_c.Dirty(DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_FRAGMENTSHADER_STATE);
|
2017-06-02 09:47:14 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
void GPU_Vulkan::Execute_Bezier(u32 op, u32 diff) {
|
2017-08-17 11:05:13 +00:00
|
|
|
Flush();
|
|
|
|
|
2017-03-11 12:09:01 +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);
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
// This also make skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManager_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2017-01-22 14:44:27 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Bezier + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
|
|
|
|
}
|
|
|
|
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Bezier + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
|
|
|
|
}
|
|
|
|
|
|
|
|
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
|
2017-04-03 14:45:58 +00:00
|
|
|
SetDrawType(DRAW_BEZIER, PatchPrimToPrim(patchPrim));
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
int bz_ucount = op & 0xFF;
|
|
|
|
int bz_vcount = (op >> 8) & 0xFF;
|
|
|
|
bool computeNormals = gstate.isLightingEnabled();
|
|
|
|
bool patchFacing = gstate.patchfacing & 1;
|
2017-02-25 09:32:39 +00:00
|
|
|
|
|
|
|
if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) {
|
2017-03-19 17:31:37 +00:00
|
|
|
gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE);
|
2017-02-25 09:32:39 +00:00
|
|
|
gstate_c.bezier = true;
|
2017-03-02 12:32:01 +00:00
|
|
|
if (gstate_c.spline_count_u != bz_ucount) {
|
2017-03-20 02:51:44 +00:00
|
|
|
gstate_c.Dirty(DIRTY_BEZIERSPLINE);
|
2017-03-02 12:32:01 +00:00
|
|
|
gstate_c.spline_count_u = bz_ucount;
|
2017-02-25 09:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 10:47:05 +00:00
|
|
|
int bytesRead = 0;
|
2017-08-17 11:53:13 +00:00
|
|
|
UpdateUVScaleOffset();
|
2017-01-22 14:44:27 +00:00
|
|
|
drawEngine_.SubmitBezier(control_points, indices, gstate.getPatchDivisionU(), gstate.getPatchDivisionV(), bz_ucount, bz_vcount, patchPrim, computeNormals, patchFacing, gstate.vertType, &bytesRead);
|
|
|
|
|
2017-03-19 17:31:37 +00:00
|
|
|
if (gstate_c.bezier)
|
|
|
|
gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE);
|
2017-02-25 09:32:39 +00:00
|
|
|
gstate_c.bezier = false;
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
// After drawing, we advance pointers - see SubmitPrim which does the same.
|
|
|
|
int count = bz_ucount * bz_vcount;
|
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::Execute_Spline(u32 op, u32 diff) {
|
2017-08-17 11:05:13 +00:00
|
|
|
Flush();
|
|
|
|
|
2017-03-11 12:09:01 +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);
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
// This also make skipping drawing very effective.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManager_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2017-01-22 14:44:27 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Spline + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
|
|
|
|
}
|
|
|
|
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
|
|
|
|
DEBUG_LOG_REPORT(G3D, "Spline + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
|
|
|
|
}
|
|
|
|
|
|
|
|
int sp_ucount = op & 0xFF;
|
|
|
|
int sp_vcount = (op >> 8) & 0xFF;
|
|
|
|
int sp_utype = (op >> 16) & 0x3;
|
|
|
|
int sp_vtype = (op >> 18) & 0x3;
|
|
|
|
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
|
2017-04-03 14:45:58 +00:00
|
|
|
SetDrawType(DRAW_SPLINE, PatchPrimToPrim(patchPrim));
|
2017-01-22 14:44:27 +00:00
|
|
|
bool computeNormals = gstate.isLightingEnabled();
|
|
|
|
bool patchFacing = gstate.patchfacing & 1;
|
|
|
|
u32 vertType = gstate.vertType;
|
2017-02-25 09:32:39 +00:00
|
|
|
|
|
|
|
if (g_Config.bHardwareTessellation && g_Config.bHardwareTransform && !g_Config.bSoftwareRendering) {
|
2017-03-19 17:31:37 +00:00
|
|
|
gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE);
|
2017-02-25 09:32:39 +00:00
|
|
|
gstate_c.spline = true;
|
2017-03-20 02:51:44 +00:00
|
|
|
bool countsChanged = gstate_c.spline_count_u != sp_ucount || gstate_c.spline_count_v != sp_vcount;
|
|
|
|
bool typesChanged = gstate_c.spline_type_u != sp_utype || gstate_c.spline_type_v != sp_vtype;
|
|
|
|
if (countsChanged || typesChanged) {
|
|
|
|
gstate_c.Dirty(DIRTY_BEZIERSPLINE);
|
2017-02-25 09:32:39 +00:00
|
|
|
gstate_c.spline_count_u = sp_ucount;
|
|
|
|
gstate_c.spline_count_v = sp_vcount;
|
|
|
|
gstate_c.spline_type_u = sp_utype;
|
|
|
|
gstate_c.spline_type_v = sp_vtype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
int bytesRead = 0;
|
2017-08-17 11:53:13 +00:00
|
|
|
UpdateUVScaleOffset();
|
2017-01-22 14:44:27 +00:00
|
|
|
drawEngine_.SubmitSpline(control_points, indices, gstate.getPatchDivisionU(), gstate.getPatchDivisionV(), sp_ucount, sp_vcount, sp_utype, sp_vtype, patchPrim, computeNormals, patchFacing, vertType, &bytesRead);
|
|
|
|
|
2017-03-19 17:31:37 +00:00
|
|
|
if (gstate_c.spline)
|
|
|
|
gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE);
|
2017-02-25 09:32:39 +00:00
|
|
|
gstate_c.spline = false;
|
|
|
|
|
2017-01-22 14:44:27 +00:00
|
|
|
// After drawing, we advance pointers - see SubmitPrim which does the same.
|
|
|
|
int count = sp_ucount * sp_vcount;
|
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::Execute_TexSize0(u32 op, u32 diff) {
|
|
|
|
// Render to texture may have overridden the width/height.
|
|
|
|
// Don't reset it unless the size is different / the texture has changed.
|
2017-01-24 08:41:38 +00:00
|
|
|
if (diff || gstate_c.IsDirty(DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS)) {
|
2016-01-05 20:18:43 +00:00
|
|
|
gstate_c.curTextureWidth = gstate.getTextureWidth(0);
|
|
|
|
gstate_c.curTextureHeight = gstate.getTextureHeight(0);
|
|
|
|
// We will need to reset the texture now.
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_UVSCALEOFFSET | DIRTY_TEXTURE_PARAMS);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::Execute_LoadClut(u32 op, u32 diff) {
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->LoadClut(gstate.getClutAddress(), gstate.getClutLoadBytes());
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 21:06:30 +00:00
|
|
|
void GPU_Vulkan::Execute_BoneMtxNum(u32 op, u32 diff) {
|
|
|
|
// This is almost always followed by GE_CMD_BONEMATRIXDATA.
|
|
|
|
const u32_le *src = (const u32_le *)Memory::GetPointerUnchecked(currentList->pc + 4);
|
|
|
|
u32 *dst = (u32 *)(gstate.boneMatrix + (op & 0x7F));
|
|
|
|
const int end = 12 * 8 - (op & 0x7F);
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// If we can't use software skinning, we have to flush and dirty.
|
|
|
|
while ((src[i] >> 24) == GE_CMD_BONEMATRIXDATA) {
|
|
|
|
const u32 newVal = src[i] << 8;
|
|
|
|
if (dst[i] != newVal) {
|
|
|
|
Flush();
|
|
|
|
dst[i] = newVal;
|
|
|
|
}
|
|
|
|
if (++i >= end) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const int numPlusCount = (op & 0x7F) + i;
|
|
|
|
for (int num = op & 0x7F; num < numPlusCount; num += 12) {
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_BONEMATRIX0 << (num / 12));
|
2017-01-23 21:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const int count = i;
|
|
|
|
gstate.boneMatrixNumber = (GE_CMD_BONEMATRIXNUMBER << 24) | ((op + count) & 0x7F);
|
|
|
|
|
|
|
|
// Skip over the loaded data, it's done now.
|
|
|
|
UpdatePC(currentList->pc, currentList->pc + count * 4);
|
|
|
|
currentList->pc += count * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::Execute_BoneMtxData(u32 op, u32 diff) {
|
|
|
|
// Note: it's uncommon to get here now, see above.
|
|
|
|
int num = gstate.boneMatrixNumber & 0x7F;
|
|
|
|
u32 newVal = op << 8;
|
|
|
|
if (num < 96 && newVal != ((const u32 *)gstate.boneMatrix)[num]) {
|
|
|
|
// Bone matrices should NOT flush when software skinning is enabled!
|
|
|
|
Flush();
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_BONEMATRIX0 << (num / 12));
|
2017-01-23 21:06:30 +00:00
|
|
|
((u32 *)gstate.boneMatrix)[num] = newVal;
|
|
|
|
}
|
|
|
|
num++;
|
|
|
|
gstate.boneMatrixNumber = (GE_CMD_BONEMATRIXNUMBER << 24) | (num & 0x7F);
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::FastLoadBoneMatrix(u32 target) {
|
|
|
|
const int num = gstate.boneMatrixNumber & 0x7F;
|
|
|
|
const int mtxNum = num / 12;
|
|
|
|
uint32_t uniformsToDirty = DIRTY_BONEMATRIX0 << mtxNum;
|
|
|
|
if ((num - 12 * mtxNum) != 0) {
|
|
|
|
uniformsToDirty |= DIRTY_BONEMATRIX0 << ((mtxNum + 1) & 7);
|
|
|
|
}
|
2016-03-20 14:46:41 +00:00
|
|
|
Flush();
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(uniformsToDirty);
|
2016-01-05 20:18:43 +00:00
|
|
|
gstate.FastLoadBoneMatrix(target);
|
|
|
|
}
|
|
|
|
|
2017-10-30 11:05:08 +00:00
|
|
|
void GPU_Vulkan::InitDeviceObjects() {
|
2017-11-09 15:02:05 +00:00
|
|
|
ILOG("GPU_Vulkan::InitDeviceObjects");
|
2017-10-30 11:05:08 +00:00
|
|
|
// Initialize framedata
|
|
|
|
for (int i = 0; i < VulkanContext::MAX_INFLIGHT_FRAMES; i++) {
|
2017-11-09 15:02:05 +00:00
|
|
|
assert(!frameData_[i].push_);
|
2017-10-30 11:05:08 +00:00
|
|
|
frameData_[i].push_ = new VulkanPushBuffer(vulkan_, 64 * 1024);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::DestroyDeviceObjects() {
|
2017-11-09 15:02:05 +00:00
|
|
|
ILOG("GPU_Vulkan::DestroyDeviceObjects");
|
2017-10-30 11:05:08 +00:00
|
|
|
for (int i = 0; i < VulkanContext::MAX_INFLIGHT_FRAMES; i++) {
|
|
|
|
if (frameData_[i].push_) {
|
|
|
|
frameData_[i].push_->Destroy(vulkan_);
|
|
|
|
delete frameData_[i].push_;
|
|
|
|
frameData_[i].push_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::DeviceLost() {
|
2017-10-30 11:05:08 +00:00
|
|
|
DestroyDeviceObjects();
|
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerVulkan_->DeviceLost();
|
2016-10-09 18:27:16 +00:00
|
|
|
drawEngine_.DeviceLost();
|
|
|
|
pipelineManager_->DeviceLost();
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->DeviceLost();
|
2016-10-09 18:27:16 +00:00
|
|
|
depalShaderCache_.Clear();
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_->ClearShaders();
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 03:29:58 +00:00
|
|
|
void GPU_Vulkan::DeviceRestore() {
|
2016-10-09 18:27:16 +00:00
|
|
|
vulkan_ = (VulkanContext *)PSP_CoreParameter().graphicsContext->GetAPIContext();
|
2017-11-09 15:28:22 +00:00
|
|
|
draw_ = (Draw::DrawContext *)PSP_CoreParameter().graphicsContext->GetDrawContext();
|
2017-11-09 15:02:05 +00:00
|
|
|
InitDeviceObjects();
|
|
|
|
|
2016-10-09 18:27:16 +00:00
|
|
|
CheckGPUFeatures();
|
|
|
|
BuildReportingInfo();
|
|
|
|
UpdateCmdInfo();
|
|
|
|
|
2017-11-09 15:28:22 +00:00
|
|
|
framebufferManagerVulkan_->DeviceRestore(vulkan_, draw_);
|
|
|
|
drawEngine_.DeviceRestore(vulkan_, draw_);
|
2016-10-09 18:27:16 +00:00
|
|
|
pipelineManager_->DeviceRestore(vulkan_);
|
2017-11-09 15:28:22 +00:00
|
|
|
textureCacheVulkan_->DeviceRestore(vulkan_, draw_);
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_->DeviceRestore(vulkan_);
|
2017-11-09 15:28:22 +00:00
|
|
|
depalShaderCache_.DeviceRestore(draw_, vulkan_);
|
2016-09-11 03:29:58 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 08:17:02 +00:00
|
|
|
void GPU_Vulkan::GetStats(char *buffer, size_t bufsize) {
|
2016-03-31 08:23:40 +00:00
|
|
|
const DrawEngineVulkanStats &drawStats = drawEngine_.GetStats();
|
2016-03-31 08:17:02 +00:00
|
|
|
float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f;
|
|
|
|
snprintf(buffer, bufsize - 1,
|
|
|
|
"DL processing time: %0.2f ms\n"
|
|
|
|
"Draw calls: %i, flushes %i\n"
|
|
|
|
"Cached Draw calls: %i\n"
|
|
|
|
"Num Tracked Vertex Arrays: %i\n"
|
|
|
|
"GPU cycles executed: %d (%f per vertex)\n"
|
|
|
|
"Commands per call level: %i %i %i %i\n"
|
|
|
|
"Vertices submitted: %i\n"
|
|
|
|
"Cached, Uncached Vertices Drawn: %i, %i\n"
|
|
|
|
"FBOs active: %i\n"
|
|
|
|
"Textures active: %i, decoded: %i invalidated: %i\n"
|
2017-11-08 10:57:53 +00:00
|
|
|
"Readbacks: %d\n"
|
2016-03-31 08:23:40 +00:00
|
|
|
"Vertex, Fragment, Pipelines loaded: %i, %i, %i\n"
|
2016-03-31 08:17:02 +00:00
|
|
|
"Pushbuffer space used: UBO %d, Vtx %d, Idx %d\n",
|
|
|
|
gpuStats.msProcessingDisplayLists * 1000.0f,
|
|
|
|
gpuStats.numDrawCalls,
|
|
|
|
gpuStats.numFlushes,
|
|
|
|
gpuStats.numCachedDrawCalls,
|
|
|
|
gpuStats.numTrackedVertexArrays,
|
|
|
|
gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles,
|
|
|
|
vertexAverageCycles,
|
|
|
|
gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3],
|
|
|
|
gpuStats.numVertsSubmitted,
|
|
|
|
gpuStats.numCachedVertsDrawn,
|
|
|
|
gpuStats.numUncachedVertsDrawn,
|
2016-03-31 08:23:40 +00:00
|
|
|
(int)framebufferManager_->NumVFBs(),
|
2016-12-21 17:07:17 +00:00
|
|
|
(int)textureCacheVulkan_->NumLoadedTextures(),
|
2016-03-31 08:17:02 +00:00
|
|
|
gpuStats.numTexturesDecoded,
|
|
|
|
gpuStats.numTextureInvalidations,
|
2017-11-08 10:57:53 +00:00
|
|
|
gpuStats.numReadbacks,
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_->GetNumVertexShaders(),
|
|
|
|
shaderManagerVulkan_->GetNumFragmentShaders(),
|
2016-03-31 08:23:40 +00:00
|
|
|
pipelineManager_->GetNumPipelines(),
|
|
|
|
drawStats.pushUBOSpaceUsed,
|
|
|
|
drawStats.pushVertexSpaceUsed,
|
|
|
|
drawStats.pushIndexSpaceUsed
|
2016-03-31 08:17:02 +00:00
|
|
|
);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::ClearCacheNextFrame() {
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->ClearNextFrame();
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::ClearShaderCache() {
|
2016-01-10 13:24:10 +00:00
|
|
|
// TODO
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::DoState(PointerWrap &p) {
|
|
|
|
GPUCommon::DoState(p);
|
|
|
|
|
|
|
|
// TODO: Some of these things may not be necessary.
|
|
|
|
// None of these are necessary when saving.
|
|
|
|
// In Freeze-Frame mode, we don't want to do any of this.
|
|
|
|
if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) {
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheVulkan_->Clear(true);
|
2016-01-05 20:18:43 +00:00
|
|
|
depalShaderCache_.Clear();
|
|
|
|
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
|
2017-04-14 06:07:21 +00:00
|
|
|
framebufferManagerVulkan_->DestroyAllFBOs();
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_->ClearShaders();
|
2016-01-10 13:24:10 +00:00
|
|
|
pipelineManager_->Clear();
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> GPU_Vulkan::DebugGetShaderIDs(DebugShaderType type) {
|
|
|
|
if (type == SHADER_TYPE_VERTEXLOADER) {
|
|
|
|
return drawEngine_.DebugGetVertexLoaderIDs();
|
2016-01-09 20:19:18 +00:00
|
|
|
} else if (type == SHADER_TYPE_PIPELINE) {
|
|
|
|
return pipelineManager_->DebugGetObjectIDs(type);
|
2017-04-04 09:09:29 +00:00
|
|
|
} else if (type == SHADER_TYPE_DEPAL) {
|
|
|
|
///...
|
|
|
|
return std::vector<std::string>();
|
2016-01-05 20:18:43 +00:00
|
|
|
} else {
|
2017-01-23 19:48:23 +00:00
|
|
|
return shaderManagerVulkan_->DebugGetShaderIDs(type);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
std::string GPU_Vulkan::DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) {
|
|
|
|
if (type == SHADER_TYPE_VERTEXLOADER) {
|
|
|
|
return drawEngine_.DebugGetVertexLoaderString(id, stringType);
|
2016-01-09 20:19:18 +00:00
|
|
|
} else if (type == SHADER_TYPE_PIPELINE) {
|
|
|
|
return pipelineManager_->DebugGetObjectString(id, type, stringType);
|
2017-04-04 09:09:29 +00:00
|
|
|
} else if (type == SHADER_TYPE_DEPAL) {
|
|
|
|
return "";
|
2016-01-05 20:18:43 +00:00
|
|
|
} else {
|
2017-01-23 19:48:23 +00:00
|
|
|
return shaderManagerVulkan_->DebugGetShaderString(id, type, stringType);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|