提问人:M_16 提问时间:11/17/2023 最后编辑:M_16 更新时间:11/18/2023 访问量:17
SlicePitch 值有误吗?
Is the SlicePitch value wrong?
问:
我一直在尝试使用 .我已经在我的旧笔记本电脑上多次执行此操作,并且运行良好,但是当我出于某种原因使用Intel Iris Xe Graphics执行此操作时,中间有零的间隙。Device.ImmediateContext.Mapsubresource()
这是它的示例代码:
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
public static unsafe float[] GetData()
{
int gpuAdapterIndex = 0;
SharpDX.DXGI.Adapter1 gpu;
using (var factory = new SharpDX.DXGI.Factory1())
{
gpu = factory.GetAdapter1(gpuAdapterIndex);
}
Device device = new Device(gpu, DeviceCreationFlags.Debug);
int pixelSize = sizeof(float);
int width = 10;
int height = 19;
int depth = 3;
float[] data = new float[width * height * depth];
for (int i = 0; i < data.Length; i++)
{
data[i] = i;
}
DataRectangle[] rectangles = new DataRectangle[depth];
fixed (float* dataPtr = data)
{
IntPtr p = (IntPtr)dataPtr;
for (int i = 0; i < rectangles.Length; i++)
{
rectangles[i] = new DataRectangle(IntPtr.Add(p, width * height * pixelSize * i), width * pixelSize);
}
}
Texture2D t = new Texture2D(device, new Texture2DDescription()
{
ArraySize = depth,
CpuAccessFlags = CpuAccessFlags.Write | CpuAccessFlags.Read,
BindFlags = BindFlags.None,
Format = SharpDX.DXGI.Format.R32_Float,
Height = height,
Width = width,
MipLevels = 1,
Usage = ResourceUsage.Staging,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
OptionFlags = ResourceOptionFlags.None,
}, rectangles);
float[] output = new float[data.Length];
DataBox box = device.ImmediateContext.MapSubresource(t, 0, MapMode.Read, MapFlags.None);
fixed (float* o = output)
{
IntPtr dst = (IntPtr)o;
IntPtr scr = box.DataPointer;
for (int z = 0; z < depth; z++)
{
for (int y = 0; y < height; y++)
{
CopyMemory(dst, scr, (uint)(width * pixelSize));
scr = IntPtr.Add(scr, box.RowPitch);
dst = IntPtr.Add(dst, width * pixelSize);
}
}
}
device.ImmediateContext.UnmapSubresource(t, 0);
t.Dispose();
device.Dispose();
return output;
}
当我检查并将其与每个切片的实际大小进行比较时,它们是不同的,如果我没记错的话,这不应该发生。box.SlicePitch
(width,height), box.rowpitch, box.slicepitch, real slice pitch
(2, 38), 64, 2432, 2560
(3, 38), 64, 2432, 2560
(4, 38), 64, 2432, 2560
(5, 38), 64, 2432, 2560
(6, 38), 64, 2432, 2560
(7, 38), 64, 2432, 2560
(8, 38), 64, 2432, 2560
(9, 38), 64, 2432, 2560
(10, 38), 64, 2432, 2560
(11, 38), 64, 2432, 2560
(12, 38), 64, 2432, 2560
(13, 38), 64, 2432, 2560
(14, 38), 64, 2432, 2560
(15, 38), 64, 2432, 2560
(17, 38), 128, 4864, 5120
(18, 38), 128, 4864, 5120
(19, 38), 128, 4864, 5120
(20, 38), 128, 4864, 5120
(21, 38), 128, 4864, 5120
(22, 38), 128, 4864, 5120
(23, 38), 128, 4864, 5120
(24, 38), 128, 4864, 5120
(25, 38), 128, 4864, 5120
(26, 38), 128, 4864, 5120
(27, 38), 128, 4864, 5120
(28, 38), 128, 4864, 5120
(29, 38), 128, 4864, 5120
(30, 38), 128, 4864, 5120
(31, 38), 128, 4864, 5120
(33, 38), 192, 7296, 7680
(34, 38), 192, 7296, 7680
(35, 38), 192, 7296, 7680
(36, 38), 192, 7296, 7680
(37, 38), 192, 7296, 7680
(38, 38), 192, 7296, 7680
(39, 38), 192, 7296, 7680
(40, 38), 192, 7296, 7680
我拥有的任何其他显卡(Intel graphics HD 520 和 nvidia mx450)都不会发生这种情况。
似乎正在发生的事情是,它不是计算切片间距,而是将高度四舍五入到它上面最接近的 4 的倍数,然后将其乘以 。我最担心的是,在其他情况下会发生这种情况吗?如果是这样,那么有没有一种通用的方法来处理它们?height * box.RowPitch
box.RowPitch
答: 暂无答案
评论