diff options
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/amiibo_crypto.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_device.cpp | 65 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_result.h | 2 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_types.h | 47 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_user.cpp | 30 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp | 25 | ||||
| -rw-r--r-- | src/video_core/macro/macro_jit_x64.cpp | 62 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp | 84 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_staging_buffer_pool.h | 3 | ||||
| -rw-r--r-- | src/web_service/web_backend.cpp | 3 |
11 files changed, 209 insertions, 122 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index e27d84734..025f1c78e 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -1017,9 +1017,11 @@ bool EmulatedController::SetPollingMode(Common::Input::PollingMode polling_mode) | |||
| 1017 | auto& output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)]; | 1017 | auto& output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)]; |
| 1018 | auto& nfc_output_device = output_devices[3]; | 1018 | auto& nfc_output_device = output_devices[3]; |
| 1019 | 1019 | ||
| 1020 | nfc_output_device->SetPollingMode(polling_mode); | 1020 | const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode); |
| 1021 | const auto mapped_nfc_result = output_device->SetPollingMode(polling_mode); | ||
| 1021 | 1022 | ||
| 1022 | return output_device->SetPollingMode(polling_mode) == Common::Input::PollingError::None; | 1023 | return virtual_nfc_result == Common::Input::PollingError::None || |
| 1024 | mapped_nfc_result == Common::Input::PollingError::None; | ||
| 1023 | } | 1025 | } |
| 1024 | 1026 | ||
| 1025 | bool EmulatedController::SetCameraFormat( | 1027 | bool EmulatedController::SetCameraFormat( |
diff --git a/src/core/hle/service/nfp/amiibo_crypto.cpp b/src/core/hle/service/nfp/amiibo_crypto.cpp index ce0bc3f75..c32a6816b 100644 --- a/src/core/hle/service/nfp/amiibo_crypto.cpp +++ b/src/core/hle/service/nfp/amiibo_crypto.cpp | |||
| @@ -28,7 +28,7 @@ bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file) { | |||
| 28 | LOG_DEBUG(Service_NFP, "model_number=0x{0:x}", | 28 | LOG_DEBUG(Service_NFP, "model_number=0x{0:x}", |
| 29 | static_cast<u16>(amiibo_data.model_info.model_number)); | 29 | static_cast<u16>(amiibo_data.model_info.model_number)); |
| 30 | LOG_DEBUG(Service_NFP, "series={}", amiibo_data.model_info.series); | 30 | LOG_DEBUG(Service_NFP, "series={}", amiibo_data.model_info.series); |
| 31 | LOG_DEBUG(Service_NFP, "fixed_value=0x{0:x}", amiibo_data.model_info.constant_value); | 31 | LOG_DEBUG(Service_NFP, "tag_type=0x{0:x}", amiibo_data.model_info.tag_type); |
| 32 | 32 | ||
| 33 | LOG_DEBUG(Service_NFP, "tag_dynamic_lock=0x{0:x}", ntag_file.dynamic_lock); | 33 | LOG_DEBUG(Service_NFP, "tag_dynamic_lock=0x{0:x}", ntag_file.dynamic_lock); |
| 34 | LOG_DEBUG(Service_NFP, "tag_CFG0=0x{0:x}", ntag_file.CFG0); | 34 | LOG_DEBUG(Service_NFP, "tag_CFG0=0x{0:x}", ntag_file.CFG0); |
| @@ -55,7 +55,7 @@ bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file) { | |||
| 55 | if (amiibo_data.constant_value != 0xA5) { | 55 | if (amiibo_data.constant_value != 0xA5) { |
| 56 | return false; | 56 | return false; |
| 57 | } | 57 | } |
| 58 | if (amiibo_data.model_info.constant_value != 0x02) { | 58 | if (amiibo_data.model_info.tag_type != PackedTagType::Type2) { |
| 59 | return false; | 59 | return false; |
| 60 | } | 60 | } |
| 61 | if ((ntag_file.dynamic_lock & 0xFFFFFF) != 0x0F0001U) { | 61 | if ((ntag_file.dynamic_lock & 0xFFFFFF) != 0x0F0001U) { |
diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp index 0d4ffd3a5..ec895ac01 100644 --- a/src/core/hle/service/nfp/nfp_device.cpp +++ b/src/core/hle/service/nfp/nfp_device.cpp | |||
| @@ -98,11 +98,6 @@ bool NfpDevice::LoadAmiibo(std::span<const u8> data) { | |||
| 98 | 98 | ||
| 99 | memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); | 99 | memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); |
| 100 | 100 | ||
| 101 | if (!AmiiboCrypto::IsAmiiboValid(encrypted_tag_data)) { | ||
| 102 | LOG_INFO(Service_NFP, "Invalid amiibo"); | ||
| 103 | return false; | ||
| 104 | } | ||
| 105 | |||
| 106 | device_state = DeviceState::TagFound; | 101 | device_state = DeviceState::TagFound; |
| 107 | deactivate_event->GetReadableEvent().Clear(); | 102 | deactivate_event->GetReadableEvent().Clear(); |
| 108 | activate_event->GetWritableEvent().Signal(); | 103 | activate_event->GetWritableEvent().Signal(); |
| @@ -148,20 +143,28 @@ void NfpDevice::Finalize() { | |||
| 148 | } | 143 | } |
| 149 | 144 | ||
| 150 | Result NfpDevice::StartDetection(s32 protocol_) { | 145 | Result NfpDevice::StartDetection(s32 protocol_) { |
| 151 | if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) { | 146 | if (device_state != DeviceState::Initialized && device_state != DeviceState::TagRemoved) { |
| 152 | npad_device->SetPollingMode(Common::Input::PollingMode::NFC); | 147 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 153 | device_state = DeviceState::SearchingForTag; | 148 | return WrongDeviceState; |
| 154 | protocol = protocol_; | ||
| 155 | return ResultSuccess; | ||
| 156 | } | 149 | } |
| 157 | 150 | ||
| 158 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 151 | if (!npad_device->SetPollingMode(Common::Input::PollingMode::NFC)) { |
| 159 | return WrongDeviceState; | 152 | LOG_ERROR(Service_NFP, "Nfc not supported"); |
| 153 | return NfcDisabled; | ||
| 154 | } | ||
| 155 | |||
| 156 | device_state = DeviceState::SearchingForTag; | ||
| 157 | protocol = protocol_; | ||
| 158 | return ResultSuccess; | ||
| 160 | } | 159 | } |
| 161 | 160 | ||
| 162 | Result NfpDevice::StopDetection() { | 161 | Result NfpDevice::StopDetection() { |
| 163 | npad_device->SetPollingMode(Common::Input::PollingMode::Active); | 162 | npad_device->SetPollingMode(Common::Input::PollingMode::Active); |
| 164 | 163 | ||
| 164 | if (device_state == DeviceState::Initialized) { | ||
| 165 | return ResultSuccess; | ||
| 166 | } | ||
| 167 | |||
| 165 | if (device_state == DeviceState::TagFound || device_state == DeviceState::TagMounted) { | 168 | if (device_state == DeviceState::TagFound || device_state == DeviceState::TagMounted) { |
| 166 | CloseAmiibo(); | 169 | CloseAmiibo(); |
| 167 | return ResultSuccess; | 170 | return ResultSuccess; |
| @@ -225,6 +228,11 @@ Result NfpDevice::Mount(MountTarget mount_target_) { | |||
| 225 | return WrongDeviceState; | 228 | return WrongDeviceState; |
| 226 | } | 229 | } |
| 227 | 230 | ||
| 231 | if (!AmiiboCrypto::IsAmiiboValid(encrypted_tag_data)) { | ||
| 232 | LOG_ERROR(Service_NFP, "Not an amiibo"); | ||
| 233 | return NotAnAmiibo; | ||
| 234 | } | ||
| 235 | |||
| 228 | if (!AmiiboCrypto::DecodeAmiibo(encrypted_tag_data, tag_data)) { | 236 | if (!AmiiboCrypto::DecodeAmiibo(encrypted_tag_data, tag_data)) { |
| 229 | LOG_ERROR(Service_NFP, "Can't decode amiibo {}", device_state); | 237 | LOG_ERROR(Service_NFP, "Can't decode amiibo {}", device_state); |
| 230 | return CorruptedData; | 238 | return CorruptedData; |
| @@ -238,6 +246,9 @@ Result NfpDevice::Mount(MountTarget mount_target_) { | |||
| 238 | Result NfpDevice::Unmount() { | 246 | Result NfpDevice::Unmount() { |
| 239 | if (device_state != DeviceState::TagMounted) { | 247 | if (device_state != DeviceState::TagMounted) { |
| 240 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 248 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 249 | if (device_state == DeviceState::TagRemoved) { | ||
| 250 | return TagRemoved; | ||
| 251 | } | ||
| 241 | return WrongDeviceState; | 252 | return WrongDeviceState; |
| 242 | } | 253 | } |
| 243 | 254 | ||
| @@ -256,6 +267,9 @@ Result NfpDevice::Unmount() { | |||
| 256 | Result NfpDevice::GetTagInfo(TagInfo& tag_info) const { | 267 | Result NfpDevice::GetTagInfo(TagInfo& tag_info) const { |
| 257 | if (device_state != DeviceState::TagFound && device_state != DeviceState::TagMounted) { | 268 | if (device_state != DeviceState::TagFound && device_state != DeviceState::TagMounted) { |
| 258 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 269 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 270 | if (device_state == DeviceState::TagRemoved) { | ||
| 271 | return TagRemoved; | ||
| 272 | } | ||
| 259 | return WrongDeviceState; | 273 | return WrongDeviceState; |
| 260 | } | 274 | } |
| 261 | 275 | ||
| @@ -287,12 +301,7 @@ Result NfpDevice::GetCommonInfo(CommonInfo& common_info) const { | |||
| 287 | 301 | ||
| 288 | // TODO: Validate this data | 302 | // TODO: Validate this data |
| 289 | common_info = { | 303 | common_info = { |
| 290 | .last_write_date = | 304 | .last_write_date = settings.write_date.GetWriteDate(), |
| 291 | { | ||
| 292 | settings.write_date.GetYear(), | ||
| 293 | settings.write_date.GetMonth(), | ||
| 294 | settings.write_date.GetDay(), | ||
| 295 | }, | ||
| 296 | .write_counter = tag_data.write_counter, | 305 | .write_counter = tag_data.write_counter, |
| 297 | .version = 0, | 306 | .version = 0, |
| 298 | .application_area_size = sizeof(ApplicationArea), | 307 | .application_area_size = sizeof(ApplicationArea), |
| @@ -303,6 +312,9 @@ Result NfpDevice::GetCommonInfo(CommonInfo& common_info) const { | |||
| 303 | Result NfpDevice::GetModelInfo(ModelInfo& model_info) const { | 312 | Result NfpDevice::GetModelInfo(ModelInfo& model_info) const { |
| 304 | if (device_state != DeviceState::TagMounted) { | 313 | if (device_state != DeviceState::TagMounted) { |
| 305 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 314 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 315 | if (device_state == DeviceState::TagRemoved) { | ||
| 316 | return TagRemoved; | ||
| 317 | } | ||
| 306 | return WrongDeviceState; | 318 | return WrongDeviceState; |
| 307 | } | 319 | } |
| 308 | 320 | ||
| @@ -341,12 +353,7 @@ Result NfpDevice::GetRegisterInfo(RegisterInfo& register_info) const { | |||
| 341 | // TODO: Validate this data | 353 | // TODO: Validate this data |
| 342 | register_info = { | 354 | register_info = { |
| 343 | .mii_char_info = manager.ConvertV3ToCharInfo(tag_data.owner_mii), | 355 | .mii_char_info = manager.ConvertV3ToCharInfo(tag_data.owner_mii), |
| 344 | .creation_date = | 356 | .creation_date = settings.init_date.GetWriteDate(), |
| 345 | { | ||
| 346 | settings.init_date.GetYear(), | ||
| 347 | settings.init_date.GetMonth(), | ||
| 348 | settings.init_date.GetDay(), | ||
| 349 | }, | ||
| 350 | .amiibo_name = GetAmiiboName(settings), | 357 | .amiibo_name = GetAmiiboName(settings), |
| 351 | .font_region = {}, | 358 | .font_region = {}, |
| 352 | }; | 359 | }; |
| @@ -478,8 +485,7 @@ Result NfpDevice::GetApplicationArea(std::vector<u8>& data) const { | |||
| 478 | } | 485 | } |
| 479 | 486 | ||
| 480 | if (data.size() > sizeof(ApplicationArea)) { | 487 | if (data.size() > sizeof(ApplicationArea)) { |
| 481 | LOG_ERROR(Service_NFP, "Wrong data size {}", data.size()); | 488 | data.resize(sizeof(ApplicationArea)); |
| 482 | return ResultUnknown; | ||
| 483 | } | 489 | } |
| 484 | 490 | ||
| 485 | memcpy(data.data(), tag_data.application_area.data(), data.size()); | 491 | memcpy(data.data(), tag_data.application_area.data(), data.size()); |
| @@ -518,7 +524,7 @@ Result NfpDevice::SetApplicationArea(std::span<const u8> data) { | |||
| 518 | 524 | ||
| 519 | Common::TinyMT rng{}; | 525 | Common::TinyMT rng{}; |
| 520 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); | 526 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); |
| 521 | // HW seems to fill excess data with garbage | 527 | // Fill remaining data with random numbers |
| 522 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), | 528 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), |
| 523 | sizeof(ApplicationArea) - data.size()); | 529 | sizeof(ApplicationArea) - data.size()); |
| 524 | 530 | ||
| @@ -561,12 +567,12 @@ Result NfpDevice::RecreateApplicationArea(u32 access_id, std::span<const u8> dat | |||
| 561 | 567 | ||
| 562 | if (data.size() > sizeof(ApplicationArea)) { | 568 | if (data.size() > sizeof(ApplicationArea)) { |
| 563 | LOG_ERROR(Service_NFP, "Wrong data size {}", data.size()); | 569 | LOG_ERROR(Service_NFP, "Wrong data size {}", data.size()); |
| 564 | return ResultUnknown; | 570 | return WrongApplicationAreaSize; |
| 565 | } | 571 | } |
| 566 | 572 | ||
| 567 | Common::TinyMT rng{}; | 573 | Common::TinyMT rng{}; |
| 568 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); | 574 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); |
| 569 | // HW seems to fill excess data with garbage | 575 | // Fill remaining data with random numbers |
| 570 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), | 576 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), |
| 571 | sizeof(ApplicationArea) - data.size()); | 577 | sizeof(ApplicationArea) - data.size()); |
| 572 | 578 | ||
| @@ -612,7 +618,6 @@ u64 NfpDevice::GetHandle() const { | |||
| 612 | } | 618 | } |
| 613 | 619 | ||
| 614 | u32 NfpDevice::GetApplicationAreaSize() const { | 620 | u32 NfpDevice::GetApplicationAreaSize() const { |
| 615 | // Investigate if this value is really constant | ||
| 616 | return sizeof(ApplicationArea); | 621 | return sizeof(ApplicationArea); |
| 617 | } | 622 | } |
| 618 | 623 | ||
diff --git a/src/core/hle/service/nfp/nfp_result.h b/src/core/hle/service/nfp/nfp_result.h index ac259e2ff..d8e4cf094 100644 --- a/src/core/hle/service/nfp/nfp_result.h +++ b/src/core/hle/service/nfp/nfp_result.h | |||
| @@ -8,6 +8,8 @@ | |||
| 8 | namespace Service::NFP { | 8 | namespace Service::NFP { |
| 9 | 9 | ||
| 10 | constexpr Result DeviceNotFound(ErrorModule::NFP, 64); | 10 | constexpr Result DeviceNotFound(ErrorModule::NFP, 64); |
| 11 | constexpr Result InvalidArgument(ErrorModule::NFP, 65); | ||
| 12 | constexpr Result WrongApplicationAreaSize(ErrorModule::NFP, 68); | ||
| 11 | constexpr Result WrongDeviceState(ErrorModule::NFP, 73); | 13 | constexpr Result WrongDeviceState(ErrorModule::NFP, 73); |
| 12 | constexpr Result NfcDisabled(ErrorModule::NFP, 80); | 14 | constexpr Result NfcDisabled(ErrorModule::NFP, 80); |
| 13 | constexpr Result WriteAmiiboFailed(ErrorModule::NFP, 88); | 15 | constexpr Result WriteAmiiboFailed(ErrorModule::NFP, 88); |
diff --git a/src/core/hle/service/nfp/nfp_types.h b/src/core/hle/service/nfp/nfp_types.h index dd4525b61..867ea2f36 100644 --- a/src/core/hle/service/nfp/nfp_types.h +++ b/src/core/hle/service/nfp/nfp_types.h | |||
| @@ -84,6 +84,15 @@ enum class TagType : u32 { | |||
| 84 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s | 84 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s |
| 85 | }; | 85 | }; |
| 86 | 86 | ||
| 87 | enum class PackedTagType : u8 { | ||
| 88 | None, | ||
| 89 | Type1, // ISO14443A RW 96-2k bytes 106kbit/s | ||
| 90 | Type2, // ISO14443A RW/RO 540 bytes 106kbit/s | ||
| 91 | Type3, // Sony Felica RW/RO 2k bytes 212kbit/s | ||
| 92 | Type4, // ISO14443A RW/RO 4k-32k bytes 424kbit/s | ||
| 93 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s | ||
| 94 | }; | ||
| 95 | |||
| 87 | enum class TagProtocol : u32 { | 96 | enum class TagProtocol : u32 { |
| 88 | None, | 97 | None, |
| 89 | TypeA, // ISO14443A | 98 | TypeA, // ISO14443A |
| @@ -104,6 +113,13 @@ struct TagUuid { | |||
| 104 | }; | 113 | }; |
| 105 | static_assert(sizeof(TagUuid) == 10, "TagUuid is an invalid size"); | 114 | static_assert(sizeof(TagUuid) == 10, "TagUuid is an invalid size"); |
| 106 | 115 | ||
| 116 | struct WriteDate { | ||
| 117 | u16 year; | ||
| 118 | u8 month; | ||
| 119 | u8 day; | ||
| 120 | }; | ||
| 121 | static_assert(sizeof(WriteDate) == 0x4, "WriteDate is an invalid size"); | ||
| 122 | |||
| 107 | struct AmiiboDate { | 123 | struct AmiiboDate { |
| 108 | u16 raw_date{}; | 124 | u16 raw_date{}; |
| 109 | 125 | ||
| @@ -121,6 +137,21 @@ struct AmiiboDate { | |||
| 121 | return static_cast<u8>(GetValue() & 0x001F); | 137 | return static_cast<u8>(GetValue() & 0x001F); |
| 122 | } | 138 | } |
| 123 | 139 | ||
| 140 | WriteDate GetWriteDate() const { | ||
| 141 | if (!IsValidDate()) { | ||
| 142 | return { | ||
| 143 | .year = 2000, | ||
| 144 | .month = 1, | ||
| 145 | .day = 1, | ||
| 146 | }; | ||
| 147 | } | ||
| 148 | return { | ||
| 149 | .year = GetYear(), | ||
| 150 | .month = GetMonth(), | ||
| 151 | .day = GetDay(), | ||
| 152 | }; | ||
| 153 | } | ||
| 154 | |||
| 124 | void SetYear(u16 year) { | 155 | void SetYear(u16 year) { |
| 125 | const u16 year_converted = static_cast<u16>((year - 2000) << 9); | 156 | const u16 year_converted = static_cast<u16>((year - 2000) << 9); |
| 126 | raw_date = Common::swap16((GetValue() & ~0xFE00) | year_converted); | 157 | raw_date = Common::swap16((GetValue() & ~0xFE00) | year_converted); |
| @@ -133,6 +164,13 @@ struct AmiiboDate { | |||
| 133 | const u16 day_converted = static_cast<u16>(day); | 164 | const u16 day_converted = static_cast<u16>(day); |
| 134 | raw_date = Common::swap16((GetValue() & ~0x001F) | day_converted); | 165 | raw_date = Common::swap16((GetValue() & ~0x001F) | day_converted); |
| 135 | } | 166 | } |
| 167 | |||
| 168 | bool IsValidDate() const { | ||
| 169 | const bool is_day_valid = GetDay() > 0 && GetDay() < 32; | ||
| 170 | const bool is_month_valid = GetMonth() >= 0 && GetMonth() < 13; | ||
| 171 | const bool is_year_valid = GetYear() >= 2000; | ||
| 172 | return is_year_valid && is_month_valid && is_day_valid; | ||
| 173 | } | ||
| 136 | }; | 174 | }; |
| 137 | static_assert(sizeof(AmiiboDate) == 2, "AmiiboDate is an invalid size"); | 175 | static_assert(sizeof(AmiiboDate) == 2, "AmiiboDate is an invalid size"); |
| 138 | 176 | ||
| @@ -163,7 +201,7 @@ struct AmiiboModelInfo { | |||
| 163 | AmiiboType amiibo_type; | 201 | AmiiboType amiibo_type; |
| 164 | u16_be model_number; | 202 | u16_be model_number; |
| 165 | AmiiboSeries series; | 203 | AmiiboSeries series; |
| 166 | u8 constant_value; // Must be 02 | 204 | PackedTagType tag_type; |
| 167 | INSERT_PADDING_BYTES(0x4); // Unknown | 205 | INSERT_PADDING_BYTES(0x4); // Unknown |
| 168 | }; | 206 | }; |
| 169 | static_assert(sizeof(AmiiboModelInfo) == 0xC, "AmiiboModelInfo is an invalid size"); | 207 | static_assert(sizeof(AmiiboModelInfo) == 0xC, "AmiiboModelInfo is an invalid size"); |
| @@ -250,13 +288,6 @@ struct TagInfo { | |||
| 250 | }; | 288 | }; |
| 251 | static_assert(sizeof(TagInfo) == 0x58, "TagInfo is an invalid size"); | 289 | static_assert(sizeof(TagInfo) == 0x58, "TagInfo is an invalid size"); |
| 252 | 290 | ||
| 253 | struct WriteDate { | ||
| 254 | u16 year; | ||
| 255 | u8 month; | ||
| 256 | u8 day; | ||
| 257 | }; | ||
| 258 | static_assert(sizeof(WriteDate) == 0x4, "WriteDate is an invalid size"); | ||
| 259 | |||
| 260 | struct CommonInfo { | 291 | struct CommonInfo { |
| 261 | WriteDate last_write_date; | 292 | WriteDate last_write_date; |
| 262 | u16 write_counter; | 293 | u16 write_counter; |
diff --git a/src/core/hle/service/nfp/nfp_user.cpp b/src/core/hle/service/nfp/nfp_user.cpp index c61df9401..4ed53b534 100644 --- a/src/core/hle/service/nfp/nfp_user.cpp +++ b/src/core/hle/service/nfp/nfp_user.cpp | |||
| @@ -93,6 +93,18 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { | |||
| 93 | return; | 93 | return; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | if (!ctx.CanWriteBuffer()) { | ||
| 97 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 98 | rb.Push(InvalidArgument); | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (ctx.GetWriteBufferSize() == 0) { | ||
| 103 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 104 | rb.Push(InvalidArgument); | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | |||
| 96 | std::vector<u64> nfp_devices; | 108 | std::vector<u64> nfp_devices; |
| 97 | const std::size_t max_allowed_devices = ctx.GetWriteBufferSize() / sizeof(u64); | 109 | const std::size_t max_allowed_devices = ctx.GetWriteBufferSize() / sizeof(u64); |
| 98 | 110 | ||
| @@ -255,6 +267,12 @@ void IUser::GetApplicationArea(Kernel::HLERequestContext& ctx) { | |||
| 255 | return; | 267 | return; |
| 256 | } | 268 | } |
| 257 | 269 | ||
| 270 | if (!ctx.CanWriteBuffer()) { | ||
| 271 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 272 | rb.Push(InvalidArgument); | ||
| 273 | return; | ||
| 274 | } | ||
| 275 | |||
| 258 | auto device = GetNfpDevice(device_handle); | 276 | auto device = GetNfpDevice(device_handle); |
| 259 | 277 | ||
| 260 | if (!device.has_value()) { | 278 | if (!device.has_value()) { |
| @@ -283,6 +301,12 @@ void IUser::SetApplicationArea(Kernel::HLERequestContext& ctx) { | |||
| 283 | return; | 301 | return; |
| 284 | } | 302 | } |
| 285 | 303 | ||
| 304 | if (!ctx.CanReadBuffer()) { | ||
| 305 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 306 | rb.Push(InvalidArgument); | ||
| 307 | return; | ||
| 308 | } | ||
| 309 | |||
| 286 | auto device = GetNfpDevice(device_handle); | 310 | auto device = GetNfpDevice(device_handle); |
| 287 | 311 | ||
| 288 | if (!device.has_value()) { | 312 | if (!device.has_value()) { |
| @@ -358,6 +382,12 @@ void IUser::CreateApplicationArea(Kernel::HLERequestContext& ctx) { | |||
| 358 | return; | 382 | return; |
| 359 | } | 383 | } |
| 360 | 384 | ||
| 385 | if (!ctx.CanReadBuffer()) { | ||
| 386 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 387 | rb.Push(InvalidArgument); | ||
| 388 | return; | ||
| 389 | } | ||
| 390 | |||
| 361 | auto device = GetNfpDevice(device_handle); | 391 | auto device = GetNfpDevice(device_handle); |
| 362 | 392 | ||
| 363 | if (!device.has_value()) { | 393 | if (!device.has_value()) { |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp index b5c08d611..7e8f37563 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp | |||
| @@ -13,9 +13,6 @@ namespace Shader::Backend::GLASM { | |||
| 13 | namespace { | 13 | namespace { |
| 14 | void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset, | 14 | void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset, |
| 15 | std::string_view size) { | 15 | std::string_view size) { |
| 16 | if (!binding.IsImmediate()) { | ||
| 17 | throw NotImplementedException("Indirect constant buffer loading"); | ||
| 18 | } | ||
| 19 | const Register ret{ctx.reg_alloc.Define(inst)}; | 16 | const Register ret{ctx.reg_alloc.Define(inst)}; |
| 20 | if (offset.type == Type::U32) { | 17 | if (offset.type == Type::U32) { |
| 21 | // Avoid reading arrays out of bounds, matching hardware's behavior | 18 | // Avoid reading arrays out of bounds, matching hardware's behavior |
| @@ -24,7 +21,27 @@ void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU | |||
| 24 | return; | 21 | return; |
| 25 | } | 22 | } |
| 26 | } | 23 | } |
| 27 | ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding.U32(), offset); | 24 | |
| 25 | if (binding.IsImmediate()) { | ||
| 26 | ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding.U32(), offset); | ||
| 27 | return; | ||
| 28 | } | ||
| 29 | |||
| 30 | const ScalarU32 idx{ctx.reg_alloc.Consume(binding)}; | ||
| 31 | for (u32 i = 0; i < Info::MAX_INDIRECT_CBUFS; i++) { | ||
| 32 | ctx.Add("SEQ.S.CC RC.x,{},{};" | ||
| 33 | "IF NE.x;" | ||
| 34 | "LDC.{} {},c{}[{}];", | ||
| 35 | idx, i, size, ret, i, offset); | ||
| 36 | |||
| 37 | if (i != Info::MAX_INDIRECT_CBUFS - 1) { | ||
| 38 | ctx.Add("ELSE;"); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | for (u32 i = 0; i < Info::MAX_INDIRECT_CBUFS; i++) { | ||
| 43 | ctx.Add("ENDIF;"); | ||
| 44 | } | ||
| 28 | } | 45 | } |
| 29 | 46 | ||
| 30 | bool IsInputArray(Stage stage) { | 47 | bool IsInputArray(Stage stage) { |
diff --git a/src/video_core/macro/macro_jit_x64.cpp b/src/video_core/macro/macro_jit_x64.cpp index aca25d902..a302a9603 100644 --- a/src/video_core/macro/macro_jit_x64.cpp +++ b/src/video_core/macro/macro_jit_x64.cpp | |||
| @@ -279,28 +279,13 @@ void MacroJITx64Impl::Compile_ExtractInsert(Macro::Opcode opcode) { | |||
| 279 | auto dst = Compile_GetRegister(opcode.src_a, RESULT); | 279 | auto dst = Compile_GetRegister(opcode.src_a, RESULT); |
| 280 | auto src = Compile_GetRegister(opcode.src_b, eax); | 280 | auto src = Compile_GetRegister(opcode.src_b, eax); |
| 281 | 281 | ||
| 282 | if (opcode.bf_src_bit != 0 && opcode.bf_src_bit != 31) { | ||
| 283 | shr(src, opcode.bf_src_bit); | ||
| 284 | } else if (opcode.bf_src_bit == 31) { | ||
| 285 | xor_(src, src); | ||
| 286 | } | ||
| 287 | // Don't bother masking the whole register since we're using a 32 bit register | ||
| 288 | if (opcode.bf_size != 31 && opcode.bf_size != 0) { | ||
| 289 | and_(src, opcode.GetBitfieldMask()); | ||
| 290 | } else if (opcode.bf_size == 0) { | ||
| 291 | xor_(src, src); | ||
| 292 | } | ||
| 293 | if (opcode.bf_dst_bit != 31 && opcode.bf_dst_bit != 0) { | ||
| 294 | shl(src, opcode.bf_dst_bit); | ||
| 295 | } else if (opcode.bf_dst_bit == 31) { | ||
| 296 | xor_(src, src); | ||
| 297 | } | ||
| 298 | |||
| 299 | const u32 mask = ~(opcode.GetBitfieldMask() << opcode.bf_dst_bit); | 282 | const u32 mask = ~(opcode.GetBitfieldMask() << opcode.bf_dst_bit); |
| 300 | if (mask != 0xffffffff) { | 283 | and_(dst, mask); |
| 301 | and_(dst, mask); | 284 | shr(src, opcode.bf_src_bit); |
| 302 | } | 285 | and_(src, opcode.GetBitfieldMask()); |
| 286 | shl(src, opcode.bf_dst_bit); | ||
| 303 | or_(dst, src); | 287 | or_(dst, src); |
| 288 | |||
| 304 | Compile_ProcessResult(opcode.result_operation, opcode.dst); | 289 | Compile_ProcessResult(opcode.result_operation, opcode.dst); |
| 305 | } | 290 | } |
| 306 | 291 | ||
| @@ -309,17 +294,9 @@ void MacroJITx64Impl::Compile_ExtractShiftLeftImmediate(Macro::Opcode opcode) { | |||
| 309 | const auto src = Compile_GetRegister(opcode.src_b, RESULT); | 294 | const auto src = Compile_GetRegister(opcode.src_b, RESULT); |
| 310 | 295 | ||
| 311 | shr(src, dst.cvt8()); | 296 | shr(src, dst.cvt8()); |
| 312 | if (opcode.bf_size != 0 && opcode.bf_size != 31) { | 297 | and_(src, opcode.GetBitfieldMask()); |
| 313 | and_(src, opcode.GetBitfieldMask()); | 298 | shl(src, opcode.bf_dst_bit); |
| 314 | } else if (opcode.bf_size == 0) { | ||
| 315 | xor_(src, src); | ||
| 316 | } | ||
| 317 | 299 | ||
| 318 | if (opcode.bf_dst_bit != 0 && opcode.bf_dst_bit != 31) { | ||
| 319 | shl(src, opcode.bf_dst_bit); | ||
| 320 | } else if (opcode.bf_dst_bit == 31) { | ||
| 321 | xor_(src, src); | ||
| 322 | } | ||
| 323 | Compile_ProcessResult(opcode.result_operation, opcode.dst); | 300 | Compile_ProcessResult(opcode.result_operation, opcode.dst); |
| 324 | } | 301 | } |
| 325 | 302 | ||
| @@ -327,13 +304,8 @@ void MacroJITx64Impl::Compile_ExtractShiftLeftRegister(Macro::Opcode opcode) { | |||
| 327 | const auto dst = Compile_GetRegister(opcode.src_a, ecx); | 304 | const auto dst = Compile_GetRegister(opcode.src_a, ecx); |
| 328 | const auto src = Compile_GetRegister(opcode.src_b, RESULT); | 305 | const auto src = Compile_GetRegister(opcode.src_b, RESULT); |
| 329 | 306 | ||
| 330 | if (opcode.bf_src_bit != 0) { | 307 | shr(src, opcode.bf_src_bit); |
| 331 | shr(src, opcode.bf_src_bit); | 308 | and_(src, opcode.GetBitfieldMask()); |
| 332 | } | ||
| 333 | |||
| 334 | if (opcode.bf_size != 31) { | ||
| 335 | and_(src, opcode.GetBitfieldMask()); | ||
| 336 | } | ||
| 337 | shl(src, dst.cvt8()); | 309 | shl(src, dst.cvt8()); |
| 338 | 310 | ||
| 339 | Compile_ProcessResult(opcode.result_operation, opcode.dst); | 311 | Compile_ProcessResult(opcode.result_operation, opcode.dst); |
| @@ -429,17 +401,11 @@ void MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) { | |||
| 429 | Xbyak::Label handle_post_exit{}; | 401 | Xbyak::Label handle_post_exit{}; |
| 430 | Xbyak::Label skip{}; | 402 | Xbyak::Label skip{}; |
| 431 | jmp(skip, T_NEAR); | 403 | jmp(skip, T_NEAR); |
| 432 | if (opcode.is_exit) { | 404 | |
| 433 | L(handle_post_exit); | 405 | L(handle_post_exit); |
| 434 | // Execute 1 instruction | 406 | xor_(BRANCH_HOLDER, BRANCH_HOLDER); |
| 435 | mov(BRANCH_HOLDER, end_of_code); | 407 | jmp(labels[jump_address], T_NEAR); |
| 436 | // Jump to next instruction to skip delay slot check | 408 | |
| 437 | jmp(labels[jump_address], T_NEAR); | ||
| 438 | } else { | ||
| 439 | L(handle_post_exit); | ||
| 440 | xor_(BRANCH_HOLDER, BRANCH_HOLDER); | ||
| 441 | jmp(labels[jump_address], T_NEAR); | ||
| 442 | } | ||
| 443 | L(skip); | 409 | L(skip); |
| 444 | mov(BRANCH_HOLDER, handle_post_exit); | 410 | mov(BRANCH_HOLDER, handle_post_exit); |
| 445 | jmp(delay_skip[pc], T_NEAR); | 411 | jmp(delay_skip[pc], T_NEAR); |
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp index 06f68d09a..7fb256953 100644 --- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp +++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp | |||
| @@ -26,20 +26,39 @@ using namespace Common::Literals; | |||
| 26 | constexpr VkDeviceSize MAX_ALIGNMENT = 256; | 26 | constexpr VkDeviceSize MAX_ALIGNMENT = 256; |
| 27 | // Maximum size to put elements in the stream buffer | 27 | // Maximum size to put elements in the stream buffer |
| 28 | constexpr VkDeviceSize MAX_STREAM_BUFFER_REQUEST_SIZE = 8_MiB; | 28 | constexpr VkDeviceSize MAX_STREAM_BUFFER_REQUEST_SIZE = 8_MiB; |
| 29 | // Stream buffer size in bytes | ||
| 30 | constexpr VkDeviceSize STREAM_BUFFER_SIZE = 128_MiB; | ||
| 31 | constexpr VkDeviceSize REGION_SIZE = STREAM_BUFFER_SIZE / StagingBufferPool::NUM_SYNCS; | ||
| 32 | 29 | ||
| 33 | constexpr VkMemoryPropertyFlags HOST_FLAGS = | 30 | constexpr VkMemoryPropertyFlags HOST_FLAGS = |
| 34 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; | 31 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; |
| 35 | constexpr VkMemoryPropertyFlags STREAM_FLAGS = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | HOST_FLAGS; | 32 | constexpr VkMemoryPropertyFlags STREAM_FLAGS = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | HOST_FLAGS; |
| 36 | 33 | ||
| 37 | bool IsStreamHeap(VkMemoryHeap heap) noexcept { | 34 | static bool IsStreamHeap(VkMemoryHeap heap, size_t staging_buffer_size) noexcept { |
| 38 | return STREAM_BUFFER_SIZE < (heap.size * 2) / 3; | 35 | return staging_buffer_size < (heap.size * 2) / 3; |
| 36 | } | ||
| 37 | |||
| 38 | static bool HasLargeDeviceLocalHostVisibleMemory(const VkPhysicalDeviceMemoryProperties& props) { | ||
| 39 | const auto flags{VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT}; | ||
| 40 | |||
| 41 | for (u32 type_index = 0; type_index < props.memoryTypeCount; ++type_index) { | ||
| 42 | const auto& memory_type{props.memoryTypes[type_index]}; | ||
| 43 | |||
| 44 | if ((memory_type.propertyFlags & flags) != flags) { | ||
| 45 | // Memory must be device local and host visible | ||
| 46 | continue; | ||
| 47 | } | ||
| 48 | |||
| 49 | const auto& heap{props.memoryHeaps[memory_type.heapIndex]}; | ||
| 50 | if (heap.size >= 7168_MiB) { | ||
| 51 | // This is the right type of memory | ||
| 52 | return true; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | return false; | ||
| 39 | } | 57 | } |
| 40 | 58 | ||
| 41 | std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask, | 59 | std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask, |
| 42 | VkMemoryPropertyFlags flags) noexcept { | 60 | VkMemoryPropertyFlags flags, |
| 61 | size_t staging_buffer_size) noexcept { | ||
| 43 | for (u32 type_index = 0; type_index < props.memoryTypeCount; ++type_index) { | 62 | for (u32 type_index = 0; type_index < props.memoryTypeCount; ++type_index) { |
| 44 | if (((type_mask >> type_index) & 1) == 0) { | 63 | if (((type_mask >> type_index) & 1) == 0) { |
| 45 | // Memory type is incompatible | 64 | // Memory type is incompatible |
| @@ -50,7 +69,7 @@ std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& p | |||
| 50 | // Memory type doesn't have the flags we want | 69 | // Memory type doesn't have the flags we want |
| 51 | continue; | 70 | continue; |
| 52 | } | 71 | } |
| 53 | if (!IsStreamHeap(props.memoryHeaps[memory_type.heapIndex])) { | 72 | if (!IsStreamHeap(props.memoryHeaps[memory_type.heapIndex], staging_buffer_size)) { |
| 54 | // Memory heap is not suitable for streaming | 73 | // Memory heap is not suitable for streaming |
| 55 | continue; | 74 | continue; |
| 56 | } | 75 | } |
| @@ -61,17 +80,17 @@ std::optional<u32> FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& p | |||
| 61 | } | 80 | } |
| 62 | 81 | ||
| 63 | u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask, | 82 | u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_mask, |
| 64 | bool try_device_local) { | 83 | bool try_device_local, size_t staging_buffer_size) { |
| 65 | std::optional<u32> type; | 84 | std::optional<u32> type; |
| 66 | if (try_device_local) { | 85 | if (try_device_local) { |
| 67 | // Try to find a DEVICE_LOCAL_BIT type, Nvidia and AMD have a dedicated heap for this | 86 | // Try to find a DEVICE_LOCAL_BIT type, Nvidia and AMD have a dedicated heap for this |
| 68 | type = FindMemoryTypeIndex(props, type_mask, STREAM_FLAGS); | 87 | type = FindMemoryTypeIndex(props, type_mask, STREAM_FLAGS, staging_buffer_size); |
| 69 | if (type) { | 88 | if (type) { |
| 70 | return *type; | 89 | return *type; |
| 71 | } | 90 | } |
| 72 | } | 91 | } |
| 73 | // Otherwise try without the DEVICE_LOCAL_BIT | 92 | // Otherwise try without the DEVICE_LOCAL_BIT |
| 74 | type = FindMemoryTypeIndex(props, type_mask, HOST_FLAGS); | 93 | type = FindMemoryTypeIndex(props, type_mask, HOST_FLAGS, staging_buffer_size); |
| 75 | if (type) { | 94 | if (type) { |
| 76 | return *type; | 95 | return *type; |
| 77 | } | 96 | } |
| @@ -79,20 +98,32 @@ u32 FindMemoryTypeIndex(const VkPhysicalDeviceMemoryProperties& props, u32 type_ | |||
| 79 | throw vk::Exception(VK_ERROR_OUT_OF_DEVICE_MEMORY); | 98 | throw vk::Exception(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
| 80 | } | 99 | } |
| 81 | 100 | ||
| 82 | size_t Region(size_t iterator) noexcept { | 101 | size_t Region(size_t iterator, size_t region_size) noexcept { |
| 83 | return iterator / REGION_SIZE; | 102 | return iterator / region_size; |
| 84 | } | 103 | } |
| 85 | } // Anonymous namespace | 104 | } // Anonymous namespace |
| 86 | 105 | ||
| 87 | StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& memory_allocator_, | 106 | StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& memory_allocator_, |
| 88 | Scheduler& scheduler_) | 107 | Scheduler& scheduler_) |
| 89 | : device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_} { | 108 | : device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_} { |
| 109 | |||
| 110 | const auto memory_properties{device.GetPhysical().GetMemoryProperties().memoryProperties}; | ||
| 111 | if (HasLargeDeviceLocalHostVisibleMemory(memory_properties)) { | ||
| 112 | // Possible on many integrated and newer discrete cards | ||
| 113 | staging_buffer_size = 1_GiB; | ||
| 114 | } else { | ||
| 115 | // Well-supported default size used by most Vulkan PC games | ||
| 116 | staging_buffer_size = 256_MiB; | ||
| 117 | } | ||
| 118 | |||
| 119 | region_size = staging_buffer_size / StagingBufferPool::NUM_SYNCS; | ||
| 120 | |||
| 90 | const vk::Device& dev = device.GetLogical(); | 121 | const vk::Device& dev = device.GetLogical(); |
| 91 | stream_buffer = dev.CreateBuffer(VkBufferCreateInfo{ | 122 | stream_buffer = dev.CreateBuffer(VkBufferCreateInfo{ |
| 92 | .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, | 123 | .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, |
| 93 | .pNext = nullptr, | 124 | .pNext = nullptr, |
| 94 | .flags = 0, | 125 | .flags = 0, |
| 95 | .size = STREAM_BUFFER_SIZE, | 126 | .size = staging_buffer_size, |
| 96 | .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | | 127 | .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | |
| 97 | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, | 128 | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, |
| 98 | .sharingMode = VK_SHARING_MODE_EXCLUSIVE, | 129 | .sharingMode = VK_SHARING_MODE_EXCLUSIVE, |
| @@ -117,19 +148,18 @@ StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& mem | |||
| 117 | .image = nullptr, | 148 | .image = nullptr, |
| 118 | .buffer = *stream_buffer, | 149 | .buffer = *stream_buffer, |
| 119 | }; | 150 | }; |
| 120 | const auto memory_properties = device.GetPhysical().GetMemoryProperties().memoryProperties; | ||
| 121 | VkMemoryAllocateInfo stream_memory_info{ | 151 | VkMemoryAllocateInfo stream_memory_info{ |
| 122 | .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, | 152 | .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, |
| 123 | .pNext = make_dedicated ? &dedicated_info : nullptr, | 153 | .pNext = make_dedicated ? &dedicated_info : nullptr, |
| 124 | .allocationSize = requirements.size, | 154 | .allocationSize = requirements.size, |
| 125 | .memoryTypeIndex = | 155 | .memoryTypeIndex = FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, true, |
| 126 | FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, true), | 156 | staging_buffer_size), |
| 127 | }; | 157 | }; |
| 128 | stream_memory = dev.TryAllocateMemory(stream_memory_info); | 158 | stream_memory = dev.TryAllocateMemory(stream_memory_info); |
| 129 | if (!stream_memory) { | 159 | if (!stream_memory) { |
| 130 | LOG_INFO(Render_Vulkan, "Dynamic memory allocation failed, trying with system memory"); | 160 | LOG_INFO(Render_Vulkan, "Dynamic memory allocation failed, trying with system memory"); |
| 131 | stream_memory_info.memoryTypeIndex = | 161 | stream_memory_info.memoryTypeIndex = FindMemoryTypeIndex( |
| 132 | FindMemoryTypeIndex(memory_properties, requirements.memoryTypeBits, false); | 162 | memory_properties, requirements.memoryTypeBits, false, staging_buffer_size); |
| 133 | stream_memory = dev.AllocateMemory(stream_memory_info); | 163 | stream_memory = dev.AllocateMemory(stream_memory_info); |
| 134 | } | 164 | } |
| 135 | 165 | ||
| @@ -137,7 +167,7 @@ StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& mem | |||
| 137 | stream_memory.SetObjectNameEXT("Stream Buffer Memory"); | 167 | stream_memory.SetObjectNameEXT("Stream Buffer Memory"); |
| 138 | } | 168 | } |
| 139 | stream_buffer.BindMemory(*stream_memory, 0); | 169 | stream_buffer.BindMemory(*stream_memory, 0); |
| 140 | stream_pointer = stream_memory.Map(0, STREAM_BUFFER_SIZE); | 170 | stream_pointer = stream_memory.Map(0, staging_buffer_size); |
| 141 | } | 171 | } |
| 142 | 172 | ||
| 143 | StagingBufferPool::~StagingBufferPool() = default; | 173 | StagingBufferPool::~StagingBufferPool() = default; |
| @@ -158,25 +188,25 @@ void StagingBufferPool::TickFrame() { | |||
| 158 | } | 188 | } |
| 159 | 189 | ||
| 160 | StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) { | 190 | StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) { |
| 161 | if (AreRegionsActive(Region(free_iterator) + 1, | 191 | if (AreRegionsActive(Region(free_iterator, region_size) + 1, |
| 162 | std::min(Region(iterator + size) + 1, NUM_SYNCS))) { | 192 | std::min(Region(iterator + size, region_size) + 1, NUM_SYNCS))) { |
| 163 | // Avoid waiting for the previous usages to be free | 193 | // Avoid waiting for the previous usages to be free |
| 164 | return GetStagingBuffer(size, MemoryUsage::Upload); | 194 | return GetStagingBuffer(size, MemoryUsage::Upload); |
| 165 | } | 195 | } |
| 166 | const u64 current_tick = scheduler.CurrentTick(); | 196 | const u64 current_tick = scheduler.CurrentTick(); |
| 167 | std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + Region(iterator), | 197 | std::fill(sync_ticks.begin() + Region(used_iterator, region_size), |
| 168 | current_tick); | 198 | sync_ticks.begin() + Region(iterator, region_size), current_tick); |
| 169 | used_iterator = iterator; | 199 | used_iterator = iterator; |
| 170 | free_iterator = std::max(free_iterator, iterator + size); | 200 | free_iterator = std::max(free_iterator, iterator + size); |
| 171 | 201 | ||
| 172 | if (iterator + size >= STREAM_BUFFER_SIZE) { | 202 | if (iterator + size >= staging_buffer_size) { |
| 173 | std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + NUM_SYNCS, | 203 | std::fill(sync_ticks.begin() + Region(used_iterator, region_size), |
| 174 | current_tick); | 204 | sync_ticks.begin() + NUM_SYNCS, current_tick); |
| 175 | used_iterator = 0; | 205 | used_iterator = 0; |
| 176 | iterator = 0; | 206 | iterator = 0; |
| 177 | free_iterator = size; | 207 | free_iterator = size; |
| 178 | 208 | ||
| 179 | if (AreRegionsActive(0, Region(size) + 1)) { | 209 | if (AreRegionsActive(0, Region(size, region_size) + 1)) { |
| 180 | // Avoid waiting for the previous usages to be free | 210 | // Avoid waiting for the previous usages to be free |
| 181 | return GetStagingBuffer(size, MemoryUsage::Upload); | 211 | return GetStagingBuffer(size, MemoryUsage::Upload); |
| 182 | } | 212 | } |
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h index 91dc84da8..90c67177f 100644 --- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h +++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h | |||
| @@ -93,6 +93,9 @@ private: | |||
| 93 | size_t free_iterator = 0; | 93 | size_t free_iterator = 0; |
| 94 | std::array<u64, NUM_SYNCS> sync_ticks{}; | 94 | std::array<u64, NUM_SYNCS> sync_ticks{}; |
| 95 | 95 | ||
| 96 | size_t staging_buffer_size = 0; | ||
| 97 | size_t region_size = 0; | ||
| 98 | |||
| 96 | StagingBuffersCache device_local_cache; | 99 | StagingBuffersCache device_local_cache; |
| 97 | StagingBuffersCache upload_cache; | 100 | StagingBuffersCache upload_cache; |
| 98 | StagingBuffersCache download_cache; | 101 | StagingBuffersCache download_cache; |
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 378804c08..12a7e4922 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp | |||
| @@ -111,7 +111,8 @@ struct Client::Impl { | |||
| 111 | httplib::Error error; | 111 | httplib::Error error; |
| 112 | 112 | ||
| 113 | if (!cli->send(request, response, error)) { | 113 | if (!cli->send(request, response, error)) { |
| 114 | LOG_ERROR(WebService, "{} to {} returned null", method, host + path); | 114 | LOG_ERROR(WebService, "{} to {} returned null (httplib Error: {})", method, host + path, |
| 115 | httplib::to_string(error)); | ||
| 115 | return WebResult{WebResult::Code::LibError, "Null response", ""}; | 116 | return WebResult{WebResult::Code::LibError, "Null response", ""}; |
| 116 | } | 117 | } |
| 117 | 118 | ||