Skip to content

Commit

Permalink
test VS2019
Browse files Browse the repository at this point in the history
  • Loading branch information
- committed Feb 28, 2023
1 parent e8b0655 commit 292e12d
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 21 deletions.
48 changes: 29 additions & 19 deletions j/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@
#include <string>
#include <tuple>
#include <vector>
typedef unsigned uint; //clang and VSCode don't do this automatically

//ghetto version of unreachable. since meson still doesn't let me configure C++23
//https://en.cppreference.com/w/cpp/utility/unreachable
[[noreturn]] inline void unreachable()
{
#if __GNUC__ // GCC, Clang, ICC
__builtin_unreachable();
#elif _MSC_VER // MSVC
__assume(false);
#endif
}

/*
three possible methods:
Expand All @@ -38,18 +48,18 @@ three possible methods:

using std::string_view;

constexpr unsigned max_buffer_size = 1024;
constexpr size_t max_buffer_size = 4096;
//future: perhaps turn position and max_buffer_size into pointers instead. because to_chars likes pointers
//but then it becomes hard to find the remaining buffer capacity. max_size - (ptr - base). so let's just leave it as an integer

void o(string_view s, char* buffer, unsigned& position) {
unsigned to_write = std::min(max_buffer_size - position, (uint)s.size());
void o(string_view s, char* buffer, size_t& position) {
size_t to_write = std::min(max_buffer_size - position, s.size());
memcpy(&buffer[position], s.data(), to_write);
position += to_write;
};

//integers can convert to chars, which is messy. so we rename it o_c instead of o
void o_c(char c, char* buffer, unsigned& position) {
void o_c(char c, char* buffer, size_t& position) {
if (position != max_buffer_size) {
buffer[position] = c;
++position;
Expand All @@ -61,7 +71,7 @@ void o_c(char c, char* buffer, unsigned& position) {
//probably has something to do with prvalues being ganked by giving them a name.
//well, I switched to std::to_chars. haven't checked the new behavior
template <typename T>
void o_convert(T s_pre_convert, char* buffer, unsigned& position) {
void o_convert(T s_pre_convert, char* buffer, size_t& position) {
using std::to_chars;
if (auto [ptr, ec] = to_chars(&buffer[position], &buffer[max_buffer_size], s_pre_convert); ec == std::errc()) {
position += ptr - &buffer[position];
Expand All @@ -74,10 +84,10 @@ void o_convert(T s_pre_convert, char* buffer, unsigned& position) {

//get rid of me after gcc std::to_chars starts supporting floats
template <typename T>
void o_convert_string(T s_pre_convert, char* buffer, unsigned& position) {
void o_convert_string(T s_pre_convert, char* buffer, size_t& position) {
using std::to_string;
std::string s = to_string(s_pre_convert);
unsigned to_write = std::min(max_buffer_size - position, (uint)s.size());
auto to_write = std::min(max_buffer_size - position, s.size());
memcpy(&buffer[position], s.data(), to_write);
position += to_write;
};
Expand Down Expand Up @@ -158,7 +168,7 @@ inline constexpr bool dependent_false = false;
//#include <algorithm>
int* arbitrary_memory_to_offset_pointer_addresses_from = new int;
#endif
void o_convert_pointer(uintptr_t w, char* buffer, unsigned& position) {
void o_convert_pointer(uintptr_t w, char* buffer, size_t& position) {
#if !NDEBUG
//std::array special_constants{0ull, 0xABABABABABABABAB, 0xBAADF00DBAADF00D, 0xFEEEFEEEFEEEFEEE};
//if (std::find(special_constants.begin(), special_constants.end(), w) == special_constants.end())
Expand All @@ -182,14 +192,14 @@ void o_convert_pointer(uintptr_t w, char* buffer, unsigned& position) {
}
};

void outc_internal(bool insert_space, char* buffer, unsigned& position) {
void outc_internal(bool insert_space, char* buffer, size_t& position) {
return;
}

//insert_space is "if necessary". so if the next thing starts with a space, don't insert a space.
//return true if this term wants whitespace after it. because we recurse on tuples, so we need to know what happened inside
template <typename T, typename... Args>
void outc_internal(bool insert_space, char* buffer, unsigned& position, T s, Args&&... args) {
void outc_internal(bool insert_space, char* buffer, size_t& position, T s, Args&&... args) {
bool wsa = true;
using type = std::remove_cvref_t<T>;
//nuking this costs 1 KB, so it's not the source of the extra file size
Expand Down Expand Up @@ -276,7 +286,7 @@ void outc_internal(bool insert_space, char* buffer, unsigned& position, T s, Arg
template <typename... Args>
void outc(Args&&... args) {
char buffer[max_buffer_size]; //change the buffer, then write everything out at once.
unsigned position = 0;
size_t position = 0;

outc_internal(false, buffer, position, std::forward<Args>(args)..., '\n'); //strings only print in emscripten when they end in \n
#if !NDEBUG
Expand All @@ -296,7 +306,7 @@ void outc(Args&&... args) {
template <typename... Args>
void outn(Args&&... args) {
char buffer[max_buffer_size];
unsigned position = 0;
size_t position = 0;
outc_internal(false, buffer, position, std::forward<Args>(args)...);
#if enable_console
fwrite(buffer, sizeof(char), position, stdout);
Expand All @@ -306,15 +316,15 @@ void outn(Args&&... args) {
template <typename... Args>
std::string out_string(Args&&... args) {
char buffer[max_buffer_size]; //might as well start with a char buffer. we have to shrink it afterward anyway, which requires a memory operation
unsigned position = 0;
size_t position = 0;
outc_internal(false, buffer, position, std::forward<Args>(args)...);
return std::string(buffer, buffer + position);
}

/*
//probably clobbers something. causes segfault
#ifndef _MSC_VER
#define error(...) outc(__VA_ARGS__); __builtin_trap(); __builtin_unreachable()
#define error(...) outc(__VA_ARGS__); __builtin_trap(); unreachable()
#else
#define error(...) outc(__VA_ARGS__); std::raise(SIGABRT)
#endif
Expand All @@ -328,7 +338,7 @@ template <typename... Args>
//maybe flush?
#ifndef _MSC_VER
__builtin_trap(); //zero frames added. used to lose frame information when compiled with clang, but seems fixed with clang 6.0.
__builtin_unreachable(); //silence noreturn warnings
unreachable(); //silence noreturn warnings
#else
std::raise(SIGABRT); //1 frame added
//abort(); //adds two frames to the debugger
Expand All @@ -355,7 +365,7 @@ inline void check(bool b, Args&&... args) {
//maybe flush?
#ifndef _MSC_VER
__builtin_trap();
__builtin_unreachable();
unreachable();
#else
std::raise(SIGABRT);
#endif
Expand All @@ -373,7 +383,7 @@ inline void check(bool b, Args&&... args) {
//#include <source_location> //compiler complains
//#define error_assert(...) (outc(std::source_location::current().function_name(), std::source_location::current().line()), error(__VA_ARGS__ ))
#else
#define error_assert(...) __builtin_unreachable()
#define error_assert(...) unreachable()
#endif
#define check_assert(b, ...) \
if (!(b)) [[unlikely]] \
Expand All @@ -383,4 +393,4 @@ inline void check(bool b, Args&&... args) {
template <typename... Args>
inline void check_assert(bool b, Args&&... args) {
if (!b) error_assert(std::forward<Args>(args)...);
}*/
}*/
2 changes: 1 addition & 1 deletion platform_vsync_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int first_scanline_in_display = -1;
int last_scanline_before_display = 0; //first line must always be vsync, according to ToastyX.
//future: Mark Rejhon reports that D3DKMTGetScanLine takes 8 scanlines on his 1080 Ti; maybe his code has a problem? he suspects maybe it's just slow on Nvidia cards
//future: Mark Rejhon reports that the scanline counter doesn't increment properly in the porch (when InVerticalBlank is true). I should investigate that when I get a new graphics card. it works fine on my Intel HD 4000
uint64_t get_scanline() {
uint get_scanline() {
auto result = D3DKMTGetScanLine(&scanline_windows); //runtime is 0.005-0.015 ms on my Intel HD 4000. 1000 calls in a loop takes 2-5 ms.
//standard deviation is 0.004 ms. Quantization error of the scanline is (16.666/1125/sqrt12 = 0.00427 ms). that means D3DKMTGetScanLine() is perfectly accurate up to its theoretical limit.
check_assert(result == STATUS_SUCCESS, "scanline error", result); //happens if you're doing double buffer vsync
Expand Down
5 changes: 5 additions & 0 deletions render_vsync_demo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#define DISABLE_FONTS 1
#if _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif
//miscellaneous helper files I carry around
#include "timing.cpp"
#include "console.h"
Expand Down
3 changes: 2 additions & 1 deletion renderer_ui_globals.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "helper.h"
#include "timing.h"

namespace render {
single_def int32_t screen_w = 0, screen_h = 0;
Expand All @@ -8,7 +9,7 @@ single_def int32_t screen_w = 0, screen_h = 0;
single_def double mouse_x_raw[2] = {0, 0}; //[0] is the more recent timepoint
single_def double mouse_y_raw[2] = {0, 0};
single_def uint64_t mouse_timepoint[2] = {0, 0};
double ticks_between_mouse_events = ticks_per_sec / 1000; //mouse sampling frequency. only has to be approximately correct. initial assumption is 1 ms. used to determine if the time after the last mouse input is because the mouse is still, or if it's just waiting for the next input
double ticks_between_mouse_events = ticks_per_sec / 1000.0; //mouse sampling frequency. only has to be approximately correct. initial assumption is 1 ms. used to determine if the time after the last mouse input is because the mouse is still, or if it's just waiting for the next input

//the mouse position is derived from the raw mouse position by extrapolation. it must be set before usage.
//for clicks and renders, these are cached automatically
Expand Down
31 changes: 31 additions & 0 deletions vsync blurbusters/vsync blurbusters.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.33328.57
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vsync blurbusters", "vsync blurbusters\vsync blurbusters.vcxproj", "{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x64.ActiveCfg = Debug|x64
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x64.Build.0 = Debug|x64
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x86.ActiveCfg = Debug|Win32
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x86.Build.0 = Debug|Win32
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x64.ActiveCfg = Release|x64
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x64.Build.0 = Release|x64
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x86.ActiveCfg = Release|Win32
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43CD7D4F-2B86-4BCA-9473-6C189C71A598}
EndGlobalSection
EndGlobal
152 changes: 152 additions & 0 deletions vsync blurbusters/vsync blurbusters/vsync blurbusters.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{5a771ef7-88c3-49f4-b4b7-a99de59841da}</ProjectGuid>
<RootNamespace>vsyncblurbusters</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);j;</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\..\j;</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\..\j;</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\render_vsync_demo.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit 292e12d

Please sign in to comment.