Compare commits

..

2 Commits

Author SHA1 Message Date
Lioncash
12ba80a86c gl_shader_gen: Make ShaderSetup's constructor explicit
Prevents implicit conversions.
2018-08-22 17:04:44 -04:00
Lioncash
1fd979f50a gl_shader_gen: Use a std::vector to represent program code instead of std::array
While convenient as a std::array, it's also quite a large set of data as
well (32KB). It being an array also means data cannot be std::moved. Any
situation where the code is being set or relocated means that a full
copy of that 32KB data must be done.

If we use a std::vector we do need to allocate on the heap, however, it
does allow us to std::move the data we have within the std::vector into
another std::vector instance, eliminating the need to always copy the
program data (as std::move in this case would just transfer the pointers
and bare necessities over to the new vector instance).
2018-08-22 17:04:44 -04:00
25 changed files with 64 additions and 152 deletions

2
externals/fmt vendored

View File

@@ -35,14 +35,6 @@ static constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONT
std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"),
std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf")};
static constexpr std::array<const char*, 7> SHARED_FONTS_TTF{"FontStandard.ttf",
"FontChineseSimplified.ttf",
"FontExtendedChineseSimplified.ttf",
"FontChineseTraditional.ttf",
"FontKorean.ttf",
"FontNintendoExtended.ttf",
"FontNintendoExtended2.ttf"};
// The below data is specific to shared font data dumped from Switch on f/w 2.2
// Virtual address and offsets/sizes likely will vary by dump
static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL};
@@ -84,17 +76,6 @@ void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, s
offset += transformed_font.size() * sizeof(u32);
}
static void EncryptSharedFont(const std::vector<u8>& input, std::vector<u8>& output,
size_t& offset) {
ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!");
const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT;
std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header
const u32 ENC_SIZE = static_cast<u32>(input.size()) ^ KEY;
std::memcpy(output.data() + offset + sizeof(u32), &ENC_SIZE, sizeof(u32));
std::memcpy(output.data() + offset + (sizeof(u32) * 2), input.data(), input.size());
offset += input.size() + (sizeof(u32) * 2);
}
static u32 GetU32Swapped(const u8* data) {
u32 value;
std::memcpy(&value, data, sizeof(value));
@@ -128,10 +109,10 @@ PL_U::PL_U() : ServiceFramework("pl:u") {
RegisterHandlers(functions);
// Attempt to load shared font data from disk
const auto nand = FileSystem::GetSystemNANDContents();
size_t offset = 0;
// Rebuild shared fonts from data ncas
if (nand->HasEntry(static_cast<u64>(FontArchives::Standard),
FileSys::ContentRecordType::Data)) {
size_t offset = 0;
shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE);
for (auto font : SHARED_FONTS) {
const auto nca =
@@ -171,45 +152,18 @@ PL_U::PL_U() : ServiceFramework("pl:u") {
DecryptSharedFont(font_data_u32, *shared_font, offset);
SHARED_FONT_REGIONS.push_back(region);
}
} else {
shared_font = std::make_shared<std::vector<u8>>(
SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size
const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir);
const std::string filepath{user_path + SHARED_FONT};
const std::string filepath{FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) +
SHARED_FONT};
// Create path if not already created
if (!FileUtil::CreateFullPath(filepath)) {
LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath);
return;
}
bool using_ttf = false;
for (const char* font_ttf : SHARED_FONTS_TTF) {
if (FileUtil::Exists(user_path + font_ttf)) {
using_ttf = true;
FileUtil::IOFile file(user_path + font_ttf, "rb");
if (file.IsOpen()) {
std::vector<u8> ttf_bytes(file.GetSize());
file.ReadBytes<u8>(ttf_bytes.data(), ttf_bytes.size());
FontRegion region{
static_cast<u32>(offset + 8),
static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account
// for the header
EncryptSharedFont(ttf_bytes, *shared_font, offset);
SHARED_FONT_REGIONS.push_back(region);
} else {
LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf);
}
} else if (using_ttf) {
LOG_WARNING(Service_NS, "Unable to find font: {}", font_ttf);
}
}
if (using_ttf)
return;
FileUtil::IOFile file(filepath, "rb");
shared_font = std::make_shared<std::vector<u8>>(
SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size
if (file.IsOpen()) {
// Read shared font data
ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE);

View File

@@ -25,8 +25,6 @@
#include "video_core/renderer_opengl/renderer_opengl.h"
#include "video_core/video_core.h"
namespace OpenGL {
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
using PixelFormat = SurfaceParams::PixelFormat;
using SurfaceType = SurfaceParams::SurfaceType;
@@ -181,7 +179,7 @@ static GLShader::ProgramCode GetShaderProgramCode(Maxwell::ShaderProgram program
auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
// Fetch program code from memory
GLShader::ProgramCode program_code;
GLShader::ProgramCode program_code(GLShader::MAX_PROGRAM_CODE_LENGTH);
auto& shader_config = gpu.regs.shader_config[static_cast<size_t>(program)];
const u64 gpu_address{gpu.regs.code_address.CodeAddress() + shader_config.offset};
const boost::optional<VAddr> cpu_address{gpu.memory_manager.GpuToCpuAddress(gpu_address)};
@@ -876,5 +874,3 @@ void RasterizerOpenGL::SyncLogicOpState() {
state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation);
}
} // namespace OpenGL

View File

@@ -22,14 +22,12 @@
#include "video_core/renderer_opengl/gl_state.h"
#include "video_core/renderer_opengl/gl_stream_buffer.h"
struct ScreenInfo;
namespace Core::Frontend {
class EmuWindow;
}
namespace OpenGL {
struct ScreenInfo;
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
public:
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& renderer, ScreenInfo& info);
@@ -186,5 +184,3 @@ private:
enum class AccelDraw { Disabled, Arrays, Indexed };
AccelDraw accelerate_draw = AccelDraw::Disabled;
};
} // namespace OpenGL

