Browse Source

Add hash16 type | Batch: use hash types

1vanK 3 years ago
parent
commit
e0ba366898

+ 8 - 8
Source/Urho3D/AngelScript/Generated_Members.h

@@ -323,8 +323,8 @@ template <class T> void RegisterMembers_Batch(asIScriptEngine* engine, const cha
     // ShaderVariation* Batch::pixelShader_
     // ShaderVariation* Batch::pixelShader_
     // Not registered because pointer
     // Not registered because pointer
 
 
-    // unsigned long long Batch::sortKey_
-    engine->RegisterObjectProperty(className, "uint64 sortKey", offsetof(T, sortKey_));
+    // hash64 Batch::sortKey_
+    engine->RegisterObjectProperty(className, "hash64 sortKey", offsetof(T, sortKey_));
 
 
     // float Batch::distance_
     // float Batch::distance_
     engine->RegisterObjectProperty(className, "float distance", offsetof(T, distance_));
     engine->RegisterObjectProperty(className, "float distance", offsetof(T, distance_));
@@ -408,12 +408,12 @@ template <class T> void RegisterMembers_BatchQueue(asIScriptEngine* engine, cons
 
 
     // HashMap<BatchGroupKey, BatchGroup> BatchQueue::batchGroups_
     // HashMap<BatchGroupKey, BatchGroup> BatchQueue::batchGroups_
     // Error: type "HashMap<BatchGroupKey, BatchGroup>" can not automatically bind
     // Error: type "HashMap<BatchGroupKey, BatchGroup>" can not automatically bind
-    // HashMap<unsigned, unsigned> BatchQueue::shaderRemapping_
-    // Error: type "HashMap<unsigned, unsigned>" can not automatically bind
-    // HashMap<unsigned short, unsigned short> BatchQueue::materialRemapping_
-    // Error: type "HashMap<unsigned short, unsigned short>" can not automatically bind
-    // HashMap<unsigned short, unsigned short> BatchQueue::geometryRemapping_
-    // Error: type "HashMap<unsigned short, unsigned short>" can not automatically bind
+    // HashMap<hash32, hash32> BatchQueue::shaderRemapping_
+    // Error: type "HashMap<hash32, hash32>" can not automatically bind
+    // HashMap<hash16, hash16> BatchQueue::materialRemapping_
+    // Error: type "HashMap<hash16, hash16>" can not automatically bind
+    // HashMap<hash16, hash16> BatchQueue::geometryRemapping_
+    // Error: type "HashMap<hash16, hash16>" can not automatically bind
     // Vector<Batch> BatchQueue::batches_
     // Vector<Batch> BatchQueue::batches_
     // Error: type "Vector<Batch>" can not automatically bind
     // Error: type "Vector<Batch>" can not automatically bind
     // Vector<Batch*> BatchQueue::sortedBatches_
     // Vector<Batch*> BatchQueue::sortedBatches_

+ 1 - 0
Source/Urho3D/AngelScript/Manual.cpp

@@ -90,6 +90,7 @@ void ASRegisterManualFirst(asIScriptEngine* engine)
 
 
     engine->RegisterTypedef("SDL_JoystickID", "int");
     engine->RegisterTypedef("SDL_JoystickID", "int");
     engine->RegisterTypedef("c32", "uint");
     engine->RegisterTypedef("c32", "uint");
+    engine->RegisterTypedef("hash16", "uint16");
     engine->RegisterTypedef("hash32", "uint");
     engine->RegisterTypedef("hash32", "uint");
     engine->RegisterTypedef("hash64", "uint64");
     engine->RegisterTypedef("hash64", "uint64");
 
 

+ 1 - 0
Source/Urho3D/Base/PrimitiveTypes.h

@@ -33,5 +33,6 @@ static_assert(sizeof(void*) == sizeof(ptrdiff_t));
 static_assert(sizeof(void*) == sizeof(intptr_t));
 static_assert(sizeof(void*) == sizeof(intptr_t));
 
 
 // Some hash value (checksum for example)
 // Some hash value (checksum for example)
+using hash16 = u16;
 using hash32 = u32;
 using hash32 = u32;
 using hash64 = u64;
 using hash64 = u64;

+ 17 - 17
Source/Urho3D/Graphics/Batch.cpp

@@ -146,18 +146,18 @@ void CalculateSpotMatrix(Matrix4& dest, Light* light)
 
 
 void Batch::CalculateSortKey()
 void Batch::CalculateSortKey()
 {
 {
-    auto shaderID = (unsigned)(
-        ((*((unsigned*)&vertexShader_) / sizeof(ShaderVariation)) + (*((unsigned*)&pixelShader_) / sizeof(ShaderVariation))) &
+    u32 shaderID = (u32)(
+        ((*((u32*)&vertexShader_) / sizeof(ShaderVariation)) + (*((u32*)&pixelShader_) / sizeof(ShaderVariation))) &
         0x7fffu);
         0x7fffu);
     if (!isBase_)
     if (!isBase_)
         shaderID |= 0x8000;
         shaderID |= 0x8000;
 
 
-    auto lightQueueID = (unsigned)((*((unsigned*)&lightQueue_) / sizeof(LightBatchQueue)) & 0xffffu);
-    auto materialID = (unsigned)((*((unsigned*)&material_) / sizeof(Material)) & 0xffffu);
-    auto geometryID = (unsigned)((*((unsigned*)&geometry_) / sizeof(Geometry)) & 0xffffu);
+    u32 lightQueueID = (u32)((*((u32*)&lightQueue_) / sizeof(LightBatchQueue)) & 0xffffu);
+    u32 materialID = (u32)((*((u32*)&material_) / sizeof(Material)) & 0xffffu);
+    u32 geometryID = (u32)((*((u32*)&geometry_) / sizeof(Geometry)) & 0xffffu);
 
 
-    sortKey_ = (((unsigned long long)shaderID) << 48u) | (((unsigned long long)lightQueueID) << 32u) |
-               (((unsigned long long)materialID) << 16u) | geometryID;
+    sortKey_ = (((hash64)shaderID) << 48u) | (((hash64)lightQueueID) << 32u) |
+               (((hash64)materialID) << 16u) | geometryID;
 }
 }
 
 
 void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool allowDepthWrite) const
 void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool allowDepthWrite) const
