18

My laptop has a nice GPU with dedicated video RAM. But I've noticed while playing Minecraft that the computer doesn't seem to be using it for anything. Only about 100 MB get used at all according to the Windows Task Manager, while it eats up about half my regular RAM.

I had thought that VRAM would be used for storing models and textures and stuff, which would reduce the demand on regular RAM; if that's true, the textures and models must be far smaller than I'd thought. (note that this is a heavily modded install, with much more complex models and textures than your standard Minecraft.)

If it's not true, what is VRAM used for? Is there any way I can get my computer to make better use of it?

13
  • 3
    If your card has dedicated VRAM, it's not "eating up" your regular RAM; dedicated means that there are separate physical chips just for graphics. – chrylis -cautiouslyoptimistic- Apr 19 '20 at 3:38
  • 4
    @chrylis-onstrike- Yes, what I'm saying is that the game is eating up my regular RAM instead of making use of the dedicated VRAM. – Hearth Apr 19 '20 at 11:10
  • 5
    Minecraft's highly pixely graphics mean that you can make the textures really small and just draw them really big to get a pixel-graphics feeling. The texture for grass, for example is roughly 2KB big, whereas, the texture for, say, a rifle in Call of Duty is several MB big. That's a factor of 1000 there. Same with the models. Even a "complex" model will only have like 100 vertices, whereas a complex model in a "realistic" game will have a couple of thousand. – MechMK1 Apr 19 '20 at 21:54
  • 2
    @Hearth Even if you use a higher resolution mod pack, the game only loads into VRAM what it actually needs to render a scene in the immediate future. A simple example: If no chunks you have loaded contain any nether blocks, there will be no texture data for these blocks in your VRAM. They may be in your regular RAM, or they will be on disk. – MechMK1 Apr 19 '20 at 21:59
  • 3
    Note that while VRAM does store models and texture it stores models and texture for the GPU to use to push it to your monitor/screen. Your CPU (minecraft) has no access to the VRAM at all so all those models and texture must also be loaded into RAM for minecraft (not your graphics card) to use and manipulate (less so texture since games don't normally modify texture so a lot of games engine actually load texture directly to the GPU) – slebetman Apr 20 '20 at 8:13
36

Video RAM is specifically designed to store anything that is necessary to render a frame of video. When gaming, this includes textures, models, and other graphics-specific data like shader information and lighting maps. Generally, none of this data is stored in main system RAM as you alluded to, although VRAM is not specifically designed to reduce demand on regular RAM.

Minecraft is a bit of a different beast than most games. I'd assume you're playing the Java version for PC. Java is a (relatively) high-level programming language compared to others such as C or C++ which other games will commonly be written in. Because of this, Java is inherently at a disadvantage when it comes to memory usage requirements. This is why your main system memory takes such a huge hit when running Minecraft, a very resource-intensive program written in Java.

I'm not surprised that your video RAM usage is low, though - and truthfully neither should you. As it is only meant to store textures and models, and Minecraft is, well, a game based on cubes and 16x16 textures, I think you can realize why your VRAM usage is so low.

7
  • 1
    Well, this is heavily modded minecraft, with much more complex models and textures, so I would expect a bit more usage. I wonder if this is just a thing where minecraft--or the mods perhaps--are poorly coded? – Hearth Apr 18 '20 at 19:41
  • 19
    @Hearth VRAM will only store what it needs, nothing less, nothing more. It's not about poor coding. The data stored in VRAM is exactly what needs to be there, otherwise the game would not work. – Sam Forbis Apr 18 '20 at 19:47
  • Makes sense. Just feels like it ought to be using more, but I suppose I'm just mad about it taking all my conventional RAM when there's so much free VRAM. Maybe I ought to upgrade my RAM... not that I can afford that right now. – Hearth Apr 19 '20 at 12:46
  • 2
    The Java version has always been a resource hog. Perhaps you can give the native Windows 10 version a try, it is basically rewritten in C++ and has huge performance increases because of that. It should be free if you bought the Java Edition. – nullability Apr 20 '20 at 0:07
  • @nullability I doubt I can use my modpack on it, though. – Hearth Apr 20 '20 at 10:22
10

Java Minecraft is CPU heavy, but the GPU really has very little to do, graphics-wise it is very simple and graphics resources are very small in comparison to say… Call of Duty. When I say small, I mean very small, 100MB sounds about right.

Because of the “block” design of the game, you can fill the screen with relatively little resources needed. Its like using “Duplo Lego” instead of “Lego Technics.”

Java is an “interpreted” language, meaning it is not compiled down to native instructions. So when it is run, it needs a virtual machine to get the instructions (or bytecode) into something the processor will understand. Your CPU is doing more work than the GPU.

5
  • 11
    Java uses JIT (Just In Time) compilation to compile (hot) code to native instructions, in that regard, Java is not (only) an interpreted language, and it is also largely irrelevant in the context of this question. – Mark Rotteveel Apr 19 '20 at 9:45
  • 7
    "Java is an “interpreted” language, meaning it is not compiled down to native instructions" – There is no such thing as an "interpreted language". Interpretation and compilation are traits of the interpreter or compiler (duh!), not the language. A language is a set of mathematical rules and restrictions. Languages aren't interpreted or compiled, they just are. The two terms live on different levels of abstraction. If English were a statically typed language, the term "interpreted language" would be a type error. The term is not only wrong, it is "not even wrong", i.e. non-sensical. – Jörg W Mittag Apr 19 '20 at 10:22
  • 9
    The vast majority of Java implementations contain compilers, most more than one. E.g. Oracle's JDK contains javac, C1, and C2, that's no less than three compilers. "it needs a virtual machine" – There is nothing in the Java Language Specification that requires the usage of a virtual machine, and there are in fact, plenty of Java implementations that don't use a virtual machine. – Jörg W Mittag Apr 19 '20 at 10:25
  • 2
    @Dai: That is a very strange use of the term "Java Virtual Machine". Typically, the term "Java Virtual Machine" is reserved for the virtual machine described by the Java Virtual Machine Specification, and not for the implicit abstract machine described in the Java Language Specification. I have no idea why you are bringing OS virtualization, paravirtualization, or containerization into this, nor what the link you posted has to do with this. Note that the JLS is structured differently than the ISO C spec and does not explicitly describe an abstract machine. – Jörg W Mittag Apr 20 '20 at 6:59
  • @JörgWMittag Thank you for the feedback, I've retracted my comment. – Dai Apr 20 '20 at 7:01
8

The Java VM, like that used in Minecraft will appear to be using a lot of RAM because of the way it will reserve large chunks of system RAM before it uses it. This appears to the OS as the application actually using that much RAM. Java uses its own memory Heap which works somewhat independently from the operating system on which it is running. (it will still use calls for growing the Heap)

The texture loading in minecraft is fairly low. What also might be happening is the way your OpenGL driver is allocating textures. For example, in OpenGL 3.3, GPU buffers can be mapped to memory such that a write and subsequent flush to that memory section causes it to appear inside the GPU's VRAM automagically. The tricky part of this is whether this buffer is truly only on the GPU side, or if it is actually on both the CPU and GPU side and the driver is simply copying it from one buffer to another. The OpenGL spec says the driver can do either at its discretion. The result is that the CPU/Java side allocates lots of address space for the buffer and we may have two copies of the buffer: One on the CPU side and one on the GPU side.

It's also possible that the java program is still storing the images in RAM in its own cache, then loading/unloading it to/from the GPU as it is needed. This would require RAM usage to always be at least the same if not greater than VRAM usage.

More recent video drivers and iterations of OpenGL support HSA Architecture, which enables the VRAM to act like a cache - the program doesn't even "upload" a texture to the GPU - it simply passes a memory address to an already loaded texture, or even references the texture from a file which as been allocated into virtual memory. This makes evaluating resource usage more difficult because now instead of simply using RAM or VRAM, we may be using only memory address ranges in some cases, and some of those ranges could be assigned to RAM and some to disk, and the VRAM could appear limitless or zero-used since, as a cache it is only storing recently-used pages which could change arbitrarily!

2
  • I'm curious: is it possible to enable this HSA architecture as a user, or does the program being run have to support it? – Hearth Apr 20 '20 at 13:53
  • @Hearth The video driver needs to support it (and, consequently, the GPU as well). HSA is implemented in a layer of abstraction under the OpenGL API, so a program that uses OpenGL doesn't need to know if the card supports it or not. – oldmud0 Apr 21 '20 at 4:41
2

It's not about poor coding.

I would like to point something out. Modern graphics cards could process a large part of Minecraft in the card itself. Systems like PhysX attempt to do just that—CUDA, OpenCL etc. Consequently, this would increase VRAM usage.

Here's some things that could easily (relatively speaking) be offloaded to the graphics driver:

  • Tick updates of blocks (think leaf blocks dying, lighting updates, etc.)
  • Procedural generation
  • Fluid updates
  • Redstone
  • Physics

However, GPU processing in a shader language (GLSL, HLSL, SPIR-V) is much more difficult and bug prone than a high level language like Java. Thus, all of these things are performed on the CPU.

Although several games have implemented some of that in GPUs before, Minecraft didn't have the large, skilled resource pool that triple-A titles have.


The Math

Suppose Minecraft uses a 32-bit color scheme.

32 bits per color
4 colors per pixel (red, green, blue, alpha)
8 bits per byte
(32 bits * 4 colors per pixel) / 8 bits per byte = 128 / 8 = 16 bytes per pixel.
100MB / 16 bytes per pixel = 6,250,000 pixels
sqrt(6250000) = 2500x2500 image resource in GPU (uncompressed)
2500 pixels wide|tall / 16 pixels wide|tall = 156.25 tiles wide|tall (assuming 16x16 tile size)
156.25 tiles wide * 156.25 tiles tall = ~24,414 16x16 tiles.

In summary, you can store ~24,414, 16x16 tiles in an uncompressed, 32-bit, image resource in VRAM.

This exercise really helped me wrap my head around why Factorio had issues with it's sprite-sheets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.