Skip to content

Commit

Permalink
[DX12] Improved how CommandListDX12.GetResourcePtr() maps buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
Syncaidius committed Jun 5, 2024
1 parent 2517747 commit c93b465
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 49 deletions.
12 changes: 6 additions & 6 deletions Molten.Audio.OpenAL/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
},
"Magick.NET-Q8-AnyCPU": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "YcmatKDklm6IEHiVoDf9x8bGNXf1jfUATNgYjsEyPYiSRiWJkhTXvwJJobKxulpDQwuXpndafUh86fBt9nv8iw==",
"resolved": "13.9.0",
"contentHash": "4fFZXA2NG3uSp2qYcYZXiEX+3fM2MT2b8/eGt6534D6Txsoh+i4PcovG+5ghqfdoTebYFXJ4VoF4mBQIcR29Cg==",
"dependencies": {
"Magick.NET.Core": "13.8.0"
"Magick.NET.Core": "13.9.0"
}
},
"Magick.NET.Core": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "XOr+EMV12PF4A5v88sbZlu/mRrqh+XYYyWay8dcjulu6ooNdQuxBv/2LIHoDqeWrrn290tyivT8OWrKAZB76sA=="
"resolved": "13.9.0",
"contentHash": "7NF8Ntd/68WQucvU46vCrbBdZDOkEWjCtCiqKj3bijrj/oaKeKxILgD7iTsaUVQm8E3EgotyQw9b12xuvA6fWA=="
},
"Microsoft.CSharp": {
"type": "Transitive",
Expand Down Expand Up @@ -136,7 +136,7 @@
"molten.engine": {
"type": "Project",
"dependencies": {
"Magick.NET-Q8-AnyCPU": "[13.8.0, )",
"Magick.NET-Q8-AnyCPU": "[13.9.0, )",
"Molten.Math": "[0.8.0, )",
"Molten.Utility": "[0.8.0, )",
"Newtonsoft.Json": "[13.0.3, )"
Expand Down
4 changes: 1 addition & 3 deletions Molten.Engine/Graphics/Tasks/Resources/BufferSetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ internal struct BufferSetTask<T> : IGpuTask<BufferSetTask<T>>

public static bool Process(GpuCommandList cmd, ref BufferSetTask<T> t)
{
ulong actualOffset = t.Buffer.Offset + t.ByteOffset;

using (GpuStream stream = cmd.MapResource(t.Buffer, 0, actualOffset, GpuMapType.Write))
using (GpuStream stream = cmd.MapResource(t.Buffer, 0, t.ByteOffset, GpuMapType.Write))
stream.WriteRange(t.Data, t.DataStartIndex, t.ElementCount);

return true;
Expand Down
12 changes: 6 additions & 6 deletions Molten.Engine/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"net8.0": {
"Magick.NET-Q8-AnyCPU": {
"type": "Direct",
"requested": "[13.8.0, )",
"resolved": "13.8.0",
"contentHash": "YcmatKDklm6IEHiVoDf9x8bGNXf1jfUATNgYjsEyPYiSRiWJkhTXvwJJobKxulpDQwuXpndafUh86fBt9nv8iw==",
"requested": "[13.9.0, )",
"resolved": "13.9.0",
"contentHash": "4fFZXA2NG3uSp2qYcYZXiEX+3fM2MT2b8/eGt6534D6Txsoh+i4PcovG+5ghqfdoTebYFXJ4VoF4mBQIcR29Cg==",
"dependencies": {
"Magick.NET.Core": "13.8.0"
"Magick.NET.Core": "13.9.0"
}
},
"Newtonsoft.Json": {
Expand All @@ -19,8 +19,8 @@
},
"Magick.NET.Core": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "XOr+EMV12PF4A5v88sbZlu/mRrqh+XYYyWay8dcjulu6ooNdQuxBv/2LIHoDqeWrrn290tyivT8OWrKAZB76sA=="
"resolved": "13.9.0",
"contentHash": "7NF8Ntd/68WQucvU46vCrbBdZDOkEWjCtCiqKj3bijrj/oaKeKxILgD7iTsaUVQm8E3EgotyQw9b12xuvA6fWA=="
},
"Microsoft.CSharp": {
"type": "Transitive",
Expand Down
24 changes: 14 additions & 10 deletions Molten.Graphics.DX12/Pipeline/CommandListDX12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,33 @@ protected override GpuResourceMap GetResourcePtr(GpuResource resource, uint subr
ulong rowPitch = 0;
ulong depthPitch = 0;

void* ptrMap = null;
HResult hr = handle.Ptr1->Map(subresource, null, &ptrMap);
if (!Device.Log.CheckResult(hr, () => $"Failed to map resource {resource.Name} for {mapType} access"))
return new GpuResourceMap();

if (resource is GpuTexture tex)
{
// TODO Calculate row pitch based on texture size, subresource level, format and dimensions. Also consider block-compression size.
}
else if (resource is BufferDX12 buffer)
{
if (buffer.RootBuffer != null)
rowPitch = buffer.RootBuffer.SizeInBytes;
else
rowPitch = buffer.SizeInBytes;
//if (buffer.RootBuffer != null)
// rowPitch = buffer.RootBuffer.SizeInBytes;
//else
// rowPitch = buffer.SizeInBytes;

rowPitch = buffer.SizeInBytes;
depthPitch = rowPitch;

byte* iPtrMap = (byte*)ptrMap + buffer.Offset;
ptrMap = iPtrMap;
}

// TODO Implement support for the read Range parameter. This determines the area of a sub-resouce that the CPU may want to read.
// Irrelevant for writing.

void* ptrMap = null;
HResult hr = handle.Ptr1->Map(subresource, null, &ptrMap);
if (!Device.Log.CheckResult(hr, () => $"Failed to map resource {resource.Name} for {mapType} access"))
return new GpuResourceMap();
else
return new GpuResourceMap(ptrMap, rowPitch, depthPitch);
return new GpuResourceMap(ptrMap, rowPitch, depthPitch);
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions Molten.Graphics.DX12/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
},
"Magick.NET-Q8-AnyCPU": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "YcmatKDklm6IEHiVoDf9x8bGNXf1jfUATNgYjsEyPYiSRiWJkhTXvwJJobKxulpDQwuXpndafUh86fBt9nv8iw==",
"resolved": "13.9.0",
"contentHash": "4fFZXA2NG3uSp2qYcYZXiEX+3fM2MT2b8/eGt6534D6Txsoh+i4PcovG+5ghqfdoTebYFXJ4VoF4mBQIcR29Cg==",
"dependencies": {
"Magick.NET.Core": "13.8.0"
"Magick.NET.Core": "13.9.0"
}
},
"Magick.NET.Core": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "XOr+EMV12PF4A5v88sbZlu/mRrqh+XYYyWay8dcjulu6ooNdQuxBv/2LIHoDqeWrrn290tyivT8OWrKAZB76sA=="
"resolved": "13.9.0",
"contentHash": "7NF8Ntd/68WQucvU46vCrbBdZDOkEWjCtCiqKj3bijrj/oaKeKxILgD7iTsaUVQm8E3EgotyQw9b12xuvA6fWA=="
},
"Microsoft.CSharp": {
"type": "Transitive",
Expand Down Expand Up @@ -137,7 +137,7 @@
"molten.engine": {
"type": "Project",
"dependencies": {
"Magick.NET-Q8-AnyCPU": "[13.8.0, )",
"Magick.NET-Q8-AnyCPU": "[13.9.0, )",
"Molten.Math": "[0.8.0, )",
"Molten.Utility": "[0.8.0, )",
"Newtonsoft.Json": "[13.0.3, )"
Expand Down
12 changes: 6 additions & 6 deletions Molten.Graphics.DXC/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
},
"Magick.NET-Q8-AnyCPU": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "YcmatKDklm6IEHiVoDf9x8bGNXf1jfUATNgYjsEyPYiSRiWJkhTXvwJJobKxulpDQwuXpndafUh86fBt9nv8iw==",
"resolved": "13.9.0",
"contentHash": "4fFZXA2NG3uSp2qYcYZXiEX+3fM2MT2b8/eGt6534D6Txsoh+i4PcovG+5ghqfdoTebYFXJ4VoF4mBQIcR29Cg==",
"dependencies": {
"Magick.NET.Core": "13.8.0"
"Magick.NET.Core": "13.9.0"
}
},
"Magick.NET.Core": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "XOr+EMV12PF4A5v88sbZlu/mRrqh+XYYyWay8dcjulu6ooNdQuxBv/2LIHoDqeWrrn290tyivT8OWrKAZB76sA=="
"resolved": "13.9.0",
"contentHash": "7NF8Ntd/68WQucvU46vCrbBdZDOkEWjCtCiqKj3bijrj/oaKeKxILgD7iTsaUVQm8E3EgotyQw9b12xuvA6fWA=="
},
"Microsoft.CSharp": {
"type": "Transitive",
Expand Down Expand Up @@ -92,7 +92,7 @@
"molten.engine": {
"type": "Project",
"dependencies": {
"Magick.NET-Q8-AnyCPU": "[13.8.0, )",
"Magick.NET-Q8-AnyCPU": "[13.9.0, )",
"Molten.Math": "[0.8.0, )",
"Molten.Utility": "[0.8.0, )",
"Newtonsoft.Json": "[13.0.3, )"
Expand Down
12 changes: 6 additions & 6 deletions Molten.Graphics.DXGI/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
},
"Magick.NET-Q8-AnyCPU": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "YcmatKDklm6IEHiVoDf9x8bGNXf1jfUATNgYjsEyPYiSRiWJkhTXvwJJobKxulpDQwuXpndafUh86fBt9nv8iw==",
"resolved": "13.9.0",
"contentHash": "4fFZXA2NG3uSp2qYcYZXiEX+3fM2MT2b8/eGt6534D6Txsoh+i4PcovG+5ghqfdoTebYFXJ4VoF4mBQIcR29Cg==",
"dependencies": {
"Magick.NET.Core": "13.8.0"
"Magick.NET.Core": "13.9.0"
}
},
"Magick.NET.Core": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "XOr+EMV12PF4A5v88sbZlu/mRrqh+XYYyWay8dcjulu6ooNdQuxBv/2LIHoDqeWrrn290tyivT8OWrKAZB76sA=="
"resolved": "13.9.0",
"contentHash": "7NF8Ntd/68WQucvU46vCrbBdZDOkEWjCtCiqKj3bijrj/oaKeKxILgD7iTsaUVQm8E3EgotyQw9b12xuvA6fWA=="
},
"Microsoft.CSharp": {
"type": "Transitive",
Expand Down Expand Up @@ -119,7 +119,7 @@
"molten.engine": {
"type": "Project",
"dependencies": {
"Magick.NET-Q8-AnyCPU": "[13.8.0, )",
"Magick.NET-Q8-AnyCPU": "[13.9.0, )",
"Molten.Math": "[0.8.0, )",
"Molten.Utility": "[0.8.0, )",
"Newtonsoft.Json": "[13.0.3, )"
Expand Down
12 changes: 6 additions & 6 deletions Molten.Graphics.Vulkan/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
},
"Magick.NET-Q8-AnyCPU": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "YcmatKDklm6IEHiVoDf9x8bGNXf1jfUATNgYjsEyPYiSRiWJkhTXvwJJobKxulpDQwuXpndafUh86fBt9nv8iw==",
"resolved": "13.9.0",
"contentHash": "4fFZXA2NG3uSp2qYcYZXiEX+3fM2MT2b8/eGt6534D6Txsoh+i4PcovG+5ghqfdoTebYFXJ4VoF4mBQIcR29Cg==",
"dependencies": {
"Magick.NET.Core": "13.8.0"
"Magick.NET.Core": "13.9.0"
}
},
"Magick.NET.Core": {
"type": "Transitive",
"resolved": "13.8.0",
"contentHash": "XOr+EMV12PF4A5v88sbZlu/mRrqh+XYYyWay8dcjulu6ooNdQuxBv/2LIHoDqeWrrn290tyivT8OWrKAZB76sA=="
"resolved": "13.9.0",
"contentHash": "7NF8Ntd/68WQucvU46vCrbBdZDOkEWjCtCiqKj3bijrj/oaKeKxILgD7iTsaUVQm8E3EgotyQw9b12xuvA6fWA=="
},
"Microsoft.CSharp": {
"type": "Transitive",
Expand Down Expand Up @@ -144,7 +144,7 @@
"molten.engine": {
"type": "Project",
"dependencies": {
"Magick.NET-Q8-AnyCPU": "[13.8.0, )",
"Magick.NET-Q8-AnyCPU": "[13.9.0, )",
"Molten.Math": "[0.8.0, )",
"Molten.Utility": "[0.8.0, )",
"Newtonsoft.Json": "[13.0.3, )"
Expand Down

0 comments on commit c93b465

Please sign in to comment.