@@ -777,16 +777,16 @@ void BatchQueue::SortFrontToBack2Pass(Vector<Batch*>& batches)
     // For desktop, first sort by distance and remap shader/material/geometry IDs in the sort key
     // For desktop, first sort by distance and remap shader/material/geometry IDs in the sort key
     Sort(batches.Begin(), batches.End(), CompareBatchesFrontToBack);
     Sort(batches.Begin(), batches.End(), CompareBatchesFrontToBack);
 
 
-    unsigned freeShaderID = 0;
-    unsigned short freeMaterialID = 0;
-    unsigned short freeGeometryID = 0;
+    hash32 freeShaderID = 0;
+    hash16 freeMaterialID = 0;
+    hash16 freeGeometryID = 0;
 
 
     for (Vector<Batch*>::Iterator i = batches.Begin(); i != batches.End(); ++i)
     for (Vector<Batch*>::Iterator i = batches.Begin(); i != batches.End(); ++i)
     {
     {
         Batch* batch = *i;
         Batch* batch = *i;
 
 
-        auto shaderID = (unsigned)(batch->sortKey_ >> 32u);
-        HashMap<unsigned, unsigned>::ConstIterator j = shaderRemapping_.Find(shaderID);
+        hash32 shaderID = (hash32)(batch->sortKey_ >> 32u);
+        HashMap<hash32, hash32>::ConstIterator j = shaderRemapping_.Find(shaderID);
         if (j != shaderRemapping_.End())
         if (j != shaderRemapping_.End())
             shaderID = j->second_;
             shaderID = j->second_;
         else
         else
@@ -795,8 +795,8 @@ void BatchQueue::SortFrontToBack2Pass(Vector<Batch*>& batches)
             ++freeShaderID;
             ++freeShaderID;
         }
         }
 
 
