Skip to content

Commit 292e12d

Browse files
author
-
committed
test VS2019
1 parent e8b0655 commit 292e12d

File tree

8 files changed

+246
-21
lines changed

8 files changed

+246
-21
lines changed

j/console.h

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@
1414
#include <string>
1515
#include <tuple>
1616
#include <vector>
17-
typedef unsigned uint; //clang and VSCode don't do this automatically
17+
18+
//ghetto version of unreachable. since meson still doesn't let me configure C++23
19+
//https://en.cppreference.com/w/cpp/utility/unreachable
20+
[[noreturn]] inline void unreachable()
21+
{
22+
#if __GNUC__ // GCC, Clang, ICC
23+
__builtin_unreachable();
24+
#elif _MSC_VER // MSVC
25+
__assume(false);
26+
#endif
27+
}
1828

1929
/*
2030
three possible methods:
@@ -38,18 +48,18 @@ three possible methods:
3848

3949
using std::string_view;
4050

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

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

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

7585
//get rid of me after gcc std::to_chars starts supporting floats
7686
template <typename T>
77-
void o_convert_string(T s_pre_convert, char* buffer, unsigned& position) {
87+
void o_convert_string(T s_pre_convert, char* buffer, size_t& position) {
7888
using std::to_string;
7989
std::string s = to_string(s_pre_convert);
80-
unsigned to_write = std::min(max_buffer_size - position, (uint)s.size());
90+
auto to_write = std::min(max_buffer_size - position, s.size());
8191
memcpy(&buffer[position], s.data(), to_write);
8292
position += to_write;
8393
};
@@ -158,7 +168,7 @@ inline constexpr bool dependent_false = false;
158168
//#include <algorithm>
159169
int* arbitrary_memory_to_offset_pointer_addresses_from = new int;
160170
#endif
161-
void o_convert_pointer(uintptr_t w, char* buffer, unsigned& position) {
171+
void o_convert_pointer(uintptr_t w, char* buffer, size_t& position) {
162172
#if !NDEBUG
163173
//std::array special_constants{0ull, 0xABABABABABABABAB, 0xBAADF00DBAADF00D, 0xFEEEFEEEFEEEFEEE};
164174
//if (std::find(special_constants.begin(), special_constants.end(), w) == special_constants.end())
@@ -182,14 +192,14 @@ void o_convert_pointer(uintptr_t w, char* buffer, unsigned& position) {
182192
}
183193
};
184194

185-
void outc_internal(bool insert_space, char* buffer, unsigned& position) {
195+
void outc_internal(bool insert_space, char* buffer, size_t& position) {
186196
return;
187197
}
188198

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

281291
outc_internal(false, buffer, position, std::forward<Args>(args)..., '\n'); //strings only print in emscripten when they end in \n
282292
#if !NDEBUG
@@ -296,7 +306,7 @@ void outc(Args&&... args) {
296306
template <typename... Args>
297307
void outn(Args&&... args) {
298308
char buffer[max_buffer_size];
299-
unsigned position = 0;
309+
size_t position = 0;
300310
outc_internal(false, buffer, position, std::forward<Args>(args)...);
301311
#if enable_console
302312
fwrite(buffer, sizeof(char), position, stdout);
@@ -306,15 +316,15 @@ void outn(Args&&... args) {
306316
template <typename... Args>
307317
std::string out_string(Args&&... args) {
308318
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
309-
unsigned position = 0;
319+
size_t position = 0;
310320
outc_internal(false, buffer, position, std::forward<Args>(args)...);
311321
return std::string(buffer, buffer + position);
312322
}
313323

314324
/*
315325
//probably clobbers something. causes segfault
316326
#ifndef _MSC_VER
317-
#define error(...) outc(__VA_ARGS__); __builtin_trap(); __builtin_unreachable()
327+
#define error(...) outc(__VA_ARGS__); __builtin_trap(); unreachable()
318328
#else
319329
#define error(...) outc(__VA_ARGS__); std::raise(SIGABRT)
320330
#endif
@@ -328,7 +338,7 @@ template <typename... Args>
328338
//maybe flush?
329339
#ifndef _MSC_VER
330340
__builtin_trap(); //zero frames added. used to lose frame information when compiled with clang, but seems fixed with clang 6.0.
331-
__builtin_unreachable(); //silence noreturn warnings
341+
unreachable(); //silence noreturn warnings
332342
#else
333343
std::raise(SIGABRT); //1 frame added
334344
//abort(); //adds two frames to the debugger
@@ -355,7 +365,7 @@ inline void check(bool b, Args&&... args) {
355365
//maybe flush?
356366
#ifndef _MSC_VER
357367
__builtin_trap();
358-
__builtin_unreachable();
368+
unreachable();
359369
#else
360370
std::raise(SIGABRT);
361371
#endif
@@ -373,7 +383,7 @@ inline void check(bool b, Args&&... args) {
373383
//#include <source_location> //compiler complains
374384
//#define error_assert(...) (outc(std::source_location::current().function_name(), std::source_location::current().line()), error(__VA_ARGS__ ))
375385
#else
376-
#define error_assert(...) __builtin_unreachable()
386+
#define error_assert(...) unreachable()
377387
#endif
378388
#define check_assert(b, ...) \
379389
if (!(b)) [[unlikely]] \
@@ -383,4 +393,4 @@ inline void check(bool b, Args&&... args) {
383393
template <typename... Args>
384394
inline void check_assert(bool b, Args&&... args) {
385395
if (!b) error_assert(std::forward<Args>(args)...);
386-
}*/
396+
}*/

