3 커밋 56e0d052f1 ... 5d63a4cad2

작성자 SHA1 메시지 날짜
  Torbjorn Laedre 5d63a4cad2 Change 3D texture memory barrier sub-resource range to be maintenance9 compatible. 1 개월 전
  Sam Lantinga 386f198622 Don't report 10% battery for Xbox controllers using XInput 4 일 전
  Rachel Blackman f8c364ae74 Ensure Android hidapi does not drop the report byte (#15527) 4 일 전
4개의 변경된 파일74개의 추가작업 그리고 39개의 파일을 삭제
  1. 16 8
      src/gpu/vulkan/SDL_gpu_vulkan.c
  2. 21 3
      src/hidapi/android/hid.cpp
  3. 18 14
      src/joystick/windows/SDL_rawinputjoystick.c
  4. 19 14
      src/joystick/windows/SDL_xinputjoystick.c

+ 16 - 8
src/gpu/vulkan/SDL_gpu_vulkan.c

@@ -2739,10 +2739,17 @@ static void VULKAN_INTERNAL_TextureSubresourceMemoryBarrier(
     memoryBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
     memoryBarrier.image = textureSubresource->parent->image;
     memoryBarrier.subresourceRange.aspectMask = textureSubresource->parent->aspectFlags;
-    memoryBarrier.subresourceRange.baseArrayLayer = textureSubresource->layer;
-    memoryBarrier.subresourceRange.layerCount = 1;
     memoryBarrier.subresourceRange.baseMipLevel = textureSubresource->level;
     memoryBarrier.subresourceRange.levelCount = 1;
+    memoryBarrier.subresourceRange.baseArrayLayer = textureSubresource->layer;
+    memoryBarrier.subresourceRange.layerCount = 1;
+
+    // VK_KHR_maintenance9 adds the ability to independently transition arbitrary subsets of slices in a 3D texture,
+    // we need to extend the barrier layer count in order to preserve intended behaviour when that extension is enabled.
+    // See https://docs.vulkan.org/features/latest/features/proposals/VK_KHR_maintenance9.html#_barriers_with_2d_array_compatible_3d_images
+    if (textureSubresource->parent->container->header.info.type == SDL_GPU_TEXTURETYPE_3D) {
+        memoryBarrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
+    }
 
     if (sourceUsageMode == VULKAN_TEXTURE_USAGE_MODE_UNINITIALIZED) {
         srcStages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
@@ -6004,12 +6011,6 @@ static void VULKAN_INTERNAL_CycleActiveTexture(
         renderer,
         &container->header.info);
 
-    VULKAN_INTERNAL_TextureTransitionToDefaultUsage(
-        renderer,
-        commandBuffer,
-        VULKAN_TEXTURE_USAGE_MODE_UNINITIALIZED,
-        texture);
-
     if (!texture) {
         return;
     }
@@ -6027,6 +6028,13 @@ static void VULKAN_INTERNAL_CycleActiveTexture(
     container->textureCount += 1;
 
     container->activeTexture = texture;
+
+    // Transition texture after storing it as the memory barrier might need to read the texture's container info
+    VULKAN_INTERNAL_TextureTransitionToDefaultUsage(
+        renderer,
+        commandBuffer,
+        VULKAN_TEXTURE_USAGE_MODE_UNINITIALIZED,
+        texture);
 }
 
 static VulkanBuffer *VULKAN_INTERNAL_PrepareBufferForWrite(

+ 21 - 3
src/hidapi/android/hid.cpp

@@ -725,9 +725,27 @@ public:
 				}
 			}
 
-			size_t uBytesToCopy = m_reportResponse.size() > nDataLen ? nDataLen : m_reportResponse.size();
-			SDL_memcpy( pData, m_reportResponse.data(), uBytesToCopy );
-			m_reportResponse.clear();
+			size_t uBytesToCopy = 0;
+
+			if ( m_reportResponse.size() > 0 )
+			{
+				// Make sure we preserve the report value if it isn't already in the report.
+				bool bHasReportAlready = ( *pData == *m_reportResponse.data() );
+
+				// Make sure we only copy as much as will fit, deducting one byte for the report if we need to leave it intact.
+				size_t nSafeDataLen = nDataLen - ( bHasReportAlready ? 0 : 1 );
+				uBytesToCopy = m_reportResponse.size() < nSafeDataLen ? m_reportResponse.size() : nSafeDataLen;
+
+				SDL_memcpy( pData + ( bHasReportAlready ? 0 : 1 ), m_reportResponse.data(), uBytesToCopy );
+				m_reportResponse.clear();
+
+				if ( !bHasReportAlready )
+				{
+					// Add the report byte back on to return the real length.
+					uBytesToCopy++;
+				}
+			}
+
 			LOGV( "=== Got %zu bytes", uBytesToCopy );
 
 			return (int)uBytesToCopy;

+ 18 - 14
src/joystick/windows/SDL_rawinputjoystick.c

@@ -1976,20 +1976,24 @@ static void RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
                 state = SDL_POWERSTATE_ON_BATTERY;
                 break;
             }
-            switch (battery_info->BatteryLevel) {
-            case BATTERY_LEVEL_EMPTY:
-                percent = 10;
-                break;
-            case BATTERY_LEVEL_LOW:
-                percent = 40;
-                break;
-            case BATTERY_LEVEL_MEDIUM:
-                percent = 70;
-                break;
-            default:
-            case BATTERY_LEVEL_FULL:
-                percent = 100;
-                break;
+            if (state == SDL_POWERSTATE_ON_BATTERY || SDL_POWERSTATE_CHARGING) {
+                switch (battery_info->BatteryLevel) {
+                case BATTERY_LEVEL_EMPTY:
+                    percent = 10;
+                    break;
+                case BATTERY_LEVEL_LOW:
+                    percent = 40;
+                    break;
+                case BATTERY_LEVEL_MEDIUM:
+                    percent = 70;
+                    break;
+                default:
+                case BATTERY_LEVEL_FULL:
+                    percent = 100;
+                    break;
+                }
+            } else {
+                percent = -1;
             }
             SDL_SendJoystickPowerInfo(joystick, state, percent);
         }

+ 19 - 14
src/joystick/windows/SDL_xinputjoystick.c

@@ -300,20 +300,24 @@ static void UpdateXInputJoystickBatteryInformation(SDL_Joystick *joystick, XINPU
         state = SDL_POWERSTATE_ON_BATTERY;
         break;
     }
-    switch (pBatteryInformation->BatteryLevel) {
-    case BATTERY_LEVEL_EMPTY:
-        percent = 10;
-        break;
-    case BATTERY_LEVEL_LOW:
-        percent = 40;
-        break;
-    case BATTERY_LEVEL_MEDIUM:
-        percent = 70;
-        break;
-    default:
-    case BATTERY_LEVEL_FULL:
-        percent = 100;
-        break;
+    if (state == SDL_POWERSTATE_ON_BATTERY || state == SDL_POWERSTATE_CHARGING) {
+        switch (pBatteryInformation->BatteryLevel) {
+        case BATTERY_LEVEL_EMPTY:
+            percent = 10;
+            break;
+        case BATTERY_LEVEL_LOW:
+            percent = 40;
+            break;
+        case BATTERY_LEVEL_MEDIUM:
+            percent = 70;
+            break;
+        default:
+        case BATTERY_LEVEL_FULL:
+            percent = 100;
+            break;
+        }
+    } else {
+        percent = -1;
     }
     SDL_SendJoystickPowerInfo(joystick, state, percent);
 }
@@ -391,6 +395,7 @@ void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick)
         return;
     }
 
+    // FIXME: This does end up making a device ioctl() to query data, we shouldn't do this every update.
     SDL_zero(XBatteryInformation);
     if (XINPUTGETBATTERYINFORMATION) {
         result = XINPUTGETBATTERYINFORMATION(joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation);