Skip to content

Commit

Permalink
Merge branch 'master' into HelloBundles
Browse files Browse the repository at this point in the history
  • Loading branch information
IngmarBitter authored May 24, 2020
2 parents 0d7516f + aaabb95 commit f0ce139
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 137 deletions.
56 changes: 18 additions & 38 deletions sources/Interop/Windows/other/d3dx12/D3D12.Manual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,41 +52,21 @@ public static byte D3D12GetFormatPlaneCount([NativeTypeName("ID3D12Device *")] I
return formatInfo.PlaneCount;
}

public static void MemcpySubresource([NativeTypeName("const D3D12_MEMCPY_DEST *")] D3D12_MEMCPY_DEST* pDest, [NativeTypeName("const D3D12_SUBRESOURCE_DATA *")] D3D12_SUBRESOURCE_DATA* pSrc, [NativeTypeName("SIZE_T")] UIntPtr RowSizeInBytes, [NativeTypeName("UINT")] uint NumRows, [NativeTypeName("UINT")] uint NumSlices)
public static void MemcpySubresource([NativeTypeName("const D3D12_MEMCPY_DEST *")] D3D12_MEMCPY_DEST* pDest, [NativeTypeName("const D3D12_SUBRESOURCE_DATA *")] D3D12_SUBRESOURCE_DATA* pSrc, [NativeTypeName("SIZE_T")] nuint RowSizeInBytes, [NativeTypeName("UINT")] uint NumRows, [NativeTypeName("UINT")] uint NumSlices)
{
for (var z = 0u; z < NumSlices; ++z)
{
var pDestSlice = (byte*)pDest->pData;
var pSrcSlice = (byte*)pSrc->pData;

if (IntPtr.Size == 4)
{
pDestSlice += (uint)pDest->SlicePitch * z;
pSrcSlice += (uint)pSrc->SlicePitch * z;
}
else
{
pDestSlice += (ulong)pDest->SlicePitch * z;
pSrcSlice += (ulong)pSrc->SlicePitch * z;
}
var pDestSlice = (byte*)pDest->pData + pDest->SlicePitch * z;
var pSrcSlice = (byte*)pSrc->pData + pSrc->SlicePitch * (nint)z;

for (var y = 0u; y < NumRows; ++y)
{
var pTempDest = pDestSlice;
var pTempSrc = pSrcSlice;

if (IntPtr.Size == 4)
{
pTempDest += (uint)pDest->RowPitch * y;
pTempSrc += (uint)pSrc->RowPitch * y;
}
else
{
pTempDest += (ulong)pDest->RowPitch * y;
pTempSrc += (ulong)pSrc->RowPitch * y;
}

Buffer.MemoryCopy(pTempSrc, pTempDest, (long)RowSizeInBytes, (long)RowSizeInBytes);
Buffer.MemoryCopy(
pSrcSlice + pSrc->RowPitch * (nint)y,
pDestSlice + pDest->RowPitch * y,
(ulong)RowSizeInBytes,
(ulong)RowSizeInBytes
);
}
}
}
Expand All @@ -111,7 +91,7 @@ public static ulong UpdateSubresources([NativeTypeName("ID3D12GraphicsCommandLis
var IntermediateDesc = pIntermediate->GetDesc();
var DestinationDesc = pDestinationResource->GetDesc();

if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset || RequiredSize > (ulong)(UIntPtr)(-1) || (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER && (FirstSubresource != 0 || NumSubresources != 1)))
if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset || RequiredSize > unchecked((nuint)(-1)) || (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER && (FirstSubresource != 0 || NumSubresources != 1)))
{
return 0;
}
Expand All @@ -126,17 +106,17 @@ public static ulong UpdateSubresources([NativeTypeName("ID3D12GraphicsCommandLis

for (var i = 0u; i < NumSubresources; ++i)
{
if (pRowSizesInBytes[i] > (ulong)(UIntPtr)(-1))
if (pRowSizesInBytes[i] > unchecked((nuint)(-1)))
return 0;

D3D12_MEMCPY_DEST DestData = new D3D12_MEMCPY_DEST
{
pData = pData + pLayouts[i].Offset,
RowPitch = (UIntPtr)pLayouts[i].Footprint.RowPitch,
SlicePitch = (UIntPtr)(pLayouts[i].Footprint.RowPitch * pNumRows[i])
RowPitch = (nuint)pLayouts[i].Footprint.RowPitch,
SlicePitch = (nuint)(pLayouts[i].Footprint.RowPitch * pNumRows[i])
};

MemcpySubresource(&DestData, &pSrcData[i], (UIntPtr)pRowSizesInBytes[i], pNumRows[i], pLayouts[i].Footprint.Depth);
MemcpySubresource(&DestData, &pSrcData[i], (nuint)pRowSizesInBytes[i], pNumRows[i], pLayouts[i].Footprint.Depth);
}
pIntermediate->Unmap(0, null);

Expand All @@ -161,12 +141,12 @@ public static ulong UpdateSubresources([NativeTypeName("ID3D12GraphicsCommandLis
ulong RequiredSize = 0;
ulong MemToAlloc = (ulong)(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(uint) + sizeof(ulong)) * NumSubresources;

if (MemToAlloc > (ulong)(UIntPtr)(-1))
if (MemToAlloc > unchecked((nuint)(-1)))
{
return 0;
}

var pMem = HeapAlloc(GetProcessHeap(), 0, (UIntPtr)MemToAlloc);
var pMem = HeapAlloc(GetProcessHeap(), 0, (nuint)MemToAlloc);

if (pMem == null)
{
Expand Down Expand Up @@ -242,7 +222,7 @@ public static int D3D12SerializeVersionedRootSignature([NativeTypeName("const D3
int hr = S_OK;
ref readonly D3D12_ROOT_SIGNATURE_DESC1 desc_1_1 = ref pRootSignatureDesc->Anonymous.Desc_1_1;

UIntPtr ParametersSize = (UIntPtr)(sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters);
nuint ParametersSize = (uint)sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters;
void* pParameters = ((ulong)ParametersSize > 0) ? HeapAlloc(GetProcessHeap(), 0, ParametersSize) : null;

if ((ulong)ParametersSize > 0 && pParameters == null)
Expand Down Expand Up @@ -279,7 +259,7 @@ public static int D3D12SerializeVersionedRootSignature([NativeTypeName("const D3
case D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE:
ref readonly D3D12_ROOT_DESCRIPTOR_TABLE1 table_1_1 = ref desc_1_1.pParameters[n].Anonymous.DescriptorTable;

UIntPtr DescriptorRangesSize = (UIntPtr)(sizeof(D3D12_DESCRIPTOR_RANGE) * table_1_1.NumDescriptorRanges);
nuint DescriptorRangesSize = (uint)sizeof(D3D12_DESCRIPTOR_RANGE) * table_1_1.NumDescriptorRanges;
void* pDescriptorRanges = ((ulong)DescriptorRangesSize > 0 && SUCCEEDED(hr)) ? HeapAlloc(GetProcessHeap(), 0, DescriptorRangesSize) : null;

if ((ulong)DescriptorRangesSize > 0 && pDescriptorRanges == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TerraFX.Interop
public unsafe partial struct D3D12_CPU_DESCRIPTOR_HANDLE : IEquatable<D3D12_CPU_DESCRIPTOR_HANDLE>
{
public static readonly D3D12_CPU_DESCRIPTOR_HANDLE DEFAULT = new D3D12_CPU_DESCRIPTOR_HANDLE {
ptr = UIntPtr.Zero
ptr = 0
};

public D3D12_CPU_DESCRIPTOR_HANDLE([NativeTypeName("const D3D12_CPU_DESCRIPTOR_HANDLE &")] in D3D12_CPU_DESCRIPTOR_HANDLE other, [NativeTypeName("INT")] int offsetScaledByIncrementSize)
Expand All @@ -25,13 +25,13 @@ public D3D12_CPU_DESCRIPTOR_HANDLE([NativeTypeName("const D3D12_CPU_DESCRIPTOR_H

public D3D12_CPU_DESCRIPTOR_HANDLE Offset([NativeTypeName("INT")] int offsetInDescriptors, [NativeTypeName("UINT")] uint descriptorIncrementSize)
{
ptr = (UIntPtr)((long)ptr + ((long)offsetInDescriptors * (long)descriptorIncrementSize));
ptr = unchecked((nuint)((long)ptr + ((long)offsetInDescriptors * (long)descriptorIncrementSize)));
return this;
}

public D3D12_CPU_DESCRIPTOR_HANDLE Offset([NativeTypeName("INT")] int offsetScaledByIncrementSize)
{
ptr = (UIntPtr)((long)ptr + (long)offsetScaledByIncrementSize);
ptr = unchecked((nuint)((long)ptr + (long)offsetScaledByIncrementSize));
return this;
}

Expand All @@ -57,12 +57,12 @@ public void InitOffsetted([NativeTypeName("const D3D12_CPU_DESCRIPTOR_HANDLE &")

public static void InitOffsetted([NativeTypeName("D3D12_CPU_DESCRIPTOR_HANDLE &")] out D3D12_CPU_DESCRIPTOR_HANDLE handle, [NativeTypeName("const D3D12_CPU_DESCRIPTOR_HANDLE &")] in D3D12_CPU_DESCRIPTOR_HANDLE @base, [NativeTypeName("INT")] int offsetScaledByIncrementSize)
{
handle.ptr = (UIntPtr)((long)@base.ptr + (long)offsetScaledByIncrementSize);
handle.ptr = (nuint)((long)@base.ptr + (long)offsetScaledByIncrementSize);
}

public static void InitOffsetted([NativeTypeName("D3D12_CPU_DESCRIPTOR_HANDLE &")] out D3D12_CPU_DESCRIPTOR_HANDLE handle, [NativeTypeName("const D3D12_CPU_DESCRIPTOR_HANDLE &")] in D3D12_CPU_DESCRIPTOR_HANDLE @base, [NativeTypeName("INT")] int offsetInDescriptors, [NativeTypeName("UINT")] uint descriptorIncrementSize)
{
handle.ptr = (UIntPtr)((long)@base.ptr + ((long)offsetInDescriptors * (long)descriptorIncrementSize));
handle.ptr = (nuint)((long)@base.ptr + ((long)offsetInDescriptors * (long)descriptorIncrementSize));
}

public override bool Equals(object? obj) => (obj is D3D12_CPU_DESCRIPTOR_HANDLE other) && Equals(other);
Expand Down
2 changes: 1 addition & 1 deletion sources/Interop/Windows/other/d3dx12/D3D12_RANGE.Manual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TerraFX.Interop
{
public partial struct D3D12_RANGE
{
public D3D12_RANGE([NativeTypeName("SIZE_T")] UIntPtr begin, [NativeTypeName("SIZE_T")] UIntPtr end)
public D3D12_RANGE([NativeTypeName("SIZE_T")] nuint begin, [NativeTypeName("SIZE_T")] nuint end)
{
Begin = begin;
End = end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public unsafe partial struct D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS

public bool Equals(D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS other) => this == other;

public override int GetHashCode() => HashCode.Combine((UIntPtr)pSrcResource, (UIntPtr)pDstResource, SubresourceCount, (UIntPtr)pSubresourceParameters, Format, ResolveMode, PreserveResolveSource);
public override int GetHashCode() => HashCode.Combine((nuint)pSrcResource, (nuint)pDstResource, SubresourceCount, (nuint)pSubresourceParameters, Format, ResolveMode, PreserveResolveSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public D3D12_SHADER_BYTECODE([NativeTypeName("ID3DBlob *")] ID3DBlob* pShaderBlo
BytecodeLength = pShaderBlob->GetBufferSize();
}

public D3D12_SHADER_BYTECODE([NativeTypeName("const void *")] void* _pShaderBytecode, [NativeTypeName("SIZE_T")] UIntPtr bytecodeLength)
public D3D12_SHADER_BYTECODE([NativeTypeName("const void *")] void* _pShaderBytecode, [NativeTypeName("SIZE_T")] nuint bytecodeLength)
{
pShaderBytecode = _pShaderBytecode;
BytecodeLength = bytecodeLength;
Expand Down
Loading

0 comments on commit f0ce139

Please sign in to comment.