Skip to content
Permalink
Browse files

MOD: Vectorized the new 16 bit data type storing instead of only load…

…ing them one at a time as it was doing beforehand.

RESULTS: Gained 0.2ms in the game_gen_instance_buffer tick. We're now at 1.6ms
  • Loading branch information...
AlexSabourinDev committed Feb 17, 2019
1 parent 565fc73 commit 24937167948a87adb116cea5e593248873c6c808

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
@@ -85,6 +85,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>-Ofast -mavx %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -95,6 +96,7 @@
<ConformanceMode>true</ConformanceMode>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MinimalRebuild />
<AdditionalOptions>-Ofast -mavx %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -105,7 +107,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>-Ofast %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>-Ofast -mavx %(AdditionalOptions)</AdditionalOptions>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
@@ -122,7 +124,7 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<MinimalRebuild />
<AdditionalOptions>-Ofast %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>-Ofast -mavx %(AdditionalOptions)</AdditionalOptions>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -10,6 +10,9 @@
#include <math.h>
#include <time.h>

#include <xmmintrin.h>
#include <emmintrin.h>

#define SWAP(type, a, b) do{ type t = b; b = a; a = t; }while(0);

// Random
@@ -514,28 +517,28 @@ uint32_t game_gen_instance_buffer(Game_InstanceBuffer* buffer)
uint32_t writeIndex = Field_Width * Field_Height + Field_CropCount;

memcpy(&buffer->positions[writeIndex * 2], AI_FarmersSearchGen, sizeof(float) * 2 * AI_FarmerSearchCount);
for (uint32_t i = 0; i < AI_FarmerSearchCount; ++i)
__m128i searchAndScale = _mm_set_epi16(FarmerState_Search, AI_FarmerScale, FarmerState_Search, AI_FarmerScale, FarmerState_Search, AI_FarmerScale, FarmerState_Search, AI_FarmerScale);
for (uint32_t i = 0; i < AI_FarmerSearchCount; i+=4)
{
uint32_t writeLoc = writeIndex++;
buffer->spriteIndicesAndScales[writeLoc * 2] = FarmerState_Search;
buffer->spriteIndicesAndScales[writeLoc * 2 + 1] = AI_FarmerScale;
_mm_storeu_si128((__m128i*)&buffer->spriteIndicesAndScales[(writeIndex + i) * 2], searchAndScale);
}
writeIndex += AI_FarmerSearchCount;

memcpy(&buffer->positions[writeIndex * 2], AI_FarmersMoveGen, sizeof(float) * 2 * AI_FarmerMoveCount);
for (uint32_t i = 0; i < AI_FarmerMoveCount; ++i)
__m128i moveAndScale = _mm_set_epi16(FarmerState_Move, AI_FarmerScale, FarmerState_Move, AI_FarmerScale, FarmerState_Move, AI_FarmerScale, FarmerState_Move, AI_FarmerScale);
for (uint32_t i = 0; i < AI_FarmerMoveCount; i+=4)
{
uint32_t writeLoc = writeIndex++;
buffer->spriteIndicesAndScales[writeLoc * 2] = FarmerState_Move;
buffer->spriteIndicesAndScales[writeLoc * 2 + 1] = AI_FarmerScale;
_mm_storeu_si128((__m128i*)&buffer->spriteIndicesAndScales[(writeIndex + i) * 2], moveAndScale);
}
writeIndex += AI_FarmerMoveCount;

memcpy(&buffer->positions[writeIndex * 2], AI_FarmersFarmGen, sizeof(float) * 2 * AI_FarmerFarmCount);
for (uint32_t i = 0; i < AI_FarmerFarmCount; ++i)
__m128i farmAndScale = _mm_set_epi16(FarmerState_Farm, AI_FarmerScale, FarmerState_Farm, AI_FarmerScale, FarmerState_Farm, AI_FarmerScale, FarmerState_Farm, AI_FarmerScale);
for (uint32_t i = 0; i < AI_FarmerFarmCount; i+=4)
{
uint32_t writeLoc = writeIndex++;
buffer->spriteIndicesAndScales[writeLoc * 2] = FarmerState_Farm;
buffer->spriteIndicesAndScales[writeLoc * 2 + 1] = AI_FarmerScale;
_mm_storeu_si128((__m128i*)&buffer->spriteIndicesAndScales[(writeIndex + i) * 2], farmAndScale);
}
writeIndex += AI_FarmerFarmCount;

MIST_PROFILE_END("Game", "Game-GenInstanceBuffer");

0 comments on commit 2493716

Please sign in to comment.
You can’t perform that action at this time.