mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									4ccd9f24fb
								
							
						
					
					
						commit
						cf9bb90ae3
					
				
					 106 changed files with 362 additions and 329 deletions
				
			
		|  | @ -226,7 +226,7 @@ void DumpShader(const std::string& filename, const ShaderRegs& config, | |||
|     std::vector<nihstro::ConstantInfo> constant_table; | ||||
|     for (unsigned i = 0; i < setup.uniforms.b.size(); ++i) { | ||||
|         nihstro::ConstantInfo constant; | ||||
|         memset(&constant, 0, sizeof(constant)); | ||||
|         std::memset(&constant, 0, sizeof(constant)); | ||||
|         constant.type = nihstro::ConstantInfo::Bool; | ||||
|         constant.regid = i; | ||||
|         constant.b = setup.uniforms.b[i]; | ||||
|  | @ -234,7 +234,7 @@ void DumpShader(const std::string& filename, const ShaderRegs& config, | |||
|     } | ||||
|     for (unsigned i = 0; i < setup.uniforms.i.size(); ++i) { | ||||
|         nihstro::ConstantInfo constant; | ||||
|         memset(&constant, 0, sizeof(constant)); | ||||
|         std::memset(&constant, 0, sizeof(constant)); | ||||
|         constant.type = nihstro::ConstantInfo::Int; | ||||
|         constant.regid = i; | ||||
|         constant.i.x = setup.uniforms.i[i].x; | ||||
|  | @ -245,7 +245,7 @@ void DumpShader(const std::string& filename, const ShaderRegs& config, | |||
|     } | ||||
|     for (unsigned i = 0; i < sizeof(setup.uniforms.f) / sizeof(setup.uniforms.f[0]); ++i) { | ||||
|         nihstro::ConstantInfo constant; | ||||
|         memset(&constant, 0, sizeof(constant)); | ||||
|         std::memset(&constant, 0, sizeof(constant)); | ||||
|         constant.type = nihstro::ConstantInfo::Float; | ||||
|         constant.regid = i; | ||||
|         constant.f.x = nihstro::to_float24(setup.uniforms.f[i].x.ToFloat32()); | ||||
|  |  | |||
|  | @ -51,7 +51,7 @@ public: | |||
|         gx_command_history.emplace_back(); | ||||
|         Service::GSP::Command& cmd = gx_command_history.back(); | ||||
| 
 | ||||
|         memcpy(&cmd, command_data, sizeof(Service::GSP::Command)); | ||||
|         std::memcpy(&cmd, command_data, sizeof(Service::GSP::Command)); | ||||
| 
 | ||||
|         ForEachObserver([this](DebuggerObserver* observer) { | ||||
|             observer->GXCommandProcessed(static_cast<int>(this->gx_command_history.size())); | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ void Shutdown() { | |||
| template <typename T> | ||||
| void Zero(T& o) { | ||||
|     static_assert(std::is_trivial_v<T>, "It's undefined behavior to memset a non-trivial type"); | ||||
|     memset(&o, 0, sizeof(o)); | ||||
|     std::memset(&o, 0, sizeof(o)); | ||||
| } | ||||
| 
 | ||||
| State::State() : geometry_pipeline(*this) { | ||||
|  |  | |||
|  | @ -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() { | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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()}; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
|  | @ -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..."); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -181,7 +181,7 @@ public: | |||
|     } | ||||
| 
 | ||||
|     /// Returns the list of available extensions.
 | ||||
|     const std::vector<std::string>& GetAvailableExtensions() const { | ||||
|     std::span<const std::string> GetAvailableExtensions() const { | ||||
|         return available_extensions; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -191,7 +191,7 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in | |||
|         u8 alpha = 255; | ||||
|         if (has_alpha) { | ||||
|             u64_le packed_alpha; | ||||
|             memcpy(&packed_alpha, subtile_ptr, sizeof(u64)); | ||||
|             std::memcpy(&packed_alpha, subtile_ptr, sizeof(u64)); | ||||
|             subtile_ptr += sizeof(u64); | ||||
| 
 | ||||
|             alpha = | ||||
|  | @ -199,7 +199,7 @@ Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned in | |||
|         } | ||||
| 
 | ||||
|         u64_le subtile_data; | ||||
|         memcpy(&subtile_data, subtile_ptr, sizeof(u64)); | ||||
|         std::memcpy(&subtile_data, subtile_ptr, sizeof(u64)); | ||||
| 
 | ||||
|         return Common::MakeVec(SampleETC1Subtile(subtile_data, x, y), | ||||
|                                disable_alpha ? (u8)255 : alpha); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue