Use short for parameter count in effect binary#5995
Use short for parameter count in effect binary#5995harry-cpp merged 5 commits intoMonoGame:developfrom
Conversation
Tools/2MGFX/EffectObject.writer.cs
Outdated
| private static void WriteParameters(BinaryWriter writer, d3dx_parameter[] parameters, int count) | ||
| { | ||
| writer.Write((byte)count); | ||
| writer.Write((short) count); |
There was a problem hiding this comment.
How about writer.Write7BitEncodedInt(count)?
"If value will fit in seven bits, it takes only one byte of space. If value will not fit in seven bits, the high bit is set on the first byte and written out. value is then shifted by seven bits and the next byte is written. This process is repeated until the entire integer has been written."
There was a problem hiding this comment.
Yeah, I'll change that. It might save a couple bytes since most of the time count will fit in one byte. Thanks for the heads up, I didn't know about that function :)
|
Should we update those two just in case? |
|
That's not necessary, row and column are never more than 4 (we could even encode them in a single byte actually). |
|
Oh, I see. you are right. |
|
|
|
Interesting, I didn't know that. The 7BitEncodedInt is used in the ContentWriter for some parts of XNB. This format matches the .NET BinaryReader.Read7BitEncodedInt method. It is a variable size encoding of a 32 bit integer value. C implementation: |
|
Oh, cool! I could just implement it like that if that's preferable. |
|
Well, it doesn't give the implementation of Write7BitEncodedInt(), something that you need to figure out. |
|
Yeah, I think this is fine as is. MG also uses the 7 bit encoded int methods in the ContentReader and ContentWriter classes, but they extend BinaryReader and BinaryWriter, so they also use the .NET implementation. |
|
@tomspilman @cra0zy This is still good to go :) Heads up, it updates the MGFX version. That's important for release notes. |
|
Will the mgfxo be up-to-date, no rebase needed? (I haven't been following much the repo history lately, just a safe check. :) ) |
|
@mrhelmut Yes, the MGFX version has not been updated by another PR (it's still 8 in develop) which means the binary format has not changed since this branch was created. I recompiled all effects in my last commit, so the .xnb files are up to date :) |
|
var sizeInBytes = (int)reader.ReadUInt16(); |
|
A checked out version of this will still crash when using arrays with size > 1541 ShaderCode (crash) ShaderCode (will work) It will crash at Ln49 of ConstantBuffers.cs with an System.OverflowException: 'Arithmetic operation resulted in an overflow.' because the sizeInBytes is negative. The real problem seems to result from ln244 of Effect.cs where var sizeInBytes = (int)reader.ReadInt16 (); results in a negative number. |
|
Looks like Jjagg's commits are effective refactoring. I'd support pushing to base. |
|
Yes, I don't remember looking into the 1541 limit for arrays mentioned above, but this still at least improves the limit. This PR is old, but still good to go. |
0c416a9 to
078a67c
Compare
|
@harry-cpp This one is good to go! |
A byte was used for the parameter count previously, this limited arrays to 255 elements. Fixes #5994.