Switching to xe::mutex.
This commit is contained in:
@@ -56,8 +56,10 @@ const uint32_t kXmaContextSize = 64;
|
||||
const uint32_t kXmaContextCount = 320;
|
||||
|
||||
AudioSystem::AudioSystem(Emulator* emulator)
|
||||
: emulator_(emulator), memory_(emulator->memory()), worker_running_(false),
|
||||
decoder_running_(false) {
|
||||
: emulator_(emulator),
|
||||
memory_(emulator->memory()),
|
||||
worker_running_(false),
|
||||
decoder_running_(false) {
|
||||
memset(clients_, 0, sizeof(clients_));
|
||||
for (size_t i = 0; i < maximum_client_count_; ++i) {
|
||||
unused_clients_.push(i);
|
||||
@@ -249,7 +251,8 @@ void AudioSystem::DecoderThreadMain() {
|
||||
// TODO - Probably need to move this, I think it might skip the very
|
||||
// last packet (see the call to PreparePacket)
|
||||
size_t input_size = (data.input_buffer_0_block_count +
|
||||
data.input_buffer_1_block_count) * 2048;
|
||||
data.input_buffer_1_block_count) *
|
||||
2048;
|
||||
size_t input_offset = (data.input_buffer_read_offset / 8 - 4);
|
||||
size_t input_remaining = input_size - input_offset;
|
||||
if (input_offset > input_size) {
|
||||
@@ -339,7 +342,7 @@ void AudioSystem::Shutdown() {
|
||||
}
|
||||
|
||||
uint32_t AudioSystem::AllocateXmaContext() {
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
std::lock_guard<xe::mutex> lock(lock_);
|
||||
|
||||
for (uint32_t n = 0; n < kXmaContextCount; n++) {
|
||||
XMAContext& context = xma_context_array_[n];
|
||||
@@ -353,7 +356,7 @@ uint32_t AudioSystem::AllocateXmaContext() {
|
||||
}
|
||||
|
||||
void AudioSystem::ReleaseXmaContext(uint32_t guest_ptr) {
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
std::lock_guard<xe::mutex> lock(lock_);
|
||||
|
||||
// Find it in the list.
|
||||
for (uint32_t n = 0; n < kXmaContextCount; n++) {
|
||||
@@ -365,9 +368,9 @@ void AudioSystem::ReleaseXmaContext(uint32_t guest_ptr) {
|
||||
|
||||
context.in_use = false;
|
||||
auto context_ptr = memory()->TranslateVirtual(guest_ptr);
|
||||
std::memset(context_ptr, 0, kXmaContextSize); // Zero it.
|
||||
std::memset(context_ptr, 0, kXmaContextSize); // Zero it.
|
||||
context.decoder->DiscardPacket();
|
||||
|
||||
|
||||
context.lock.unlock();
|
||||
}
|
||||
}
|
||||
@@ -376,7 +379,7 @@ void AudioSystem::ReleaseXmaContext(uint32_t guest_ptr) {
|
||||
X_STATUS AudioSystem::RegisterClient(uint32_t callback, uint32_t callback_arg,
|
||||
size_t* out_index) {
|
||||
assert_true(unused_clients_.size());
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
std::lock_guard<xe::mutex> lock(lock_);
|
||||
|
||||
auto index = unused_clients_.front();
|
||||
|
||||
@@ -406,7 +409,7 @@ X_STATUS AudioSystem::RegisterClient(uint32_t callback, uint32_t callback_arg,
|
||||
void AudioSystem::SubmitFrame(size_t index, uint32_t samples_ptr) {
|
||||
SCOPE_profile_cpu_f("apu");
|
||||
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
std::lock_guard<xe::mutex> lock(lock_);
|
||||
assert_true(index < maximum_client_count_);
|
||||
assert_true(clients_[index].driver != NULL);
|
||||
(clients_[index].driver)->SubmitFrame(samples_ptr);
|
||||
@@ -416,7 +419,7 @@ void AudioSystem::SubmitFrame(size_t index, uint32_t samples_ptr) {
|
||||
void AudioSystem::UnregisterClient(size_t index) {
|
||||
SCOPE_profile_cpu_f("apu");
|
||||
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
std::lock_guard<xe::mutex> lock(lock_);
|
||||
assert_true(index < maximum_client_count_);
|
||||
DestroyDriver(clients_[index].driver);
|
||||
clients_[index] = {0};
|
||||
@@ -478,9 +481,10 @@ void AudioSystem::WriteRegister(uint32_t addr, uint64_t value) {
|
||||
auto context_ptr = memory()->TranslateVirtual(context.guest_ptr);
|
||||
XMAContextData data(context_ptr);
|
||||
|
||||
XELOGAPU("AudioSystem: kicking context %d (%d/%d bytes)", context_id,
|
||||
data.input_buffer_read_offset, data.input_buffer_0_block_count
|
||||
* XMAContextData::kBytesPerBlock);
|
||||
XELOGAPU(
|
||||
"AudioSystem: kicking context %d (%d/%d bytes)", context_id,
|
||||
data.input_buffer_read_offset,
|
||||
data.input_buffer_0_block_count * XMAContextData::kBytesPerBlock);
|
||||
|
||||
// Reset valid flags so our audio decoder knows to process this one
|
||||
data.input_buffer_0_valid = data.input_buffer_0_ptr != 0;
|
||||
|
||||
@@ -51,25 +51,27 @@ struct XMAContextData {
|
||||
uint32_t input_buffer_0_valid : 1; // +20bit, XMAIsInputBuffer0Valid
|
||||
uint32_t input_buffer_1_valid : 1; // +21bit, XMAIsInputBuffer1Valid
|
||||
uint32_t output_buffer_block_count : 5; // +22bit SizeWrite 256byte blocks
|
||||
uint32_t output_buffer_write_offset : 5; // +27bit, XMAGetOutputBufferWriteOffset
|
||||
// AKA OffsetWrite
|
||||
uint32_t
|
||||
output_buffer_write_offset : 5; // +27bit, XMAGetOutputBufferWriteOffset
|
||||
// AKA OffsetWrite
|
||||
|
||||
// DWORD 1
|
||||
uint32_t input_buffer_1_block_count : 12; // XMASetInputBuffer1, number of
|
||||
// 2KB blocks.
|
||||
uint32_t loop_subframe_end : 2; // +12bit, XMASetLoopData
|
||||
uint32_t unk_dword_1_a : 3; // ? might be loop_subframe_skip
|
||||
uint32_t loop_subframe_skip : 3; // +17bit, XMASetLoopData might be subframe_decode_count
|
||||
uint32_t subframe_decode_count : 4; // +20bit might be subframe_skip_count
|
||||
uint32_t unk_dword_1_b : 3; // ? NumSubframesToSkip/NumChannels(?)
|
||||
uint32_t sample_rate : 2; // +27bit enum of sample rates
|
||||
uint32_t is_stereo : 1; // +29bit might be NumChannels
|
||||
uint32_t unk_dword_1_c : 1; // ? part of NumChannels?
|
||||
uint32_t output_buffer_valid : 1; // +31bit, XMAIsOutputBufferValid
|
||||
uint32_t loop_subframe_skip : 3; // +17bit, XMASetLoopData might be
|
||||
// subframe_decode_count
|
||||
uint32_t subframe_decode_count : 4; // +20bit might be subframe_skip_count
|
||||
uint32_t unk_dword_1_b : 3; // ? NumSubframesToSkip/NumChannels(?)
|
||||
uint32_t sample_rate : 2; // +27bit enum of sample rates
|
||||
uint32_t is_stereo : 1; // +29bit might be NumChannels
|
||||
uint32_t unk_dword_1_c : 1; // ? part of NumChannels?
|
||||
uint32_t output_buffer_valid : 1; // +31bit, XMAIsOutputBufferValid
|
||||
|
||||
// DWORD 2
|
||||
uint32_t input_buffer_read_offset : 30; // XMAGetInputBufferReadOffset
|
||||
uint32_t unk_dword_2 : 2; // ErrorStatus/ErrorSet (?)
|
||||
uint32_t input_buffer_read_offset : 30; // XMAGetInputBufferReadOffset
|
||||
uint32_t unk_dword_2 : 2; // ErrorStatus/ErrorSet (?)
|
||||
|
||||
// DWORD 3
|
||||
uint32_t loop_start : 26; // XMASetLoopData LoopStartOffset
|
||||
@@ -85,25 +87,25 @@ struct XMAContextData {
|
||||
// DWORD 6
|
||||
uint32_t input_buffer_1_ptr; // physical address
|
||||
// DWORD 7
|
||||
uint32_t output_buffer_ptr; // physical address
|
||||
uint32_t output_buffer_ptr; // physical address
|
||||
// DWORD 8
|
||||
uint32_t overlap_add_ptr; // PtrOverlapAdd(?)
|
||||
uint32_t overlap_add_ptr; // PtrOverlapAdd(?)
|
||||
|
||||
// DWORD 9
|
||||
// +0bit, XMAGetOutputBufferReadOffset AKA WriteBufferOffsetRead
|
||||
uint32_t output_buffer_read_offset : 5;
|
||||
uint32_t unk_dword_9 : 27; // StopWhenDone/InterruptWhenDone(?)
|
||||
uint32_t output_buffer_read_offset : 5;
|
||||
uint32_t unk_dword_9 : 27; // StopWhenDone/InterruptWhenDone(?)
|
||||
|
||||
XMAContextData(const void* ptr) {
|
||||
xe::copy_and_swap_32_aligned(reinterpret_cast<uint32_t*>(this),
|
||||
reinterpret_cast<const uint32_t*>(ptr),
|
||||
sizeof(XMAContextData) / 4);
|
||||
reinterpret_cast<const uint32_t*>(ptr),
|
||||
sizeof(XMAContextData) / 4);
|
||||
}
|
||||
|
||||
void Store(void* ptr) {
|
||||
xe::copy_and_swap_32_aligned(reinterpret_cast<uint32_t*>(ptr),
|
||||
reinterpret_cast<const uint32_t*>(this),
|
||||
sizeof(XMAContextData) / 4);
|
||||
reinterpret_cast<const uint32_t*>(this),
|
||||
sizeof(XMAContextData) / 4);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(XMAContextData) == 4 * 10, "Must be packed");
|
||||
@@ -166,7 +168,7 @@ class AudioSystem {
|
||||
kernel::object_ref<kernel::XHostThread> decoder_thread_;
|
||||
xe::threading::Fence decoder_fence_;
|
||||
|
||||
std::mutex lock_;
|
||||
xe::mutex lock_;
|
||||
|
||||
// Stored little endian, accessed through 0x7FEA....
|
||||
union {
|
||||
@@ -189,16 +191,16 @@ class AudioSystem {
|
||||
uint32_t register_file_[0xFFFF / 4];
|
||||
};
|
||||
struct XMAContext {
|
||||
uint32_t guest_ptr;
|
||||
std::mutex lock;
|
||||
bool in_use;
|
||||
uint32_t guest_ptr;
|
||||
xe::mutex lock;
|
||||
bool in_use;
|
||||
|
||||
AudioDecoder* decoder;
|
||||
};
|
||||
|
||||
XMAContext xma_context_array_[320];
|
||||
std::vector<uint32_t> xma_context_free_list_;
|
||||
std::vector<uint32_t> xma_context_used_list_; // XMA contexts in use
|
||||
std::vector<uint32_t> xma_context_used_list_; // XMA contexts in use
|
||||
|
||||
static const size_t maximum_client_count_ = 8;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user