instancing issues
dx9.0c shader model 2 code. hardware instancing.
just got shader_test5 running - instancing with texturing and lighting and alpha test.
i can draw 14,400 instances of a 30-40 vertex plant mesh with unique worldmats no problem. 62 fps rock solid vsync on. no culling at all.
the problem seems to be the size of the instance data.
kick it up from 120*120 to 130*130 = 16,900 instances.and it blows up.
i create an array of 4x4 worldmats. set the mats, then copy them to a vb.
the array is currently a local variable allocated on the stack.
130*130 is an array a little over 1 meg. would that make it blow up? win32. wouldn't think so...
a concern is that my terrain chunks are 300*300 in size. so far i can't get over 120*120.
ideas:
put the array on the heap.
lock the vb and set it directly, removing the need for an array.
pass x,y,z, and yr (all i really need) and compute the worldmat from those in the shader. saves me 12 floats per instance. i assume HLSL 2 or 3 can do that, correct?
use smaller 100x100 "grass chunks" that are separate from terrain chunks.
ideally, i'd like to have plants just be part of a terrain chunk, with 300*300 = 90,000 instances per chunk.
but that's 90,000 instances * at least 4 floats per instance * 4 bytes per float = 1.44 million bytes. whats the max size of a VB?
is it just me or does 16,900 seem a little low to be running out of ram?
EDIT: Ok, looks like there's a 1 meg default limit on the stack. That answers that. Well, I have a few gig of heap to work with - working set size of about 700-800 meg the last time I looked. That would be preferable to increasing the stack. In general, i would prefer a solution that doesn't require "big memory". But i have the megs available to burn if i need to use them.
But i would think that instance bandwidth would be a greater issue.
should i just pass x,y,z,and yr? can HLSL create a worldmat from those params? premature optimization?
any problem with locking and editing the vb directly? this is done before the render loop in the test. in the game this would be foreground or background chunk generation.
what about max VB size? check caps?
time to google!