ID3DXBaseEffect::SetValue Bug?

Started by
5 comments, last by Mike.Popoloski 15 years, 5 months ago
I think ID3DXBaseEffect::SetValue may contain a bug pertaining to size validation. As an example, say I have an effect file with a simple vector array like so: float4 myArray[20]; In my code, if I call ID3DXBaseEffect::SetVectorArray("myArray", data, 10), I can set the first ten elements of the array with my own data. If, however, I use ID3DXBaseEffect::SetValue, which the documentation claims is a valid replacement for most of the SetXXX methods, including arrays, I run into problems. Setting the full length of the array, like this: ID3DXBaseEffect::SetValue("myArray", data, sizeof(D3DXVECTOR4) * 20) will compile and run just fine. However, if I choose to set only a portion of the array, like in the first example, I get an error result from the function. Is this valid behavior, or have I encountered a bug? Has anyone else run into this issue? It's been makes things difficult, since I'm using SetValue as a generic replacement for all of the other SetXXX methods. I emailed the DX team a few weeks ago, but haven't received a reply.
Mike Popoloski | Journal | SlimDX
Advertisement

From what I've seen, things are a bit sketchy when dealing with array ranges. I'd said this is expected behavior since you're effectively setting a single value with that method1, so it's likely that the method isn't smart enough to handle array ranges. You could check what the valid behavior should be with the reference device though and you might want try posting your question on MS Connect to see if you can get some feedback there.

Out of curiosity though, wouldn't it work for you to just keep a fixed size array on the CPU side of things, fill that up to where needed and copy it over completely? As I recall SetVectorArray was either missing or buggy back in MDX, so I went with this workaround. I know it's not sparkly clean, but with all the other data on the move those few extra bytes shouldn't be that big a deal.

1 For some speculation, couldn't it be that the effects framework/the driver queues all constants data in a big buffer for optimizing transfer, which is causing stuff to end up in the wrong registers? It's a wild guess, but I could imagine that happening when you pass in sizeof(D3DXVECTOR4) * 10 to SetValue while the array has 20 elements.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Quote:Out of curiosity though, wouldn't it work for you to just keep a fixed size array on the CPU side of things, fill that up to where needed and copy it over completely? As I recall SetVectorArray was either missing or buggy back in MDX, so I went with this workaround. I know it's not sparkly clean, but with all the other data on the move those few extra bytes shouldn't be that big a deal.


Yes, that works, but the basic issue here is that I'm using SetValue as the back end in SlimDX for all SetXXX methods, thereby saving me from having to define a ton of overloads and rewriting the same basic code over and over. A user reported this issue because he could no longer set subsections of the array.

You could indeed be right that this is valid behavior. I'd just like some confirmation from the DX team before I close this issue as "expected behavior".
Mike Popoloski | Journal | SlimDX
It looks like you should be getting this debug spew: ID3DXEffect::SetValue: Data size mismatch

So it looks to be expected behavior, ::SetValue expects the entire data type to be set. Note that you can pass D3DX_DEFAULT for the size and it will assume that you passed in enough data to fill the value.
Hmmm, I don't recall getting any debug spew, but it's quite possible that I just missed it. It seems odd that SetValue would require the full array, but perhaps its due to the way it's implemented. I'll look into specializing the method using the SetXXXArray methods. Thanks for your help.
Mike Popoloski | Journal | SlimDX
If you figure anything out can you post back here. I've just been setting it to the full array, but it would be nice if I didn't have to update the entire array each time.
Treb, I just uploaded the fix to the repository. Try it out and let me know if you still have any problems.
Mike Popoloski | Journal | SlimDX

This topic is closed to new replies.

Advertisement