Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 97d1a26

Browse files
committed
[ISPC] Commented all Intel changes
1 parent e9e6b57 commit 97d1a26

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ spirv_cross_add_library(spirv-cross-hlsl spirv_cross_hlsl STATIC
101101
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.hpp
102102
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.cpp)
103103

104+
# BEGIN INTEL
104105
spirv_cross_add_library(spirv-cross-ispc spirv_cross_ispc STATIC
105106
${CMAKE_CURRENT_SOURCE_DIR}/spirv_ispc.hpp
106107
${CMAKE_CURRENT_SOURCE_DIR}/spirv_ispc.cpp)
107108

109+
# END INTEL
108110
spirv_cross_add_library(spirv-cross-util spirv_cross_util STATIC
109111
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.hpp
110112
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.cpp)
@@ -114,13 +116,17 @@ target_compile_options(spirv-cross PRIVATE ${spirv-compiler-options})
114116
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines})
115117

116118
install(TARGETS spirv-cross RUNTIME DESTINATION bin)
119+
# BEGIN INTEL
117120
target_link_libraries(spirv-cross spirv-cross-glsl spirv-cross-hlsl spirv-cross-cpp spirv-cross-msl spirv-cross-ispc spirv-cross-util spirv-cross-core)
121+
# END INTEL
118122
target_link_libraries(spirv-cross-util spirv-cross-core)
119123
target_link_libraries(spirv-cross-glsl spirv-cross-core)
120124
target_link_libraries(spirv-cross-msl spirv-cross-glsl)
121125
target_link_libraries(spirv-cross-hlsl spirv-cross-glsl)
122126
target_link_libraries(spirv-cross-cpp spirv-cross-glsl)
127+
# BEGIN INTEL
123128
target_link_libraries(spirv-cross-ispc spirv-cross-glsl)
129+
# END INTEL
124130

125131
# Set up tests, using only the simplest modes of the test_shaders
126132
# script. You have to invoke the script manually to:

