diff options
-rw-r--r-- | src/common/file_util.cpp | 11 | ||||
-rw-r--r-- | src/common/file_util.h | 3 | ||||
-rw-r--r-- | src/core/file_sys/mode.h | 6 | ||||
-rw-r--r-- | src/core/file_sys/partition_filesystem.cpp | 6 | ||||
-rw-r--r-- | src/core/file_sys/vfs_real.cpp | 47 | ||||
-rw-r--r-- | src/core/hle/ipc_helpers.h | 34 | ||||
-rw-r--r-- | src/core/hle/kernel/hle_ipc.h | 2 | ||||
-rw-r--r-- | src/core/hle/service/filesystem/filesystem.cpp | 45 | ||||
-rw-r--r-- | src/video_core/gpu.cpp | 2 | ||||
-rw-r--r-- | src/video_core/gpu.h | 2 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 9 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 5 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 18 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.h | 56 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 13 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/maxwell_to_gl.h | 5 | ||||
-rw-r--r-- | src/video_core/textures/decoders.cpp | 4 | ||||
-rw-r--r-- | src/video_core/textures/texture.h | 8 |
18 files changed, 193 insertions, 83 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 1bc291cf9..b8dd92b65 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -826,7 +826,7 @@ std::string_view GetPathWithoutTop(std::string_view path) { } while (path[0] == '\\' || path[0] == '/') { - path.remove_suffix(1); + path.remove_prefix(1); if (path.empty()) { return path; } @@ -870,6 +870,15 @@ std::string_view RemoveTrailingSlash(std::string_view path) { return path; } +std::string SanitizePath(std::string_view path_) { + std::string path(path_); + std::replace(path.begin(), path.end(), '\\', '/'); + path.erase(std::unique(path.begin(), path.end(), + [](char c1, char c2) { return c1 == '/' && c2 == '/'; }), + path.end()); + return std::string(RemoveTrailingSlash(path)); +} + IOFile::IOFile() {} IOFile::IOFile(const std::string& filename, const char openmode[], int flags) { diff --git a/src/common/file_util.h b/src/common/file_util.h index abfa79eae..bc9272d89 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -178,6 +178,9 @@ std::vector<T> SliceVector(const std::vector<T>& vector, size_t first, size_t la return std::vector<T>(vector.begin() + first, vector.begin() + first + last); } +// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. +std::string SanitizePath(std::string_view path); + // simple wrapper for cstdlib file functions to // hopefully will make error checking easier // and make forgetting an fclose() harder diff --git a/src/core/file_sys/mode.h b/src/core/file_sys/mode.h index b4363152a..c95205668 100644 --- a/src/core/file_sys/mode.h +++ b/src/core/file_sys/mode.h @@ -11,7 +11,13 @@ namespace FileSys { enum class Mode : u32 { Read = 1, Write = 2, + ReadWrite = 3, Append = 4, + WriteAppend = 6, }; +inline u32 operator&(Mode lhs, Mode rhs) { + return static_cast<u32>(lhs) & static_cast<u32>(rhs); +} + } // namespace FileSys diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index 8d2bd9f6b..521e21078 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp @@ -65,8 +65,8 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { std::string name( reinterpret_cast<const char*>(&file_data[strtab_offset + entry.strtab_offset])); - pfs_files.emplace_back( - std::make_shared<OffsetVfsFile>(file, entry.size, content_offset + entry.offset, name)); + pfs_files.emplace_back(std::make_shared<OffsetVfsFile>( + file, entry.size, content_offset + entry.offset, std::move(name))); } status = Loader::ResultStatus::Success; @@ -109,7 +109,7 @@ bool PartitionFilesystem::ReplaceFileWithSubdirectory(VirtualFile file, VirtualD return false; const std::ptrdiff_t offset = std::distance(pfs_files.begin(), iter); - pfs_files[offset] = pfs_files.back(); + pfs_files[offset] = std::move(pfs_files.back()); pfs_files.pop_back(); pfs_dirs.emplace_back(std::move(dir)); diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 095fec77e..9ce2e1efa 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -13,24 +13,31 @@ namespace FileSys { -static std::string PermissionsToCharArray(Mode perms) { - std::string out; - switch (perms) { - case Mode::Read: - out += "r"; - break; - case Mode::Write: - out += "r+"; - break; - case Mode::Append: - out += "a"; - break; +static std::string ModeFlagsToString(Mode mode) { + std::string mode_str; + + // Calculate the correct open mode for the file. + if (mode & Mode::Read && mode & Mode::Write) { + if (mode & Mode::Append) + mode_str = "a+"; + else + mode_str = "r+"; + } else { + if (mode & Mode::Read) + mode_str = "r"; + else if (mode & Mode::Append) + mode_str = "a"; + else if (mode & Mode::Write) + mode_str = "w"; } - return out + "b"; + + mode_str += "b"; + + return mode_str; } RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) - : backing(path_, PermissionsToCharArray(perms_).c_str()), path(path_), + : backing(path_, ModeFlagsToString(perms_).c_str()), path(path_), parent_path(FileUtil::GetParentPath(path_)), path_components(FileUtil::SplitPathComponents(path_)), parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), @@ -53,11 +60,11 @@ std::shared_ptr<VfsDirectory> RealVfsFile::GetContainingDirectory() const { } bool RealVfsFile::IsWritable() const { - return perms == Mode::Append || perms == Mode::Write; + return (perms & Mode::WriteAppend) != 0; } bool RealVfsFile::IsReadable() const { - return perms == Mode::Read || perms == Mode::Write; + return (perms & Mode::ReadWrite) != 0; } size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { @@ -79,7 +86,7 @@ bool RealVfsFile::Rename(std::string_view name) { path = (parent_path + DIR_SEP).append(name); path_components = parent_components; path_components.push_back(std::move(name_str)); - backing = FileUtil::IOFile(path, PermissionsToCharArray(perms).c_str()); + backing = FileUtil::IOFile(path, ModeFlagsToString(perms).c_str()); return out; } @@ -93,7 +100,7 @@ RealVfsDirectory::RealVfsDirectory(const std::string& path_, Mode perms_) path_components(FileUtil::SplitPathComponents(path)), parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), perms(perms_) { - if (!FileUtil::Exists(path) && (perms == Mode::Write || perms == Mode::Append)) + if (!FileUtil::Exists(path) && perms & Mode::WriteAppend) FileUtil::CreateDir(path); if (perms == Mode::Append) @@ -120,11 +127,11 @@ std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() } bool RealVfsDirectory::IsWritable() const { - return perms == Mode::Write || perms == Mode::Append; + return (perms & Mode::WriteAppend) != 0; } bool RealVfsDirectory::IsReadable() const { - return perms == Mode::Read || perms == Mode::Write; + return (perms & Mode::ReadWrite) != 0; } std::string RealVfsDirectory::GetName() const { diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 8b5b06f31..f5bd27a75 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -25,9 +25,9 @@ protected: ptrdiff_t index = 0; public: - RequestHelperBase(u32* command_buffer) : cmdbuf(command_buffer) {} + explicit RequestHelperBase(u32* command_buffer) : cmdbuf(command_buffer) {} - RequestHelperBase(Kernel::HLERequestContext& context) + explicit RequestHelperBase(Kernel::HLERequestContext& context) : context(&context), cmdbuf(context.CommandBuffer()) {} void Skip(unsigned size_in_words, bool set_to_null) { @@ -56,13 +56,6 @@ public: class ResponseBuilder : public RequestHelperBase { public: - ResponseBuilder(u32* command_buffer) : RequestHelperBase(command_buffer) {} - - u32 normal_params_size{}; - u32 num_handles_to_copy{}; - u32 num_objects_to_move{}; ///< Domain objects or move handles, context dependent - std::ptrdiff_t datapayload_index{}; - /// Flags used for customizing the behavior of ResponseBuilder enum class Flags : u32 { None = 0, @@ -71,9 +64,11 @@ public: AlwaysMoveHandles = 1, }; - ResponseBuilder(Kernel::HLERequestContext& context, u32 normal_params_size, - u32 num_handles_to_copy = 0, u32 num_objects_to_move = 0, - Flags flags = Flags::None) + explicit ResponseBuilder(u32* command_buffer) : RequestHelperBase(command_buffer) {} + + explicit ResponseBuilder(Kernel::HLERequestContext& context, u32 normal_params_size, + u32 num_handles_to_copy = 0, u32 num_objects_to_move = 0, + Flags flags = Flags::None) : RequestHelperBase(context), normal_params_size(normal_params_size), num_handles_to_copy(num_handles_to_copy), num_objects_to_move(num_objects_to_move) { @@ -206,6 +201,12 @@ public: template <typename... O> void PushCopyObjects(Kernel::SharedPtr<O>... pointers); + +private: + u32 normal_params_size{}; + u32 num_handles_to_copy{}; + u32 num_objects_to_move{}; ///< Domain objects or move handles, context dependent + std::ptrdiff_t datapayload_index{}; }; /// Push /// @@ -273,9 +274,9 @@ inline void ResponseBuilder::PushMoveObjects(Kernel::SharedPtr<O>... pointers) { class RequestParser : public RequestHelperBase { public: - RequestParser(u32* command_buffer) : RequestHelperBase(command_buffer) {} + explicit RequestParser(u32* command_buffer) : RequestHelperBase(command_buffer) {} - RequestParser(Kernel::HLERequestContext& context) : RequestHelperBase(context) { + explicit RequestParser(Kernel::HLERequestContext& context) : RequestHelperBase(context) { ASSERT_MSG(context.GetDataPayloadOffset(), "context is incomplete"); Skip(context.GetDataPayloadOffset(), false); // Skip the u64 command id, it's already stored in the context @@ -285,8 +286,9 @@ public: ResponseBuilder MakeBuilder(u32 normal_params_size, u32 num_handles_to_copy, u32 num_handles_to_move, - ResponseBuilder::Flags flags = ResponseBuilder::Flags::None) { - return {*context, normal_params_size, num_handles_to_copy, num_handles_to_move, flags}; + ResponseBuilder::Flags flags = ResponseBuilder::Flags::None) const { + return ResponseBuilder{*context, normal_params_size, num_handles_to_copy, + num_handles_to_move, flags}; } template <typename T> diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 01b805df8..84727f748 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -91,7 +91,7 @@ protected: */ class HLERequestContext { public: - HLERequestContext(SharedPtr<Kernel::ServerSession> session); + explicit HLERequestContext(SharedPtr<ServerSession> session); ~HLERequestContext(); /// Returns a pointer to the IPC command buffer for this request. diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index dbfe06cbc..fdd2fda18 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -24,7 +24,8 @@ namespace Service::FileSystem { constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000; static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base, - std::string_view dir_name) { + std::string_view dir_name_) { + std::string dir_name(FileUtil::SanitizePath(dir_name_)); if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\") return base; @@ -38,7 +39,8 @@ std::string VfsDirectoryServiceWrapper::GetName() const { return backing->GetName(); } -ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 size) const { +ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const { + std::string path(FileUtil::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); auto file = dir->CreateFile(FileUtil::GetFilename(path)); if (file == nullptr) { @@ -52,7 +54,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 s return RESULT_SUCCESS; } -ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const { +ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const { + std::string path(FileUtil::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); if (path == "/" || path == "\\") { // TODO(DarkLordZach): Why do games call this and what should it do? Works as is but... @@ -60,14 +63,15 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const } if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) return FileSys::ERROR_PATH_NOT_FOUND; - if (!backing->DeleteFile(FileUtil::GetFilename(path))) { + if (!dir->DeleteFile(FileUtil::GetFilename(path))) { // TODO(DarkLordZach): Find a better error code for this return ResultCode(-1); } return RESULT_SUCCESS; } -ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path) const { +ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const { + std::string path(FileUtil::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty()) dir = backing; @@ -79,7 +83,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path) return RESULT_SUCCESS; } -ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path) const { +ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const { + std::string path(FileUtil::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) { // TODO(DarkLordZach): Find a better error code for this @@ -88,7 +93,8 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path) return RESULT_SUCCESS; } -ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path) const { +ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const { + std::string path(FileUtil::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) { // TODO(DarkLordZach): Find a better error code for this @@ -97,8 +103,10 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::str return RESULT_SUCCESS; } -ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path, - const std::string& dest_path) const { +ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_, + const std::string& dest_path_) const { + std::string src_path(FileUtil::SanitizePath(src_path_)); + std::string dest_path(FileUtil::SanitizePath(dest_path_)); auto src = backing->GetFileRelative(src_path); if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { // Use more-optimized vfs implementation rename. @@ -130,8 +138,10 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path, return RESULT_SUCCESS; } -ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path, - const std::string& dest_path) const { +ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_, + const std::string& dest_path_) const { + std::string src_path(FileUtil::SanitizePath(src_path_)); + std::string dest_path(FileUtil::SanitizePath(dest_path_)); auto src = GetDirectoryRelativeWrapped(backing, src_path); if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { // Use more-optimized vfs implementation rename. @@ -154,8 +164,9 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa return ResultCode(-1); } -ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path, +ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_, FileSys::Mode mode) const { + std::string path(FileUtil::SanitizePath(path_)); auto npath = path; while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\')) npath = npath.substr(1); @@ -171,7 +182,8 @@ ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std:: return MakeResult<FileSys::VirtualFile>(file); } -ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path) { +ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) { + std::string path(FileUtil::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, path); if (dir == nullptr) { // TODO(DarkLordZach): Find a better error code for this @@ -188,7 +200,8 @@ u64 VfsDirectoryServiceWrapper::GetFreeSpaceSize() const { } ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( - const std::string& path) const { + const std::string& path_) const { + std::string path(FileUtil::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); if (dir == nullptr) return FileSys::ERROR_PATH_NOT_FOUND; @@ -272,9 +285,9 @@ void RegisterFileSystems() { sdmc_factory = nullptr; auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( - FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::Write); + FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::ReadWrite); auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( - FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::Write); + FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::ReadWrite); auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); save_data_factory = std::move(savedata); diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index a003bc9e3..60c49d672 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -35,9 +35,11 @@ u32 RenderTargetBytesPerPixel(RenderTargetFormat format) { case RenderTargetFormat::RGBA32_FLOAT: return 16; case RenderTargetFormat::RGBA16_FLOAT: + case RenderTargetFormat::RG32_FLOAT: return 8; case RenderTargetFormat::RGBA8_UNORM: case RenderTargetFormat::RGB10_A2_UNORM: + case RenderTargetFormat::BGRA8_UNORM: return 4; default: UNIMPLEMENTED_MSG("Unimplemented render target format {}", static_cast<u32>(format)); diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index a32148ecd..58501ca8b 100644 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h @@ -18,6 +18,8 @@ enum class RenderTargetFormat : u32 { RGBA32_FLOAT = 0xC0, RGBA32_UINT = 0xC2, RGBA16_FLOAT = 0xCA, + RG32_FLOAT = 0xCB, + BGRA8_UNORM = 0xCF, RGB10_A2_UNORM = 0xD1, RGBA8_UNORM = 0xD5, RGBA8_SRGB = 0xD6, diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 56d9c575b..5d5ad84b7 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -601,7 +601,6 @@ void RasterizerOpenGL::SamplerInfo::Create() { sampler.Create(); mag_filter = min_filter = Tegra::Texture::TextureFilter::Linear; wrap_u = wrap_v = Tegra::Texture::WrapMode::Wrap; - border_color_r = border_color_g = border_color_b = border_color_a = 0; // default is GL_LINEAR_MIPMAP_LINEAR glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -630,8 +629,12 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr } if (wrap_u == Tegra::Texture::WrapMode::Border || wrap_v == Tegra::Texture::WrapMode::Border) { - // TODO(Subv): Implement border color - ASSERT(false); + const GLvec4 new_border_color = {{config.border_color_r, config.border_color_g, + config.border_color_b, config.border_color_a}}; + if (border_color != new_border_color) { + border_color = new_border_color; + glSamplerParameterfv(s, GL_TEXTURE_BORDER_COLOR, border_color.data()); + } } } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index c406142e4..ab06e2d95 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -77,10 +77,7 @@ private: Tegra::Texture::TextureFilter min_filter; Tegra::Texture::WrapMode wrap_u; Tegra::Texture::WrapMode wrap_v; - u32 border_color_r; - u32 border_color_g; - u32 border_color_b; - u32 border_color_a; + GLvec4 border_color; }; /// Configures the color and depth framebuffer states and returns the dirty <Color, Depth> diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 28f0bc379..8f99864a0 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -38,7 +38,8 @@ struct FormatTuple { params.addr = config.tic.Address(); params.is_tiled = config.tic.IsTiled(); params.block_height = params.is_tiled ? config.tic.BlockHeight() : 0, - params.pixel_format = PixelFormatFromTextureFormat(config.tic.format); + params.pixel_format = + PixelFormatFromTextureFormat(config.tic.format, config.tic.r_type.Value()); params.component_type = ComponentTypeFromTexture(config.tic.r_type.Value()); params.type = GetFormatType(params.pixel_format); params.width = Common::AlignUp(config.tic.Width(), GetCompressionFactor(params.pixel_format)); @@ -106,6 +107,9 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form true}, // BC7U {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_4X4 {GL_RG8, GL_RG, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // G8R8 + {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // BGRA8 + {GL_RGBA32F, GL_RGBA, GL_FLOAT, ComponentType::Float, false}, // RGBA32F + {GL_RG32F, GL_RG, GL_FLOAT, ComponentType::Float, false}, // RG32F // DepthStencil formats {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, ComponentType::UNorm, @@ -197,9 +201,10 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr), MortonCopy<true, PixelFormat::DXT1>, MortonCopy<true, PixelFormat::DXT23>, MortonCopy<true, PixelFormat::DXT45>, MortonCopy<true, PixelFormat::DXN1>, MortonCopy<true, PixelFormat::BC7U>, MortonCopy<true, PixelFormat::ASTC_2D_4X4>, - MortonCopy<true, PixelFormat::G8R8>, MortonCopy<true, PixelFormat::Z24S8>, - MortonCopy<true, PixelFormat::S8Z24>, MortonCopy<true, PixelFormat::Z32F>, - MortonCopy<true, PixelFormat::Z16>, + MortonCopy<true, PixelFormat::G8R8>, MortonCopy<true, PixelFormat::BGRA8>, + MortonCopy<true, PixelFormat::RGBA32F>, MortonCopy<true, PixelFormat::RG32F>, + MortonCopy<true, PixelFormat::Z24S8>, MortonCopy<true, PixelFormat::S8Z24>, + MortonCopy<true, PixelFormat::Z32F>, MortonCopy<true, PixelFormat::Z16>, }; static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr), @@ -213,7 +218,7 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr), MortonCopy<false, PixelFormat::RGBA16F>, MortonCopy<false, PixelFormat::R11FG11FB10F>, MortonCopy<false, PixelFormat::RGBA32UI>, - // TODO(Subv): Swizzling the DXT1/DXT23/DXT45/DXN1/BC7U formats is not yet supported + // TODO(Subv): Swizzling DXT1/DXT23/DXT45/DXN1/BC7U/ASTC_2D_4X4 formats is not supported nullptr, nullptr, nullptr, @@ -221,6 +226,9 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr), nullptr, nullptr, MortonCopy<false, PixelFormat::G8R8>, + MortonCopy<false, PixelFormat::BGRA8>, + MortonCopy<false, PixelFormat::RGBA32F>, + MortonCopy<false, PixelFormat::RG32F>, MortonCopy<false, PixelFormat::Z24S8>, MortonCopy<false, PixelFormat::S8Z24>, MortonCopy<false, PixelFormat::Z32F>, diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index b084c4db4..23efbe67c 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -37,14 +37,17 @@ struct SurfaceParams { BC7U = 12, ASTC_2D_4X4 = 13, G8R8 = 14, + BGRA8 = 15, + RGBA32F = 16, + RG32F = 17, MaxColorFormat, // DepthStencil formats - Z24S8 = 15, - S8Z24 = 16, - Z32F = 17, - Z16 = 18, + Z24S8 = 18, + S8Z24 = 19, + Z32F = 20, + Z16 = 21, MaxDepthStencilFormat, @@ -97,6 +100,9 @@ struct SurfaceParams { 4, // BC7U 4, // ASTC_2D_4X4 1, // G8R8 + 1, // BGRA8 + 1, // RGBA32F + 1, // RG32F 1, // Z24S8 1, // S8Z24 1, // Z32F @@ -127,6 +133,9 @@ struct SurfaceParams { 128, // BC7U 32, // ASTC_2D_4X4 16, // G8R8 + 32, // BGRA8 + 128, // RGBA32F + 64, // RG32F 32, // Z24S8 32, // S8Z24 32, // Z32F @@ -162,10 +171,16 @@ struct SurfaceParams { case Tegra::RenderTargetFormat::RGBA8_UNORM: case Tegra::RenderTargetFormat::RGBA8_SRGB: return PixelFormat::ABGR8; + case Tegra::RenderTargetFormat::BGRA8_UNORM: + return PixelFormat::BGRA8; case Tegra::RenderTargetFormat::RGB10_A2_UNORM: return PixelFormat::A2B10G10R10; case Tegra::RenderTargetFormat::RGBA16_FLOAT: return PixelFormat::RGBA16F; + case Tegra::RenderTargetFormat::RGBA32_FLOAT: + return PixelFormat::RGBA32F; + case Tegra::RenderTargetFormat::RG32_FLOAT: + return PixelFormat::RG32F; case Tegra::RenderTargetFormat::R11G11B10_FLOAT: return PixelFormat::R11FG11FB10F; case Tegra::RenderTargetFormat::RGBA32_UINT: @@ -176,7 +191,8 @@ struct SurfaceParams { } } - static PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format) { + static PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format, + Tegra::Texture::ComponentType component_type) { // TODO(Subv): Properly implement this switch (format) { case Tegra::Texture::TextureFormat::A8R8G8B8: @@ -196,7 +212,17 @@ struct SurfaceParams { case Tegra::Texture::TextureFormat::BF10GF11RF11: return PixelFormat::R11FG11FB10F; case Tegra::Texture::TextureFormat::R32_G32_B32_A32: - return PixelFormat::RGBA32UI; + switch (component_type) { + case Tegra::Texture::ComponentType::FLOAT: + return PixelFormat::RGBA32F; + case Tegra::Texture::ComponentType::UINT: + return PixelFormat::RGBA32UI; + } + LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", + static_cast<u32>(component_type)); + UNREACHABLE(); + case Tegra::Texture::TextureFormat::R32_G32: + return PixelFormat::RG32F; case Tegra::Texture::TextureFormat::DXT1: return PixelFormat::DXT1; case Tegra::Texture::TextureFormat::DXT23: @@ -210,7 +236,8 @@ struct SurfaceParams { case Tegra::Texture::TextureFormat::ASTC_2D_4X4: return PixelFormat::ASTC_2D_4X4; default: - LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); + LOG_CRITICAL(HW_GPU, "Unimplemented format={}, component_type={}", + static_cast<u32>(format), static_cast<u32>(component_type)); UNREACHABLE(); } } @@ -248,7 +275,16 @@ struct SurfaceParams { return Tegra::Texture::TextureFormat::BC7U; case PixelFormat::ASTC_2D_4X4: return Tegra::Texture::TextureFormat::ASTC_2D_4X4; + case PixelFormat::BGRA8: + // TODO(bunnei): This is fine for unswizzling (since we just need the right component + // sizes), but could be a bug if we used this function in different ways. + return Tegra::Texture::TextureFormat::A8R8G8B8; + case PixelFormat::RGBA32F: + return Tegra::Texture::TextureFormat::R32_G32_B32_A32; + case PixelFormat::RG32F: + return Tegra::Texture::TextureFormat::R32_G32; default: + LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); UNREACHABLE(); } } @@ -264,6 +300,7 @@ struct SurfaceParams { case PixelFormat::Z16: return Tegra::DepthFormat::Z16_UNORM; default: + LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); UNREACHABLE(); } } @@ -273,6 +310,8 @@ struct SurfaceParams { switch (type) { case Tegra::Texture::ComponentType::UNORM: return ComponentType::UNorm; + case Tegra::Texture::ComponentType::FLOAT: + return ComponentType::Float; default: LOG_CRITICAL(HW_GPU, "Unimplemented component type={}", static_cast<u32>(type)); UNREACHABLE(); @@ -284,10 +323,13 @@ struct SurfaceParams { switch (format) { case Tegra::RenderTargetFormat::RGBA8_UNORM: case Tegra::RenderTargetFormat::RGBA8_SRGB: + case Tegra::RenderTargetFormat::BGRA8_UNORM: case Tegra::RenderTargetFormat::RGB10_A2_UNORM: return ComponentType::UNorm; case Tegra::RenderTargetFormat::RGBA16_FLOAT: case Tegra::RenderTargetFormat::R11G11B10_FLOAT: + case Tegra::RenderTargetFormat::RGBA32_FLOAT: + case Tegra::RenderTargetFormat::RG32_FLOAT: return ComponentType::Float; case Tegra::RenderTargetFormat::RGBA32_UINT: return ComponentType::UInt; diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 4e36b6de8..acf067050 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -488,6 +488,12 @@ private: */ void SetRegister(const Register& reg, u64 elem, const std::string& value, u64 dest_num_components, u64 value_num_components, u64 dest_elem) { + if (reg == Register::ZeroIndex) { + LOG_CRITICAL(HW_GPU, "Cannot set Register::ZeroIndex"); + UNREACHABLE(); + return; + } + std::string dest = GetRegister(reg, static_cast<u32>(dest_elem)); if (dest_num_components > 1) { dest += GetSwizzle(elem); @@ -750,8 +756,8 @@ private: } } - std::string WriteTexsInstruction(const Instruction& instr, const std::string& coord, - const std::string& texture) { + void WriteTexsInstruction(const Instruction& instr, const std::string& coord, + const std::string& texture) { // Add an extra scope and declare the texture coords inside to prevent // overwriting them in case they are used as outputs of the texs instruction. shader.AddLine('{'); @@ -804,7 +810,8 @@ private: return offset + 1; } - shader.AddLine("// " + std::to_string(offset) + ": " + opcode->GetName()); + shader.AddLine("// " + std::to_string(offset) + ": " + opcode->GetName() + " (" + + std::to_string(instr.value) + ')'); using Tegra::Shader::Pred; ASSERT_MSG(instr.pred.full_pred != Pred::NeverExecute, diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h index e19c3b280..16b1bd606 100644 --- a/src/video_core/renderer_opengl/maxwell_to_gl.h +++ b/src/video_core/renderer_opengl/maxwell_to_gl.h @@ -56,6 +56,9 @@ inline GLenum VertexType(Maxwell::VertexAttribute attrib) { return {}; } + case Maxwell::VertexAttribute::Type::UnsignedInt: + return GL_UNSIGNED_INT; + case Maxwell::VertexAttribute::Type::Float: return GL_FLOAT; } @@ -112,6 +115,8 @@ inline GLenum WrapMode(Tegra::Texture::WrapMode wrap_mode) { return GL_MIRRORED_REPEAT; case Tegra::Texture::WrapMode::ClampToEdge: return GL_CLAMP_TO_EDGE; + case Tegra::Texture::WrapMode::Border: + return GL_CLAMP_TO_BORDER; case Tegra::Texture::WrapMode::ClampOGL: // TODO(Subv): GL_CLAMP was removed as of OpenGL 3.1, to implement GL_CLAMP, we can use // GL_CLAMP_TO_BORDER to get the border color of the texture, and then sample the edge to diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index a3e67d105..e5e9e1898 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp @@ -72,6 +72,8 @@ u32 BytesPerPixel(TextureFormat format) { return 8; case TextureFormat::R32_G32_B32_A32: return 16; + case TextureFormat::R32_G32: + return 8; default: UNIMPLEMENTED_MSG("Format not implemented"); break; @@ -118,6 +120,7 @@ std::vector<u8> UnswizzleTexture(VAddr address, TextureFormat format, u32 width, case TextureFormat::G8R8: case TextureFormat::R16_G16_B16_A16: case TextureFormat::R32_G32_B32_A32: + case TextureFormat::R32_G32: case TextureFormat::BF10GF11RF11: case TextureFormat::ASTC_2D_4X4: CopySwizzledData(width, height, bytes_per_pixel, bytes_per_pixel, data, @@ -174,6 +177,7 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat case TextureFormat::G8R8: case TextureFormat::BF10GF11RF11: case TextureFormat::R32_G32_B32_A32: + case TextureFormat::R32_G32: // TODO(Subv): For the time being just forward the same data without any decoding. rgba_data = texture_data; break; diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h index d1c755033..c6bd2f4b9 100644 --- a/src/video_core/textures/texture.h +++ b/src/video_core/textures/texture.h @@ -242,10 +242,10 @@ struct TSCEntry { BitField<6, 2, TextureMipmapFilter> mip_filter; }; INSERT_PADDING_BYTES(8); - u32 border_color_r; - u32 border_color_g; - u32 border_color_b; - u32 border_color_a; + float border_color_r; + float border_color_g; + float border_color_b; + float border_color_a; }; static_assert(sizeof(TSCEntry) == 0x20, "TSCEntry has wrong size"); |