Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shader constants and constant buffers ?

24 views
Skip to first unread message

dylan

unread,
Mar 2, 2008, 3:31:42 PM3/2/08
to
Dear Angels,

(This is a rephrasing of my own recent post "accessing constant buffers
shader resources,etc.")

Can anyone tell me if they've used the shader constant buffers and
texture arrays and how ? (specifically when to use "Buffer<int4>"
compared to "cbuffer", and which application side functions are used to
set up which ?)

Below is the approach I've used for reference,
Thanks,

Dylan

------------------------------------------------------------------

For creating and accessing a texture array (in a vertex shader):
App:
-create (with initialization) an ID3D10Texture2D
-create the associated ID3D10ShaderResourceView
-set the texture array to the device ('VSSetShaderResources')
Shader:
-declare a Texture2DArray instance (tried globally and locally)
-call the Texture's Load(int4) method, tried with the following usage
combinations:
.x as array index, .y as texcoord 'u', .z as 'v', .w = 0
.x as 'u', .y as 'v', .z as array index, .w = 0

------------------------------------------------------------------

This is the original post for extra detail, again thank you for any insight,

"...I'd like to have a texture array and a constant buffer (array also)
available from the vertex shader, then another texture array for the
pixel shader.

In all it seems that there may be 3 distinct ways to set up, populate
and access variables/buffers (cbuffer/tbuffer, variable by name,
create/setbuffers and views) and essentially that's where my confusion
lies, as well as, in the last two, setting and accessing.

On the C++ side i'm using the CreateTexture2D followed by a
CreateShaderResourceView for the texture arrays, and a CreateBuffer call
for the constant buffer.
The texture arrays are initialized during creation.
I use VSSetShaderResources for the textures and VSSetConstantBuffers for
the constant buffer.
I declared 3 corresponding variable (tried at global scope as well as
local to vertex shader) like this:
Buffer<int4> g_bufCells;
Texture2DArray g_texTerrain; //4 integers per texel
Texture2DArray g_texAltitude; //1 integer per texel

My understanding is that I should be able to access the values in the
shader code using a 'Load' method from a Texture object (appears to
apply also to Buffers, but not 100% sure). So :

-What scope should these buffers be declared at, global to the shader or
inside the vertex shader ?

-How can I write (c++) to the constant buffer as needed (update the
values)? I believe I saw this once in the documentation or examples,
but I'm not seeing it anywhere anymore.

-After updating the values, do I need to call VSSetConstantBuffers
(again) or once they are linked/tied to my ID3D10Buffer instance is that
sufficient (assuming I'm updating directly through that reference) ?

- The Texure::Load method documentation does not state precisely the
usage of it's first argument, the example given is for a single 2D
texture only. for example, what would I fill in for each of the
(ordered) int4 values calling Load on a 2D texture array ? (i'm assuming
that one of the integers represents the index of the array that I'm
trying to access, not sure which one, tried 0 and 3).

- In the case of a texture (sub?) resource, for a 2D texture array, what
does one scan line constitute (ie. one texture size or one row of one
texture) ?
- Similarly for a constant buffer array of int4, I'm using a scan line
of 4 * sizeof(int), is this correct ?
- The bigger picture confusion: there are data types that can be
declared for constant and texture buffers like this (psuedo):
"cbuffer/tbuffer {{name, variable declaration(s)}". What are these
types of declarations compared to Texture2DArray and Buffer<int4> style
data types and how are they set up from c++ and accessed from shaders ?

Please note that I'm familiar with setting variables through the
'GetVariableByName' methodology, however I"m under the impression that
constant buffers and texture arrays are handled otherwise (since they
are noted to require use of the shader 'Load' intrinsic function) and
thus I haven't included that in any of my steps or attempts.


I appreciate very much any answers for these questions, and trust that
I've made every honest attempt through documentation, google and
newsgroups to find the answers, including a nice new book that seems to
cover just about everything except these questions. What i've seen are
hints of using the buffer and resourceview approach but no one complete
picture or example that I can apply to my case, so I'm sure it's my
fault as I'm just not getting it at the fundamental level.

Thanks,

Dylan
"

0 new messages