platform_vsync_windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int first_scanline_in_display = -1;
139139
int last_scanline_before_display = 0; //first line must always be vsync, according to ToastyX.
140140
//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
141141
//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
142-
uint64_t get_scanline() {
142+
uint get_scanline() {
143143
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.
144144
//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.
145145
check_assert(result == STATUS_SUCCESS, "scanline error", result); //happens if you're doing double buffer vsync

render_vsync_demo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#define DISABLE_FONTS 1
2+
#if _WIN32
3+
#define WIN32_LEAN_AND_MEAN
4+
#define NOMINMAX
5+
#include <windows.h>
6+
#endif
27
//miscellaneous helper files I carry around
38
#include "timing.cpp"
49
#include "console.h"

renderer_ui_globals.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "helper.h"
3+
#include "timing.h"
34

45
namespace render {
56
single_def int32_t screen_w = 0, screen_h = 0;
@@ -8,7 +9,7 @@ single_def int32_t screen_w = 0, screen_h = 0;
89
single_def double mouse_x_raw[2] = {0, 0}; //[0] is the more recent timepoint
910
single_def double mouse_y_raw[2] = {0, 0};
1011
single_def uint64_t mouse_timepoint[2] = {0, 0};
11-
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
12+
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
1213

1314
//the mouse position is derived from the raw mouse position by extrapolation. it must be set before usage.
1415
//for clicks and renders, these are cached automatically
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.33328.57
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vsync blurbusters", "vsync blurbusters\vsync blurbusters.vcxproj", "{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x64.ActiveCfg = Debug|x64
17+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x64.Build.0 = Debug|x64
18+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x86.ActiveCfg = Debug|Win32
19+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Debug|x86.Build.0 = Debug|Win32
20+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x64.ActiveCfg = Release|x64
21+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x64.Build.0 = Release|x64
22+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x86.ActiveCfg = Release|Win32
23+
{5A771EF7-88C3-49F4-B4B7-A99DE59841DA}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {43CD7D4F-2B86-4BCA-9473-6C189C71A598}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{5a771ef7-88c3-49f4-b4b7-a99de59841da}</ProjectGuid>
25+
<RootNamespace>vsyncblurbusters</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v142</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v142</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v142</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v142</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<LinkIncremental>true</LinkIncremental>
75+
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);j;</IncludePath>
76+
</PropertyGroup>
77+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
78+
<LinkIncremental>false</LinkIncremental>
79+
</PropertyGroup>
80+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
81+
<LinkIncremental>true</LinkIncremental>
82+
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\..\j;</IncludePath>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
85+
<LinkIncremental>false</LinkIncremental>
86+
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\..\j;</IncludePath>
87+
</PropertyGroup>
88+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
89+
<ClCompile>
90+
<WarningLevel>Level3</WarningLevel>
91+
<SDLCheck>true</SDLCheck>
92+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<ConformanceMode>true</ConformanceMode>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>Console</SubSystem>
97+
<GenerateDebugInformation>true</GenerateDebugInformation>
98+
</Link>
99+
</ItemDefinitionGroup>
100+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
101+
<ClCompile>
102+
<WarningLevel>Level3</WarningLevel>
103+
<FunctionLevelLinking>true</FunctionLevelLinking>
104+
<IntrinsicFunctions>true</IntrinsicFunctions>
105+
<SDLCheck>true</SDLCheck>
106+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
<ConformanceMode>true</ConformanceMode>
108+
</ClCompile>
109+
<Link>
110+
<SubSystem>Console</SubSystem>
111+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
112+
<OptimizeReferences>true</OptimizeReferences>
113+
<GenerateDebugInformation>true</GenerateDebugInformation>
114+
</Link>
115+
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
117+
<ClCompile>
118+
<WarningLevel>Level3</WarningLevel>
119+
<SDLCheck>true</SDLCheck>
120+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
121+
<ConformanceMode>true</ConformanceMode>
122+
<LanguageStandard>stdcpplatest</LanguageStandard>
123+
</ClCompile>
124+
<Link>
125+
<SubSystem>Console</SubSystem>
126+
<GenerateDebugInformation>true</GenerateDebugInformation>
127+
</Link>
128+
</ItemDefinitionGroup>
129+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
130+
<ClCompile>
131+
<WarningLevel>Level3</WarningLevel>
132+
<FunctionLevelLinking>true</FunctionLevelLinking>
133+
<IntrinsicFunctions>true</IntrinsicFunctions>
134+
<SDLCheck>true</SDLCheck>
135+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
136+
<ConformanceMode>true</ConformanceMode>
137+
<LanguageStandard>stdcpplatest</LanguageStandard>
138+
</ClCompile>
139+
<Link>
140+
<SubSystem>Console</SubSystem>
141+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
142+
<OptimizeReferences>true</OptimizeReferences>
143+
<GenerateDebugInformation>true</GenerateDebugInformation>
144+
</Link>
145+
</ItemDefinitionGroup>
146+
<ItemGroup>
147+
<ClCompile Include="..\..\render_vsync_demo.cpp" />
148+
</ItemGroup>
149+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
150+
<ImportGroup Label="ExtensionTargets">
151+
</ImportGroup>
152+
</Project>

0 commit comments

Comments
 (0)