View File

@@ -19,8 +19,6 @@
#include "video_core/textures/decoders.h"
#include "video_core/utils.h"
namespace OpenGL {
using SurfaceType = SurfaceParams::SurfaceType;
using PixelFormat = SurfaceParams::PixelFormat;
using ComponentType = SurfaceParams::ComponentType;
@@ -969,5 +967,3 @@ void RasterizerCacheOpenGL::UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 siz
if (delta < 0)
cached_pages.add({pages_interval, delta});
}
} // namespace OpenGL

View File

@@ -16,8 +16,6 @@
#include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/textures/texture.h"
namespace OpenGL {
class CachedSurface;
using Surface = std::shared_ptr<CachedSurface>;
using SurfaceSurfaceRect_Tuple = std::tuple<Surface, Surface, MathUtil::Rectangle<u32>>;
@@ -761,5 +759,3 @@ private:
OGLFramebuffer read_framebuffer;
OGLFramebuffer draw_framebuffer;
};
} // namespace OpenGL

View File

@@ -10,8 +10,6 @@
#include "video_core/renderer_opengl/gl_shader_util.h"
#include "video_core/renderer_opengl/gl_state.h"
namespace OpenGL {
class OGLTexture : private NonCopyable {
public:
OGLTexture() = default;
@@ -333,5 +331,3 @@ public:
GLuint handle = 0;
};
} // namespace OpenGL

View File

@@ -15,7 +15,7 @@
#include "video_core/renderer_opengl/gl_rasterizer.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
namespace OpenGL::GLShader::Decompiler {
namespace GLShader::Decompiler {
using Tegra::Shader::Attribute;
using Tegra::Shader::Instruction;
@@ -2176,4 +2176,4 @@ boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code,
return boost::none;
}
} // namespace OpenGL::GLShader::Decompiler
} // namespace GLShader::Decompiler

View File

@@ -12,7 +12,7 @@
#include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_opengl/gl_shader_gen.h"
namespace OpenGL::GLShader::Decompiler {
namespace GLShader::Decompiler {
using Tegra::Engines::Maxwell3D;
@@ -22,4 +22,4 @@ boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code,
Maxwell3D::Regs::ShaderStage stage,
const std::string& suffix);
} // namespace OpenGL::GLShader::Decompiler
} // namespace GLShader::Decompiler

View File

@@ -7,7 +7,7 @@
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
#include "video_core/renderer_opengl/gl_shader_gen.h"
namespace OpenGL::GLShader {
namespace GLShader {
using Tegra::Engines::Maxwell3D;
@@ -103,4 +103,4 @@ void main() {
return {out, program.second};
}
} // namespace OpenGL::GLShader
} // namespace GLShader