-        auto materialID = (unsigned short)((batch->sortKey_ & 0xffff0000) >> 16u);
-        HashMap<unsigned short, unsigned short>::ConstIterator k = materialRemapping_.Find(materialID);
+        hash16 materialID = (hash16)((batch->sortKey_ & 0xffff0000) >> 16u);
+        HashMap<hash16, hash16>::ConstIterator k = materialRemapping_.Find(materialID);
         if (k != materialRemapping_.End())
         if (k != materialRemapping_.End())
             materialID = k->second_;
             materialID = k->second_;
         else
         else
@@ -805,8 +805,8 @@ void BatchQueue::SortFrontToBack2Pass(Vector<Batch*>& batches)
             ++freeMaterialID;
             ++freeMaterialID;
         }
         }
 
 
-        auto geometryID = (unsigned short)(batch->sortKey_ & 0xffffu);
-        HashMap<unsigned short, unsigned short>::ConstIterator l = geometryRemapping_.Find(geometryID);
+        hash16 geometryID = (hash16)(batch->sortKey_ & 0xffffu);
+        HashMap<hash16, hash16>::ConstIterator l = geometryRemapping_.Find(geometryID);
         if (l != geometryRemapping_.End())
         if (l != geometryRemapping_.End())
             geometryID = l->second_;
             geometryID = l->second_;
         else
         else
@@ -815,7 +815,7 @@ void BatchQueue::SortFrontToBack2Pass(Vector<Batch*>& batches)
             ++freeGeometryID;
             ++freeGeometryID;
         }
         }
 
 
-        batch->sortKey_ = (((unsigned long long)shaderID) << 32u) | (((unsigned long long)materialID) << 16u) | geometryID;
+        batch->sortKey_ = (((hash64)shaderID) << 32u) | (((hash64)materialID) << 16u) | geometryID;
     }
     }
 
 
     shaderRemapping_.Clear();
     shaderRemapping_.Clear();

+ 4 - 4
Source/Urho3D/Graphics/Batch.h

@@ -56,7 +56,7 @@ struct Batch
     void Draw(View* view, Camera* camera, bool allowDepthWrite) const;
     void Draw(View* view, Camera* camera, bool allowDepthWrite) const;
 
 
     /// State sorting key.
     /// State sorting key.
-    unsigned long long sortKey_{};
+    hash64 sortKey_{};
     /// Distance from camera.
     /// Distance from camera.
     float distance_{};
     float distance_{};
     /// 8-bit render order modifier from material.
     /// 8-bit render order modifier from material.
@@ -228,11 +228,11 @@ public:
     /// Instanced draw calls.
     /// Instanced draw calls.
     HashMap<BatchGroupKey, BatchGroup> batchGroups_;
     HashMap<BatchGroupKey, BatchGroup> batchGroups_;
     /// Shader remapping table for 2-pass state and distance sort.
     /// Shader remapping table for 2-pass state and distance sort.
-    HashMap<unsigned, unsigned> shaderRemapping_;
+    HashMap<hash32, hash32> shaderRemapping_;
     /// Material remapping table for 2-pass state and distance sort.
     /// Material remapping table for 2-pass state and distance sort.
-    HashMap<unsigned short, unsigned short> materialRemapping_;
+    HashMap<hash16, hash16> materialRemapping_;
     /// Geometry remapping table for 2-pass state and distance sort.
     /// Geometry remapping table for 2-pass state and distance sort.
-    HashMap<unsigned short, unsigned short> geometryRemapping_;
+    HashMap<hash16, hash16> geometryRemapping_;
 
 
     /// Unsorted non-instanced draw calls.
     /// Unsorted non-instanced draw calls.
     Vector<Batch> batches_;
     Vector<Batch> batches_;