Created
May 2, 2016 10:15
-
-
Save jamesu/60bf8bcef74077a5fac5d3791fa39b0e to your computer and use it in GitHub Desktop.
A casual exploration of potential hash conflicts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Don't ask | |
#include "core/crc.h" | |
struct GFXSamplerStateDesc2 | |
{ | |
GFXTextureAddressMode addressModeU; | |
GFXTextureAddressMode addressModeV; | |
GFXTextureAddressMode addressModeW; | |
GFXTextureFilterType magFilter; | |
GFXTextureFilterType minFilter; | |
GFXTextureFilterType mipFilter; | |
GFXCmpFunc samplerFunc; | |
/// The maximum anisotropy used when one of the filter types | |
/// is set to anisotropic. | |
/// | |
/// Defaults to 1. | |
/// | |
/// @see GFXTextureFilterType | |
U32 maxAnisotropy; | |
/// Used to offset the mipmap selection by whole or | |
/// fractional amounts either postively or negatively. | |
/// | |
/// Defaults to zero. | |
F32 mipLODBias; | |
GFXTextureOp textureColorOp; | |
GFXTextureOp alphaOp; | |
GFXTextureArgument alphaArg1; | |
GFXTextureArgument alphaArg2; | |
GFXTextureArgument alphaArg3; | |
GFXTextureArgument colorArg1; | |
GFXTextureArgument colorArg2; | |
GFXTextureArgument colorArg3; | |
GFXTextureArgument resultArg; | |
GFXTextureTransformFlags textureTransform; | |
}; | |
ConsoleFunction(kaboom, void, 1, 1, "") | |
{ | |
GFXSamplerStateDesc2 secState; | |
GFXSamplerStateDesc2 hashedState; | |
Map<U32, GFXSamplerStateDesc2> stateHash; | |
dMemset(&secState, '\0', sizeof(secState)); | |
Con::printf("Size of struct is %i", sizeof(GFXSamplerStateDesc2)); | |
for (U32 i = GFXAddress_FIRST; i<GFXAddress_COUNT; i++) | |
{ | |
for (U32 j = GFXAddress_FIRST; j<GFXAddress_COUNT; j++) | |
{ | |
for (U32 k = GFXAddress_FIRST; k<GFXAddress_COUNT; k++) | |
{ | |
for (U32 mi = GFXTextureFilter_FIRST; mi<GFXTextureFilter_COUNT; mi++) | |
{ | |
for (U32 mj = GFXTextureFilter_FIRST; mj<GFXTextureFilter_COUNT; mj++) | |
{ | |
for (U32 mk = GFXTextureFilter_FIRST; mk<GFXTextureFilter_COUNT; mk++) | |
{ | |
for (U32 wii = GFXCmp_FIRST; wii<GFXCmp_COUNT; wii++) | |
{ | |
for (U32 ai = 0; ai<4; ai++) | |
{ | |
for (S32 li = -10; li<11; li++) | |
{ | |
for (U32 textureColorOp_i = GFXTOP_FIRST; textureColorOp_i<GFXTOP_COUNT; textureColorOp_i++) | |
{ | |
for (U32 alphaOp_i = GFXTOP_FIRST; alphaOp_i<GFXTOP_COUNT; alphaOp_i++) | |
{ | |
for (U32 alphaArg1_i = GFXTA_FIRST; alphaArg1_i<GFXTA_COUNT; alphaArg1_i++) | |
{ | |
for (U32 alphaArg2_i = GFXTA_FIRST; alphaArg2_i<GFXTA_COUNT; alphaArg2_i++) | |
{ | |
for (U32 alphaArg3_i = GFXTA_FIRST; alphaArg3_i<GFXTA_COUNT; alphaArg3_i++) | |
{ | |
for (U32 colorArg1_i = GFXTA_FIRST; colorArg1_i<GFXTA_COUNT; colorArg1_i++) | |
{ | |
for (U32 colorArg2_i = GFXTA_FIRST; colorArg2_i<GFXTA_COUNT; colorArg2_i++) | |
{ | |
for (U32 colorArg3_i = GFXTA_FIRST; colorArg3_i<GFXTA_COUNT; colorArg3_i++) | |
{ | |
for (U32 resultArg_i = GFXTA_FIRST; resultArg_i<GFXTA_COUNT; resultArg_i++) | |
{ | |
for (U32 textureTransform_i = GFXTTFFDisable; textureTransform_i <= GFXTTFFCoord4D + 1; textureTransform_i++) | |
{ | |
if (textureTransform_i == GFXTTFFCoord4D + 1) textureTransform_i = GFXTTFFProjected; | |
secState.addressModeU = (GFXTextureAddressMode)i; | |
secState.addressModeV = (GFXTextureAddressMode)j; | |
secState.addressModeW = (GFXTextureAddressMode)k; | |
secState.samplerFunc = (GFXCmpFunc)wii; | |
secState.magFilter = (GFXTextureFilterType)mi; | |
secState.minFilter = (GFXTextureFilterType)mi; | |
secState.mipFilter = (GFXTextureFilterType)mi; | |
secState.maxAnisotropy = ai; | |
secState.mipLODBias = (0.1f * li); | |
secState.textureColorOp = (GFXTextureOp)textureColorOp_i; | |
secState.alphaOp = (GFXTextureOp)alphaOp_i; | |
secState.alphaArg1 = (GFXTextureArgument)alphaArg1_i; | |
secState.alphaArg2 = (GFXTextureArgument)alphaArg2_i; | |
secState.alphaArg3 = (GFXTextureArgument)alphaArg3_i; | |
secState.colorArg1 = (GFXTextureArgument)colorArg1_i; | |
secState.colorArg2 = (GFXTextureArgument)colorArg2_i; | |
secState.colorArg3 = (GFXTextureArgument)colorArg3_i; | |
secState.resultArg = (GFXTextureArgument)resultArg_i; | |
secState.textureTransform = (GFXTextureTransformFlags)textureTransform_i; | |
U32 hash = CRC::calculateCRC(&secState, sizeof(GFXSamplerStateDesc2));; | |
if (stateHash.tryGetValue(hash, hashedState)) | |
{ | |
Con::warnf("Stateblock hash is already in map!"); | |
} | |
else | |
{ | |
stateHash[hash] = secState; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
Con::printf("%i possible states stored in map.", stateHash.size()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment