code: Use std::span where appropriate (#6658)

* code: Use std::span when possible

* code: Prefix memcpy and memcmp with std::
This commit is contained in:
GPUCode 2023-07-07 01:52:40 +03:00 committed by GitHub
parent 4ccd9f24fb
commit cf9bb90ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
106 changed files with 362 additions and 329 deletions

View file

@ -122,7 +122,7 @@ void OGLShader::Release() {
handle = 0;
}
void OGLProgram::Create(bool separable_program, const std::vector<GLuint>& shaders) {
void OGLProgram::Create(bool separable_program, std::span<const GLuint> shaders) {
if (handle != 0)
return;
@ -136,7 +136,8 @@ void OGLProgram::Create(std::string_view vert_shader, std::string_view frag_shad
frag.Create(frag_shader, GL_FRAGMENT_SHADER);
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
Create(false, {vert.handle, frag.handle});
const std::array shaders{vert.handle, frag.handle};
Create(false, shaders);
}
void OGLProgram::Release() {

View file

@ -4,6 +4,7 @@
#pragma once
#include <span>
#include <utility>
#include <vector>
#include <glad/glad.h>
@ -129,7 +130,7 @@ public:
}
/// Creates a new program from given shader objects
void Create(bool separable_program, const std::vector<GLuint>& shaders);
void Create(bool separable_program, std::span<const GLuint> shaders);
/// Creates a new program from given shader soruce code
void Create(std::string_view vert_shader, std::string_view frag_shader);

View file

@ -507,8 +507,8 @@ void ShaderDiskCache::SavePrecompiledHeaderToVirtualPrecompiledCache() {
void ShaderDiskCache::SaveVirtualPrecompiledFile() {
decompressed_precompiled_cache_offset = 0;
const std::vector<u8>& compressed = Common::Compression::CompressDataZSTDDefault(
decompressed_precompiled_cache.data(), decompressed_precompiled_cache.size());
const auto compressed =
Common::Compression::CompressDataZSTDDefault(decompressed_precompiled_cache);
const auto precompiled_path{GetPrecompiledPath()};

View file

@ -4,6 +4,7 @@
#include <algorithm>
#include <set>
#include <span>
#include <thread>
#include <unordered_map>
#include <variant>
@ -174,7 +175,7 @@ public:
OGLShader shader;
shader.Create(source, type);
OGLProgram& program = std::get<OGLProgram>(shader_or_program);
program.Create(true, {shader.handle});
program.Create(true, std::array{shader.handle});
SetShaderUniformBlockBindings(program.handle);
if (type == GL_FRAGMENT_SHADER) {
@ -449,7 +450,8 @@ void ShaderProgramManager::ApplyTo(OpenGLState& state) {
const u64 unique_identifier = impl->current.GetConfigHash();
OGLProgram& cached_program = impl->program_cache[unique_identifier];
if (cached_program.handle == 0) {
cached_program.Create(false, {impl->current.vs, impl->current.gs, impl->current.fs});
cached_program.Create(false,
std::array{impl->current.vs, impl->current.gs, impl->current.fs});
auto& disk_cache = impl->disk_cache;
disk_cache.SaveDumpToFile(unique_identifier, cached_program.handle,
VideoCore::g_hw_shader_accurate_mul);
@ -492,7 +494,7 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
std::vector<std::size_t> load_raws_index;
// Loads both decompiled and precompiled shaders from the cache. If either one is missing for
const auto LoadPrecompiledShader = [&](std::size_t begin, std::size_t end,
const std::vector<ShaderDiskCacheRaw>& raw_cache,
std::span<const ShaderDiskCacheRaw> raw_cache,
const ShaderDecompiledMap& decompiled_map,
const ShaderDumpsMap& dump_map) {
for (std::size_t i = begin; i < end; ++i) {

View file

@ -70,7 +70,7 @@ GLuint LoadShader(std::string_view source, GLenum type) {
return shader_id;
}
GLuint LoadProgram(bool separable_program, const std::vector<GLuint>& shaders) {
GLuint LoadProgram(bool separable_program, std::span<const GLuint> shaders) {
// Link the program
LOG_DEBUG(Render_OpenGL, "Linking program...");

View file

@ -4,7 +4,7 @@
#pragma once
#include <vector>
#include <span>
#include <glad/glad.h>
namespace OpenGL {
@ -37,6 +37,6 @@ GLuint LoadShader(std::string_view source, GLenum type);
* @param shaders ID of shaders to attach to the program
* @returns Handle of the newly created OpenGL program object
*/
GLuint LoadProgram(bool separable_program, const std::vector<GLuint>& shaders);
GLuint LoadProgram(bool separable_program, std::span<const GLuint> shaders);
} // namespace OpenGL