amerkoleci / Vortice.Windows

.NET bindings for Direct3D12, Direct3D11, WIC, Direct2D1, XInput, XAudio, X3DAudio, DXC, Direct3D9 and DirectInput.
MIT License
1.01k stars 73 forks source link

Bigger than expected Span returned from Map<> #366

Closed Kharzette closed 1 year ago

Kharzette commented 1 year ago

I'm using the ID3D11DeviceContext Map call to write to a dynamic 1D texture, and I noticed the span returned is rather large.

The texture itself is 1000 wide with format R8_UInt. The returned pitch is 1024, but there's a multiply by mipSize which in my case is 1000, so I end up with a uint span of 256000.

So I'm not sure if the math is off in CalculateSubResourceIndex or if this is some kind of special case for 1D textures?

I've also been having trouble with UpdateSubresource but I haven't narrowed down what the problem is other than nothing seems to get copied into the texture. I'll keep investigating that.

Thanks!

amerkoleci commented 1 year ago

Hi, Do you have any repro case? The texture is 1D texture and you call Map right?

Kharzette commented 1 year ago

Yes I was using Map\<uint>, but really I probably should have been using Map\<byte>. R8_UInt format is byte sized I think.

With Map\<byte> my span size is still 1000x1024 but the call actually works and I can see the data copied in my shader.

Kharzette commented 1 year ago

If you want to see where I'm using it, this is a bit of code that acts like an old character mode screen on a C64: https://github.com/Kharzette/GrogLibs/blob/e0a68a9c92fb7830ac511ff52dcce0c85b0f7baf/MaterialLib/Screen.cs

SetScreenContents has some of the other things I tried commented out. It hooks up with the TextMode.hlsl shader in groglibs shaderlib.

Groglibs is a mess right now as I'm still converting over from sharpDX so it might be hard to build that stuff.

amerkoleci commented 1 year ago

I've FIXED the Map method with commit: https://github.com/amerkoleci/Vortice.Windows/commit/08bfced011dc93f5896613e0bb967c35e0a99593, now you can create texture with R32_Uint and map it as byte.

Tell me if you have any issues.

Kharzette commented 1 year ago

The span returned is now 1024, which is exactly what I'd expect. Thanks!

amerkoleci commented 1 year ago

Nice, I'll push new stable nuget version soon