diff options
| author | 2016-03-07 20:29:30 -0500 | |
|---|---|---|
| committer | 2016-03-07 20:29:30 -0500 | |
| commit | 58c336b67109e89b3d47e2873e8271e7291a59d0 (patch) | |
| tree | 9b0707e1162d9b828e7baa206dcda8b69fd774e0 /src/audio_core | |
| parent | Merge pull request #1467 from LittleWhite-tb/bug-shader-object (diff) | |
| parent | DSP: Implement Pipe 2 (diff) | |
| download | yuzu-58c336b67109e89b3d47e2873e8271e7291a59d0.tar.gz yuzu-58c336b67109e89b3d47e2873e8271e7291a59d0.tar.xz yuzu-58c336b67109e89b3d47e2873e8271e7291a59d0.zip | |
Merge pull request #1441 from MerryMage/dsp-pipes
AudioCore: Implement Pipe 2
Diffstat (limited to 'src/audio_core')
| -rw-r--r-- | src/audio_core/hle/dsp.h | 45 | ||||
| -rw-r--r-- | src/audio_core/hle/pipe.cpp | 150 | ||||
| -rw-r--r-- | src/audio_core/hle/pipe.h | 33 |
3 files changed, 194 insertions, 34 deletions
diff --git a/src/audio_core/hle/dsp.h b/src/audio_core/hle/dsp.h index 14c4000c6..376436c29 100644 --- a/src/audio_core/hle/dsp.h +++ b/src/audio_core/hle/dsp.h | |||
| @@ -66,9 +66,9 @@ static_assert(std::is_trivially_copyable<u32_dsp>::value, "u32_dsp isn't trivial | |||
| 66 | #endif | 66 | #endif |
| 67 | 67 | ||
| 68 | // There are 15 structures in each memory region. A table of them in the order they appear in memory | 68 | // There are 15 structures in each memory region. A table of them in the order they appear in memory |
| 69 | // is presented below | 69 | // is presented below: |
| 70 | // | 70 | // |
| 71 | // Pipe 2 # First Region DSP Address Purpose Control | 71 | // # First Region DSP Address Purpose Control |
| 72 | // 5 0x8400 DSP Status DSP | 72 | // 5 0x8400 DSP Status DSP |
| 73 | // 9 0x8410 DSP Debug Info DSP | 73 | // 9 0x8410 DSP Debug Info DSP |
| 74 | // 6 0x8540 Final Mix Samples DSP | 74 | // 6 0x8540 Final Mix Samples DSP |
| @@ -85,6 +85,9 @@ static_assert(std::is_trivially_copyable<u32_dsp>::value, "u32_dsp isn't trivial | |||
| 85 | // 14 0xAC5C Surround Sound Related | 85 | // 14 0xAC5C Surround Sound Related |
| 86 | // 0 0xBFFF Frame Counter Application | 86 | // 0 0xBFFF Frame Counter Application |
| 87 | // | 87 | // |
| 88 | // #: This refers to the order in which they appear in the DspPipe::Audio DSP pipe. | ||
| 89 | // See also: DSP::HLE::PipeRead. | ||
| 90 | // | ||
| 88 | // Note that the above addresses do vary slightly between audio firmwares observed; the addresses are | 91 | // Note that the above addresses do vary slightly between audio firmwares observed; the addresses are |
| 89 | // not fixed in stone. The addresses above are only an examplar; they're what this implementation | 92 | // not fixed in stone. The addresses above are only an examplar; they're what this implementation |
| 90 | // does and provides to applications. | 93 | // does and provides to applications. |
| @@ -472,13 +475,47 @@ struct SharedMemory { | |||
| 472 | 475 | ||
| 473 | AdpcmCoefficients adpcm_coefficients; | 476 | AdpcmCoefficients adpcm_coefficients; |
| 474 | 477 | ||
| 475 | /// Unknown 10-14 (Surround sound related) | 478 | struct { |
| 476 | INSERT_PADDING_DSPWORDS(0x16ED); | 479 | INSERT_PADDING_DSPWORDS(0x100); |
| 480 | } unknown10; | ||
| 481 | |||
| 482 | struct { | ||
| 483 | INSERT_PADDING_DSPWORDS(0xC0); | ||
| 484 | } unknown11; | ||
| 485 | |||
| 486 | struct { | ||
| 487 | INSERT_PADDING_DSPWORDS(0x180); | ||
| 488 | } unknown12; | ||
| 489 | |||
| 490 | struct { | ||
| 491 | INSERT_PADDING_DSPWORDS(0xA); | ||
| 492 | } unknown13; | ||
| 493 | |||
| 494 | struct { | ||
| 495 | INSERT_PADDING_DSPWORDS(0x13A3); | ||
| 496 | } unknown14; | ||
| 477 | 497 | ||
| 478 | u16_le frame_counter; | 498 | u16_le frame_counter; |
| 479 | }; | 499 | }; |
| 480 | ASSERT_DSP_STRUCT(SharedMemory, 0x8000); | 500 | ASSERT_DSP_STRUCT(SharedMemory, 0x8000); |
| 481 | 501 | ||
| 502 | // Structures must have an offset that is a multiple of two. | ||
| 503 | static_assert(offsetof(SharedMemory, frame_counter) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 504 | static_assert(offsetof(SharedMemory, source_configurations) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 505 | static_assert(offsetof(SharedMemory, source_statuses) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 506 | static_assert(offsetof(SharedMemory, adpcm_coefficients) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 507 | static_assert(offsetof(SharedMemory, dsp_configuration) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 508 | static_assert(offsetof(SharedMemory, dsp_status) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 509 | static_assert(offsetof(SharedMemory, final_samples) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 510 | static_assert(offsetof(SharedMemory, intermediate_mix_samples) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 511 | static_assert(offsetof(SharedMemory, compressor) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 512 | static_assert(offsetof(SharedMemory, dsp_debug) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 513 | static_assert(offsetof(SharedMemory, unknown10) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 514 | static_assert(offsetof(SharedMemory, unknown11) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 515 | static_assert(offsetof(SharedMemory, unknown12) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 516 | static_assert(offsetof(SharedMemory, unknown13) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 517 | static_assert(offsetof(SharedMemory, unknown14) % 2 == 0, "Structures in DSP::HLE::SharedMemory must be 2-byte aligned"); | ||
| 518 | |||
| 482 | #undef INSERT_PADDING_DSPWORDS | 519 | #undef INSERT_PADDING_DSPWORDS |
| 483 | #undef ASSERT_DSP_STRUCT | 520 | #undef ASSERT_DSP_STRUCT |
| 484 | 521 | ||
diff --git a/src/audio_core/hle/pipe.cpp b/src/audio_core/hle/pipe.cpp index 6542c760c..9381883b4 100644 --- a/src/audio_core/hle/pipe.cpp +++ b/src/audio_core/hle/pipe.cpp | |||
| @@ -5,50 +5,154 @@ | |||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | 7 | ||
| 8 | #include "audio_core/hle/dsp.h" | ||
| 8 | #include "audio_core/hle/pipe.h" | 9 | #include "audio_core/hle/pipe.h" |
| 9 | 10 | ||
| 11 | #include "common/assert.h" | ||
| 10 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 11 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 12 | 14 | ||
| 13 | namespace DSP { | 15 | namespace DSP { |
| 14 | namespace HLE { | 16 | namespace HLE { |
| 15 | 17 | ||
| 16 | static size_t pipe2position = 0; | 18 | static DspState dsp_state = DspState::Off; |
| 19 | |||
| 20 | static std::array<std::vector<u8>, static_cast<size_t>(DspPipe::DspPipe_MAX)> pipe_data; | ||
| 17 | 21 | ||
| 18 | void ResetPipes() { | 22 | void ResetPipes() { |
| 19 | pipe2position = 0; | 23 | for (auto& data : pipe_data) { |
| 24 | data.clear(); | ||
| 25 | } | ||
| 26 | dsp_state = DspState::Off; | ||
| 20 | } | 27 | } |
| 21 | 28 | ||
| 22 | std::vector<u8> PipeRead(u32 pipe_number, u32 length) { | 29 | std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { |
| 23 | if (pipe_number != 2) { | 30 | if (pipe_number >= DspPipe::DspPipe_MAX) { |
| 24 | LOG_WARNING(Audio_DSP, "pipe_number = %u (!= 2), unimplemented", pipe_number); | 31 | LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); |
| 25 | return {}; // We currently don't handle anything other than the audio pipe. | 32 | return {}; |
| 33 | } | ||
| 34 | |||
| 35 | std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; | ||
| 36 | |||
| 37 | if (length > data.size()) { | ||
| 38 | LOG_WARNING(Audio_DSP, "pipe_number = %u is out of data, application requested read of %u but %zu remain", | ||
| 39 | pipe_number, length, data.size()); | ||
| 40 | length = data.size(); | ||
| 26 | } | 41 | } |
| 27 | 42 | ||
| 28 | // Canned DSP responses that games expect. These were taken from HW by 3dmoo team. | 43 | if (length == 0) |
| 29 | // TODO: Our implementation will actually use a slightly different response than this one. | ||
| 30 | // TODO: Use offsetof on DSP structures instead for a proper response. | ||
| 31 | static const std::array<u8, 32> canned_response {{ | ||
| 32 | 0x0F, 0x00, 0xFF, 0xBF, 0x8E, 0x9E, 0x80, 0x86, 0x8E, 0xA7, 0x30, 0x94, 0x00, 0x84, 0x40, 0x85, | ||
| 33 | 0x8E, 0x94, 0x10, 0x87, 0x10, 0x84, 0x0E, 0xA9, 0x0E, 0xAA, 0xCE, 0xAA, 0x4E, 0xAC, 0x58, 0xAC | ||
| 34 | }}; | ||
| 35 | |||
| 36 | // TODO: Move this into dsp::DSP service since it happens on the service side. | ||
| 37 | // Hardware observation: No data is returned if requested length reads beyond the end of the data in-pipe. | ||
| 38 | if (pipe2position + length > canned_response.size()) { | ||
| 39 | return {}; | 44 | return {}; |
| 45 | |||
| 46 | std::vector<u8> ret(data.begin(), data.begin() + length); | ||
| 47 | data.erase(data.begin(), data.begin() + length); | ||
| 48 | return ret; | ||
| 49 | } | ||
| 50 | |||
| 51 | size_t GetPipeReadableSize(DspPipe pipe_number) { | ||
| 52 | if (pipe_number >= DspPipe::DspPipe_MAX) { | ||
| 53 | LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); | ||
| 54 | return 0; | ||
| 40 | } | 55 | } |
| 41 | 56 | ||
| 42 | std::vector<u8> ret; | 57 | return pipe_data[static_cast<size_t>(pipe_number)].size(); |
| 43 | for (size_t i = 0; i < length; i++, pipe2position++) { | 58 | } |
| 44 | ret.emplace_back(canned_response[pipe2position]); | 59 | |
| 60 | static void WriteU16(DspPipe pipe_number, u16 value) { | ||
| 61 | std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; | ||
| 62 | // Little endian | ||
| 63 | data.emplace_back(value & 0xFF); | ||
| 64 | data.emplace_back(value >> 8); | ||
| 65 | } | ||
| 66 | |||
| 67 | static void AudioPipeWriteStructAddresses() { | ||
| 68 | // These struct addresses are DSP dram addresses. | ||
| 69 | // See also: DSP_DSP::ConvertProcessAddressFromDspDram | ||
| 70 | static const std::array<u16, 15> struct_addresses = { | ||
| 71 | 0x8000 + offsetof(SharedMemory, frame_counter) / 2, | ||
| 72 | 0x8000 + offsetof(SharedMemory, source_configurations) / 2, | ||
| 73 | 0x8000 + offsetof(SharedMemory, source_statuses) / 2, | ||
| 74 | 0x8000 + offsetof(SharedMemory, adpcm_coefficients) / 2, | ||
| 75 | 0x8000 + offsetof(SharedMemory, dsp_configuration) / 2, | ||
| 76 | 0x8000 + offsetof(SharedMemory, dsp_status) / 2, | ||
| 77 | 0x8000 + offsetof(SharedMemory, final_samples) / 2, | ||
| 78 | 0x8000 + offsetof(SharedMemory, intermediate_mix_samples) / 2, | ||
| 79 | 0x8000 + offsetof(SharedMemory, compressor) / 2, | ||
| 80 | 0x8000 + offsetof(SharedMemory, dsp_debug) / 2, | ||
| 81 | 0x8000 + offsetof(SharedMemory, unknown10) / 2, | ||
| 82 | 0x8000 + offsetof(SharedMemory, unknown11) / 2, | ||
| 83 | 0x8000 + offsetof(SharedMemory, unknown12) / 2, | ||
| 84 | 0x8000 + offsetof(SharedMemory, unknown13) / 2, | ||
| 85 | 0x8000 + offsetof(SharedMemory, unknown14) / 2 | ||
| 86 | }; | ||
| 87 | |||
| 88 | // Begin with a u16 denoting the number of structs. | ||
| 89 | WriteU16(DspPipe::Audio, struct_addresses.size()); | ||
| 90 | // Then write the struct addresses. | ||
| 91 | for (u16 addr : struct_addresses) { | ||
| 92 | WriteU16(DspPipe::Audio, addr); | ||
| 45 | } | 93 | } |
| 94 | } | ||
| 46 | 95 | ||
| 47 | return ret; | 96 | void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { |
| 97 | switch (pipe_number) { | ||
| 98 | case DspPipe::Audio: { | ||
| 99 | if (buffer.size() != 4) { | ||
| 100 | LOG_ERROR(Audio_DSP, "DspPipe::Audio: Unexpected buffer length %zu was written", buffer.size()); | ||
| 101 | return; | ||
| 102 | } | ||
| 103 | |||
| 104 | enum class StateChange { | ||
| 105 | Initalize = 0, | ||
| 106 | Shutdown = 1, | ||
| 107 | Wakeup = 2, | ||
| 108 | Sleep = 3 | ||
| 109 | }; | ||
| 110 | |||
| 111 | // The difference between Initialize and Wakeup is that Input state is maintained | ||
| 112 | // when sleeping but isn't when turning it off and on again. (TODO: Implement this.) | ||
| 113 | // Waking up from sleep garbles some of the structs in the memory region. (TODO: | ||
| 114 | // Implement this.) Applications store away the state of these structs before | ||
| 115 | // sleeping and reset it back after wakeup on behalf of the DSP. | ||
| 116 | |||
| 117 | switch (static_cast<StateChange>(buffer[0])) { | ||
| 118 | case StateChange::Initalize: | ||
| 119 | LOG_INFO(Audio_DSP, "Application has requested initialization of DSP hardware"); | ||
| 120 | ResetPipes(); | ||
| 121 | AudioPipeWriteStructAddresses(); | ||
| 122 | dsp_state = DspState::On; | ||
| 123 | break; | ||
| 124 | case StateChange::Shutdown: | ||
| 125 | LOG_INFO(Audio_DSP, "Application has requested shutdown of DSP hardware"); | ||
| 126 | dsp_state = DspState::Off; | ||
| 127 | break; | ||
| 128 | case StateChange::Wakeup: | ||
| 129 | LOG_INFO(Audio_DSP, "Application has requested wakeup of DSP hardware"); | ||
| 130 | ResetPipes(); | ||
| 131 | AudioPipeWriteStructAddresses(); | ||
| 132 | dsp_state = DspState::On; | ||
| 133 | break; | ||
| 134 | case StateChange::Sleep: | ||
| 135 | LOG_INFO(Audio_DSP, "Application has requested sleep of DSP hardware"); | ||
| 136 | UNIMPLEMENTED(); | ||
| 137 | dsp_state = DspState::Sleeping; | ||
| 138 | break; | ||
| 139 | default: | ||
| 140 | LOG_ERROR(Audio_DSP, "Application has requested unknown state transition of DSP hardware %hhu", buffer[0]); | ||
| 141 | dsp_state = DspState::Off; | ||
| 142 | break; | ||
| 143 | } | ||
| 144 | |||
| 145 | return; | ||
| 146 | } | ||
| 147 | default: | ||
| 148 | LOG_CRITICAL(Audio_DSP, "pipe_number = %u unimplemented", pipe_number); | ||
| 149 | UNIMPLEMENTED(); | ||
| 150 | return; | ||
| 151 | } | ||
| 48 | } | 152 | } |
| 49 | 153 | ||
| 50 | void PipeWrite(u32 pipe_number, const std::vector<u8>& buffer) { | 154 | DspState GetDspState() { |
| 51 | // TODO: proper pipe behaviour | 155 | return dsp_state; |
| 52 | } | 156 | } |
| 53 | 157 | ||
| 54 | } // namespace HLE | 158 | } // namespace HLE |
diff --git a/src/audio_core/hle/pipe.h b/src/audio_core/hle/pipe.h index ff6536950..382d35e87 100644 --- a/src/audio_core/hle/pipe.h +++ b/src/audio_core/hle/pipe.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstddef> | ||
| 7 | #include <vector> | 8 | #include <vector> |
| 8 | 9 | ||
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| @@ -14,25 +15,43 @@ namespace HLE { | |||
| 14 | /// Reset the pipes by setting pipe positions back to the beginning. | 15 | /// Reset the pipes by setting pipe positions back to the beginning. |
| 15 | void ResetPipes(); | 16 | void ResetPipes(); |
| 16 | 17 | ||
| 18 | enum class DspPipe { | ||
| 19 | Debug = 0, | ||
| 20 | Dma = 1, | ||
| 21 | Audio = 2, | ||
| 22 | Binary = 3, | ||
| 23 | DspPipe_MAX | ||
| 24 | }; | ||
| 25 | |||
| 17 | /** | 26 | /** |
| 18 | * Read a DSP pipe. | 27 | * Read a DSP pipe. |
| 19 | * Pipe IDs: | ||
| 20 | * pipe_number = 0: Debug | ||
| 21 | * pipe_number = 1: P-DMA | ||
| 22 | * pipe_number = 2: Audio | ||
| 23 | * pipe_number = 3: Binary | ||
| 24 | * @param pipe_number The Pipe ID | 28 | * @param pipe_number The Pipe ID |
| 25 | * @param length How much data to request. | 29 | * @param length How much data to request. |
| 26 | * @return The data read from the pipe. The size of this vector can be less than the length requested. | 30 | * @return The data read from the pipe. The size of this vector can be less than the length requested. |
| 27 | */ | 31 | */ |
| 28 | std::vector<u8> PipeRead(u32 pipe_number, u32 length); | 32 | std::vector<u8> PipeRead(DspPipe pipe_number, u32 length); |
| 33 | |||
| 34 | /** | ||
| 35 | * How much data is left in pipe | ||
| 36 | * @param pipe_number The Pipe ID | ||
| 37 | * @return The amount of data remaning in the pipe. This is the maximum length PipeRead will return. | ||
| 38 | */ | ||
| 39 | size_t GetPipeReadableSize(DspPipe pipe_number); | ||
| 29 | 40 | ||
| 30 | /** | 41 | /** |
| 31 | * Write to a DSP pipe. | 42 | * Write to a DSP pipe. |
| 32 | * @param pipe_number The Pipe ID | 43 | * @param pipe_number The Pipe ID |
| 33 | * @param buffer The data to write to the pipe. | 44 | * @param buffer The data to write to the pipe. |
| 34 | */ | 45 | */ |
| 35 | void PipeWrite(u32 pipe_number, const std::vector<u8>& buffer); | 46 | void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer); |
| 47 | |||
| 48 | enum class DspState { | ||
| 49 | Off, | ||
| 50 | On, | ||
| 51 | Sleeping | ||
| 52 | }; | ||
| 53 | /// Get the state of the DSP | ||
| 54 | DspState GetDspState(); | ||
| 36 | 55 | ||
| 37 | } // namespace HLE | 56 | } // namespace HLE |
| 38 | } // namespace DSP | 57 | } // namespace DSP |