[SlimDx] Loading textures into system memory

Started by
1 comment, last by nanckekr 14 years, 5 months ago
I am building an application using SlimDx where I have a collection of graphics cards connected and a lot of SRAM memory. For best performance I want to have complete control of what textures are loaded into each of the graphics cards. To do that, the plan is to load textures from disk into system memory (SRAM). Then as needed, copy textures from SRAM into VRAM for the graphics cards that will benefit from having the textures in local VRAM. In theory this sounded perfectly doable with SlimDx. You will load textures from SRAM into VRAM using this method.
public static Texture FromMemory(
	Device device,
	byte[] memory
)

The method asks for a list of bytes. I am not sure how you will define that list in C#, so this is question #1. The second and more complicated question is how to load the textures from disk into SRAM. The most applicable method I could find is this one:
public static Texture FromFile(
	Device device,
	string fileName
)
The problem here is that it asks for a specific device. Obviously I wanted to be able to store textures in SRAM and then later decide which textures I want to send to device 1 and which textures to send to device 2 etc. If I am forced to load all textures into a SRAM memmory slot reserved for each GPU will not only slow down loading significantly, it will also waste SRAM resources as all textures are now represented once for each GPU. On my system I will have many GPU's connected so this will be problematic. My question #2 is: How can I load textures into SRAM without tying them to a specific device, and thus later allow myself to load them directly into the device using the FromMemory method mentioned above?
Advertisement
Quote:
The method asks for a list of bytes. I am not sure how you will define that list in C#, so this is question #1.

byte[] bytes = new byte[size here];

then fill that array with the bytes of the texture, in a loop, or whatever. Mostly this will depend on how you're even getting that texture data.

Quote:
My question #2 is: How can I load textures into SRAM without tying them to a specific device, and thus later allow myself to load them directly into the device using the FromMemory method mentioned above?

You can share resources across devices but it requires hardware support that is relatively new or rare, as far as I know. A better idea may be to simply cache all your texture data (the byte arrays) yourself until you can make the decision which device to put the texture on, and create the SlimDX texture then.
Thanks for the ideas - it makes complete sense to me and it answers one concern I have on how to convert from PNG files into the format required by the graphics card. That conversion happens when loading the texture into the device from the byte array :-)

I am not 100% sure how to fill the byte array in a way that allow me to later use the FromMemory method..

Today I am testing with bypassing the SRAM, i.e. loading directly from disk like this:

string filename = "c:/myfile.png";texture = SlimDX.Direct3D9.Texture.FromFile(device, fileName);


I assume I need to do something like this

byte[] rawData = File.ReadAllBytes(filename);SlimDX.Direct3D9.Texture.FromMemory(device, rawData);

This topic is closed to new replies.

Advertisement