diff options
-rw-r--r-- | src/core/file_sys/disk_filesystem.cpp | 12 | ||||
-rw-r--r-- | src/core/file_sys/disk_filesystem.h | 2 | ||||
-rw-r--r-- | src/core/file_sys/filesystem.h | 2 | ||||
-rw-r--r-- | src/core/file_sys/romfs_filesystem.cpp | 2 | ||||
-rw-r--r-- | src/core/file_sys/romfs_filesystem.h | 2 | ||||
-rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.cpp | 16 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 85 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 13 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 5 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.h | 14 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_manager.h | 11 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_state.h | 2 |
12 files changed, 121 insertions, 45 deletions
diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp index 4235f3935..263392930 100644 --- a/src/core/file_sys/disk_filesystem.cpp +++ b/src/core/file_sys/disk_filesystem.cpp @@ -57,10 +57,14 @@ ResultVal<std::unique_ptr<StorageBackend>> Disk_FileSystem::OpenFile(const std:: std::make_unique<Disk_Storage>(std::move(file))); } -ResultCode Disk_FileSystem::DeleteFile(const Path& path) const { - LOG_WARNING(Service_FS, "(STUBBED) called"); - // TODO(bunnei): Use correct error code - return ResultCode(-1); +ResultCode Disk_FileSystem::DeleteFile(const std::string& path) const { + if (!FileUtil::Exists(path)) { + return ERROR_PATH_NOT_FOUND; + } + + FileUtil::Delete(path); + + return RESULT_SUCCESS; } ResultCode Disk_FileSystem::RenameFile(const Path& src_path, const Path& dest_path) const { diff --git a/src/core/file_sys/disk_filesystem.h b/src/core/file_sys/disk_filesystem.h index 742d7db1a..05a29bc3a 100644 --- a/src/core/file_sys/disk_filesystem.h +++ b/src/core/file_sys/disk_filesystem.h @@ -25,7 +25,7 @@ public: ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const std::string& path, Mode mode) const override; - ResultCode DeleteFile(const Path& path) const override; + ResultCode DeleteFile(const std::string& path) const override; ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; ResultCode DeleteDirectory(const Path& path) const override; ResultCode DeleteDirectoryRecursively(const Path& path) const override; diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h index 399427ca2..beefcfdb2 100644 --- a/src/core/file_sys/filesystem.h +++ b/src/core/file_sys/filesystem.h @@ -97,7 +97,7 @@ public: * @param path Path relative to the archive * @return Result of the operation */ - virtual ResultCode DeleteFile(const Path& path) const = 0; + virtual ResultCode DeleteFile(const std::string& path) const = 0; /** * Create a directory specified by its path diff --git a/src/core/file_sys/romfs_filesystem.cpp b/src/core/file_sys/romfs_filesystem.cpp index 0c6cc3157..3d77e2d5f 100644 --- a/src/core/file_sys/romfs_filesystem.cpp +++ b/src/core/file_sys/romfs_filesystem.cpp @@ -20,7 +20,7 @@ ResultVal<std::unique_ptr<StorageBackend>> RomFS_FileSystem::OpenFile(const std: std::make_unique<RomFS_Storage>(romfs_file, data_offset, data_size)); } -ResultCode RomFS_FileSystem::DeleteFile(const Path& path) const { +ResultCode RomFS_FileSystem::DeleteFile(const std::string& path) const { LOG_CRITICAL(Service_FS, "Attempted to delete a file from an ROMFS archive (%s).", GetName().c_str()); // TODO(bunnei): Use correct error code diff --git a/src/core/file_sys/romfs_filesystem.h b/src/core/file_sys/romfs_filesystem.h index 3f94c04d0..1b5cac409 100644 --- a/src/core/file_sys/romfs_filesystem.h +++ b/src/core/file_sys/romfs_filesystem.h @@ -31,7 +31,7 @@ public: ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const std::string& path, Mode mode) const override; - ResultCode DeleteFile(const Path& path) const override; + ResultCode DeleteFile(const std::string& path) const override; ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; ResultCode DeleteDirectory(const Path& path) const override; ResultCode DeleteDirectoryRecursively(const Path& path) const override; diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 458210a55..45accbf0e 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -236,7 +236,7 @@ public: : ServiceFramework("IFileSystem"), backend(std::move(backend)) { static const FunctionInfo functions[] = { {0, &IFileSystem::CreateFile, "CreateFile"}, - {1, nullptr, "DeleteFile"}, + {1, &IFileSystem::DeleteFile, "DeleteFile"}, {2, &IFileSystem::CreateDirectory, "CreateDirectory"}, {3, nullptr, "DeleteDirectory"}, {4, nullptr, "DeleteDirectoryRecursively"}, @@ -273,6 +273,20 @@ public: rb.Push(backend->CreateFile(name, size)); } + void DeleteFile(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + auto file_buffer = ctx.ReadBuffer(); + auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0'); + + std::string name(file_buffer.begin(), end); + + LOG_DEBUG(Service_FS, "called file %s", name.c_str()); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(backend->DeleteFile(name)); + } + void CreateDirectory(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 2a2268c20..28abc563a 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -193,6 +193,9 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size auto& gpu = Core::System().GetInstance().GPU().Maxwell3D(); ASSERT_MSG(!gpu.regs.shader_config[0].enable, "VertexA is unsupported!"); + // Next available bindpoint to use when uploading the const buffers to the GLSL shaders. + u32 current_constbuffer_bindpoint = 0; + for (unsigned index = 1; index < Maxwell::MaxShaderProgram; ++index) { ptr_pos += sizeof(GLShader::MaxwellUniformData); @@ -223,15 +226,19 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size Memory::ReadBlock(cpu_address, program_code.data(), program_code.size() * sizeof(u64)); GLShader::ShaderSetup setup{std::move(program_code)}; + GLShader::ShaderEntries shader_resources; + switch (program) { case Maxwell::ShaderProgram::VertexB: { GLShader::MaxwellVSConfig vs_config{setup}; - shader_program_manager->UseProgrammableVertexShader(vs_config, setup); + shader_resources = + shader_program_manager->UseProgrammableVertexShader(vs_config, setup); break; } case Maxwell::ShaderProgram::Fragment: { GLShader::MaxwellFSConfig fs_config{setup}; - shader_program_manager->UseProgrammableFragmentShader(fs_config, setup); + shader_resources = + shader_program_manager->UseProgrammableFragmentShader(fs_config, setup); break; } default: @@ -239,6 +246,14 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size shader_config.enable.Value(), shader_config.offset); UNREACHABLE(); } + + GLuint gl_stage_program = shader_program_manager->GetCurrentProgramStage( + static_cast<Maxwell::ShaderStage>(stage)); + + // Configure the const buffers for this shader stage. + current_constbuffer_bindpoint = + SetupConstBuffers(static_cast<Maxwell::ShaderStage>(stage), gl_stage_program, + current_constbuffer_bindpoint, shader_resources.const_buffer_entries); } shader_program_manager->UseTrivialGeometryShader(); @@ -306,8 +321,6 @@ void RasterizerOpenGL::DrawArrays() { // Sync and bind the texture surfaces BindTextures(); - // Configure the constant buffer objects - SetupConstBuffers(); // Viewport can have negative offsets or larger dimensions than our framebuffer sub-rect. Enable // scissor test to prevent drawing outside of the framebuffer region @@ -537,39 +550,53 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr } } -void RasterizerOpenGL::SetupConstBuffers() { - using Regs = Tegra::Engines::Maxwell3D::Regs; +u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint program, + u32 current_bindpoint, + const std::vector<GLShader::ConstBufferEntry>& entries) { auto& gpu = Core::System::GetInstance().GPU(); auto& maxwell3d = gpu.Get3DEngine(); - // Upload only the enabled buffers from the 16 constbuffers of each shader stage - u32 current_bindpoint = 0; - for (u32 stage = 0; stage < Regs::MaxShaderStage; ++stage) { - auto& shader_stage = maxwell3d.state.shader_stages[stage]; - bool stage_enabled = maxwell3d.IsShaderStageEnabled(static_cast<Regs::ShaderStage>(stage)); - - for (u32 buffer_id = 0; buffer_id < Regs::MaxConstBuffers; ++buffer_id) { - const auto& buffer = shader_stage.const_buffers[buffer_id]; + ASSERT_MSG(maxwell3d.IsShaderStageEnabled(stage), + "Attempted to upload constbuffer of disabled shader stage"); - state.draw.const_buffers[stage][buffer_id].enabled = buffer.enabled && stage_enabled; - - if (buffer.enabled && stage_enabled) { - state.draw.const_buffers[stage][buffer_id].bindpoint = current_bindpoint; - current_bindpoint++; + // Reset all buffer draw state for this stage. + for (auto& buffer : state.draw.const_buffers[static_cast<size_t>(stage)]) { + buffer.bindpoint = 0; + buffer.enabled = false; + } - VAddr addr = gpu.memory_manager->PhysicalToVirtualAddress(buffer.address); - const u8* data = Memory::GetPointer(addr); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, - state.draw.const_buffers[stage][buffer_id].ssbo); - glBufferData(GL_SHADER_STORAGE_BUFFER, buffer.size, data, GL_DYNAMIC_DRAW); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); - } else { - state.draw.const_buffers[stage][buffer_id].bindpoint = -1; - } - } + // Upload only the enabled buffers from the 16 constbuffers of each shader stage + auto& shader_stage = maxwell3d.state.shader_stages[static_cast<size_t>(stage)]; + + for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { + const auto& used_buffer = entries[bindpoint]; + const auto& buffer = shader_stage.const_buffers[used_buffer.GetIndex()]; + auto& buffer_draw_state = + state.draw.const_buffers[static_cast<size_t>(stage)][used_buffer.GetIndex()]; + + ASSERT_MSG(buffer.enabled, "Attempted to upload disabled constbuffer"); + buffer_draw_state.enabled = true; + buffer_draw_state.bindpoint = current_bindpoint + bindpoint; + + VAddr addr = gpu.memory_manager->PhysicalToVirtualAddress(buffer.address); + std::vector<u8> data(used_buffer.GetSize() * sizeof(float)); + Memory::ReadBlock(addr, data.data(), data.size()); + + glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer_draw_state.ssbo); + glBufferData(GL_SHADER_STORAGE_BUFFER, data.size(), data.data(), GL_DYNAMIC_DRAW); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + + // Now configure the bindpoint of the buffer inside the shader + std::string buffer_name = used_buffer.GetName(); + GLuint index = + glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, buffer_name.c_str()); + if (index != -1) + glShaderStorageBlockBinding(program, index, buffer_draw_state.bindpoint); } state.Apply(); + + return current_bindpoint + entries.size(); } void RasterizerOpenGL::BindFramebufferSurfaces(const Surface& color_surface, diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index bf3308aef..548ce0453 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -87,8 +87,17 @@ private: /// Binds the required textures to OpenGL before drawing a batch. void BindTextures(); - /// Configures the current constbuffers to use for the draw command. - void SetupConstBuffers(); + /* + * Configures the current constbuffers to use for the draw command. + * @param stage The shader stage to configure buffers for. + * @param program The OpenGL program object that contains the specified stage. + * @param current_bindpoint The offset at which to start counting new buffer bindpoints. + * @param entries Vector describing the buffers that are actually used in the guest shader. + * @returns The next available bindpoint for use in the next shader stage. + */ + u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, GLuint program, + u32 current_bindpoint, + const std::vector<GLShader::ConstBufferEntry>& entries); /// Syncs the viewport to match the guest state void SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale); diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 9cf2c6a0c..e11711533 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -192,7 +192,7 @@ private: /// Generates code representing a uniform (C buffer) register. std::string GetUniform(const Uniform& reg) { - declr_const_buffers[reg.index].MarkAsUsed(reg.index, reg.offset); + declr_const_buffers[reg.index].MarkAsUsed(reg.index, reg.offset, stage); return 'c' + std::to_string(reg.index) + '[' + std::to_string(reg.offset) + ']'; } @@ -478,8 +478,7 @@ private: unsigned const_buffer_layout = 0; for (const auto& entry : GetConstBuffersDeclarations()) { - declarations.AddLine("layout(std430, binding = " + std::to_string(const_buffer_layout) + - ") buffer c" + std::to_string(entry.GetIndex()) + "_buffer"); + declarations.AddLine("layout(std430) buffer " + entry.GetName()); declarations.AddLine("{"); declarations.AddLine(" float c" + std::to_string(entry.GetIndex()) + "[];"); declarations.AddLine("};"); diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h index 3d9aead74..458032b5c 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.h +++ b/src/video_core/renderer_opengl/gl_shader_gen.h @@ -19,10 +19,13 @@ constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000}; using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>; class ConstBufferEntry { + using Maxwell = Tegra::Engines::Maxwell3D::Regs; + public: - void MarkAsUsed(unsigned index, unsigned offset) { + void MarkAsUsed(unsigned index, unsigned offset, Maxwell::ShaderStage stage) { is_used = true; this->index = index; + this->stage = stage; max_offset = std::max(max_offset, offset); } @@ -38,10 +41,19 @@ public: return max_offset + 1; } + std::string GetName() const { + return BufferBaseNames[static_cast<size_t>(stage)] + std::to_string(index); + } + private: + static constexpr std::array<const char*, Maxwell::MaxShaderStage> BufferBaseNames = { + "buffer_vs_c", "buffer_tessc_c", "buffer_tesse_c", "buffer_gs_c", "buffer_fs_c", + }; + bool is_used{}; unsigned index{}; unsigned max_offset{}; + Maxwell::ShaderStage stage; }; struct ShaderEntries { diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index ecc92d986..be63320e0 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h @@ -121,6 +121,17 @@ public: return result; } + GLuint GetCurrentProgramStage(Maxwell3D::Regs::ShaderStage stage) { + switch (stage) { + case Maxwell3D::Regs::ShaderStage::Vertex: + return current.vs; + case Maxwell3D::Regs::ShaderStage::Fragment: + return current.fs; + } + + UNREACHABLE(); + } + void UseTrivialGeometryShader() { current.gs = 0; } diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 6a80e6a7d..75c08e645 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -124,7 +124,7 @@ public: GLuint shader_program; // GL_CURRENT_PROGRAM GLuint program_pipeline; // GL_PROGRAM_PIPELINE_BINDING struct ConstBufferConfig { - bool enabled; + bool enabled = false; GLuint bindpoint; GLuint ssbo; }; |