diff options
| author | 2018-11-06 11:43:17 -0500 | |
|---|---|---|
| committer | 2018-11-06 11:43:17 -0500 | |
| commit | dd321dc85f5ff4ee421b04f2d57ad17af85d90fb (patch) | |
| tree | fac9a98650484c3ce58ba60c468fee552a3fa845 | |
| parent | Merge pull request #1616 from FernandoS27/cube-array (diff) | |
| parent | gl_resource_manager: Split implementations in .cpp file. (diff) | |
| download | yuzu-dd321dc85f5ff4ee421b04f2d57ad17af85d90fb.tar.gz yuzu-dd321dc85f5ff4ee421b04f2d57ad17af85d90fb.tar.xz yuzu-dd321dc85f5ff4ee421b04f2d57ad17af85d90fb.zip | |
Merge pull request #1649 from degasus/split_resource_manager
gl_resource_manager: Split implementations in .cpp file.
| -rw-r--r-- | src/video_core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_resource_manager.cpp | 146 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_resource_manager.h | 132 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_manager.h | 1 |
5 files changed, 167 insertions, 114 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index ddb1a1d69..0b1cc1290 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -33,6 +33,7 @@ add_library(video_core STATIC | |||
| 33 | renderer_opengl/gl_rasterizer.h | 33 | renderer_opengl/gl_rasterizer.h |
| 34 | renderer_opengl/gl_rasterizer_cache.cpp | 34 | renderer_opengl/gl_rasterizer_cache.cpp |
| 35 | renderer_opengl/gl_rasterizer_cache.h | 35 | renderer_opengl/gl_rasterizer_cache.h |
| 36 | renderer_opengl/gl_resource_manager.cpp | ||
| 36 | renderer_opengl/gl_resource_manager.h | 37 | renderer_opengl/gl_resource_manager.h |
| 37 | renderer_opengl/gl_shader_cache.cpp | 38 | renderer_opengl/gl_shader_cache.cpp |
| 38 | renderer_opengl/gl_shader_cache.h | 39 | renderer_opengl/gl_shader_cache.h |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index dcbf009c0..7d970efa0 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "core/settings.h" | 16 | #include "core/settings.h" |
| 17 | #include "video_core/engines/maxwell_3d.h" | 17 | #include "video_core/engines/maxwell_3d.h" |
| 18 | #include "video_core/renderer_opengl/gl_rasterizer_cache.h" | 18 | #include "video_core/renderer_opengl/gl_rasterizer_cache.h" |
| 19 | #include "video_core/renderer_opengl/gl_state.h" | ||
| 19 | #include "video_core/renderer_opengl/utils.h" | 20 | #include "video_core/renderer_opengl/utils.h" |
| 20 | #include "video_core/surface.h" | 21 | #include "video_core/surface.h" |
| 21 | #include "video_core/textures/astc.h" | 22 | #include "video_core/textures/astc.h" |
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp new file mode 100644 index 000000000..c10863337 --- /dev/null +++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <utility> | ||
| 6 | #include <glad/glad.h> | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "video_core/renderer_opengl/gl_resource_manager.h" | ||
| 9 | #include "video_core/renderer_opengl/gl_shader_util.h" | ||
| 10 | #include "video_core/renderer_opengl/gl_state.h" | ||
| 11 | |||
| 12 | namespace OpenGL { | ||
| 13 | |||
| 14 | void OGLTexture::Create() { | ||
| 15 | if (handle != 0) | ||
| 16 | return; | ||
| 17 | glGenTextures(1, &handle); | ||
| 18 | } | ||
| 19 | |||
| 20 | void OGLTexture::Release() { | ||
| 21 | if (handle == 0) | ||
| 22 | return; | ||
| 23 | glDeleteTextures(1, &handle); | ||
| 24 | OpenGLState::GetCurState().UnbindTexture(handle).Apply(); | ||
| 25 | handle = 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | void OGLSampler::Create() { | ||
| 29 | if (handle != 0) | ||
| 30 | return; | ||
| 31 | glGenSamplers(1, &handle); | ||
| 32 | } | ||
| 33 | |||
| 34 | void OGLSampler::Release() { | ||
| 35 | if (handle == 0) | ||
| 36 | return; | ||
| 37 | glDeleteSamplers(1, &handle); | ||
| 38 | OpenGLState::GetCurState().ResetSampler(handle).Apply(); | ||
| 39 | handle = 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | void OGLShader::Create(const char* source, GLenum type) { | ||
| 43 | if (handle != 0) | ||
| 44 | return; | ||
| 45 | if (source == nullptr) | ||
| 46 | return; | ||
| 47 | handle = GLShader::LoadShader(source, type); | ||
| 48 | } | ||
| 49 | |||
| 50 | void OGLShader::Release() { | ||
| 51 | if (handle == 0) | ||
| 52 | return; | ||
| 53 | glDeleteShader(handle); | ||
| 54 | handle = 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | void OGLProgram::CreateFromSource(const char* vert_shader, const char* geo_shader, | ||
| 58 | const char* frag_shader, bool separable_program) { | ||
| 59 | OGLShader vert, geo, frag; | ||
| 60 | if (vert_shader) | ||
| 61 | vert.Create(vert_shader, GL_VERTEX_SHADER); | ||
| 62 | if (geo_shader) | ||
| 63 | geo.Create(geo_shader, GL_GEOMETRY_SHADER); | ||
| 64 | if (frag_shader) | ||
| 65 | frag.Create(frag_shader, GL_FRAGMENT_SHADER); | ||
| 66 | Create(separable_program, vert.handle, geo.handle, frag.handle); | ||
| 67 | } | ||
| 68 | |||
| 69 | void OGLProgram::Release() { | ||
| 70 | if (handle == 0) | ||
| 71 | return; | ||
| 72 | glDeleteProgram(handle); | ||
| 73 | OpenGLState::GetCurState().ResetProgram(handle).Apply(); | ||
| 74 | handle = 0; | ||
| 75 | } | ||
| 76 | |||
| 77 | void OGLPipeline::Create() { | ||
| 78 | if (handle != 0) | ||
| 79 | return; | ||
| 80 | glGenProgramPipelines(1, &handle); | ||
| 81 | } | ||
| 82 | |||
| 83 | void OGLPipeline::Release() { | ||
| 84 | if (handle == 0) | ||
| 85 | return; | ||
| 86 | glDeleteProgramPipelines(1, &handle); | ||
| 87 | OpenGLState::GetCurState().ResetPipeline(handle).Apply(); | ||
| 88 | handle = 0; | ||
| 89 | } | ||
| 90 | |||
| 91 | void OGLBuffer::Create() { | ||
| 92 | if (handle != 0) | ||
| 93 | return; | ||
| 94 | glGenBuffers(1, &handle); | ||
| 95 | } | ||
| 96 | |||
| 97 | void OGLBuffer::Release() { | ||
| 98 | if (handle == 0) | ||
| 99 | return; | ||
| 100 | glDeleteBuffers(1, &handle); | ||
| 101 | OpenGLState::GetCurState().ResetBuffer(handle).Apply(); | ||
| 102 | handle = 0; | ||
| 103 | } | ||
| 104 | |||
| 105 | void OGLSync::Create() { | ||
| 106 | if (handle != 0) | ||
| 107 | return; | ||
| 108 | handle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | ||
| 109 | } | ||
| 110 | |||
| 111 | void OGLSync::Release() { | ||
| 112 | if (handle == 0) | ||
| 113 | return; | ||
| 114 | glDeleteSync(handle); | ||
| 115 | handle = 0; | ||
| 116 | } | ||
| 117 | |||
| 118 | void OGLVertexArray::Create() { | ||
| 119 | if (handle != 0) | ||
| 120 | return; | ||
| 121 | glGenVertexArrays(1, &handle); | ||
| 122 | } | ||
| 123 | |||
| 124 | void OGLVertexArray::Release() { | ||
| 125 | if (handle == 0) | ||
| 126 | return; | ||
| 127 | glDeleteVertexArrays(1, &handle); | ||
| 128 | OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); | ||
| 129 | handle = 0; | ||
| 130 | } | ||
| 131 | |||
| 132 | void OGLFramebuffer::Create() { | ||
| 133 | if (handle != 0) | ||
| 134 | return; | ||
| 135 | glGenFramebuffers(1, &handle); | ||
| 136 | } | ||
| 137 | |||
| 138 | void OGLFramebuffer::Release() { | ||
| 139 | if (handle == 0) | ||
| 140 | return; | ||
| 141 | glDeleteFramebuffers(1, &handle); | ||
| 142 | OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); | ||
| 143 | handle = 0; | ||
| 144 | } | ||
| 145 | |||
| 146 | } // namespace OpenGL | ||
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index 3bc1b83b5..e33f1e973 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <glad/glad.h> | 8 | #include <glad/glad.h> |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "video_core/renderer_opengl/gl_shader_util.h" | 10 | #include "video_core/renderer_opengl/gl_shader_util.h" |
| 11 | #include "video_core/renderer_opengl/gl_state.h" | ||
| 12 | 11 | ||
| 13 | namespace OpenGL { | 12 | namespace OpenGL { |
| 14 | 13 | ||
| @@ -29,20 +28,10 @@ public: | |||
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | /// Creates a new internal OpenGL resource and stores the handle | 30 | /// Creates a new internal OpenGL resource and stores the handle |
| 32 | void Create() { | 31 | void Create(); |
| 33 | if (handle != 0) | ||
| 34 | return; | ||
| 35 | glGenTextures(1, &handle); | ||
| 36 | } | ||
| 37 | 32 | ||
| 38 | /// Deletes the internal OpenGL resource | 33 | /// Deletes the internal OpenGL resource |
| 39 | void Release() { | 34 | void Release(); |
| 40 | if (handle == 0) | ||
| 41 | return; | ||
| 42 | glDeleteTextures(1, &handle); | ||
| 43 | OpenGLState::GetCurState().UnbindTexture(handle).Apply(); | ||
| 44 | handle = 0; | ||
| 45 | } | ||
| 46 | 35 | ||
| 47 | GLuint handle = 0; | 36 | GLuint handle = 0; |
| 48 | }; | 37 | }; |
| @@ -64,20 +53,10 @@ public: | |||
| 64 | } | 53 | } |
| 65 | 54 | ||
| 66 | /// Creates a new internal OpenGL resource and stores the handle | 55 | /// Creates a new internal OpenGL resource and stores the handle |
| 67 | void Create() { | 56 | void Create(); |
| 68 | if (handle != 0) | ||
| 69 | return; | ||
| 70 | glGenSamplers(1, &handle); | ||
| 71 | } | ||
| 72 | 57 | ||
| 73 | /// Deletes the internal OpenGL resource | 58 | /// Deletes the internal OpenGL resource |
| 74 | void Release() { | 59 | void Release(); |
| 75 | if (handle == 0) | ||
| 76 | return; | ||
| 77 | glDeleteSamplers(1, &handle); | ||
| 78 | OpenGLState::GetCurState().ResetSampler(handle).Apply(); | ||
| 79 | handle = 0; | ||
| 80 | } | ||
| 81 | 60 | ||
| 82 | GLuint handle = 0; | 61 | GLuint handle = 0; |
| 83 | }; | 62 | }; |
| @@ -98,20 +77,9 @@ public: | |||
| 98 | return *this; | 77 | return *this; |
| 99 | } | 78 | } |
| 100 | 79 | ||
| 101 | void Create(const char* source, GLenum type) { | 80 | void Create(const char* source, GLenum type); |
| 102 | if (handle != 0) | ||
| 103 | return; | ||
| 104 | if (source == nullptr) | ||
| 105 | return; | ||
| 106 | handle = GLShader::LoadShader(source, type); | ||
| 107 | } | ||
| 108 | 81 | ||
| 109 | void Release() { | 82 | void Release(); |
| 110 | if (handle == 0) | ||
| 111 | return; | ||
| 112 | glDeleteShader(handle); | ||
| 113 | handle = 0; | ||
| 114 | } | ||
| 115 | 83 | ||
| 116 | GLuint handle = 0; | 84 | GLuint handle = 0; |
| 117 | }; | 85 | }; |
| @@ -141,25 +109,10 @@ public: | |||
| 141 | 109 | ||
| 142 | /// Creates a new internal OpenGL resource and stores the handle | 110 | /// Creates a new internal OpenGL resource and stores the handle |
| 143 | void CreateFromSource(const char* vert_shader, const char* geo_shader, const char* frag_shader, | 111 | void CreateFromSource(const char* vert_shader, const char* geo_shader, const char* frag_shader, |
| 144 | bool separable_program = false) { | 112 | bool separable_program = false); |
| 145 | OGLShader vert, geo, frag; | ||
| 146 | if (vert_shader) | ||
| 147 | vert.Create(vert_shader, GL_VERTEX_SHADER); | ||
| 148 | if (geo_shader) | ||
| 149 | geo.Create(geo_shader, GL_GEOMETRY_SHADER); | ||
| 150 | if (frag_shader) | ||
| 151 | frag.Create(frag_shader, GL_FRAGMENT_SHADER); | ||
| 152 | Create(separable_program, vert.handle, geo.handle, frag.handle); | ||
| 153 | } | ||
| 154 | 113 | ||
| 155 | /// Deletes the internal OpenGL resource | 114 | /// Deletes the internal OpenGL resource |
| 156 | void Release() { | 115 | void Release(); |
| 157 | if (handle == 0) | ||
| 158 | return; | ||
| 159 | glDeleteProgram(handle); | ||
| 160 | OpenGLState::GetCurState().ResetProgram(handle).Apply(); | ||
| 161 | handle = 0; | ||
| 162 | } | ||
| 163 | 116 | ||
| 164 | GLuint handle = 0; | 117 | GLuint handle = 0; |
| 165 | }; | 118 | }; |
| @@ -178,20 +131,10 @@ public: | |||
| 178 | } | 131 | } |
| 179 | 132 | ||
| 180 | /// Creates a new internal OpenGL resource and stores the handle | 133 | /// Creates a new internal OpenGL resource and stores the handle |
| 181 | void Create() { | 134 | void Create(); |
| 182 | if (handle != 0) | ||
| 183 | return; | ||
| 184 | glGenProgramPipelines(1, &handle); | ||
| 185 | } | ||
| 186 | 135 | ||
| 187 | /// Deletes the internal OpenGL resource | 136 | /// Deletes the internal OpenGL resource |
| 188 | void Release() { | 137 | void Release(); |
| 189 | if (handle == 0) | ||
| 190 | return; | ||
| 191 | glDeleteProgramPipelines(1, &handle); | ||
| 192 | OpenGLState::GetCurState().ResetPipeline(handle).Apply(); | ||
| 193 | handle = 0; | ||
| 194 | } | ||
| 195 | 138 | ||
| 196 | GLuint handle = 0; | 139 | GLuint handle = 0; |
| 197 | }; | 140 | }; |
| @@ -213,20 +156,10 @@ public: | |||
| 213 | } | 156 | } |
| 214 | 157 | ||
| 215 | /// Creates a new internal OpenGL resource and stores the handle | 158 | /// Creates a new internal OpenGL resource and stores the handle |
| 216 | void Create() { | 159 | void Create(); |
| 217 | if (handle != 0) | ||
| 218 | return; | ||
| 219 | glGenBuffers(1, &handle); | ||
| 220 | } | ||
| 221 | 160 | ||
| 222 | /// Deletes the internal OpenGL resource | 161 | /// Deletes the internal OpenGL resource |
| 223 | void Release() { | 162 | void Release(); |
| 224 | if (handle == 0) | ||
| 225 | return; | ||
| 226 | glDeleteBuffers(1, &handle); | ||
| 227 | OpenGLState::GetCurState().ResetBuffer(handle).Apply(); | ||
| 228 | handle = 0; | ||
| 229 | } | ||
| 230 | 163 | ||
| 231 | GLuint handle = 0; | 164 | GLuint handle = 0; |
| 232 | }; | 165 | }; |
| @@ -247,19 +180,10 @@ public: | |||
| 247 | } | 180 | } |
| 248 | 181 | ||
| 249 | /// Creates a new internal OpenGL resource and stores the handle | 182 | /// Creates a new internal OpenGL resource and stores the handle |
| 250 | void Create() { | 183 | void Create(); |
| 251 | if (handle != 0) | ||
| 252 | return; | ||
| 253 | handle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | ||
| 254 | } | ||
| 255 | 184 | ||
| 256 | /// Deletes the internal OpenGL resource | 185 | /// Deletes the internal OpenGL resource |
| 257 | void Release() { | 186 | void Release(); |
| 258 | if (handle == 0) | ||
| 259 | return; | ||
| 260 | glDeleteSync(handle); | ||
| 261 | handle = 0; | ||
| 262 | } | ||
| 263 | 187 | ||
| 264 | GLsync handle = 0; | 188 | GLsync handle = 0; |
| 265 | }; | 189 | }; |
| @@ -281,20 +205,10 @@ public: | |||
| 281 | } | 205 | } |
| 282 | 206 | ||
| 283 | /// Creates a new internal OpenGL resource and stores the handle | 207 | /// Creates a new internal OpenGL resource and stores the handle |
| 284 | void Create() { | 208 | void Create(); |
| 285 | if (handle != 0) | ||
| 286 | return; | ||
| 287 | glGenVertexArrays(1, &handle); | ||
| 288 | } | ||
| 289 | 209 | ||
| 290 | /// Deletes the internal OpenGL resource | 210 | /// Deletes the internal OpenGL resource |
| 291 | void Release() { | 211 | void Release(); |
| 292 | if (handle == 0) | ||
| 293 | return; | ||
| 294 | glDeleteVertexArrays(1, &handle); | ||
| 295 | OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); | ||
| 296 | handle = 0; | ||
| 297 | } | ||
| 298 | 212 | ||
| 299 | GLuint handle = 0; | 213 | GLuint handle = 0; |
| 300 | }; | 214 | }; |
| @@ -316,20 +230,10 @@ public: | |||
| 316 | } | 230 | } |
| 317 | 231 | ||
| 318 | /// Creates a new internal OpenGL resource and stores the handle | 232 | /// Creates a new internal OpenGL resource and stores the handle |
| 319 | void Create() { | 233 | void Create(); |
| 320 | if (handle != 0) | ||
| 321 | return; | ||
| 322 | glGenFramebuffers(1, &handle); | ||
| 323 | } | ||
| 324 | 234 | ||
| 325 | /// Deletes the internal OpenGL resource | 235 | /// Deletes the internal OpenGL resource |
| 326 | void Release() { | 236 | void Release(); |
| 327 | if (handle == 0) | ||
| 328 | return; | ||
| 329 | glDeleteFramebuffers(1, &handle); | ||
| 330 | OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); | ||
| 331 | handle = 0; | ||
| 332 | } | ||
| 333 | 237 | ||
| 334 | GLuint handle = 0; | 238 | GLuint handle = 0; |
| 335 | }; | 239 | }; |
diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index 36fe1f04c..2a069cdd8 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <glad/glad.h> | 7 | #include <glad/glad.h> |
| 8 | 8 | ||
| 9 | #include "video_core/renderer_opengl/gl_resource_manager.h" | 9 | #include "video_core/renderer_opengl/gl_resource_manager.h" |
| 10 | #include "video_core/renderer_opengl/gl_state.h" | ||
| 10 | #include "video_core/renderer_opengl/maxwell_to_gl.h" | 11 | #include "video_core/renderer_opengl/maxwell_to_gl.h" |
| 11 | 12 | ||
| 12 | namespace OpenGL::GLShader { | 13 | namespace OpenGL::GLShader { |