Skip to content

Commit 7ba3bb1

Browse files
committed
Merge branch 'main' of github.com:simul/Platform
2 parents 93d07b4 + 738729c commit 7ba3bb1

22 files changed

+139
-70
lines changed

Applications/Sfx/Sfx.lpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ the last is C code to be copied verbatim to the output.
6969
{
7070
insert_line_statement++;
7171
}
72+
bool charisspace(char c)
73+
{
74+
return std::isspace((int)c);
75+
}
7276
float ToFloat(const char * txr)
7377
{
7478
std::string yytextStr=yytext;
@@ -78,7 +82,7 @@ the last is C code to be copied verbatim to the output.
7882
// Clang/Gcc still doesn't implement the standard function std::from_chars properly.
7983
float value=atof(yytextStr.c_str());
8084
#else
81-
yytextStr.erase(std::remove_if(yytextStr.begin(),yytextStr.end(),std::isspace),yytextStr.end());
85+
yytextStr.erase(std::remove_if(yytextStr.begin(),yytextStr.end(),charisspace),yytextStr.end());
8286
float value=0.0f;
8387
std::from_chars(yytextStr.data(),yytextStr.data()+yytextStr.size(),value,std::chars_format::general);
8488
#endif
@@ -146,8 +150,8 @@ the last is C code to be copied verbatim to the output.
146150
%}
147151
%x renderstate_mode IN_SHADER IN_SHADER_COMPILE IN_LINE IN_RENDER_STATE IN_TEXTURE_DECL IN_LAYOUT IN_STRUCT IN_MULTILINE_COMMENT IN_VARIANT_CASE
148152
ID_BLCK [a-zA-Z_][a-zA-Z0-9_]*
149-
NUM_BLCK ([0-9][0-9]*)[uU]?
150-
HEX_BLCK 0x[0-9A-Fa-f][0-9A-Fa-f]*[uU]?
153+
NUM_BLCK ([0-9][0-9]*)[uU]?L?
154+
HEX_BLCK 0x[0-9A-Fa-f][0-9A-Fa-f]*[uU]?L?
151155
STR_BLCK \"[^"\n]*\"
152156
FLOAT_BLCK [0-9]*((\.[0-9])|([0-9]\.))[0-9]*([eE][+-]?[0-9]+)?f?
153157

@@ -802,6 +806,7 @@ FLOAT_BLCK [0-9]*((\.[0-9])|([0-9]\.))[0-9]*([eE][+-]?[0-9]+)?f?
802806
<IN_SHADER>"continue" stdReturn(CONTINUE);
803807
<IN_SHADER>"do" stdReturn(DO);
804808
<IN_SHADER>"for" stdReturn(FOR);
809+
<IN_SHADER>"unroll" stdReturn(UNROLL);
805810
<IN_SHADER>"goto" stdReturn(GOTO);
806811
<IN_SHADER>"if" stdReturn(IF);
807812
<IN_SHADER>"switch" stdReturn(SWITCH);

Applications/Sfx/Sfx.ypp

