@@ -1005,7 +1005,6 @@ private protected override MappedResource MapCore(
1005
1005
if ( resource is VkBuffer buffer )
1006
1006
{
1007
1007
memoryBlock = buffer . Memory ;
1008
- sizeInBytes = buffer . SizeInBytes ;
1009
1008
}
1010
1009
else
1011
1010
{
@@ -1020,15 +1019,20 @@ private protected override MappedResource MapCore(
1020
1019
1021
1020
if ( memoryBlock . DeviceMemory != VkDeviceMemory . NULL )
1022
1021
{
1022
+ ulong atomSize = _physicalDeviceProperties . limits . nonCoherentAtomSize ;
1023
+ ulong mapOffset = memoryBlock . Offset + offsetInBytes ;
1024
+ ulong bindOffset = ( ( mapOffset / atomSize ) * atomSize ) ;
1025
+ ulong bindSize = ( ( sizeInBytes + atomSize - 1 ) / atomSize ) * atomSize ;
1026
+
1023
1027
if ( memoryBlock . IsPersistentMapped )
1024
1028
{
1025
- mappedPtr = ( IntPtr ) memoryBlock . BlockMappedPointer ;
1029
+ mappedPtr = ( IntPtr ) ( ( byte * ) memoryBlock . BaseMappedPointer + mapOffset ) ;
1026
1030
}
1027
1031
else
1028
1032
{
1029
1033
void * ret ;
1030
1034
VkResult result = vkMapMemory (
1031
- _device , memoryBlock . DeviceMemory , memoryBlock . Offset , memoryBlock . Size , 0 , & ret ) ;
1035
+ _device , memoryBlock . DeviceMemory , bindOffset , bindSize , 0 , & ret ) ;
1032
1036
if ( result != VkResult . VK_ERROR_MEMORY_MAP_FAILED )
1033
1037
{
1034
1038
CheckResult ( result ) ;
@@ -1037,15 +1041,14 @@ private protected override MappedResource MapCore(
1037
1041
{
1038
1042
ThrowMapFailedException ( resource , subresource ) ;
1039
1043
}
1040
- mappedPtr = ( IntPtr ) ret ;
1044
+ mappedPtr = ( IntPtr ) ( ( byte * ) ret + ( mapOffset - bindOffset ) ) ;
1041
1045
}
1042
1046
}
1043
1047
1044
- byte * dataPtr = ( byte * ) mappedPtr . ToPointer ( ) + offsetInBytes ;
1045
1048
return new MappedResource (
1046
1049
resource ,
1047
1050
mode ,
1048
- ( IntPtr ) dataPtr ,
1051
+ mappedPtr ,
1049
1052
offsetInBytes ,
1050
1053
sizeInBytes ,
1051
1054
subresource ,
@@ -1280,7 +1283,7 @@ internal VkCommandList GetAndBeginCommandList()
1280
1283
{
1281
1284
Transient = true
1282
1285
} ;
1283
- sharedList = ( VkCommandList ) ResourceFactory . CreateCommandList ( desc ) ;
1286
+ sharedList = ( VkCommandList ) ResourceFactory . CreateCommandList ( desc ) ;
1284
1287
}
1285
1288
1286
1289
sharedList . Begin ( ) ;
0 commit comments