diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.h | 8 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/maxwell_to_gl.h | 4 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/util_shaders.cpp | 85 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/util_shaders.h | 19 |
5 files changed, 36 insertions, 82 deletions
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index b0aee6cc1..3ec78d866 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -461,7 +461,7 @@ bool TextureCacheRuntime::CanImageBeCopied(const Image& dst, const Image& src) { | |||
| 461 | if (dst.info.type == ImageType::e3D && dst.info.format == PixelFormat::BC4_UNORM) { | 461 | if (dst.info.type == ImageType::e3D && dst.info.format == PixelFormat::BC4_UNORM) { |
| 462 | return false; | 462 | return false; |
| 463 | } | 463 | } |
| 464 | if (IsPixelFormatBGR(dst.info.format) || IsPixelFormatBGR(src.info.format)) { | 464 | if (IsPixelFormatBGR(dst.info.format) != IsPixelFormatBGR(src.info.format)) { |
| 465 | return false; | 465 | return false; |
| 466 | } | 466 | } |
| 467 | return true; | 467 | return true; |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h index 4a4f6301c..990a8ddcb 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.h +++ b/src/video_core/renderer_opengl/gl_texture_cache.h | |||
| @@ -162,6 +162,14 @@ public: | |||
| 162 | return texture.handle; | 162 | return texture.handle; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | GLuint GlFormat() const noexcept { | ||
| 166 | return gl_format; | ||
| 167 | } | ||
| 168 | |||
| 169 | GLuint GlType() const noexcept { | ||
| 170 | return gl_type; | ||
| 171 | } | ||
| 172 | |||
| 165 | private: | 173 | private: |
| 166 | void CopyBufferToImage(const VideoCommon::BufferImageCopy& copy, size_t buffer_offset); | 174 | void CopyBufferToImage(const VideoCommon::BufferImageCopy& copy, size_t buffer_offset); |
| 167 | 175 | ||
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h index 672f94bfc..39158aa3e 100644 --- a/src/video_core/renderer_opengl/maxwell_to_gl.h +++ b/src/video_core/renderer_opengl/maxwell_to_gl.h | |||
| @@ -52,7 +52,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB | |||
| 52 | {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UFLOAT | 52 | {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UFLOAT |
| 53 | {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SFLOAT | 53 | {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SFLOAT |
| 54 | {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4_UNORM | 54 | {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4_UNORM |
| 55 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // B8G8R8A8_UNORM | 55 | {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, // B8G8R8A8_UNORM |
| 56 | {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // R32G32B32A32_FLOAT | 56 | {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // R32G32B32A32_FLOAT |
| 57 | {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // R32G32B32A32_SINT | 57 | {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // R32G32B32A32_SINT |
| 58 | {GL_RG32F, GL_RG, GL_FLOAT}, // R32G32_FLOAT | 58 | {GL_RG32F, GL_RG, GL_FLOAT}, // R32G32_FLOAT |
| @@ -81,7 +81,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB | |||
| 81 | {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8_UNORM | 81 | {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8_UNORM |
| 82 | {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5_UNORM | 82 | {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5_UNORM |
| 83 | {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4_UNORM | 83 | {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4_UNORM |
| 84 | {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, // B8G8R8A8_SRGB | 84 | {GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, // B8G8R8A8_SRGB |
| 85 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // BC1_RGBA_SRGB | 85 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // BC1_RGBA_SRGB |
| 86 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // BC2_SRGB | 86 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // BC2_SRGB |
| 87 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // BC3_SRGB | 87 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // BC3_SRGB |
diff --git a/src/video_core/renderer_opengl/util_shaders.cpp b/src/video_core/renderer_opengl/util_shaders.cpp index 333f35a1c..2cb6e19b3 100644 --- a/src/video_core/renderer_opengl/util_shaders.cpp +++ b/src/video_core/renderer_opengl/util_shaders.cpp | |||
| @@ -257,38 +257,31 @@ void UtilShaders::CopyBC4(Image& dst_image, Image& src_image, std::span<const Im | |||
| 257 | 257 | ||
| 258 | void UtilShaders::CopyBGR(Image& dst_image, Image& src_image, | 258 | void UtilShaders::CopyBGR(Image& dst_image, Image& src_image, |
| 259 | std::span<const VideoCommon::ImageCopy> copies) { | 259 | std::span<const VideoCommon::ImageCopy> copies) { |
| 260 | static constexpr GLuint BINDING_INPUT_IMAGE = 0; | ||
| 261 | static constexpr GLuint BINDING_OUTPUT_IMAGE = 1; | ||
| 262 | static constexpr VideoCommon::Offset3D zero_offset{0, 0, 0}; | 260 | static constexpr VideoCommon::Offset3D zero_offset{0, 0, 0}; |
| 263 | const u32 bytes_per_block = BytesPerBlock(dst_image.info.format); | 261 | for (const ImageCopy& copy : copies) { |
| 264 | switch (bytes_per_block) { | 262 | ASSERT(copy.src_offset == zero_offset); |
| 265 | case 2: | 263 | ASSERT(copy.dst_offset == zero_offset); |
| 266 | // BGR565 copy | 264 | |
| 267 | for (const ImageCopy& copy : copies) { | 265 | if (bgr_pbo_size < dst_image.unswizzled_size_bytes) { |
| 268 | ASSERT(copy.src_offset == zero_offset); | 266 | bgr_pbo.Create(); |
| 269 | ASSERT(copy.dst_offset == zero_offset); | 267 | bgr_pbo_size = dst_image.unswizzled_size_bytes; |
| 270 | bgr_copy_pass.Execute(dst_image, src_image, copy); | 268 | glNamedBufferData(bgr_pbo.handle, bgr_pbo_size, nullptr, GL_STREAM_COPY); |
| 271 | } | ||
| 272 | break; | ||
| 273 | case 4: { | ||
| 274 | // BGRA8 copy | ||
| 275 | program_manager.BindComputeProgram(copy_bgra_program.handle); | ||
| 276 | constexpr GLenum FORMAT = GL_RGBA8; | ||
| 277 | for (const ImageCopy& copy : copies) { | ||
| 278 | ASSERT(copy.src_offset == zero_offset); | ||
| 279 | ASSERT(copy.dst_offset == zero_offset); | ||
| 280 | glBindImageTexture(BINDING_INPUT_IMAGE, src_image.StorageHandle(), | ||
| 281 | copy.src_subresource.base_level, GL_FALSE, 0, GL_READ_ONLY, FORMAT); | ||
| 282 | glBindImageTexture(BINDING_OUTPUT_IMAGE, dst_image.StorageHandle(), | ||
| 283 | copy.dst_subresource.base_level, GL_FALSE, 0, GL_WRITE_ONLY, FORMAT); | ||
| 284 | glDispatchCompute(copy.extent.width, copy.extent.height, copy.extent.depth); | ||
| 285 | } | 269 | } |
| 286 | program_manager.RestoreGuestCompute(); | 270 | // Copy from source to PBO |
| 287 | break; | 271 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 288 | } | 272 | glPixelStorei(GL_PACK_ROW_LENGTH, copy.extent.width); |
| 289 | default: | 273 | glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr_pbo.handle); |
| 290 | UNREACHABLE(); | 274 | glGetTextureSubImage(src_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, |
| 291 | break; | 275 | copy.src_subresource.num_layers, src_image.GlFormat(), |
| 276 | src_image.GlType(), static_cast<GLsizei>(bgr_pbo_size), nullptr); | ||
| 277 | |||
| 278 | // Copy from PBO to destination in reverse order | ||
| 279 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||
| 280 | glPixelStorei(GL_UNPACK_ROW_LENGTH, copy.extent.width); | ||
| 281 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bgr_pbo.handle); | ||
| 282 | glTextureSubImage3D(dst_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, | ||
| 283 | copy.dst_subresource.num_layers, dst_image.GlFormat(), | ||
| 284 | dst_image.GlType(), nullptr); | ||
| 292 | } | 285 | } |
| 293 | } | 286 | } |
| 294 | 287 | ||
| @@ -309,36 +302,4 @@ GLenum StoreFormat(u32 bytes_per_block) { | |||
| 309 | return GL_R8UI; | 302 | return GL_R8UI; |
| 310 | } | 303 | } |
| 311 | 304 | ||
| 312 | void Bgr565CopyPass::Execute(const Image& dst_image, const Image& src_image, | ||
| 313 | const ImageCopy& copy) { | ||
| 314 | if (CopyBufferCreationNeeded(copy)) { | ||
| 315 | CreateNewCopyBuffer(copy, GL_TEXTURE_2D_ARRAY, GL_RGB565); | ||
| 316 | } | ||
| 317 | // Copy from source to PBO | ||
| 318 | glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||
| 319 | glPixelStorei(GL_PACK_ROW_LENGTH, copy.extent.width); | ||
| 320 | glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr16_pbo.handle); | ||
| 321 | glGetTextureSubImage(src_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, | ||
| 322 | copy.src_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, | ||
| 323 | static_cast<GLsizei>(bgr16_pbo_size), nullptr); | ||
| 324 | |||
| 325 | // Copy from PBO to destination in reverse order | ||
| 326 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||
| 327 | glPixelStorei(GL_UNPACK_ROW_LENGTH, copy.extent.width); | ||
| 328 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bgr16_pbo.handle); | ||
| 329 | glTextureSubImage3D(dst_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, | ||
| 330 | copy.dst_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, | ||
| 331 | nullptr); | ||
| 332 | } | ||
| 333 | |||
| 334 | bool Bgr565CopyPass::CopyBufferCreationNeeded(const ImageCopy& copy) { | ||
| 335 | return bgr16_pbo_size < NumPixelsInCopy(copy) * sizeof(u16); | ||
| 336 | } | ||
| 337 | |||
| 338 | void Bgr565CopyPass::CreateNewCopyBuffer(const ImageCopy& copy, GLenum target, GLuint format) { | ||
| 339 | bgr16_pbo.Create(); | ||
| 340 | bgr16_pbo_size = NumPixelsInCopy(copy) * sizeof(u16); | ||
| 341 | glNamedBufferData(bgr16_pbo.handle, bgr16_pbo_size, nullptr, GL_STREAM_COPY); | ||
| 342 | } | ||
| 343 | |||
| 344 | } // namespace OpenGL | 305 | } // namespace OpenGL |
diff --git a/src/video_core/renderer_opengl/util_shaders.h b/src/video_core/renderer_opengl/util_shaders.h index ef881e35f..b474480cb 100644 --- a/src/video_core/renderer_opengl/util_shaders.h +++ b/src/video_core/renderer_opengl/util_shaders.h | |||
| @@ -19,22 +19,6 @@ class ProgramManager; | |||
| 19 | 19 | ||
| 20 | struct ImageBufferMap; | 20 | struct ImageBufferMap; |
| 21 | 21 | ||
| 22 | class Bgr565CopyPass { | ||
| 23 | public: | ||
| 24 | Bgr565CopyPass() = default; | ||
| 25 | ~Bgr565CopyPass() = default; | ||
| 26 | |||
| 27 | void Execute(const Image& dst_image, const Image& src_image, | ||
| 28 | const VideoCommon::ImageCopy& copy); | ||
| 29 | |||
| 30 | private: | ||
| 31 | [[nodiscard]] bool CopyBufferCreationNeeded(const VideoCommon::ImageCopy& copy); | ||
| 32 | void CreateNewCopyBuffer(const VideoCommon::ImageCopy& copy, GLenum target, GLuint format); | ||
| 33 | |||
| 34 | OGLBuffer bgr16_pbo; | ||
| 35 | size_t bgr16_pbo_size{}; | ||
| 36 | }; | ||
| 37 | |||
| 38 | class UtilShaders { | 22 | class UtilShaders { |
| 39 | public: | 23 | public: |
| 40 | explicit UtilShaders(ProgramManager& program_manager); | 24 | explicit UtilShaders(ProgramManager& program_manager); |
| @@ -70,7 +54,8 @@ private: | |||
| 70 | OGLProgram copy_bgra_program; | 54 | OGLProgram copy_bgra_program; |
| 71 | OGLProgram copy_bc4_program; | 55 | OGLProgram copy_bc4_program; |
| 72 | 56 | ||
| 73 | Bgr565CopyPass bgr_copy_pass; | 57 | OGLBuffer bgr_pbo; |
| 58 | size_t bgr_pbo_size{}; | ||
| 74 | }; | 59 | }; |
| 75 | 60 | ||
| 76 | GLenum StoreFormat(u32 bytes_per_block); | 61 | GLenum StoreFormat(u32 bytes_per_block); |