diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_resource_manager.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp index c10863337..161318c5f 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.cpp +++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp | |||
| @@ -5,21 +5,31 @@ | |||
| 5 | #include <utility> | 5 | #include <utility> |
| 6 | #include <glad/glad.h> | 6 | #include <glad/glad.h> |
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/microprofile.h" | ||
| 8 | #include "video_core/renderer_opengl/gl_resource_manager.h" | 9 | #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_shader_util.h" |
| 10 | #include "video_core/renderer_opengl/gl_state.h" | 11 | #include "video_core/renderer_opengl/gl_state.h" |
| 11 | 12 | ||
| 13 | MICROPROFILE_DEFINE(OpenGL_ResourceCreation, "OpenGL", "Resource Creation", | ||
| 14 | MP_RGB(128, 128, 192)); | ||
| 15 | MICROPROFILE_DEFINE(OpenGL_ResourceDeletion, "OpenGL", "Resource Deletion", | ||
| 16 | MP_RGB(128, 128, 192)); | ||
| 17 | |||
| 12 | namespace OpenGL { | 18 | namespace OpenGL { |
| 13 | 19 | ||
| 14 | void OGLTexture::Create() { | 20 | void OGLTexture::Create() { |
| 15 | if (handle != 0) | 21 | if (handle != 0) |
| 16 | return; | 22 | return; |
| 23 | |||
| 24 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 17 | glGenTextures(1, &handle); | 25 | glGenTextures(1, &handle); |
| 18 | } | 26 | } |
| 19 | 27 | ||
| 20 | void OGLTexture::Release() { | 28 | void OGLTexture::Release() { |
| 21 | if (handle == 0) | 29 | if (handle == 0) |
| 22 | return; | 30 | return; |
| 31 | |||
| 32 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 23 | glDeleteTextures(1, &handle); | 33 | glDeleteTextures(1, &handle); |
| 24 | OpenGLState::GetCurState().UnbindTexture(handle).Apply(); | 34 | OpenGLState::GetCurState().UnbindTexture(handle).Apply(); |
| 25 | handle = 0; | 35 | handle = 0; |
| @@ -28,12 +38,16 @@ void OGLTexture::Release() { | |||
| 28 | void OGLSampler::Create() { | 38 | void OGLSampler::Create() { |
| 29 | if (handle != 0) | 39 | if (handle != 0) |
| 30 | return; | 40 | return; |
| 41 | |||
| 42 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 31 | glGenSamplers(1, &handle); | 43 | glGenSamplers(1, &handle); |
| 32 | } | 44 | } |
| 33 | 45 | ||
| 34 | void OGLSampler::Release() { | 46 | void OGLSampler::Release() { |
| 35 | if (handle == 0) | 47 | if (handle == 0) |
| 36 | return; | 48 | return; |
| 49 | |||
| 50 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 37 | glDeleteSamplers(1, &handle); | 51 | glDeleteSamplers(1, &handle); |
| 38 | OpenGLState::GetCurState().ResetSampler(handle).Apply(); | 52 | OpenGLState::GetCurState().ResetSampler(handle).Apply(); |
| 39 | handle = 0; | 53 | handle = 0; |
| @@ -44,12 +58,16 @@ void OGLShader::Create(const char* source, GLenum type) { | |||
| 44 | return; | 58 | return; |
| 45 | if (source == nullptr) | 59 | if (source == nullptr) |
| 46 | return; | 60 | return; |
| 61 | |||
| 62 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 47 | handle = GLShader::LoadShader(source, type); | 63 | handle = GLShader::LoadShader(source, type); |
| 48 | } | 64 | } |
| 49 | 65 | ||
| 50 | void OGLShader::Release() { | 66 | void OGLShader::Release() { |
| 51 | if (handle == 0) | 67 | if (handle == 0) |
| 52 | return; | 68 | return; |
| 69 | |||
| 70 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 53 | glDeleteShader(handle); | 71 | glDeleteShader(handle); |
| 54 | handle = 0; | 72 | handle = 0; |
| 55 | } | 73 | } |
| @@ -63,12 +81,16 @@ void OGLProgram::CreateFromSource(const char* vert_shader, const char* geo_shade | |||
| 63 | geo.Create(geo_shader, GL_GEOMETRY_SHADER); | 81 | geo.Create(geo_shader, GL_GEOMETRY_SHADER); |
| 64 | if (frag_shader) | 82 | if (frag_shader) |
| 65 | frag.Create(frag_shader, GL_FRAGMENT_SHADER); | 83 | frag.Create(frag_shader, GL_FRAGMENT_SHADER); |
| 84 | |||
| 85 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 66 | Create(separable_program, vert.handle, geo.handle, frag.handle); | 86 | Create(separable_program, vert.handle, geo.handle, frag.handle); |
| 67 | } | 87 | } |
| 68 | 88 | ||
| 69 | void OGLProgram::Release() { | 89 | void OGLProgram::Release() { |
| 70 | if (handle == 0) | 90 | if (handle == 0) |
| 71 | return; | 91 | return; |
| 92 | |||
| 93 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 72 | glDeleteProgram(handle); | 94 | glDeleteProgram(handle); |
| 73 | OpenGLState::GetCurState().ResetProgram(handle).Apply(); | 95 | OpenGLState::GetCurState().ResetProgram(handle).Apply(); |
| 74 | handle = 0; | 96 | handle = 0; |
| @@ -77,12 +99,16 @@ void OGLProgram::Release() { | |||
| 77 | void OGLPipeline::Create() { | 99 | void OGLPipeline::Create() { |
| 78 | if (handle != 0) | 100 | if (handle != 0) |
| 79 | return; | 101 | return; |
| 102 | |||
| 103 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 80 | glGenProgramPipelines(1, &handle); | 104 | glGenProgramPipelines(1, &handle); |
| 81 | } | 105 | } |
| 82 | 106 | ||
| 83 | void OGLPipeline::Release() { | 107 | void OGLPipeline::Release() { |
| 84 | if (handle == 0) | 108 | if (handle == 0) |
| 85 | return; | 109 | return; |
| 110 | |||
| 111 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 86 | glDeleteProgramPipelines(1, &handle); | 112 | glDeleteProgramPipelines(1, &handle); |
| 87 | OpenGLState::GetCurState().ResetPipeline(handle).Apply(); | 113 | OpenGLState::GetCurState().ResetPipeline(handle).Apply(); |
| 88 | handle = 0; | 114 | handle = 0; |
| @@ -91,12 +117,16 @@ void OGLPipeline::Release() { | |||
| 91 | void OGLBuffer::Create() { | 117 | void OGLBuffer::Create() { |
| 92 | if (handle != 0) | 118 | if (handle != 0) |
| 93 | return; | 119 | return; |
| 120 | |||
| 121 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 94 | glGenBuffers(1, &handle); | 122 | glGenBuffers(1, &handle); |
| 95 | } | 123 | } |
| 96 | 124 | ||
| 97 | void OGLBuffer::Release() { | 125 | void OGLBuffer::Release() { |
| 98 | if (handle == 0) | 126 | if (handle == 0) |
| 99 | return; | 127 | return; |
| 128 | |||
| 129 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 100 | glDeleteBuffers(1, &handle); | 130 | glDeleteBuffers(1, &handle); |
| 101 | OpenGLState::GetCurState().ResetBuffer(handle).Apply(); | 131 | OpenGLState::GetCurState().ResetBuffer(handle).Apply(); |
| 102 | handle = 0; | 132 | handle = 0; |
| @@ -105,12 +135,16 @@ void OGLBuffer::Release() { | |||
| 105 | void OGLSync::Create() { | 135 | void OGLSync::Create() { |
| 106 | if (handle != 0) | 136 | if (handle != 0) |
| 107 | return; | 137 | return; |
| 138 | |||
| 139 | // Don't profile here, this one is expected to happen ingame. | ||
| 108 | handle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | 140 | handle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
| 109 | } | 141 | } |
| 110 | 142 | ||
| 111 | void OGLSync::Release() { | 143 | void OGLSync::Release() { |
| 112 | if (handle == 0) | 144 | if (handle == 0) |
| 113 | return; | 145 | return; |
| 146 | |||
| 147 | // Don't profile here, this one is expected to happen ingame. | ||
| 114 | glDeleteSync(handle); | 148 | glDeleteSync(handle); |
| 115 | handle = 0; | 149 | handle = 0; |
| 116 | } | 150 | } |
| @@ -118,12 +152,16 @@ void OGLSync::Release() { | |||
| 118 | void OGLVertexArray::Create() { | 152 | void OGLVertexArray::Create() { |
| 119 | if (handle != 0) | 153 | if (handle != 0) |
| 120 | return; | 154 | return; |
| 155 | |||
| 156 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 121 | glGenVertexArrays(1, &handle); | 157 | glGenVertexArrays(1, &handle); |
| 122 | } | 158 | } |
| 123 | 159 | ||
| 124 | void OGLVertexArray::Release() { | 160 | void OGLVertexArray::Release() { |
| 125 | if (handle == 0) | 161 | if (handle == 0) |
| 126 | return; | 162 | return; |
| 163 | |||
| 164 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 127 | glDeleteVertexArrays(1, &handle); | 165 | glDeleteVertexArrays(1, &handle); |
| 128 | OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); | 166 | OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); |
| 129 | handle = 0; | 167 | handle = 0; |
| @@ -132,12 +170,16 @@ void OGLVertexArray::Release() { | |||
| 132 | void OGLFramebuffer::Create() { | 170 | void OGLFramebuffer::Create() { |
| 133 | if (handle != 0) | 171 | if (handle != 0) |
| 134 | return; | 172 | return; |
| 173 | |||
| 174 | MICROPROFILE_SCOPE(OpenGL_ResourceCreation); | ||
| 135 | glGenFramebuffers(1, &handle); | 175 | glGenFramebuffers(1, &handle); |
| 136 | } | 176 | } |
| 137 | 177 | ||
| 138 | void OGLFramebuffer::Release() { | 178 | void OGLFramebuffer::Release() { |
| 139 | if (handle == 0) | 179 | if (handle == 0) |
| 140 | return; | 180 | return; |
| 181 | |||
| 182 | MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); | ||
| 141 | glDeleteFramebuffers(1, &handle); | 183 | glDeleteFramebuffers(1, &handle); |
| 142 | OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); | 184 | OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); |
| 143 | handle = 0; | 185 | handle = 0; |