+33-8
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,17 @@
9191
{
9292
write_line_number_next=true;
9393
}
94-
void WriteLineNumber(std::ostringstream &str,const std::string &filename,int lineno)
94+
bool WriteLineNumber(std::ostringstream &str,const std::string &filename,int lineno)
9595
{
96-
if(!lineno)
97-
return;
96+
if(lineno==0)
97+
{
98+
return true;
99+
}
100+
if(lineno<0)
101+
{
102+
std::cerr<<"line: "<<lineno<<" not valid for #line directive.\n";
103+
return false;
104+
}
98105
std::string f=filename;
99106
size_t p=f.find("\\");
100107
while(p<f.length())
@@ -105,16 +112,20 @@
105112
if (gEffect->GetOptions()->disableLineWrites)
106113
str<<"//";
107114
str<<"#line "<<lineno<<" "<<gEffect->GetFilenameOrNumber(f)<<endl;
115+
return true;
108116
}
109-
void WriteLineNumber(std::ostringstream &str,int lineno)
117+
bool WriteLineNumber(std::ostringstream &str,int lineno)
110118
{
111-
WriteLineNumber(str,current_filename,lineno);//.c_str()<<"\""<<endl;
119+
return WriteLineNumber(str,current_filename,lineno);//.c_str()<<"\""<<endl;
112120
}
113121
std::string CreateLineStatement(int lineno)
114122
{
115123
ostringstream ostr;
116124
ostr<<"\n";
117-
WriteLineNumber(ostr,current_filename,lineno+last_linenumber-global_linenumber);
125+
if(!WriteLineNumber(ostr,current_filename,lineno+last_linenumber-global_linenumber))
126+
{
127+
std::cerr<<"lineno: "<<lineno<<" last_linenumber: "<<last_linenumber<<", global_linenumber: "<<global_linenumber<<".\n";
128+
}
118129
return ostr.str();
119130
}
120131
void stringReplaceAll(std::string& str, const std::string& from, const std::string& to)
@@ -616,6 +627,7 @@
616627
%token SET_RAY_GENERATION SET_MISS SET_CALLABLE SET_HIT_GROUP SET_CLOSEST_HIT SET_ANY_HIT SET_INTERSECTION SET_MISS_SHADERS SET_CALLABLE_SHADERS SET_RAY_TRACING_SHADER_CONFIG SET_RAY_TRACING_PIPELINE_CONFIG SET_MAX_PAYLOAD_SIZE SET_MAX_ATTRIBUTE_SIZE SET_MAX_TRACE_RECURSION_DEPTH
617628
%token SFX_VARIANT SFX_VARIANT_IF SFX_VARIANT_ELSE SFX_VARIANT_END
618629

630+
%token UNROLL
619631
%%
620632

621633
prog : prog tok
@@ -1056,6 +1068,13 @@ gslayout : '[' MAX_VERTEX_COUNT '(' NUM ')' ']'
10561068
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+$4.strs[0]+$5.strs[0]+$6.strs[0];
10571069
}
10581070