main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,10 @@ struct CLIArguments
476476
bool fixup = false;
477477
bool yflip = false;
478478
bool sso = false;
479+
// BEGIN INTEL
479480
bool ispc_ignore_runtimearray_padding = false;
480481
bool ispc_ignore_group_barriers = false;
482+
// END INTEL
481483
vector<PLSArg> pls_in;
482484
vector<PLSArg> pls_out;
483485
vector<Remap> remaps;
@@ -533,10 +535,12 @@ static void print_help()
533535
"\t[--hlsl]\n"
534536
"\t[--shader-model]\n"
535537
"\t[--hlsl-enable-compat]\n"
538+
// BEGIN INTEL
536539
"\t[--ispc]\n"
537540
"\t[--ispc-interface-name]\n"
538541
"\t[--ispc-ignore-runtimearray-padding]\n"
539542
"\t[--ispc-ignore-group-barriers]\n"
543+
// END INTEL
540544
"\t[--separate-shader-objects]\n"
541545
"\t[--pls-in format input-name]\n"
542546
"\t[--pls-out format output-name]\n"
@@ -691,6 +695,7 @@ static int main_inner(int argc, char *argv[])
691695
cbs.add("--msl", [&args](CLIParser &) { args.msl = true; });
692696
cbs.add("--hlsl", [&args](CLIParser &) { args.hlsl = true; });
693697
cbs.add("--hlsl-enable-compat", [&args](CLIParser &) { args.hlsl_compat = true; });
698+
// BEGIN INTEL
694699
cbs.add("--ispc", [&args](CLIParser &) {
695700
args.ispc = true;
696701
args.vulkan_semantics = true;
@@ -700,6 +705,7 @@ static int main_inner(int argc, char *argv[])
700705
cbs.add("--ispc-ignore-runtimearray-padding",
701706
[&args](CLIParser &) { args.ispc_ignore_runtimearray_padding = true; });
702707
cbs.add("--ispc-ignore-group-barriers", [&args](CLIParser &) { args.ispc_ignore_group_barriers = true; });
708+
// END INTEL
703709
cbs.add("--vulkan-semantics", [&args](CLIParser &) { args.vulkan_semantics = true; });
704710
cbs.add("--flatten-multidimensional-arrays", [&args](CLIParser &) { args.flatten_multidimensional_arrays = true; });
705711
cbs.add("--no-420pack-extension", [&args](CLIParser &) { args.use_420pack_extension = false; });
@@ -812,6 +818,7 @@ static int main_inner(int argc, char *argv[])
812818
}
813819
else if (args.hlsl)
814820
compiler = unique_ptr<CompilerHLSL>(new CompilerHLSL(read_spirv_file(args.input)));
821+
// BEGIN INTEL
815822
else if (args.ispc)
816823
{
817824
compiler = unique_ptr<CompilerISPC>(new CompilerISPC(read_spirv_file(args.input)));
@@ -838,6 +845,7 @@ static int main_inner(int argc, char *argv[])
838845
if (args.ispc_ignore_group_barriers)
839846
static_cast<CompilerISPC *>(compiler.get())->set_ignore_group_barriers();
840847
}
848+
// END INTEL
841849
else
842850
{
843851
combined_image_samplers = !args.vulkan_semantics;

spirv_common.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,9 @@ struct SPIRConstant : IVariant
10351035
SPIRConstant(uint32_t constant_type_, const uint32_t *elements, uint32_t num_elements, bool specialized)
10361036
: constant_type(constant_type_)
10371037
, specialization(specialized)
1038+
// BEGIN INTEL
10381039
, varying_constant_id(-1)
1040+
// END INTEL
10391041
{
10401042
subconstants.insert(end(subconstants), elements, elements + num_elements);
10411043
specialization = specialized;
@@ -1045,7 +1047,9 @@ struct SPIRConstant : IVariant
10451047
SPIRConstant(uint32_t constant_type_, uint32_t v0, bool specialized)
10461048
: constant_type(constant_type_)
10471049
, specialization(specialized)
1050+
// BEGIN INTEL
10481051
, varying_constant_id(-1)
1052+
// END INTEL
10491053
{
10501054
m.c[0].r[0].u32 = v0;
10511055
m.c[0].vecsize = 1;
@@ -1056,7 +1060,9 @@ struct SPIRConstant : IVariant
10561060
SPIRConstant(uint32_t constant_type_, uint64_t v0, bool specialized)
10571061
: constant_type(constant_type_)
10581062
, specialization(specialized)
1063+
// BEGIN INTEL
10591064
, varying_constant_id(-1)
1065+
// END INTEL
10601066
{
10611067
m.c[0].r[0].u64 = v0;
10621068
m.c[0].vecsize = 1;
@@ -1068,7 +1074,9 @@ struct SPIRConstant : IVariant
10681074
bool specialized)
10691075
: constant_type(constant_type_)
10701076
, specialization(specialized)
1077+
// BEGIN INTEL
10711078
, varying_constant_id(-1)
1079+
// END INTEL
10721080
{
10731081
bool matrix = vector_elements[0]->m.c[0].vecsize > 1;
10741082

@@ -1104,8 +1112,10 @@ struct SPIRConstant : IVariant
11041112
bool specialization = false;
11051113
// If this constant is used as an array length which creates specialization restrictions on some backends.
11061114
bool is_used_as_array_length = false;
1115+
// BEGIN INTEL
11071116
// ISPC requires varying/uniform versions of constants
11081117
uint32_t varying_constant_id;
1118+
// END INTEL
11091119

11101120
// For composites which are constant arrays, etc.
11111121
std::vector<uint32_t> subconstants;

spirv_glsl.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2969,7 +2969,9 @@ string CompilerGLSL::constant_expression_vector(const SPIRConstant &c, uint32_t
29692969
string res;
29702970
bool splat = backend.use_constructor_splatting && c.vector_size() > 1;
29712971
bool swizzle_splat = backend.can_swizzle_scalar && c.vector_size() > 1;
2972+
// BEGIN INTEL
29722973
bool is_ispc_varying = meta[c.self].decoration.ispc_varying;
2974+
// END INTEL
29732975

29742976
if (!type_is_floating_point(type))
29752977
{
@@ -3020,12 +3022,14 @@ string CompilerGLSL::constant_expression_vector(const SPIRConstant &c, uint32_t
30203022
}
30213023
}
30223024

3025+
// BEGIN INTEL
30233026
// This ISPC code should not be in the GLSL compiler, but this function was sufficiently complex enough that
30243027
// it warranted making the small mod here rather than copying the function. Could abstract into some form of vector qualifier...?
30253028
if (is_ispc_varying && !(splat || swizzle_splat))
30263029
{
30273030
res += join("(varying ", type_to_glsl(type, 0), ")");
30283031
}
3032+
// END INTEL
30293033

30303034
if (c.vector_size() > 1 && !swizzle_splat)
30313035
res += type_to_glsl(type) + "(";
@@ -3275,8 +3279,10 @@ string CompilerGLSL::declare_temporary(uint32_t result_type, uint32_t result_id)
32753279
{
32763280
// The result_id has not been made into an expression yet, so use flags interface.
32773281
add_local_variable_name(result_id);
3282+
// BEGIN INTEL - Add ISPC varying qualifiers
32783283
return join(flags_to_precision_qualifiers_glsl(type, flags), to_varying_qualifiers_ispc(result_id),
32793284
variable_decl(type, to_name(result_id), result_id), " = ");
3285+
// END INTEL
32803286
}
32813287
}
32823288

@@ -5142,6 +5148,7 @@ const char *CompilerGLSL::index_to_swizzle(uint32_t index)
51425148
}
51435149
}
51445150

5151+
// BEGIN INTEL - ISPC requires a further dereference to access a vector from a matrix
51455152
std::string CompilerGLSL::matrix_to_vector(uint32_t index, bool index_is_literal)
51465153
{
51475154
string expr = "[";
@@ -5152,6 +5159,7 @@ std::string CompilerGLSL::matrix_to_vector(uint32_t index, bool index_is_literal
51525159
expr += "]";
51535160
return expr;
51545161
}
5162+
// END INTEL
51555163

51565164
string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indices, uint32_t count,
51575165
bool index_is_literal, bool chain_only, bool *need_transpose,
@@ -5320,7 +5328,9 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice
53205328
is_packed = false;
53215329
}
53225330

5331+
// BEGIN INTEL
53235332
expr += matrix_to_vector(index, index_is_literal);
5333+
// END INTEL
53245334

53255335
type_id = type->parent_type;
53265336
type = &get<SPIRType>(type_id);
@@ -5975,8 +5985,10 @@ string CompilerGLSL::build_composite_combiner(uint32_t return_type, const uint32
59755985

59765986
// Can only merge swizzles for vectors.
59775987
auto &type = get<SPIRType>(return_type);
5988+
// BEGIN INTEL - not all compilers support native swizzle
59785989
bool can_apply_swizzle_opt =
59795990
backend.supports_native_swizzle && type.basetype != SPIRType::Struct && type.array.empty() && type.columns == 1;
5991+
// END INTEL
59805992
bool swizzle_optimization = false;
59815993

59825994
for (uint32_t i = 0; i < length; i++)
@@ -6484,6 +6496,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
64846496

64856497
auto &type = get<SPIRType>(result_type);
64866498

6499+
// BEGIN INTEL
64876500
auto *composite_expr = maybe_get<SPIRExpression>(ops[2]);
64886501
auto &composite_type = expression_type(ops[2]);
64896502

@@ -6493,6 +6506,8 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
64936506
if (composite_expr && !composite_expr->loaded_from &&
64946507
!(should_forward(ops[2]) && !composite_type.array.empty()))
64956508
{
6509+
// ISPC doesn't support complex composite extraction, of the form
6510+
// texturelod().x
64966511
if (!backend.supports_complex_composite_extraction)
64976512
{
64986513
if (forced_temporaries.find(ops[2]) == end(forced_temporaries))
@@ -6502,6 +6517,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
65026517
}
65036518
}
65046519
}
6520+
// END INTEL
65056521

65066522
// We can only split the expression here if our expression is forwarded as a temporary.
65076523
bool allow_base_expression = forced_temporaries.find(id) == end(forced_temporaries);
@@ -9544,16 +9560,19 @@ void CompilerGLSL::emit_hoisted_temporaries(vector<pair<uint32_t, uint32_t>> &te
95449560
sort(begin(temporaries), end(temporaries),
95459561
[](const pair<uint32_t, uint32_t> &a, const pair<uint32_t, uint32_t> &b) { return a.second < b.second; });
95469562

9547-
// Remove any duplicates. There shouldn't be any, but the odd one can creep in.
9563+
// BEGIN INTEL - Remove any duplicates. There shouldn't be any, but the odd one can creep in.
95489564
temporaries.erase(unique(temporaries.begin(), temporaries.end()), temporaries.end());
9565+
// END INTEL
95499566

95509567
for (auto &tmp : temporaries)
95519568
{
95529569
add_local_variable_name(tmp.second);
95539570
auto flags = meta[tmp.second].decoration.decoration_flags;
95549571
auto &type = get<SPIRType>(tmp.first);
9572+
// BEGIN INTEL - Add ISPC varying qualifiers
95559573
statement(flags_to_precision_qualifiers_glsl(type, flags), to_varying_qualifiers_ispc(tmp.second),
95569574
variable_decl(type, to_name(tmp.second), tmp.second), ";");
9575+
// END INTEL
95579576

95589577
hoisted_temporaries.insert(tmp.second);
95599578
forced_temporaries.insert(tmp.second);

spirv_glsl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,13 @@ class CompilerGLSL : public Compiler
336336
uint32_t to_array_size_literal(const SPIRType &type, uint32_t index) const;
337337
std::string variable_decl(const SPIRVariable &variable);
338338
std::string variable_decl_function_local(SPIRVariable &variable);
339+
// BEGIN INTEL
339340
virtual std::string to_varying_qualifiers_ispc(uint32_t id)
340341
{
341342
return "";
342343
};
343344
virtual std::string matrix_to_vector(uint32_t index, bool index_is_literal);
345+
// END INTEL
344346

345347
void add_local_variable_name(uint32_t id);
346348
void add_resource_name(uint32_t id);
@@ -388,8 +390,10 @@ class CompilerGLSL : public Compiler
388390
bool allow_truncated_access_chain = false;
389391
bool supports_extensions = false;
390392
bool supports_empty_struct = false;
393+
// BEGIN INTEL
391394
bool supports_native_swizzle = true; // Used in build_composite_combiner to generate swizzles
392395
bool supports_complex_composite_extraction = true; // When false, composite extracts are forced to temporaries
396+
// END INTEL
393397
std::string stdlib_filename = "sprivcross_stdlib";
394398
} backend;
395399

@@ -478,7 +482,9 @@ class CompilerGLSL : public Compiler
478482
void strip_enclosed_expression(std::string &expr);
479483
std::string to_member_name(const SPIRType &type, uint32_t index);
480484
virtual std::string type_to_glsl_constructor(const SPIRType &type);
485+
// BEGIN INTEL
481486
virtual std::string argument_decl(const SPIRFunction::Parameter &arg);
487+
// END INTEL
482488
virtual std::string to_qualifiers_glsl(uint32_t id);
483489
const char *to_precision_qualifiers_glsl(uint32_t id);
484490
virtual const char *to_storage_qualifiers_glsl(const SPIRVariable &var);

0 commit comments

Comments
 (0)