This project is read-only.

Possible bug in ParameterContainer?

Jan 13, 2014 at 3:14 PM
Edited Jan 13, 2014 at 3:26 PM
In ParameterContainer, in the destructor you delete all parameters in the container.The problem is, they might be needed somewhere else, like if another entity modifies the same CBuffer prior to its rendering or something.What I mean is the parameters are located in other places too, so deleting them from the parameter container of a single entity when than entity is removed, would cause a malfunction in some other place in the code?

Also I think the ParameterManager kills all the parameters in the static map too, even tho they might be used by one of its parents/children, then again the ParameterManager dies only at program end, so it might not be a big deal.
Jan 13, 2014 at 4:37 PM
The ParameterContainer only holds ParameterWriter instances - which are essentially objects that can take a resource or value and submit it to the parameter manager for use in a rendering operation. This is kind of like a white board pattern, where the writers put the data on the board (i.e. the ParameterManager) and anyone else can consume that data (i.e. the RenderEffect class). So in this case, the ParameterContainer is expected to own its writers, and can safely delete them when it goes out of scope. Any resources, or the actual parameter objects in the ParameterManager class, are not modified by this operation.

Your second point is also correct - the parameter manager is expected to live throughout the life of the application, so as a convenience I just wipe out the parameters there. Has this adversely affected a project you are working on?
Jan 13, 2014 at 9:55 PM
no, it's ok, everything is working properly so far.btw not sure if I should start another thread about this, but it's also about the parameters - when creating different parameters for float2, float3, float4, how do you differentiate between them?I think going from D3D_SHADER_VARIABLE_CLASS::D3D_SVC_VECTOR and then between D3D_SHADER_VARIABLE_TYPE of D3D_SVT_INT / D3D_SVT_FLOAT / D3D_SVT_DOUBLE / D3D_SVT_UINT you can find out that it's some kind of int2-4/float1-4/double1-4/uint1-4, but how to get the vector dimension?
UINT                        Rows;           // Number of rows (for matrices, 1 for other numeric, 0 if not applicable)
UINT                        Columns;        // Number of columns (for vectors & matrices, 1 for other numeric, 0 if not applicable)
UINT                        Elements;       // Number of elements (0 if not an array)
UINT                        Members;        // Number of members (0 if not a structure)
UINT                        Offset;         // Offset from the start of structure (0 if not a structure member)
LPCSTR                      Name;           // Name of type, can be NULL
Rows and Columns don't tell me anything.Elements, Members and Offset are for structs and Name doesn't help me.How else do I find the vector dimension?I thought of using D3D11_SHADER_VARIABLE_DESC::Size, however a 32bit int is the same size as a 32bit float, so that's not it either...
Jan 15, 2014 at 2:55 AM
It has been ages since I dug around in the shader description structures, but I seem to recall that there is a way to see the dimensionality of a parameter. In Hieroglyph3, I just use 4 element vectors for any parameter and just pad the values or combine multiple smaller vectors to fit into a 4D vector.

You could try to compile the shader with different input parameter sizes, then check the text output from FXC.exe. That might give you some clues about how to work backwards and find out where to see the data. If I recall correctly, I think it was in a second structure that is different from the one you would expect the data to be in... but that is just from memory and is subject to error!
Jan 16, 2014 at 2:06 AM
Edited Jan 16, 2014 at 2:07 AM
Ok here it is:

for a float3:
Rows: 1
Columns: 3
Elements: 0
Members: 0
Offset: 0
Name: "float3"
for a float:
Rows: 1
Columns: 1
Elements: 0
Members: 0
Offset: 0
Name: "float"
So I guess it counts rows/columns for vectors too, from there on it's easy.You can even search for the name directly - "float2", "float3", "float4" and so on.
Jan 16, 2014 at 2:20 AM
Cool - thanks for sharing that. Hopefully it will help someone else out in the future!