Sign in to follow this  
Krohm

Is IDirect3DVertexDeclaration9 the really correct name?

Recommended Posts

I am still having trouble digesting D3D9 binding semantics. In particular, is IDirect3DVertexDeclaration9 named correctly? In fact the vertex shader varying inputs define the vertex format. This seems more like a "vertex buffer format" (which must include the VS input semantics). Do I miss something here? By the way, could you please point me to the matching rules for VS semantics agains the VertexDecl? I've lost the link again. Thanks!

Share this post


Link to post
Share on other sites
Quote:

In fact the vertex shader varying inputs define the vertex format.

No they don't. Vertex shader input semantics define the vertex attributes the shader requires to function, not the format of vertex stream that contains the attributes. The shader has no need of the formatting details, all it needs to know are the attributes themselves. Additionally, the term "varying" is generally meant to apply to pixel shader inputs that vary across the interpolation of the face being rasterized, not to vertex shader inputs.

IDirect3DVertexDeclaration9 is named correctly. It's a declaration of the vertex (buffer) format, defined by an array of vertex element structures that describe the format details of each vertex attribute. This includes information like what the attribute is used for (the usage, which maps to the HLSL input semantics) and its size (which is also relevant to HLSL), but also things like the attributes offset in the stream and how to interpret that data on the card. The latter types of formatting information are irrelevant to HLSL.

However, the format information is required CPU-side because that's where you put stuff in the buffer. In order for the card to know how to map the current buffer to the semantic inputs the current shader wants, it needs to know the format that you used to fill the buffer.

Quote:

By the way, could you please point me to the matching rules for VS semantics agains the VertexDecl? I've lost the link again.

The D3DDECL_USAGE values match up to HLSL input semantics. The list of values is in the documentation file that is installed with the DX SDK. You can also find it on MSDN via search.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
No they don't. Vertex shader input semantics define the vertex attributes the shader requires to function, not the format of vertex stream that contains the attributes.
I recognize I failed to express a vital concept: I suspect the proposed naming to be non-optimal. I have no doubt there's considerable difference between the VS semantics mapping and the stream ports mapping.
Quote:
Original post by jpetrie
Additionally, the term "varying" is generally meant to apply to pixel shader inputs that vary across the interpolation of the face being rasterized, not to vertex shader inputs.
Ok, let's call "attributes" then or "vertex inputs" as you want but it seems to me that attributes are so much like varyings. Ok, there's the extra interpolation stage. I still think at "varying shader inputs". In fact the syntax for GLSL varyings is very similar to GLSL attributes - it's just similar as well in HLSL9. No doubt it boils down to considerably different ops.
Quote:
Original post by jpetrie
IDirect3DVertexDeclaration9 is named correctly. It's a declaration of the vertex (buffer) format...
Yes, exactly. Wouldn't have been better to call it IDirect3DVertexBufferFormat then? Why the current solution was choosen above the other one? I mean: the actual information is just the same, I am speaking about minor syntactic sugar, there's no real need to be so involved. The info itself is just ok.
Quote:
Original post by jpetrie
However, the format information is required CPU-side because that's where you put stuff in the buffer. In order for the card to know how to map the current buffer to the semantic inputs the current shader wants, it needs to know the format that you used to fill the buffer.
Uhm... err... that's the point. It's more like "buffer" than "vertex", it then happens that the "vertex" must be a subset of the "buffer"... I feel I am failing expressing something here.
Quote:
Original post by jpetrie
The D3DDECL_USAGE values match up to HLSL input semantics. The list of values is in the documentation file that is installed with the DX SDK. You can also find it on MSDN via search.

Thank you, unluckly, I've posted this because I felt it wasn't the only source. If you say it is, I fear I'll have to just live with intuitive idea of subsets...

Share this post


Link to post
Share on other sites
Quote:

Yes, exactly. Wouldn't have been better to call it IDirect3DVertexBufferFormat then? Why the current solution was choosen above the other one? I mean: the actual information is just the same, I am speaking about minor syntactic sugar, there's no real need to be so involved. The info itself is just ok.


Because it had to be called something. The object is a declaration of the format of a vertex within a buffer. All of the italicized words are potential candidates for parts of the object name. Buffer is not a valid candidate because the object describes a single element of that buffer, and the buffer is implicitly formatted as a linear array of such elements. In theory the object in question could be used for other uses that require description of a vertex format without having a buffer association.

That said, any sane combination of the words "vertex," "format," "declaration," or their synonyms could be used. It doesn't really matter much. VertexDeclaration, VertexFormatSpecification, VertexFormatDescriptor -- anything could be used. There's nothing really particularly flawed with the name it stands -- vertex declaration makes the same kind of sense as class declaration, for example, and they do very similar things (define the format and layout of a particular element that might be used in a buffer of such elements, e.g., an array of classes).

Quote:

I feel I am failing expressing something here.

It really just sounds like you're complaining that you don't like the name, which is subjective and consequently not worth arguing about. However, the name is accurate, as are a number of other potential names that were ultimately discarded in favor of the current name.

Share this post


Link to post
Share on other sites
Vertex declarations can apply to vertices not in a vertex buffer, such as with DrawIndexedPrimitiveUP, so putting Buffer in the name would imply a restriction that doesn't exist.

A declaration may mismatch the shader inputs. It may contain extra items that the shader doesn't care about. It may contain data of a different format. D3DCOLOR is a dword, but in HLSL we often expect a float4. Position is usually float3 data, but we can tell the shader to expect float4 to get the implied w=1.0 for free.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
In theory the object in question could be used for other uses that require description of a vertex format without having a buffer association.
Quote:
Original post by Namethatnobodyelsetook
...so putting Buffer in the name would imply a restriction that doesn't exist.
Yes, I see this is a good reason. I'll have to bonk my head a bit to get this in - I don't like nor use unbuffered data anyway. It's just sad the docs themselves say "...defines the vertex buffer layout...".
Thank you for pointing this out!
Quote:
Original post by jpetrie
That said, any sane combination of the words "vertex," "format," "declaration," or their synonyms could be used. It doesn't really matter much...
That's sure.
Quote:
Original post by jpetrie
It really just sounds like you're complaining that you don't like the name, which is subjective and consequently not worth arguing about.
I apologize, I didn't want to say "this sucks", I wanted to know why it was named this way to get in the right point of view. In the end, a good reason came out. Anyway, I like ID3D10InputLayout much more (probably because it doesn't specifically name "vertex" and "Layout" is exactly what I would have used.
Quote:
Original post by Namethatnobodyelsetook
A declaration may mismatch the shader inputs. It may contain extra items that the shader doesn't care about. It may contain data of a different format. D3DCOLOR is a dword, but in HLSL we often expect a float4. Position is usually float3 data, but we can tell the shader to expect float4 to get the implied w=1.0 for free.
Yes, that's about the link I was asking about. I searched with google, the SDK search and the msdn for the conversion rules. I remember there was a page called like "vertex declaration matching rules" or something with all the valid coversions... I guess I'll go exploring a bit!

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