1071+
optional_unroll : '[' UNROLL ']'
1072+
{
1073+
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+" ";
1074+
} | %empty
1075+
{
1076+
$$.strs[0] = "";
1077+
}
10591078
optional_expression : expression
10601079
{
10611080
$$.strs[0]=$1.strs[0];
@@ -2598,7 +2617,7 @@ statement : COMMENT
25982617
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+$4.strs[0]+$5.strs[0]+$6.strs[0]+$7.strs[0];
25992618
$$.strs[1]="";
26002619
}
2601-
| FOR '(' for_init_statement ';' optional_expression ';' optional_expression ')' statement
2620+
| for '(' for_init_statement ';' optional_expression ';' optional_expression ')' statement
26022621
{
26032622
string statement=$9.strs[0];
26042623
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+$4.strs[0]+$5.strs[0]+$6.strs[0]+$7.strs[0]+$8.strs[0]+statement;
@@ -2644,7 +2663,13 @@ statement : COMMENT
26442663
$$.strs[1]="";
26452664
$$.lineno=$1.lineno;
26462665
}
2647-
2666+
for: optional_unroll FOR
2667+
{
2668+
int line=$2.lineno;
2669+
$$.lineno=line;
2670+
$$.strs[0] = $1.strs[0] + $2.strs[0] ;
2671+
$$.strs[1] = "";
2672+
}
26482673
variant_conditional_expression: SFX_VARIANT_IF '(' conditional_exp ')'
26492674
{
26502675
// TODO: Properly change the identifiers, instead of this hack.

CMake/Include.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include_guard()
22

3-
set( PLATFORM_CPP_VERSION 17 CACHE STRING "Set the C++ version to compile." )
3+
set( PLATFORM_CPP_VERSION 20 CACHE STRING "Set the C++ version to compile." )
44
set( CMAKE_CXX_STANDARD_REQUIRED ON )
55
set( CMAKE_CXX_EXTENSIONS ON )
66
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Core/DefaultFileLoader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ uint64_t DefaultFileLoader::GetFileDate(const char *filename_utf8) const
176176
// https://stackoverflow.com/questions/61030383/how-to-convert-stdfilesystemfile-time-type-to-time-t
177177
// https://stackoverflow.com/questions/51273205/how-to-compare-time-t-and-stdfilesystemfile-time-type
178178
fs::file_time_type fileTime = fs::last_write_time(filename_utf8);
179-
#if PLATFORM_CXX20
179+
#if PLATFORM_CXX20_OR_ABOVE
180180
const std::chrono::system_clock systemTime = std::chrono::clock_cast<std::chrono::system_clock>(fileTime);
181181
const time_t time = std::chrono::system_clock::to_time_t(systemTime);
182182
#else

Core/RuntimeError.h

+30-16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
#ifndef PLATFORM_RUNTIMEERROR_H
2-
#define PLATFORM_RUNTIMEERROR_H
1+
#pragma once
2+
3+
// C++ Versions
4+
#if defined(_WIN64)
5+
#define PLATFORM_CXX20_OR_ABOVE _HAS_CXX20
6+
#define PLATFORM_CXX17_OR_ABOVE _HAS_CXX17
7+
#elif defined(__linux__)
8+
#define PLATFORM_CXX20_OR_ABOVE (__cplusplus >= 202002L)
9+
#define PLATFORM_CXX17_OR_ABOVE (__cplusplus >= 201703L)
10+
#endif
311

412
#include "Export.h"
513

614
#include <string>
15+
#include <string_view>
716
#include <string.h>
817
#include <iostream>
918
#include <cerrno>
1019
#include <assert.h>
20+
#if PLATFORM_CXX20_OR_ABOVE
21+
#include <format>
22+
#include <fmt/core.h>
23+
#else
1124
#include <fmt/core.h>
25+
#endif
1226

1327
#ifndef SIMUL_INTERNAL_CHECKS
1428
#define SIMUL_INTERNAL_CHECKS 0
@@ -35,14 +49,6 @@
3549
#endif
3650
#include <stdexcept> // for runtime_error
3751

38-
// C++ Versions
39-
#if defined(_WIN64)
40-
#define PLATFORM_CXX20 _HAS_CXX20
41-
#define PLATFORM_CXX17 _HAS_CXX17
42-
#elif defined(__linux__)
43-
#define PLATFORM_CXX20 (__cplusplus == 202002L)
44-
#define PLATFORM_CXX17 (__cplusplus == 201703L)
45-
#endif
4652

4753
#define SIMUL_COUT \
4854
std::cout << __FILE__ << "(" << std::dec << __LINE__ << "): info: "
@@ -121,13 +127,22 @@ namespace platform
121127
#endif
122128

123129
#define PLATFORM_ERROR(txt, ...) \
124-
platform::core::Error(txt, __FILE__, __LINE__, ##__VA_ARGS__)
130+
{\
131+
std::string str = fmt::format(txt, ##__VA_ARGS__);\
132+
std::cerr << fmt::format("{} ({}): error: {}", __FILE__, __LINE__, str) << "\n";\
133+
}
125134

126135
#define PLATFORM_WARN(txt, ...) \
127-
platform::core::Warn(txt, __FILE__, __LINE__, ##__VA_ARGS__)
136+
{\
137+
std::string str = fmt::format(txt, ##__VA_ARGS__);\
138+
std::cerr << fmt::format("{} ({}): warn: {}", __FILE__, __LINE__, str) << "\n";\
139+
}
128140

129141
#define PLATFORM_LOG(txt, ...) \
130-
platform::core::Info(txt, __FILE__, __LINE__, ##__VA_ARGS__)
142+
{\
143+
std::string str = fmt::format(txt, ##__VA_ARGS__);\
144+
std::cout << fmt::format("{} ({}): info: {}", __FILE__, __LINE__, str) << "\n";\
145+
}
131146

132147

133148
#define SIMUL_INTERNAL_COUT \
@@ -187,7 +202,7 @@ namespace platform
187202

188203
#define SIMUL_BREAK(msg, ...) \
189204
{ \
190-
platform::core::Error(msg, __FILE__, __LINE__, ##__VA_ARGS__); \
205+
PLATFORM_ERROR(msg, ##__VA_ARGS__); \
191206
BREAK_IF_DEBUGGING \
192207
}
193208

@@ -196,7 +211,7 @@ namespace platform
196211
static bool done = false; \
197212
if (!done) \
198213
{ \
199-
platform::core::Error(msg, __FILE__, __LINE__, ##__VA_ARGS__); \
214+
PLATFORM_ERROR(msg, ##__VA_ARGS__); \
200215
BREAK_IF_DEBUGGING; \
201216
done = true; \
202217
} \
@@ -347,4 +362,3 @@ namespace platform
347362
#pragma warning(pop)
348363
#endif
349364

350-
#endif

Core/TrackingAllocator.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
#include "Platform/Core/StringFunctions.h"
33
#include "Platform/Core/RuntimeError.h"
44
#include <string.h> // for strlen
5+
#if PLATFORM_CXX20_OR_ABOVE
6+
#include <format>
57
#include <fmt/format.h>
8+
#else
9+
#include <fmt/format.h>
10+
#endif
611

712
using namespace platform;
813
using namespace core;

CrossPlatform/Effect.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ crossplatform::SamplerStateDesc::Wrapping stringToWrapping(string s)
674674
return crossplatform::SamplerStateDesc::CLAMP;
675675
if(is_equal(s,"MIRROR"))
676676
return crossplatform::SamplerStateDesc::MIRROR;
677-
SIMUL_BREAK_ONCE((string("Invalid string")+s).c_str());
677+
SIMUL_BREAK_ONCE("Invalid string: {}",s);
678678
return crossplatform::SamplerStateDesc::WRAP;
679679
}
680680

@@ -686,7 +686,7 @@ crossplatform::SamplerStateDesc::Filtering stringToFilter(string s)
686686
return crossplatform::SamplerStateDesc::LINEAR;
687687
if(is_equal(s,"ANISOTROPIC"))
688688
return crossplatform::SamplerStateDesc::ANISOTROPIC;
689-
SIMUL_BREAK((string("Invalid string: ")+s).c_str());
689+
SIMUL_BREAK("Invalid string: {}",s);
690690
return crossplatform::SamplerStateDesc::POINT;
691691
}
692692

@@ -706,7 +706,7 @@ static crossplatform::CullFaceMode toCullFadeMode(string s)
706706
return crossplatform::CULL_FACE_FRONTANDBACK;
707707
else if(is_equal(s,"CULL_NONE"))
708708
return crossplatform::CULL_FACE_NONE;
709-
SIMUL_BREAK((string("Invalid string")+s).c_str());
709+
SIMUL_BREAK("Invalid string: {}",s);
710710
return crossplatform::CULL_FACE_NONE;
711711
}
712712

@@ -730,7 +730,7 @@ static crossplatform::Topology toTopology(string s)
730730
return crossplatform::Topology::TRIANGLELIST_ADJ;
731731
else if(is_equal(s,"TriangleStripAdjacency"))
732732
return crossplatform::Topology::TRIANGLESTRIP_ADJ;
733-
SIMUL_BREAK((string("Invalid string")+s).c_str());
733+
SIMUL_BREAK("Invalid string: {}",s);
734734
return crossplatform::Topology::UNDEFINED;
735735
}
736736

@@ -1015,8 +1015,7 @@ bool Effect::Load(crossplatform::RenderPlatform *r, const char *filename_utf8)
10151015
std::transform(binFilenameUtf8.begin(), binFilenameUtf8.end(), binFilenameUtf8.begin(), ::tolower);
10161016
if(!platform::core::FileLoader::GetFileLoader()->FileExists(binFilenameUtf8.c_str()))
10171017
{
1018-
string err= platform::core::QuickFormat("Shader effect file not found: %s",binFilenameUtf8.c_str());
1019-
SIMUL_BREAK_ONCE(err.c_str());
1018+
SIMUL_BREAK_ONCE("Shader effect file not found: {}",binFilenameUtf8);
10201019
static bool already = false;
10211020
if (!already)
10221021
{
@@ -1515,7 +1514,7 @@ bool Effect::Load(crossplatform::RenderPlatform *r, const char *filename_utf8)
15151514
platform::core::FileLoader::GetFileLoader()->AcquireFileContents(bin_ptr, bin_num_bytes, sfxbFilenameUtf8.c_str(), true);
15161515
if (!bin_ptr)
15171516
{
1518-
SIMUL_BREAK(platform::core::QuickFormat("Failed to load combined shader binary: %s\n", sfxbFilenameUtf8.c_str()));
1517+
SIMUL_BREAK("Failed to load combined shader binary: {}\n", sfxbFilenameUtf8);
15191518
}
15201519
}
15211520
}
@@ -1701,7 +1700,7 @@ bool Effect::Load(crossplatform::RenderPlatform *r, const char *filename_utf8)
17011700
}
17021701
else
17031702
{
1704-
SIMUL_BREAK(platform::core::QuickFormat("Unknown shader type or command: %s\n",type.c_str()));
1703+
SIMUL_BREAK("Unknown shader type or command: {}\n",type);
17051704
continue;
17061705
}
17071706
Shader *s = nullptr;

CrossPlatform/PlatformStructuredBuffer.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace platform
7171
public:
7272
virtual ~BaseStructuredBuffer() = default;
7373
PlatformStructuredBuffer* platformStructuredBuffer=nullptr;
74+
int count=0;
7475
};
7576
class PlatformStructuredBuffer;
7677
/// Templated structured buffer, which uses platform-specific implementations of PlatformStructuredBuffer.
@@ -83,7 +84,6 @@ namespace platform
8384
{
8485
public:
8586
StructuredBuffer()
86-
:count(0)
8787
{
8888
}
8989
~StructuredBuffer()
@@ -187,8 +187,6 @@ namespace platform
187187
if (platformStructuredBuffer)
188188
platformStructuredBuffer->ResetCopies();
189189
}
190-
191-
int count;
192190
};
193191

194192
}

CrossPlatform/RenderPlatform.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <algorithm>
3232
#include <array>
3333
#include <atomic>
34-
#include <fmt/core.h>
3534

3635
using namespace std::literals;
3736
using namespace std::string_literals;
@@ -1982,6 +1981,8 @@ void RenderPlatform::SetConstantBuffer(DeviceContext& deviceContext,ConstantBuff
19821981

19831982
void RenderPlatform::SetStructuredBuffer(DeviceContext& deviceContext, BaseStructuredBuffer* s, const ShaderResource& shaderResource)
19841983
{
1984+
if(!s||!s->platformStructuredBuffer)
1985+
return;
19851986
if((shaderResource.shaderResourceType & ShaderResourceType::RW) == ShaderResourceType::RW)
19861987
s->platformStructuredBuffer->ApplyAsUnorderedAccessView(deviceContext, shaderResource);
19871988
else
@@ -2059,7 +2060,7 @@ std::shared_ptr<Effect> RenderPlatform::GetOrCreateEffect(const char *filename_u
20592060
bool success = e->Load(this,filename_utf8);
20602061
if (!success)
20612062
{
2062-
SIMUL_BREAK(platform::core::QuickFormat("Failed to load effect file: %s. Effect will be placeholder.\n", filename_utf8));
2063+
SIMUL_BREAK("Failed to load effect file: {}. Effect will be placeholder.\n", filename_utf8);
20632064
return e;
20642065
}
20652066
return e;

CrossPlatform/Shaders/vec2.sl

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ struct tvector2
223223
}
224224
friend tvector2 operator/(const T &m, const tvector2 &v)
225225
{
226-
tvector3 r;
226+
tvector2 r;
227227
r.x = m / v.x;
228228
r.y = m / v.y;
229229
return r;

CrossPlatform/Shaders/vec4.sl

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ struct tvector4
291291
}
292292
friend tvector4 operator/(const T &m, const tvector4 &v)
293293
{
294-
tvector3 r;
294+
tvector4 r;
295295
r.x = m / v.x;
296296
r.y = m / v.y;
297297
r.z = m / v.z;

DirectX12/BottomLevelAccelerationStructure.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ void BottomLevelAccelerationStructure::BuildAccelerationStructureAtRuntime(cross
201201
//BuildRaytracingAccelerationStructure need the StructuredBuffer for AABB in D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE
202202
//Transition to D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE (from D3D12_RESOURCE_STATE_UNORDERED_ACCESS).
203203
if (aabbBuffer)
204-
commandList4->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(aabbBuffer->platformStructuredBuffer->AsD3D12Resource(deviceContext), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE));
204+
{
205+
auto b=CD3DX12_RESOURCE_BARRIER::Transition(aabbBuffer->platformStructuredBuffer->AsD3D12Resource(deviceContext), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
206+
commandList4->ResourceBarrier(1, &b);
207+
}
205208

206209
commandList4->BuildRaytracingAccelerationStructure(&buildDesc, 0, nullptr);
207210

0 commit comments

Comments
 (0)