New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: GetLongOffset
and GetLongOffsetAndLength
#102114
Comments
Related: |
|
With .NET 9, you’ll be able to could convert a (nint offset, nint length) = ((NRange)myRange).GetOffsetAndLength(); |
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
Accessing the GPU memory requires mapping it into CPU memory, in which case you're still limited to 32-bits at a time (much less in practice due to general system overhead). This is why, for example, the There is a very small subset of GPU commands which operate exclusively on the GPU side, such as |
That's a fair assessment, most operations are indeed related to mapping to CPU memory. The main issue is the I also have to say that implementing these extension methods yourself can be a bit trickier than initially expected. The value that is used internally by |
The base address being 64-bits doesn't matter, you aren't passing the base address into In many cases, the allocations even for the GPU are similarly going to be restricted. A typical GPU has 8GB of VRAM and while some have more, it becomes less common. In practice, you can't and will never actually get the entire memory space in a single allocation due to general system overhead. In many cases the actual GPU APIs have restrictions on the maximum sizes allowed as well (for textures, buffers, etc; often well below even 1GB), often causing these buffers to be far smaller than the theoretical limit. For practicality reasons, you're going to be chunking and sharing that VRAM space across many allocations and will almost certainly never encounter one in a typical real world production app that is even close to 2GB in size. If you're working in such a specialize domain where it is necessary, extension methods are perfectly suitable and that just solidifies such an API being a bad fit for the BCL. -- Plus if you're on a 64-bit computer, then |
Background and motivation
I am building C# wrappers around modern graphics APIs (DirectX/Vulkan/Metal), which allow the user to allocate large blocks of GPU memory directly. These sizes can go beyond the capacity of a 32 bit integer, so the APIs always use 64 bit integers, even if the application itself is compiled as 32 bit.
To make interacting with these APIs more ergonomic, I wanted to add support for
Index
andRange
. And whileIndex
andRange
won't be suitable for situations where you indeed exceed the maximum size of anint
, most of the time your buffers and textures will be smaller than that.Index
andRange
have a couple of convenience functions, specificallyIndex.GetOffset
andRange.GetOffset
. I would like to use these, but because they operate onint
instead oflong
, they are unusable for APIs with 64 bit integers (at least without additional checks and casting).My proposal is to add
long
versions of these APIs calledGetLongOffset
andGetLongOffsetAndLength
, similar to otherlong
versions of APIs such asLongLength
,LongCount
, etc.API Proposal
The following methods are copies from their non
long
counterparts, just withint
replaced withlong
.API Usage
This is how I currently use it, with
GetLongOffsetAndLength
implemented as and extension method.Alternative Designs
long
methods in other APIs.Risks
This change would be purely additive, so there should be no risks.
The text was updated successfully, but these errors were encountered: