diff options
| author | 2021-03-25 16:53:51 -0400 | |
|---|---|---|
| committer | 2021-03-25 16:53:51 -0400 | |
| commit | 2f83d9a61bca42d9ef24074beb2b11b19bd4cecd (patch) | |
| tree | 514e40eb750280c2e3025f9301befb6f8c9b46e9 /src/video_core/renderer_opengl | |
| parent | astc_decoder: Reimplement Layers (diff) | |
| download | yuzu-2f83d9a61bca42d9ef24074beb2b11b19bd4cecd.tar.gz yuzu-2f83d9a61bca42d9ef24074beb2b11b19bd4cecd.tar.xz yuzu-2f83d9a61bca42d9ef24074beb2b11b19bd4cecd.zip | |
astc_decoder: Refactor for style and more efficient memory use
Diffstat (limited to 'src/video_core/renderer_opengl')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 11 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/util_shaders.cpp | 96 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/util_shaders.h | 8 |
3 files changed, 46 insertions, 69 deletions
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 29105ecad..623b43d8a 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -307,7 +307,7 @@ void ApplySwizzle(GLuint handle, PixelFormat format, std::array<SwizzleSource, 4 | |||
| 307 | 307 | ||
| 308 | [[nodiscard]] bool CanBeAccelerated(const TextureCacheRuntime& runtime, | 308 | [[nodiscard]] bool CanBeAccelerated(const TextureCacheRuntime& runtime, |
| 309 | const VideoCommon::ImageInfo& info) { | 309 | const VideoCommon::ImageInfo& info) { |
| 310 | return (!runtime.HasNativeASTC() && IsPixelFormatASTC(info.format)); | 310 | return !runtime.HasNativeASTC() && IsPixelFormatASTC(info.format); |
| 311 | // Disable other accelerated uploads for now as they don't implement swizzled uploads | 311 | // Disable other accelerated uploads for now as they don't implement swizzled uploads |
| 312 | return false; | 312 | return false; |
| 313 | switch (info.type) { | 313 | switch (info.type) { |
| @@ -568,12 +568,13 @@ void TextureCacheRuntime::BlitFramebuffer(Framebuffer* dst, Framebuffer* src, | |||
| 568 | 568 | ||
| 569 | void TextureCacheRuntime::AccelerateImageUpload(Image& image, const ImageBufferMap& map, | 569 | void TextureCacheRuntime::AccelerateImageUpload(Image& image, const ImageBufferMap& map, |
| 570 | std::span<const SwizzleParameters> swizzles) { | 570 | std::span<const SwizzleParameters> swizzles) { |
| 571 | if (IsPixelFormatASTC(image.info.format)) { | ||
| 572 | return util_shaders.ASTCDecode(image, map, swizzles); | ||
| 573 | } | ||
| 574 | switch (image.info.type) { | 571 | switch (image.info.type) { |
| 575 | case ImageType::e2D: | 572 | case ImageType::e2D: |
| 576 | return util_shaders.BlockLinearUpload2D(image, map, swizzles); | 573 | if (IsPixelFormatASTC(image.info.format)) { |
| 574 | return util_shaders.ASTCDecode(image, map, swizzles); | ||
| 575 | } else { | ||
| 576 | return util_shaders.BlockLinearUpload2D(image, map, swizzles); | ||
| 577 | } | ||
| 577 | case ImageType::e3D: | 578 | case ImageType::e3D: |
| 578 | return util_shaders.BlockLinearUpload3D(image, map, swizzles); | 579 | return util_shaders.BlockLinearUpload3D(image, map, swizzles); |
| 579 | case ImageType::Linear: | 580 | case ImageType::Linear: |
diff --git a/src/video_core/renderer_opengl/util_shaders.cpp b/src/video_core/renderer_opengl/util_shaders.cpp index 85722c54a..47fddcb6e 100644 --- a/src/video_core/renderer_opengl/util_shaders.cpp +++ b/src/video_core/renderer_opengl/util_shaders.cpp | |||
| @@ -2,11 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <bit> | ||
| 6 | #include <fstream> | ||
| 7 | #include <span> | 5 | #include <span> |
| 8 | #include <streambuf> | ||
| 9 | #include <string> | ||
| 10 | #include <string_view> | 6 | #include <string_view> |
| 11 | 7 | ||
| 12 | #include <glad/glad.h> | 8 | #include <glad/glad.h> |
| @@ -24,7 +20,6 @@ | |||
| 24 | #include "video_core/renderer_opengl/gl_shader_manager.h" | 20 | #include "video_core/renderer_opengl/gl_shader_manager.h" |
| 25 | #include "video_core/renderer_opengl/gl_texture_cache.h" | 21 | #include "video_core/renderer_opengl/gl_texture_cache.h" |
| 26 | #include "video_core/renderer_opengl/util_shaders.h" | 22 | #include "video_core/renderer_opengl/util_shaders.h" |
| 27 | #include "video_core/surface.h" | ||
| 28 | #include "video_core/texture_cache/accelerated_swizzle.h" | 23 | #include "video_core/texture_cache/accelerated_swizzle.h" |
| 29 | #include "video_core/texture_cache/types.h" | 24 | #include "video_core/texture_cache/types.h" |
| 30 | #include "video_core/texture_cache/util.h" | 25 | #include "video_core/texture_cache/util.h" |
| @@ -36,6 +31,7 @@ namespace OpenGL { | |||
| 36 | using namespace HostShaders; | 31 | using namespace HostShaders; |
| 37 | using namespace Tegra::Texture::ASTC; | 32 | using namespace Tegra::Texture::ASTC; |
| 38 | 33 | ||
| 34 | using VideoCommon::Extent2D; | ||
| 39 | using VideoCommon::Extent3D; | 35 | using VideoCommon::Extent3D; |
| 40 | using VideoCommon::ImageCopy; | 36 | using VideoCommon::ImageCopy; |
| 41 | using VideoCommon::ImageType; | 37 | using VideoCommon::ImageType; |
| @@ -69,33 +65,15 @@ UtilShaders::UtilShaders(ProgramManager& program_manager_) | |||
| 69 | pitch_unswizzle_program(MakeProgram(PITCH_UNSWIZZLE_COMP)), | 65 | pitch_unswizzle_program(MakeProgram(PITCH_UNSWIZZLE_COMP)), |
| 70 | copy_bgra_program(MakeProgram(OPENGL_COPY_BGRA_COMP)), | 66 | copy_bgra_program(MakeProgram(OPENGL_COPY_BGRA_COMP)), |
| 71 | copy_bc4_program(MakeProgram(OPENGL_COPY_BC4_COMP)) { | 67 | copy_bc4_program(MakeProgram(OPENGL_COPY_BC4_COMP)) { |
| 72 | MakeBuffers(); | ||
| 73 | } | ||
| 74 | |||
| 75 | UtilShaders::~UtilShaders() = default; | ||
| 76 | |||
| 77 | void UtilShaders::MakeBuffers() { | ||
| 78 | const auto swizzle_table = Tegra::Texture::MakeSwizzleTable(); | 68 | const auto swizzle_table = Tegra::Texture::MakeSwizzleTable(); |
| 79 | swizzle_table_buffer.Create(); | 69 | swizzle_table_buffer.Create(); |
| 70 | astc_buffer.Create(); | ||
| 80 | glNamedBufferStorage(swizzle_table_buffer.handle, sizeof(swizzle_table), &swizzle_table, 0); | 71 | glNamedBufferStorage(swizzle_table_buffer.handle, sizeof(swizzle_table), &swizzle_table, 0); |
| 81 | 72 | glNamedBufferStorage(astc_buffer.handle, sizeof(ASTC_BUFFER_DATA), &ASTC_BUFFER_DATA, 0); | |
| 82 | astc_encodings_buffer.Create(); | ||
| 83 | glNamedBufferStorage(astc_encodings_buffer.handle, sizeof(EncodingsValues), &EncodingsValues, | ||
| 84 | 0); | ||
| 85 | replicate_6_to_8_buffer.Create(); | ||
| 86 | glNamedBufferStorage(replicate_6_to_8_buffer.handle, sizeof(REPLICATE_6_BIT_TO_8_TABLE), | ||
| 87 | &REPLICATE_6_BIT_TO_8_TABLE, 0); | ||
| 88 | replicate_7_to_8_buffer.Create(); | ||
| 89 | glNamedBufferStorage(replicate_7_to_8_buffer.handle, sizeof(REPLICATE_7_BIT_TO_8_TABLE), | ||
| 90 | &REPLICATE_7_BIT_TO_8_TABLE, 0); | ||
| 91 | replicate_8_to_8_buffer.Create(); | ||
| 92 | glNamedBufferStorage(replicate_8_to_8_buffer.handle, sizeof(REPLICATE_8_BIT_TO_8_TABLE), | ||
| 93 | &REPLICATE_8_BIT_TO_8_TABLE, 0); | ||
| 94 | replicate_byte_to_16_buffer.Create(); | ||
| 95 | glNamedBufferStorage(replicate_byte_to_16_buffer.handle, sizeof(REPLICATE_BYTE_TO_16_TABLE), | ||
| 96 | &REPLICATE_BYTE_TO_16_TABLE, 0); | ||
| 97 | } | 73 | } |
| 98 | 74 | ||
| 75 | UtilShaders::~UtilShaders() = default; | ||
| 76 | |||
| 99 | void UtilShaders::ASTCDecode(Image& image, const ImageBufferMap& map, | 77 | void UtilShaders::ASTCDecode(Image& image, const ImageBufferMap& map, |
| 100 | std::span<const VideoCommon::SwizzleParameters> swizzles) { | 78 | std::span<const VideoCommon::SwizzleParameters> swizzles) { |
| 101 | static constexpr GLuint BINDING_SWIZZLE_BUFFER = 0; | 79 | static constexpr GLuint BINDING_SWIZZLE_BUFFER = 0; |
| @@ -108,47 +86,51 @@ void UtilShaders::ASTCDecode(Image& image, const ImageBufferMap& map, | |||
| 108 | static constexpr GLuint BINDING_BYTE_TO_16_BUFFER = 6; | 86 | static constexpr GLuint BINDING_BYTE_TO_16_BUFFER = 6; |
| 109 | 87 | ||
| 110 | static constexpr GLuint BINDING_OUTPUT_IMAGE = 0; | 88 | static constexpr GLuint BINDING_OUTPUT_IMAGE = 0; |
| 111 | static constexpr GLuint LOC_NUM_IMAGE_BLOCKS = 0; | ||
| 112 | static constexpr GLuint LOC_BLOCK_DIMS = 1; | ||
| 113 | 89 | ||
| 114 | const Extent3D tile_size = { | 90 | const Extent2D tile_size{ |
| 115 | VideoCore::Surface::DefaultBlockWidth(image.info.format), | 91 | .width = VideoCore::Surface::DefaultBlockWidth(image.info.format), |
| 116 | VideoCore::Surface::DefaultBlockHeight(image.info.format), | 92 | .height = VideoCore::Surface::DefaultBlockHeight(image.info.format), |
| 117 | }; | 93 | }; |
| 118 | program_manager.BindHostCompute(astc_decoder_program.handle); | 94 | program_manager.BindHostCompute(astc_decoder_program.handle); |
| 119 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_SWIZZLE_BUFFER, swizzle_table_buffer.handle); | 95 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_SWIZZLE_BUFFER, swizzle_table_buffer.handle); |
| 120 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_ENC_BUFFER, astc_encodings_buffer.handle); | 96 | glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_ENC_BUFFER, astc_buffer.handle, |
| 121 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_6_TO_8_BUFFER, | 97 | offsetof(AstcBufferData, encoding_values), |
| 122 | replicate_6_to_8_buffer.handle); | 98 | sizeof(AstcBufferData::encoding_values)); |
| 123 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_7_TO_8_BUFFER, | 99 | glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_6_TO_8_BUFFER, astc_buffer.handle, |
| 124 | replicate_7_to_8_buffer.handle); | 100 | offsetof(AstcBufferData, replicate_6_to_8), |
| 125 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_8_TO_8_BUFFER, | 101 | sizeof(AstcBufferData::replicate_6_to_8)); |
| 126 | replicate_8_to_8_buffer.handle); | 102 | glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_7_TO_8_BUFFER, astc_buffer.handle, |
| 127 | glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BYTE_TO_16_BUFFER, | 103 | offsetof(AstcBufferData, replicate_7_to_8), |
| 128 | replicate_byte_to_16_buffer.handle); | 104 | sizeof(AstcBufferData::replicate_7_to_8)); |
| 105 | glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_8_TO_8_BUFFER, astc_buffer.handle, | ||
| 106 | offsetof(AstcBufferData, replicate_8_to_8), | ||
| 107 | sizeof(AstcBufferData::replicate_8_to_8)); | ||
| 108 | glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_BYTE_TO_16_BUFFER, astc_buffer.handle, | ||
| 109 | offsetof(AstcBufferData, replicate_byte_to_16), | ||
| 110 | sizeof(AstcBufferData::replicate_byte_to_16)); | ||
| 129 | 111 | ||
| 130 | glFlushMappedNamedBufferRange(map.buffer, map.offset, image.guest_size_bytes); | 112 | glFlushMappedNamedBufferRange(map.buffer, map.offset, image.guest_size_bytes); |
| 131 | glUniform2ui(LOC_BLOCK_DIMS, tile_size.width, tile_size.height); | 113 | glUniform2ui(1, tile_size.width, tile_size.height); |
| 114 | // Ensure buffer data is valid before dispatching | ||
| 115 | glFlush(); | ||
| 132 | for (const SwizzleParameters& swizzle : swizzles) { | 116 | for (const SwizzleParameters& swizzle : swizzles) { |
| 133 | glBindImageTexture(BINDING_OUTPUT_IMAGE, image.StorageHandle(), swizzle.level, GL_TRUE, 0, | ||
| 134 | GL_WRITE_ONLY, GL_RGBA8); | ||
| 135 | const size_t input_offset = swizzle.buffer_offset + map.offset; | 117 | const size_t input_offset = swizzle.buffer_offset + map.offset; |
| 136 | const auto num_dispatches_x = Common::DivCeil(swizzle.num_tiles.width, 32U); | 118 | const u32 num_dispatches_x = Common::DivCeil(swizzle.num_tiles.width, 32U); |
| 137 | const auto num_dispatches_y = Common::DivCeil(swizzle.num_tiles.height, 32U); | 119 | const u32 num_dispatches_y = Common::DivCeil(swizzle.num_tiles.height, 32U); |
| 138 | |||
| 139 | glUniform2ui(LOC_NUM_IMAGE_BLOCKS, swizzle.num_tiles.width, swizzle.num_tiles.height); | ||
| 140 | 120 | ||
| 141 | // To unswizzle the ASTC data | ||
| 142 | const auto params = MakeBlockLinearSwizzle2DParams(swizzle, image.info); | 121 | const auto params = MakeBlockLinearSwizzle2DParams(swizzle, image.info); |
| 143 | glUniform3uiv(2, 1, params.origin.data()); | 122 | ASSERT(params.origin == (std::array<u32, 3>{0, 0, 0})); |
| 144 | glUniform3iv(3, 1, params.destination.data()); | 123 | ASSERT(params.destination == (std::array<s32, 3>{0, 0, 0})); |
| 145 | glUniform1ui(4, params.bytes_per_block_log2); | ||
| 146 | glUniform1ui(5, params.layer_stride); | ||
| 147 | glUniform1ui(6, params.block_size); | ||
| 148 | glUniform1ui(7, params.x_shift); | ||
| 149 | glUniform1ui(8, params.block_height); | ||
| 150 | glUniform1ui(9, params.block_height_mask); | ||
| 151 | 124 | ||
| 125 | glUniform1ui(2, params.bytes_per_block_log2); | ||
| 126 | glUniform1ui(3, params.layer_stride); | ||
| 127 | glUniform1ui(4, params.block_size); | ||
| 128 | glUniform1ui(5, params.x_shift); | ||
| 129 | glUniform1ui(6, params.block_height); | ||
| 130 | glUniform1ui(7, params.block_height_mask); | ||
| 131 | |||
| 132 | glBindImageTexture(BINDING_OUTPUT_IMAGE, image.StorageHandle(), swizzle.level, GL_TRUE, 0, | ||
| 133 | GL_WRITE_ONLY, GL_RGBA8); | ||
| 152 | // ASTC texture data | 134 | // ASTC texture data |
| 153 | glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_INPUT_BUFFER, map.buffer, input_offset, | 135 | glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_INPUT_BUFFER, map.buffer, input_offset, |
| 154 | image.guest_size_bytes - swizzle.buffer_offset); | 136 | image.guest_size_bytes - swizzle.buffer_offset); |
diff --git a/src/video_core/renderer_opengl/util_shaders.h b/src/video_core/renderer_opengl/util_shaders.h index 08a1cb9b2..53d65f368 100644 --- a/src/video_core/renderer_opengl/util_shaders.h +++ b/src/video_core/renderer_opengl/util_shaders.h | |||
| @@ -40,8 +40,6 @@ public: | |||
| 40 | explicit UtilShaders(ProgramManager& program_manager); | 40 | explicit UtilShaders(ProgramManager& program_manager); |
| 41 | ~UtilShaders(); | 41 | ~UtilShaders(); |
| 42 | 42 | ||
| 43 | void MakeBuffers(); | ||
| 44 | |||
| 45 | void ASTCDecode(Image& image, const ImageBufferMap& map, | 43 | void ASTCDecode(Image& image, const ImageBufferMap& map, |
| 46 | std::span<const VideoCommon::SwizzleParameters> swizzles); | 44 | std::span<const VideoCommon::SwizzleParameters> swizzles); |
| 47 | 45 | ||
| @@ -64,11 +62,7 @@ private: | |||
| 64 | ProgramManager& program_manager; | 62 | ProgramManager& program_manager; |
| 65 | 63 | ||
| 66 | OGLBuffer swizzle_table_buffer; | 64 | OGLBuffer swizzle_table_buffer; |
| 67 | OGLBuffer astc_encodings_buffer; | 65 | OGLBuffer astc_buffer; |
| 68 | OGLBuffer replicate_6_to_8_buffer; | ||
| 69 | OGLBuffer replicate_7_to_8_buffer; | ||
| 70 | OGLBuffer replicate_8_to_8_buffer; | ||
| 71 | OGLBuffer replicate_byte_to_16_buffer; | ||
| 72 | 66 | ||
| 73 | OGLProgram astc_decoder_program; | 67 | OGLProgram astc_decoder_program; |
| 74 | OGLProgram block_linear_unswizzle_2d_program; | 68 | OGLProgram block_linear_unswizzle_2d_program; |