Sign in to follow this  
NickUdell

Sample a Texture2D with the CPU

Recommended Posts

I'm using SlimDX and Direct3D11 and I have a Texture2D created by loading from a file. I want to use this, and a couple of other textures to build a set of procedural textures at runtime - however I don't want to use the GPU as it's already very busy doing other things.

Unfortunately I can't find any way of sampling a Texture2D outside of HLSL or using Texture2D.SaveToStream() and skipping through to the pixels I want manually.

Is there a simpler way of doing it? Something similar to HLSL's Texture2D.Sample(sampler,coords) or am I going to have to wade through the data stream?

Thanks

Share this post


Link to post
Share on other sites
Keep a copy of the texture data in system memory and then it's just a simple array lookup.

[center][size=6][b]BUT.[/b][/size][/center]

Are you really [i]quite[/i] certain about the "I don't want to use the GPU as it's already very busy doing other things" part? Chances are that it's nowhere near as busy as you [i]think[/i] it is, and even if so, the bottleneck on your program from creating procedural textures at runtime on the CPU (and then having to upload them to the GPU as dynamic texture resources) is very likely going to be FAR higher than doing so on the GPU.

In other words you're talking about something in the region of accepting a 100% performance overhead on the CPU side (especially if the CPU needs to block while uploading one of those textures) in exchange for something like a 5% or 10% performance saving on the GPU. That seems like it's the wrong way around to me.

Share this post


Link to post
Share on other sites
I was planning to build the CPU implementation on a separate thread so I could run it with low priority and build the textures slowly. It's a space game and I'm actually limiting the number of procedurally-textured objects on screen at any one time to 8 or 9, and due to the distances involved, this will update very slowly - so I have in the order of several minutes to actually generate the new textures - this in turn allows me to build very detailed (many octaves of fBm noise) texture representations without causing stuttering due to the GPU currently generating a large texture while my render thread waits.

Share this post


Link to post
Share on other sites
Even if you build it on another thread, it´s probably gona take alot longer. ALOT longe than building it on the gpu.
i mean, the gpu have like 1k cores, Or more/less depending on chip. but it´s far more than 8 cores.

So i have to agree with what mhagain said, it sounds wrong to do it on the cpu.
you could have the cpu to calculate what the gpu should do on the other thread but not build the texture itself.

Share this post


Link to post
Share on other sites
[quote name='NickUdell' timestamp='1339667933' post='4949098']
Hmm I see your point, I'll do a GPU implementation for now then and when it comes to optimization later I'll write up a CPU implementation and test them side by side.
[/quote]
That, Sir, is a excellent approach! and make sure to post the results!
[img]http://static.tumblr.com/c5veyqk/8mzm4w1j8/feel_like_a_sir.jpg[/img] Edited by Tordin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this