Skip to content

Commit

Permalink
Merge pull request #18346 from hrydgard/assorted-cleanups-15
Browse files Browse the repository at this point in the history
Assorted cleanups
  • Loading branch information
hrydgard committed Oct 12, 2023
2 parents f1bc547 + f842f16 commit 6f28c5d
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 54 deletions.
5 changes: 3 additions & 2 deletions Common/GPU/Vulkan/VulkanDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <mutex>

#include "Common/Log.h"
#include "Common/System/System.h"
#include "Common/GPU/Vulkan/VulkanContext.h"
#include "Common/GPU/Vulkan/VulkanDebug.h"

Expand Down Expand Up @@ -139,15 +140,15 @@ VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugUtilsCallback(
#ifdef _WIN32
OutputDebugStringA(msg.c_str());
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
if (options->breakOnError && IsDebuggerPresent()) {
if (options->breakOnError && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT)) {
DebugBreak();
}
if (options->msgBoxOnError) {
MessageBoxA(NULL, pMessage, "Alert", MB_OK);
}
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
// Don't break on perf warnings for now, even with a debugger. We log them at least.
if (options->breakOnWarning && IsDebuggerPresent() && 0 == (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)) {
if (options->breakOnWarning && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT) && 0 == (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)) {
DebugBreak();
}
}
Expand Down
2 changes: 2 additions & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ enum SystemProperty {

SYSPROP_SUPPORTS_HTTPS,

SYSPROP_DEBUGGER_PRESENT,

// Available as Int:
SYSPROP_SYSTEMVERSION,
SYSPROP_DISPLAY_XRES,
Expand Down
3 changes: 2 additions & 1 deletion GPU/D3D11/DrawEngineD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ void DrawEngineD3D11::DoFlush() {

DecodeVerts(decoded_);
DecodeInds();
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();

bool useElements = !indexGen.SeenOnlyPurePrims() || prim == GE_PRIM_TRIANGLE_FAN;
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
int maxIndex = MaxIndex();
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
Expand Down
30 changes: 13 additions & 17 deletions GPU/Directx9/DrawEngineDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,20 @@ void DrawEngineDX9::DoFlush() {
bool useHWTransform = CanUseHardwareTransform(prim) && (tess || gstate.getShadeMode() != GE_SHADE_FLAT);

if (useHWTransform) {
LPDIRECT3DVERTEXBUFFER9 vb_ = NULL;
LPDIRECT3DINDEXBUFFER9 ib_ = NULL;

int vertexCount = 0;
int maxIndex = 0;
bool useElements = true;
{
DecodeVerts(decoded_);
DecodeInds();
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
useElements = !indexGen.SeenOnlyPurePrims();
vertexCount = indexGen.VertexCount();
maxIndex = MaxIndex();
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
}
prim = indexGen.Prim();
LPDIRECT3DVERTEXBUFFER9 vb_ = nullptr;
LPDIRECT3DINDEXBUFFER9 ib_ = nullptr;

DecodeVerts(decoded_);
DecodeInds();

bool useElements = !indexGen.SeenOnlyPurePrims();
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
int maxIndex = MaxIndex();
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
}
prim = indexGen.Prim();

_dbg_assert_((int)prim > 0);

Expand Down
22 changes: 8 additions & 14 deletions GPU/GLES/DrawEngineGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ void DrawEngineGLES::DoFlush() {
uint32_t indexBufferOffset = 0;

if (vshader->UseHWTransform()) {
int vertexCount = 0;
bool useElements = true;

if (decOptions_.applySkinInDecode && (lastVType_ & GE_VTYPE_WEIGHT_MASK)) {
// If software skinning, we're predecoding into "decoded". So make sure we're done, then push that content.
DecodeVerts(decoded_);
Expand All @@ -288,24 +285,16 @@ void DrawEngineGLES::DoFlush() {
}
DecodeInds();

gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();

// If there's only been one primitive type, and it's either TRIANGLES, LINES or POINTS,
// there is no need for the index buffer we built. We can then use glDrawArrays instead
// for a very minor speed boost. TODO: We can probably detect this case earlier, like before
// actually doing any vertex decoding (unless we're doing soft skinning and pre-decode on submit).
useElements = !indexGen.SeenOnlyPurePrims();
vertexCount = indexGen.VertexCount();
bool useElements = !indexGen.SeenOnlyPurePrims();
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
}
if (useElements) {
uint32_t esz = sizeof(uint16_t) * indexGen.VertexCount();
void *dest = frameData.pushIndex->Allocate(esz, 2, &indexBuffer, &indexBufferOffset);
// TODO: When we need to apply an index offset, we can apply it directly when copying the indices here.
// Of course, minding the maximum value of 65535...
memcpy(dest, decIndex_, esz);
}
prim = indexGen.Prim();

bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE;
Expand All @@ -326,6 +315,11 @@ void DrawEngineGLES::DoFlush() {
LinkedShader *program = shaderManager_->ApplyFragmentShader(vsid, vshader, pipelineState_, framebufferManager_->UseBufferedRendering());
GLRInputLayout *inputLayout = SetupDecFmtForDraw(dec_->GetDecVtxFmt());
if (useElements) {
uint32_t esz = sizeof(uint16_t) * indexGen.VertexCount();
void *dest = frameData.pushIndex->Allocate(esz, 2, &indexBuffer, &indexBufferOffset);
// TODO: When we need to apply an index offset, we can apply it directly when copying the indices here.
// Of course, minding the maximum value of 65535...
memcpy(dest, decIndex_, esz);
render_->DrawIndexed(inputLayout,
vertexBuffer, vertexBufferOffset,
indexBuffer, indexBufferOffset,
Expand Down
18 changes: 5 additions & 13 deletions GPU/Vulkan/DrawEngineVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,6 @@ void DrawEngineVulkan::EndFrame() {
stats_.pushIndexSpaceUsed = (int)pushIndex_->GetUsedThisFrame();
}

void DrawEngineVulkan::DecodeVertsToPushPool(VulkanPushPool *push, uint32_t *bindOffset, VkBuffer *vkbuf) {
u8 *dest = decoded_;

// Figure out how much pushbuffer space we need to allocate.
if (push) {
int vertsToDecode = ComputeNumVertsToDecode();
dest = push->Allocate(vertsToDecode * dec_->GetDecVtxFmt().stride, 4, vkbuf, bindOffset);
}
DecodeVerts(dest);
}

void DrawEngineVulkan::DirtyAllUBOs() {
baseUBOOffset = 0;
lightUBOOffset = 0;
Expand Down Expand Up @@ -263,14 +252,17 @@ void DrawEngineVulkan::DoFlush() {
u8 *dest = (u8 *)pushVertex_->Allocate(size, 4, &vbuf, &vbOffset);
memcpy(dest, decoded_, size);
} else {
// Figure out how much pushbuffer space we need to allocate.
int vertsToDecode = ComputeNumVertsToDecode();
// Decode directly into the pushbuffer
DecodeVertsToPushPool(pushVertex_, &vbOffset, &vbuf);
u8 *dest = pushVertex_->Allocate(vertsToDecode * dec_->GetDecVtxFmt().stride, 4, &vbuf, &vbOffset);
DecodeVerts(dest);
}
DecodeInds();
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();

bool useElements;
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
if (forceIndexed) {
useElements = true;
prim = indexGen.GeneralPrim();
Expand Down
2 changes: 0 additions & 2 deletions GPU/Vulkan/DrawEngineVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ class DrawEngineVulkan : public DrawEngineCommon {

void DestroyDeviceObjects();

void DecodeVertsToPushPool(VulkanPushPool *push, uint32_t *bindOffset, VkBuffer *vkbuf);

void DoFlush();
void UpdateUBOs();

Expand Down
4 changes: 1 addition & 3 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,9 @@ void SystemInfoScreen::CreateTabs() {
if (!board.empty())
systemInfo->Add(new InfoItem(si->T("Board"), board));
systemInfo->Add(new InfoItem(si->T("ABI"), GetCompilerABI()));
#ifdef _WIN32
if (IsDebuggerPresent()) {
if (System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT)) {
systemInfo->Add(new InfoItem(si->T("Debugger Present"), di->T("Yes")));
}
#endif

CollapsibleSection *cpuInfo = deviceSpecs->Add(new CollapsibleSection(si->T("CPU Information")));

Expand Down
2 changes: 2 additions & 0 deletions UWP/PPSSPP_UWPMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
// I don't know any possible way to display input dialog in non-xaml apps
return isKeyboardAvailable() || isTouchAvailable();
}
case SYSPROP_DEBUGGER_PRESENT:
return IsDebuggerPresent();
default:
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Windows/MainWindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ namespace MainWindow {
}

static void RestartApp() {
if (IsDebuggerPresent()) {
if (System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT)) {
PostMessage(MainWindow::GetHWND(), WM_USER_RESTART_EMUTHREAD, 0, 0);
} else {
g_Config.bRestartRequired = true;
Expand Down
4 changes: 3 additions & 1 deletion Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
return true; // FileUtil.cpp: OpenFileInEditor
case SYSPROP_SUPPORTS_HTTPS:
return !g_Config.bDisableHTTPS;
case SYSPROP_DEBUGGER_PRESENT:
return IsDebuggerPresent();
default:
return false;
}
Expand Down Expand Up @@ -494,7 +496,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
restartArgs = param1;
if (!restartArgs.empty())
AddDebugRestartArgs();
if (IsDebuggerPresent()) {
if (System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT)) {
PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_RESTART_EMUTHREAD, 0, 0);
} else {
g_Config.bRestartRequired = true;
Expand Down

0 comments on commit 6f28c5d

Please sign in to comment.