diff options
| author | 2018-03-19 18:00:29 -0500 | |
|---|---|---|
| committer | 2018-03-24 11:30:56 -0500 | |
| commit | 71ebc3e90da9882139d2a5695ca1ed59ea77e94f (patch) | |
| tree | 48139f0812ee19b69c51db347d4cc4acb23f948b /src | |
| parent | Merge pull request #275 from MerryMage/addticks-dynarmic (diff) | |
| download | yuzu-71ebc3e90da9882139d2a5695ca1ed59ea77e94f.tar.gz yuzu-71ebc3e90da9882139d2a5695ca1ed59ea77e94f.tar.xz yuzu-71ebc3e90da9882139d2a5695ca1ed59ea77e94f.zip | |
GPU: Preliminary work for texture decoding.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 45 | ||||
| -rw-r--r-- | src/video_core/textures/decoders.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/textures/decoders.h | 20 | ||||
| -rw-r--r-- | src/video_core/textures/texture.h | 57 |
5 files changed, 139 insertions, 0 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index e56253c4c..8c0e6663b 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -31,6 +31,9 @@ add_library(video_core STATIC | |||
| 31 | renderer_opengl/gl_stream_buffer.h | 31 | renderer_opengl/gl_stream_buffer.h |
| 32 | renderer_opengl/renderer_opengl.cpp | 32 | renderer_opengl/renderer_opengl.cpp |
| 33 | renderer_opengl/renderer_opengl.h | 33 | renderer_opengl/renderer_opengl.h |
| 34 | textures/decoders.cpp | ||
| 35 | textures/decoders.h | ||
| 36 | textures/texture.h | ||
| 34 | utils.h | 37 | utils.h |
| 35 | video_core.cpp | 38 | video_core.cpp |
| 36 | video_core.h | 39 | video_core.h |
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 4d9745e48..ca1b150a7 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -2,8 +2,11 @@ | |||
| 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 <cinttypes> | ||
| 5 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 6 | #include "video_core/engines/maxwell_3d.h" | 7 | #include "video_core/engines/maxwell_3d.h" |
| 8 | #include "video_core/textures/decoders.h" | ||
| 9 | #include "video_core/textures/texture.h" | ||
| 7 | 10 | ||
| 8 | namespace Tegra { | 11 | namespace Tegra { |
| 9 | namespace Engines { | 12 | namespace Engines { |
| @@ -160,6 +163,48 @@ void Maxwell3D::ProcessQueryGet() { | |||
| 160 | 163 | ||
| 161 | void Maxwell3D::DrawArrays() { | 164 | void Maxwell3D::DrawArrays() { |
| 162 | LOG_WARNING(HW_GPU, "Game requested a DrawArrays, ignoring"); | 165 | LOG_WARNING(HW_GPU, "Game requested a DrawArrays, ignoring"); |
| 166 | |||
| 167 | auto& fragment_shader = state.shader_stages[static_cast<size_t>(Regs::ShaderStage::Fragment)]; | ||
| 168 | auto& tex_info_buffer = fragment_shader.const_buffers[regs.tex_cb_index]; | ||
| 169 | ASSERT(tex_info_buffer.enabled && tex_info_buffer.address != 0); | ||
| 170 | |||
| 171 | GPUVAddr tic_base_address = regs.tic.TICAddress(); | ||
| 172 | |||
| 173 | GPUVAddr tex_info_buffer_end = tex_info_buffer.address + tex_info_buffer.size; | ||
| 174 | |||
| 175 | for (GPUVAddr current_texture = tex_info_buffer.address + 0x20; | ||
| 176 | current_texture < tex_info_buffer_end; current_texture += 4) { | ||
| 177 | |||
| 178 | Texture::TextureHandle tex_info{ | ||
| 179 | Memory::Read32(memory_manager.PhysicalToVirtualAddress(current_texture))}; | ||
| 180 | |||
| 181 | if (tex_info.tic_id != 0 || tex_info.tsc_id != 0) { | ||
| 182 | GPUVAddr tic_address_gpu = | ||
| 183 | tic_base_address + tex_info.tic_id * sizeof(Texture::TICEntry); | ||
| 184 | VAddr tic_address_cpu = memory_manager.PhysicalToVirtualAddress(tic_address_gpu); | ||
| 185 | |||
| 186 | Texture::TICEntry tic_entry; | ||
| 187 | Memory::ReadBlock(tic_address_cpu, &tic_entry, sizeof(Texture::TICEntry)); | ||
| 188 | |||
| 189 | auto r_type = tic_entry.r_type.Value(); | ||
| 190 | auto g_type = tic_entry.g_type.Value(); | ||
| 191 | auto b_type = tic_entry.b_type.Value(); | ||
| 192 | auto a_type = tic_entry.a_type.Value(); | ||
| 193 | |||
| 194 | // TODO(Subv): Different data types for separate components are not supported | ||
| 195 | ASSERT(r_type == g_type && r_type == b_type && r_type == a_type); | ||
| 196 | |||
| 197 | auto format = tic_entry.format.Value(); | ||
| 198 | |||
| 199 | auto texture = Texture::DecodeTexture( | ||
| 200 | memory_manager.PhysicalToVirtualAddress(tic_entry.Address()), | ||
| 201 | tic_entry.format.Value(), tic_entry.Width(), tic_entry.Height()); | ||
| 202 | |||
| 203 | LOG_CRITICAL(HW_GPU, | ||
| 204 | "Fragment shader using texture TIC %08X TSC %08X at address %016" PRIX64, | ||
| 205 | tex_info.tic_id.Value(), tex_info.tsc_id.Value(), tic_entry.Address()); | ||
| 206 | } | ||
| 207 | } | ||
| 163 | } | 208 | } |
| 164 | 209 | ||
| 165 | void Maxwell3D::BindTextureInfoBuffer(const std::vector<u32>& parameters) { | 210 | void Maxwell3D::BindTextureInfoBuffer(const std::vector<u32>& parameters) { |
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp new file mode 100644 index 000000000..705e2e066 --- /dev/null +++ b/src/video_core/textures/decoders.cpp | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "video_core/textures/decoders.h" | ||
| 6 | |||
| 7 | namespace Tegra { | ||
| 8 | namespace Texture { | ||
| 9 | |||
| 10 | std::vector<u8> DecodeTexture(VAddr address, TextureFormat format, u32 width, u32 height) { | ||
| 11 | return {}; | ||
| 12 | } | ||
| 13 | } | ||
| 14 | } // namespace Tegra | ||
diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h new file mode 100644 index 000000000..e0d55600e --- /dev/null +++ b/src/video_core/textures/decoders.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "video_core/textures/texture.h" | ||
| 10 | |||
| 11 | namespace Tegra { | ||
| 12 | namespace Texture { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Decodes a swizzled texture into a RGBA8888 texture. | ||
| 16 | */ | ||
| 17 | std::vector<u8> DecodeTexture(VAddr address, TextureFormat format, u32 width, u32 height); | ||
| 18 | |||
| 19 | } // namespace Texture | ||
| 20 | } // namespace Tegra | ||
diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h new file mode 100644 index 000000000..3306d2ab2 --- /dev/null +++ b/src/video_core/textures/texture.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | ||
| 8 | #include "common/common_funcs.h" | ||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "video_core/memory_manager.h" | ||
| 11 | |||
| 12 | namespace Tegra { | ||
| 13 | namespace Texture { | ||
| 14 | |||
| 15 | enum class TextureFormat : u32 { | ||
| 16 | DXT1 = 0x24, | ||
| 17 | }; | ||
| 18 | |||
| 19 | union TextureHandle { | ||
| 20 | u32 raw; | ||
| 21 | BitField<0, 20, u32> tic_id; | ||
| 22 | BitField<20, 12, u32> tsc_id; | ||
| 23 | }; | ||
| 24 | |||
| 25 | struct TICEntry { | ||
| 26 | union { | ||
| 27 | u32 raw; | ||
| 28 | BitField<0, 7, TextureFormat> format; | ||
| 29 | BitField<7, 3, u32> r_type; | ||
| 30 | BitField<10, 3, u32> g_type; | ||
| 31 | BitField<13, 3, u32> b_type; | ||
| 32 | BitField<16, 3, u32> a_type; | ||
| 33 | }; | ||
| 34 | u32 address_low; | ||
| 35 | u16 address_high; | ||
| 36 | INSERT_PADDING_BYTES(6); | ||
| 37 | u16 width_minus_1; | ||
| 38 | INSERT_PADDING_BYTES(2); | ||
| 39 | u16 height_minus_1; | ||
| 40 | INSERT_PADDING_BYTES(10); | ||
| 41 | |||
| 42 | GPUVAddr Address() const { | ||
| 43 | return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | address_low); | ||
| 44 | } | ||
| 45 | |||
| 46 | u32 Width() const { | ||
| 47 | return width_minus_1 + 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | u32 Height() const { | ||
| 51 | return height_minus_1 + 1; | ||
| 52 | } | ||
| 53 | }; | ||
| 54 | static_assert(sizeof(TICEntry) == 0x20, "TICEntry has wrong size"); | ||
| 55 | |||
| 56 | } // namespace Texture | ||
| 57 | } // namespace Tegra | ||