Skip to content

Commit

Permalink
Merge pull request #14 from hrydgard/master
Browse files Browse the repository at this point in the history
Merge pull request hrydgard#17314 from unknownbrackets/framebuf-shrink
  • Loading branch information
fengjixuchui authored Apr 20, 2023
2 parents 6dafe86 + 0d20da6 commit cb7b9e1
Show file tree
Hide file tree
Showing 65 changed files with 340 additions and 386 deletions.
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2490,11 +2490,18 @@ endif()
if(TargetBin)
if(APPLE)
if(NOT IOS)
set(ICON_PATH_ABS ${CMAKE_CURRENT_SOURCE_DIR}/icons/ppsspp.icns)
set(MACOSX_BUNDLE_ICON_FILE ppsspp.icns)
if(GOLD)
set(ICON_PATH_ABS ${CMAKE_CURRENT_SOURCE_DIR}/icons/ppsspp_gold.icns)
set(MACOSX_BUNDLE_ICON_FILE ppsspp_gold.icns)
set(MACOSX_BUNDLE_BUNDLE_NAME "PPSSPP Gold")
set(MACOSX_BUNDLE_GUI_IDENTIFIER org.ppsspp.ppssppgold)
else()
set(ICON_PATH_ABS ${CMAKE_CURRENT_SOURCE_DIR}/icons/ppsspp.icns)
set(MACOSX_BUNDLE_ICON_FILE ppsspp.icns)
set(MACOSX_BUNDLE_BUNDLE_NAME "PPSSPP")
set(MACOSX_BUNDLE_GUI_IDENTIFIER org.ppsspp.ppsspp)
endif()
set_source_files_properties(${ICON_PATH_ABS} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
set(MACOSX_BUNDLE_BUNDLE_NAME PPSSPP)
set(MACOSX_BUNDLE_GUI_IDENTIFIER org.ppsspp.ppsspp)
endif()

# TODO: there must a native way to copy these.
Expand All @@ -2505,7 +2512,7 @@ if(TargetBin)
file(GLOB_RECURSE SHADER_FILES assets/shaders/*)
file(GLOB_RECURSE THEME_FILE assets/themes/*)
file(GLOB_RECURSE DEBUGGER_FILES assets/debugger/*)
file(GLOB_RECURSE VFPU_FILES assets/vfpu/*)
file(GLOB_RECURSE VFPU_FILES assets/vfpu/*)

if(NOT IOS)
set_source_files_properties(${BigFontAssets} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets")
Expand All @@ -2515,7 +2522,7 @@ if(TargetBin)
set_source_files_properties(${SHADER_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/shaders")
set_source_files_properties(${THEME_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/themes")
set_source_files_properties(${DEBUGGER_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/debugger")
set_source_files_properties(${VFPU_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/vfpu")
set_source_files_properties(${VFPU_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/vfpu")
endif()

if(IOS)
Expand Down
24 changes: 4 additions & 20 deletions Common/GPU/OpenGL/GLQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ void GLQueueRunner::CreateDeviceObjects() {

void GLQueueRunner::DestroyDeviceObjects() {
CHECK_GL_ERROR_IF_DEBUG();
if (!nameCache_.empty()) {
glDeleteTextures((GLsizei)nameCache_.size(), &nameCache_[0]);
nameCache_.clear();
}
if (gl_extensions.ARB_vertex_array_object) {
glDeleteVertexArrays(1, &globalVAO_);
}
Expand Down Expand Up @@ -327,8 +323,8 @@ void GLQueueRunner::RunInitSteps(const std::vector<GLRInitStep> &steps, bool ski
glCompileShader(shader);
GLint success = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
std::string infoLog = GetInfoLog(shader, glGetShaderiv, glGetShaderInfoLog);
if (!success) {
std::string infoLog = GetInfoLog(shader, glGetShaderiv, glGetShaderInfoLog);
std::string errorString = StringFromFormat(
"Error in shader compilation for: %s\n"
"Info log: %s\n"
Expand Down Expand Up @@ -799,10 +795,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
glDisable(GL_COLOR_LOGIC_OP);
}
#endif
}

if (first && gl_extensions.ARB_vertex_array_object) {
glBindVertexArray(globalVAO_);
if (gl_extensions.ARB_vertex_array_object) {
glBindVertexArray(globalVAO_);
}
}

GLRProgram *curProgram = nullptr;
Expand Down Expand Up @@ -1630,17 +1625,6 @@ void GLQueueRunner::CopyFromReadbackBuffer(GLRFramebuffer *framebuffer, int widt
}
}

GLuint GLQueueRunner::AllocTextureName() {
if (nameCache_.empty()) {
nameCache_.resize(TEXCACHE_NAME_CACHE_SIZE);
glGenTextures(TEXCACHE_NAME_CACHE_SIZE, &nameCache_[0]);
}
u32 name = nameCache_.back();
nameCache_.pop_back();
CHECK_GL_ERROR_IF_DEBUG();
return name;
}

// On PC, we always use GL_DEPTH24_STENCIL8.
// On Android, we try to use what's available.

Expand Down
5 changes: 0 additions & 5 deletions Common/GPU/OpenGL/GLQueueRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ struct GLRInitStep {
union {
struct {
GLRTexture *texture;
GLenum target;
} create_texture;
struct {
GLRShader *shader;
Expand Down Expand Up @@ -420,10 +419,6 @@ class GLQueueRunner {
GLuint currentDrawHandle_ = 0;
GLuint currentReadHandle_ = 0;

GLuint AllocTextureName();

// Texture name cache. Ripped straight from TextureCacheGLES.
std::vector<GLuint> nameCache_;
std::unordered_map<int, std::string> glStrings_;

bool sawOutOfMemory_ = false;
Expand Down
4 changes: 2 additions & 2 deletions Common/GPU/OpenGL/GLRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ void GLRenderManager::BindFramebufferAsRenderTarget(GLRFramebuffer *fb, GLRRende
#endif

// Eliminate dupes.
if (steps_.size() && steps_.back()->render.framebuffer == fb && steps_.back()->stepType == GLRStepType::RENDER) {
if (steps_.size() && steps_.back()->stepType == GLRStepType::RENDER && steps_.back()->render.framebuffer == fb) {
if (color != GLRRenderPassAction::CLEAR && depth != GLRRenderPassAction::CLEAR && stencil != GLRRenderPassAction::CLEAR) {
// We don't move to a new step, this bind was unnecessary and we can safely skip it.
curRenderStep_ = steps_.back();
return;
}
}
if (curRenderStep_ && curRenderStep_->commands.size() == 0) {
VLOG("Empty render step. Usually happens after uploading pixels..");
VLOG("Empty render step. Usually happens after uploading pixels.");
}

GLRStep *step = new GLRStep{ GLRStepType::RENDER };
Expand Down
13 changes: 3 additions & 10 deletions Common/GPU/OpenGL/GLRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ class GLRenderManager {
void BeginFrame();
// Can run on a different thread!
void Finish();
bool Run(GLRRenderThreadTask &task);

// Creation commands. These were not needed in Vulkan since there we can do that on the main thread.
// We pass in width/height here even though it's not strictly needed until we support glTextureStorage
Expand Down Expand Up @@ -535,7 +534,7 @@ class GLRenderManager {

// This starts a new step (like a "render pass" in Vulkan).
//
// After a "CopyFramebuffer" or the other functions that start "steps", you need to call this beforce
// After a "CopyFramebuffer" or the other functions that start "steps", you need to call this before
// making any new render state changes or draw calls.
//
// The following state needs to be reset by the caller after calling this (and will thus not safely carry over from
Expand Down Expand Up @@ -632,14 +631,6 @@ class GLRenderManager {
#endif
}

void BindPixelPackBuffer(GLRBuffer *buffer) { // Want to support an offset but can't in ES 2.0. We supply an offset when binding the buffers instead.
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
GLRRenderData data{ GLRRenderCommand::BIND_BUFFER };
data.bind_buffer.buffer = buffer;
data.bind_buffer.target = GL_PIXEL_PACK_BUFFER;
curRenderStep_->commands.push_back(data);
}

void BindIndexBuffer(GLRBuffer *buffer) { // Want to support an offset but can't in ES 2.0. We supply an offset when binding the buffers instead.
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
GLRRenderData data{ GLRRenderCommand::BIND_BUFFER};
Expand Down Expand Up @@ -1008,6 +999,8 @@ class GLRenderManager {
}

private:
bool Run(GLRRenderThreadTask &task);

// Bad for performance but sometimes necessary for synchronous CPU readbacks (screenshots and whatnot).
void FlushSync();

Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/OpenGL/thin3d_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ bool OpenGLPipeline::LinkShaders(const PipelineDesc &desc) {
for (int i = 0; i < (int)std::min((const uint32_t)samplers_.size(), MAX_TEXTURE_SLOTS); i++) {
queries.push_back({ &locs_->samplerLocs_[i], samplers_[i].name, true });
}
samplersToCheck = (int)samplers_.size();
samplersToCheck = (int)std::min((const uint32_t)samplers_.size(), MAX_TEXTURE_SLOTS);
} else {
queries.push_back({ &locs_->samplerLocs_[0], "sampler0" });
queries.push_back({ &locs_->samplerLocs_[1], "sampler1" });
Expand Down
11 changes: 8 additions & 3 deletions Common/GPU/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ std::string VulkanVendorString(uint32_t vendorId) {
}
}

const char *PresentModeString(VkPresentModeKHR presentMode) {
const char *VulkanPresentModeToString(VkPresentModeKHR presentMode) {
switch (presentMode) {
case VK_PRESENT_MODE_IMMEDIATE_KHR: return "IMMEDIATE";
case VK_PRESENT_MODE_MAILBOX_KHR: return "MAILBOX";
Expand Down Expand Up @@ -1233,16 +1233,19 @@ bool VulkanContext::InitSwapchain() {
surfCapabilities_.maxImageExtent.width, surfCapabilities_.maxImageExtent.height,
swapChainExtent_.width, swapChainExtent_.height);

availablePresentModes_.clear();
// TODO: Find a better way to specify the prioritized present mode while being able
// to fall back in a sensible way.
VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
std::string modes = "";
for (size_t i = 0; i < presentModeCount; i++) {
modes += PresentModeString(presentModes[i]);
modes += VulkanPresentModeToString(presentModes[i]);
if (i != presentModeCount - 1) {
modes += ", ";
}
availablePresentModes_.push_back(presentModes[i]);
}

INFO_LOG(G3D, "Supported present modes: %s", modes.c_str());
for (size_t i = 0; i < presentModeCount; i++) {
bool match = false;
Expand Down Expand Up @@ -1276,7 +1279,7 @@ bool VulkanContext::InitSwapchain() {
}

INFO_LOG(G3D, "Chosen present mode: %d (%s). numSwapChainImages: %d/%d",
swapchainPresentMode, PresentModeString(swapchainPresentMode),
swapchainPresentMode, VulkanPresentModeToString(swapchainPresentMode),
desiredNumberOfSwapChainImages, surfCapabilities_.maxImageCount);

// We mostly follow the practices from
Expand Down Expand Up @@ -1356,6 +1359,8 @@ bool VulkanContext::InitSwapchain() {
swap_chain_info.clipped = true;
swap_chain_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

presentMode_ = swapchainPresentMode;

// Don't ask for TRANSFER_DST for the swapchain image, we don't use that.
// if (surfCapabilities_.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT)
// swap_chain_info.imageUsage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Expand Down
12 changes: 12 additions & 0 deletions Common/GPU/Vulkan/VulkanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ class VulkanContext {
return surfFormats_;
}

VkPresentModeKHR GetPresentMode() const {
return presentMode_;
}

std::vector<VkPresentModeKHR> GetAvailablePresentModes() const {
return availablePresentModes_;
}

private:
bool ChooseQueue();

Expand Down Expand Up @@ -462,6 +470,9 @@ class VulkanContext {
VkSurfaceCapabilitiesKHR surfCapabilities_{};
std::vector<VkSurfaceFormatKHR> surfFormats_{};

VkPresentModeKHR presentMode_;
std::vector<VkPresentModeKHR> availablePresentModes_;

std::vector<VkCommandBuffer> cmdQueue_;

VmaAllocator allocator_ = VK_NULL_HANDLE;
Expand All @@ -487,6 +498,7 @@ bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *sourceCode,

const char *VulkanColorSpaceToString(VkColorSpaceKHR colorSpace);
const char *VulkanFormatToString(VkFormat format);
const char *VulkanPresentModeToString(VkPresentModeKHR presentMode);

std::string FormatDriverVersion(const VkPhysicalDeviceProperties &props);

Expand Down
1 change: 0 additions & 1 deletion Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,6 @@ std::vector<std::string> VKContext::GetFeatureList() const {
AddFeature(features, "geometryShader", available.geometryShader, enabled.geometryShader);
AddFeature(features, "depthBounds", available.depthBounds, enabled.depthBounds);
AddFeature(features, "depthClamp", available.depthClamp, enabled.depthClamp);
AddFeature(features, "fillModeNonSolid", available.fillModeNonSolid, enabled.fillModeNonSolid);
AddFeature(features, "pipelineStatisticsQuery", available.pipelineStatisticsQuery, enabled.pipelineStatisticsQuery);
AddFeature(features, "samplerAnisotropy", available.samplerAnisotropy, enabled.samplerAnisotropy);
AddFeature(features, "textureCompressionBC", available.textureCompressionBC, enabled.textureCompressionBC);
Expand Down
2 changes: 1 addition & 1 deletion Common/Render/TextureAtlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct AtlasFont {
char name[32];

// Returns 0 on no match.
const AtlasChar *getChar(int utf32) const ;
const AtlasChar *getChar(int utf32) const;
};

struct AtlasImage {
Expand Down
10 changes: 6 additions & 4 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,18 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(Framebuffer
bool needsRecreate = vfb->bufferWidth > params.fb_stride;
needsRecreate = needsRecreate || vfb->newWidth > vfb->bufferWidth || vfb->newWidth * 2 < vfb->bufferWidth;
needsRecreate = needsRecreate || vfb->newHeight > vfb->bufferHeight || vfb->newHeight * 2 < vfb->bufferHeight;

// Whether we resize or not, change the size parameters so we stop detecting a resize.
// It might be larger if all drawing has been in throughmode.
vfb->width = drawing_width;
vfb->height = drawing_height;

if (needsRecreate) {
ResizeFramebufFBO(vfb, vfb->width, vfb->height, true);
resized = true;
// Let's discard this information, might be wrong now.
vfb->safeWidth = 0;
vfb->safeHeight = 0;
} else {
// Even though we won't resize it, let's at least change the size params.
vfb->width = drawing_width;
vfb->height = drawing_height;
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion SDL/SDLGLGraphicsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SDLGLGraphicsContext : public GraphicsContext {

private:
Draw::DrawContext *draw_ = nullptr;
SDL_Window *window_;
SDL_Window *window_ = nullptr;
SDL_GLContext glContext = nullptr;
GLRenderManager *renderManager_ = nullptr;
};
3 changes: 2 additions & 1 deletion SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case SystemRequestType::SET_WINDOW_TITLE:
{
std::lock_guard<std::mutex> guard(g_mutexWindow);
g_windowState.title = param1.empty() ? "PPSSPP " : param1;
const char *app_name = System_GetPropertyBool(SYSPROP_APP_GOLD) ? "PPSSPP Gold" : "PPSSPP";
g_windowState.title = param1.empty() ? app_name : param1;
g_windowState.update = true;
return true;
}
Expand Down
19 changes: 14 additions & 5 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,20 +784,29 @@ void SystemInfoScreen::CreateViews() {
}
}
} else if (GetGPUBackend() == GPUBackend::VULKAN) {
#if !PPSSPP_PLATFORM(UWP)
// Vulkan specific code here, can't be bothered to abstract.
// OK because of above check.

tabHolder->AddTab(si->T("Vulkan Features"), gpuExtensionsScroll);
VulkanContext *vk = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);

gpuExtensions->Add(new ItemHeader(si->T("Vulkan Features")));
std::vector<std::string> features = draw->GetFeatureList();
for (auto &feature : features) {
gpuExtensions->Add(new TextView(feature, new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetFocusable(true);
}

#if !PPSSPP_PLATFORM(UWP)

// Vulkan specific code here, can't be bothered to abstract.
// OK because of above check.
gpuExtensions->Add(new ItemHeader(si->T("Present Modes")));
for (auto mode : vk->GetAvailablePresentModes()) {
std::string str = VulkanPresentModeToString(mode);
if (mode == vk->GetPresentMode()) {
str += std::string(" (") + di->T("Current") + ")";
}
gpuExtensions->Add(new TextView(VulkanPresentModeToString(mode), new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetFocusable(true);
}

gpuExtensions->Add(new ItemHeader(si->T("Display Color Formats")));
VulkanContext *vk = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
if (vk) {
for (auto &format : vk->SurfaceFormats()) {
std::string line = StringFromFormat("%s : %s", VulkanFormatToString(format.format), VulkanColorSpaceToString(format.colorSpace));
Expand Down
4 changes: 2 additions & 2 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,8 @@ void CreditsScreen::render() {
specialthankssolarmystic += cr->T("testing");
specialthankssolarmystic += ')';

const char * credits[] = {
"PPSSPP",
const char *credits[] = {
System_GetPropertyBool(SYSPROP_APP_GOLD) ? "PPSSPP Gold" : "PPSSPP",
"",
cr->T("title", "A fast and portable PSP emulator"),
"",
Expand Down
12 changes: 3 additions & 9 deletions UWP/UWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,10 @@
<None Include="Content\shaders\tex_mmpx.csh">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="Content\shaders\upscale_catmull_rom.fsh">
<None Include="Content\shaders\upscale_bicubic.fsh">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="Content\shaders\upscale_catmull_rom.vsh">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="Content\shaders\upscale_mitchell_netravali.fsh">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="Content\shaders\upscale_mitchell_netravali.vsh">
<None Include="Content\shaders\upscale_bicubic.vsh">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="Content\shaders\upscale_spline36.fsh">
Expand Down Expand Up @@ -959,4 +953,4 @@
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\MeshContentTask.targets" />
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\ShaderGraphContentTask.targets" />
</ImportGroup>
</Project>
</Project>
Loading

0 comments on commit cb7b9e1

Please sign in to comment.