Skip to content

Commit 55e187f

Browse files
committed
Follow up of material parser:
- Fix CMakeLists to correctly include src files in matp test - Replace std::string to std::string_view FIXES=440579712
1 parent e3384fe commit 55e187f

File tree

11 files changed

+50
-30
lines changed

11 files changed

+50
-30
lines changed

libs/filament-matp/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ set(PUBLIC_HDRS
1313
)
1414

1515
set(SRCS
16-
src/DirIncluder.h
1716
src/JsonishLexeme.h
1817
src/JsonishLexer.h
1918
src/JsonishParser.h
@@ -22,7 +21,6 @@ set(SRCS
2221
src/MaterialLexeme.h
2322
src/MaterialLexer.h
2423
src/ParametersProcessor.h
25-
src/DirIncluder.cpp
2624
src/JsonishLexer.cpp
2725
src/JsonishParser.cpp
2826
src/MaterialLexer.cpp
@@ -56,7 +54,6 @@ project(test_matp)
5654
set(TARGET test_matp)
5755
set(SRCS
5856
tests/test_matp.cpp
59-
tests/test_includer.cpp
6057
tests/TestMaterialParser.h
6158
tests/test_compute_material.cpp
6259
)

libs/filament-matp/include/filament-matp/MaterialParser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class MaterialParser {
3939
// Parses a string material so that it can be used in MaterialBuilder.
4040
// Call MaterialBuilder::init before passing in the builder; call MaterialBuilder::build to
4141
// create filamat::Package after.
42+
// When the input shader has #includes, it has to be resolved before calling into parse.
4243
bool parse(
4344
filamat::MaterialBuilder& builder,
44-
const Config& config,
45-
Config::Input* input, ssize_t& size, std::unique_ptr<const char[]>& buffer);
45+
const Config& config, ssize_t& size, std::unique_ptr<const char[]>& buffer);
4646
// Replaces macro keywords with user specified ones. Must be called before parse.
4747
bool processTemplateSubstitutions(
4848
const Config& config, ssize_t& size, std::unique_ptr<const char[]>& buffer);

libs/filament-matp/src/MaterialParser.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <utils/Log.h>
2828
#include <utils/JobSystem.h>
2929

30-
#include "DirIncluder.h"
3130
#include "JsonishLexer.h"
3231
#include "JsonishParser.h"
3332
#include "MaterialLexeme.h"
@@ -458,11 +457,7 @@ bool MaterialParser::processTemplateSubstitutions(
458457
}
459458

460459
bool MaterialParser::parse(filamat::MaterialBuilder& builder,
461-
const Config& config,
462-
Config::Input* input, ssize_t& size, std::unique_ptr<const char[]>& buffer) {
463-
464-
utils::Path const materialFilePath = utils::Path(input->getName()).getAbsolutePath();
465-
assert(materialFilePath.isFile());
460+
const Config& config, ssize_t& size, std::unique_ptr<const char[]>& buffer) {
466461

467462
if (builder.getFeatureLevel() > config.getFeatureLevel()) {
468463
std::cerr << "Material feature level (" << +builder.getFeatureLevel()
@@ -489,15 +484,9 @@ bool MaterialParser::parse(filamat::MaterialBuilder& builder,
489484
return reflectParameters(builder);
490485
}
491486

492-
// Set the root include directory to the directory containing the material file.
493-
DirIncluder includer;
494-
includer.setIncludeDirectory(materialFilePath.getParent());
495-
496487
builder
497488
.noSamplerValidation(config.noSamplerValidation())
498489
.includeEssl1(config.includeEssl1())
499-
.includeCallback(includer)
500-
.fileName(materialFilePath.getName().c_str())
501490
.platform(config.getPlatform())
502491
.targetApi(config.getTargetApi())
503492
.optimization(config.getOptimizationLevel())

tools/matc/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ set(TARGET matlang)
1212
set(HDRS
1313
src/matc/CommandlineConfig.h
1414
src/matc/Compiler.h
15+
src/matc/DirIncluder.h
1516
src/matc/MaterialCompiler.h
1617
)
1718

1819
set(SRCS
1920
src/matc/Compiler.cpp
2021
src/matc/MaterialCompiler.cpp
2122
src/matc/CommandlineConfig.cpp
23+
src/matc/DirIncluder.cpp
2224
)
2325

2426
# ==================================================================================================
@@ -62,3 +64,16 @@ set_target_properties(${TARGET} PROPERTIES FOLDER Tools)
6264
# Installation
6365
# ==================================================================================================
6466
install(TARGETS ${TARGET} RUNTIME DESTINATION bin)
67+
68+
# ==================================================================================================
69+
# Tests
70+
# ==================================================================================================
71+
project(test_matc)
72+
set(TARGET test_matc)
73+
set(SRCS tests/test_includer.cpp)
74+
75+
add_executable(${TARGET} ${SRCS})
76+
77+
target_link_libraries(${TARGET} matlang gtest)
78+
79+
set_target_properties(test_matc PROPERTIES FOLDER Tests)

libs/filament-matp/src/DirIncluder.cpp renamed to tools/matc/src/matc/DirIncluder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <fstream>
2222

23-
namespace matp {
23+
namespace matc {
2424

2525
bool DirIncluder::operator()(const utils::CString& includedBy, filamat::IncludeResult& result) {
2626
auto getHeaderPath = [&result, &includedBy, this]() {
@@ -66,5 +66,5 @@ bool DirIncluder::operator()(const utils::CString& includedBy, filamat::IncludeR
6666
return true;
6767
}
6868

69-
} // namespace matp
69+
} // namespace matc
7070

libs/filament-matp/src/DirIncluder.h renamed to tools/matc/src/matc/DirIncluder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <utils/Path.h>
2323

24-
namespace matp {
24+
namespace matc {
2525

2626
// Functor callback handler used to resolve includes relative to a root include directory.
2727
class DirIncluder {
@@ -38,6 +38,6 @@ class DirIncluder {
3838

3939
};
4040

41-
} // namespace matp
41+
} // namespace matc
4242

4343
#endif

tools/matc/src/matc/MaterialCompiler.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "MaterialCompiler.h"
1818

19+
#include "DirIncluder.h"
20+
1921
#include <memory>
2022
#include <iostream>
2123
#include <utility>
@@ -52,21 +54,33 @@ bool MaterialCompiler::run(const matp::Config& config) {
5254

5355
mParser.processTemplateSubstitutions(config, size, buffer);
5456

57+
utils::Path const materialFilePath = utils::Path(input->getName()).getAbsolutePath();
58+
assert(materialFilePath.isFile());
59+
5560
if (config.rawShaderMode()) {
56-
utils::Path const materialFilePath = utils::Path(config.getInput()->getName()).getAbsolutePath();
57-
assert(materialFilePath.isFile());
5861
const std::string extension = materialFilePath.getExtension();
5962
glslang::InitializeProcess();
60-
bool const success = compileRawShader(buffer.get(), size, config.isDebug(), config.getOutput(),
61-
extension.c_str());
63+
bool const success =
64+
compileRawShader(
65+
buffer.get(), size,
66+
config.isDebug(),
67+
config.getOutput(),
68+
extension.c_str());
6269
glslang::FinalizeProcess();
6370
return success;
6471
}
6572

6673
MaterialBuilder::init();
6774
MaterialBuilder builder;
6875

69-
if (!mParser.parse(builder, config, input, size, buffer)) {
76+
// Set the root include directory to the directory containing the material file.
77+
DirIncluder includer;
78+
includer.setIncludeDirectory(materialFilePath.getParent());
79+
80+
builder.includeCallback(includer)
81+
.fileName(materialFilePath.getName().c_str());
82+
83+
if (!mParser.parse(builder, config, size, buffer)) {
7084
return false;
7185
}
7286

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)