View File

@@ -9,14 +9,14 @@
#include <type_traits>
#include <utility>
#include <vector>
#include <boost/functional/hash.hpp>
#include "common/common_types.h"
#include "common/hash.h"
namespace OpenGL::GLShader {
namespace GLShader {
constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000};
using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>;
using ProgramCode = std::vector<u64>;
class ConstBufferEntry {
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
@@ -115,8 +115,8 @@ struct ShaderEntries {
using ProgramResult = std::pair<std::string, ShaderEntries>;
struct ShaderSetup {
ShaderSetup(const ProgramCode& program_code) {
program.code = program_code;
explicit ShaderSetup(ProgramCode program_code) {
program.code = std::move(program_code);
}
struct {
@@ -135,8 +135,8 @@ struct ShaderSetup {
}
/// Used in scenarios where we have a dual vertex shaders
void SetProgramB(const ProgramCode& program_b) {
program.code_b = program_b;
void SetProgramB(ProgramCode program_b) {
program.code_b = std::move(program_b);
has_program_b = true;
}
@@ -146,13 +146,18 @@ struct ShaderSetup {
private:
u64 GetNewHash() const {
size_t hash = 0;
const u64 hash_a = Common::ComputeHash64(program.code.data(), program.code.size());
boost::hash_combine(hash, hash_a);
if (has_program_b) {
// Compute hash over dual shader programs
return Common::ComputeHash64(&program, sizeof(program));
} else {
// Compute hash over a single shader program
return Common::ComputeHash64(&program.code, program.code.size());
const u64 hash_b = Common::ComputeHash64(program.code_b.data(), program.code_b.size());
boost::hash_combine(hash, hash_b);
}
return hash;
}
u64 program_code_hash{};
@@ -191,20 +196,20 @@ ProgramResult GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConf
*/
ProgramResult GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config);
} // namespace OpenGL::GLShader
} // namespace GLShader
namespace std {
template <>
struct hash<OpenGL::GLShader::MaxwellVSConfig> {
size_t operator()(const OpenGL::GLShader::MaxwellVSConfig& k) const {
struct hash<GLShader::MaxwellVSConfig> {
size_t operator()(const GLShader::MaxwellVSConfig& k) const {
return k.Hash();
}
};
template <>
struct hash<OpenGL::GLShader::MaxwellFSConfig> {
size_t operator()(const OpenGL::GLShader::MaxwellFSConfig& k) const {
struct hash<GLShader::MaxwellFSConfig> {
size_t operator()(const GLShader::MaxwellFSConfig& k) const {
return k.Hash();
}
};

View File

@@ -7,7 +7,7 @@
#include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_opengl/gl_shader_manager.h"
namespace OpenGL::GLShader {
namespace GLShader {
namespace Impl {
static void SetShaderUniformBlockBinding(GLuint shader, const char* name,
@@ -49,4 +49,4 @@ void MaxwellUniformData::SetFromRegs(const Maxwell3D::State::ShaderStageInfo& sh
instance_id[0] = state.current_instance;
}
} // namespace OpenGL::GLShader
} // namespace GLShader

View File

@@ -12,7 +12,7 @@
#include "video_core/renderer_opengl/gl_shader_gen.h"
#include "video_core/renderer_opengl/maxwell_to_gl.h"
namespace OpenGL::GLShader {
namespace GLShader {
/// Number of OpenGL texture samplers that can be used in the fragment shader
static constexpr size_t NumTextureSamplers = 32;
@@ -171,4 +171,4 @@ private:
OGLPipeline pipeline;
};
} // namespace OpenGL::GLShader
} // namespace GLShader

View File

@@ -8,7 +8,7 @@
#include "common/logging/log.h"
#include "video_core/renderer_opengl/gl_shader_util.h"
namespace OpenGL::GLShader {
namespace GLShader {
GLuint LoadShader(const char* source, GLenum type) {
const char* debug_type;
@@ -47,4 +47,4 @@ GLuint LoadShader(const char* source, GLenum type) {
return shader_id;
}
} // namespace OpenGL::GLShader
} // namespace GLShader

View File

@@ -10,7 +10,7 @@
#include "common/assert.h"
#include "common/logging/log.h"
namespace OpenGL::GLShader {
namespace GLShader {
/**
* Utility function to log the source code of a list of shaders.
@@ -89,4 +89,4 @@ GLuint LoadProgram(bool separable_program, T... shaders) {
return program_id;
}
} // namespace OpenGL::GLShader
} // namespace GLShader

View File

@@ -7,8 +7,6 @@
#include "common/logging/log.h"
#include "video_core/renderer_opengl/gl_state.h"
namespace OpenGL {
OpenGLState OpenGLState::cur_state;
OpenGLState::OpenGLState() {
@@ -340,5 +338,3 @@ OpenGLState& OpenGLState::ResetFramebuffer(GLuint handle) {
}
return *this;
}
} // namespace OpenGL

View File

@@ -9,8 +9,6 @@
#include "video_core/engines/maxwell_3d.h"
namespace OpenGL {
using Regs = Tegra::Engines::Maxwell3D::Regs;
namespace TextureUnits {
@@ -165,5 +163,3 @@ public:
private:
static OpenGLState cur_state;
};
} // namespace OpenGL

View File

@@ -9,8 +9,6 @@
#include "video_core/renderer_opengl/gl_state.h"
#include "video_core/renderer_opengl/gl_stream_buffer.h"
namespace OpenGL {
OGLStreamBuffer::OGLStreamBuffer(GLenum target, GLsizeiptr size, bool prefer_coherent)
: gl_target(target), buffer_size(size) {
gl_buffer.Create();
@@ -99,5 +97,3 @@ void OGLStreamBuffer::Unmap(GLsizeiptr size) {
buffer_pos += size;
}
} // namespace OpenGL

View File

@@ -9,8 +9,6 @@
#include "common/common_types.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"
namespace OpenGL {
class OGLStreamBuffer : private NonCopyable {
public:
explicit OGLStreamBuffer(GLenum target, GLsizeiptr size, bool prefer_coherent = false);
@@ -44,5 +42,3 @@ private:
GLsizeiptr mapped_size = 0;
u8* mapped_ptr = nullptr;
};
} // namespace OpenGL

View File

@@ -10,8 +10,6 @@
#include "common/logging/log.h"
#include "video_core/engines/maxwell_3d.h"
namespace OpenGL {
using GLvec2 = std::array<GLfloat, 2>;
using GLvec3 = std::array<GLfloat, 3>;
using GLvec4 = std::array<GLfloat, 4>;
@@ -362,4 +360,3 @@ inline GLenum LogicOp(Maxwell::LogicOperation operation) {
}
} // namespace MaxwellToGL
} // namespace OpenGL

View File

@@ -20,8 +20,6 @@
#include "video_core/renderer_opengl/renderer_opengl.h"
#include "video_core/utils.h"
namespace OpenGL {
static const char vertex_shader[] = R"(
#version 150 core
@@ -478,5 +476,3 @@ bool RendererOpenGL::Init() {
/// Shutdown the renderer
void RendererOpenGL::ShutDown() {}
} // namespace OpenGL

View File

@@ -16,8 +16,6 @@ namespace Core::Frontend {
class EmuWindow;
}
namespace OpenGL {
/// Structure used for storing information about the textures for the Switch screen
struct TextureInfo {
OGLTexture resource;
@@ -100,5 +98,3 @@ private:
Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags;
MathUtil::Rectangle<int> framebuffer_crop_rect;
};
} // namespace OpenGL

View File

@@ -10,7 +10,7 @@
namespace VideoCore {
std::unique_ptr<RendererBase> CreateRenderer(Core::Frontend::EmuWindow& emu_window) {
return std::make_unique<OpenGL::RendererOpenGL>(emu_window);
return std::make_unique<RendererOpenGL>(emu_window);
}
} // namespace VideoCore

View File

@@ -29,24 +29,6 @@
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<layout class="QVBoxLayout" name="buttonMiscMinusVerticalLayout">
<item>
<widget class="QLabel" name="labelMinus">
<property name="text">
<string>Minus:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonMinus">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="buttonMiscPlusVerticalLayout">
<item>
<widget class="QLabel" name="labelPlus">
@@ -64,6 +46,24 @@
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="buttonMiscMinusVerticalLayout">
<item>
<widget class="QLabel" name="labelMinus">
<property name="text">
<string>Minus:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonMinus">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="buttonMiscHomeVerticalLayout">
<item>