Skip to content
Permalink
Browse files

Implement Vertex Buffer Caching

  • Loading branch information...
LukeUsher authored and PatrickvL committed Jun 12, 2019
1 parent a76bac4 commit f36cd0540a297d2706d4c6dc7dbfc3bfc41e8f11
@@ -205,6 +205,7 @@ file (GLOB CXBXR_SOURCE_COMMON
"${CXBXR_ROOT_DIR}/src/common/Timer.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/crc32c.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/CxbxUtil.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/hasher.cpp"
"${CXBXR_ROOT_DIR}/src/common/win32/DInputController.cpp"
"${CXBXR_ROOT_DIR}/src/common/win32/EmuShared.cpp"
"${CXBXR_ROOT_DIR}/src/common/win32/InlineFunc.cpp"
@@ -32,10 +32,9 @@ link_directories(

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_definitions(
_CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
# Windows 7 minimum requirement
_WIN32_WINNT=0x0601

LTM_DESC
USE_LTM
LTC_NO_TEST
@@ -45,6 +44,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
LTC_NO_PRNGS
LTC_NO_MISC
LTC_NO_PROTOTYPES

# Use inline XXHash version
XXH_INLINE_ALL
)

# Reference: https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically
@@ -0,0 +1,42 @@
#include "hasher.h"

#include "xxhash.h"
#include "crc32c.h"
#include <cstdio>

enum {
HASH_NONE = 0,
HASH_XXH3,
HASH_CRC32C
};

static int g_HashAlgorithm = HASH_NONE;

void InitHasher()
{
// Detect the best hashing algorithm to use for the host machine
// TODO/Future Improvement: This could be expanded to support even more hash algorithims
// And we could hash a random buffer to calculate the fastest hash to use on a given host
printf("Selecting hash algorithm: ");
if (crc32c_hw_available()) {
printf("CRC32C\n");
g_HashAlgorithm = HASH_CRC32C;
} else {
printf("XXH3\n");
g_HashAlgorithm = HASH_XXH3;
}
}

__forceinline uint64_t ComputeHash(void* data, size_t len)
{
if (g_HashAlgorithm == HASH_NONE) {
InitHasher();
}

switch (g_HashAlgorithm) {
case HASH_XXH3: return XXH3_64bits(data, len);
case HASH_CRC32C: return crc32c_append(0, (uint8_t*)data, len);
}

return 0;
}
@@ -0,0 +1,34 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * This file is part of the Cxbx project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2019 - Luke Usher
// *
// * All rights reserved
// *
// ******************************************************************
#ifndef _HASHER_H
#define _HASHER_H

#include <stdint.h>

extern __forceinline uint64_t ComputeHash(void* data, size_t len);

#endif

0 comments on commit f36cd05

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