Cleanup unused assets and finished comments

This commit is contained in:
Digital Artifex
2026-08-25 11:00:04 -04:00
parent 2ffe0bba88
commit cf5baa0684
2 changed files with 214 additions and 77 deletions
+13 -49
View File
@@ -24,17 +24,17 @@ PackCompiler::PackCompiler(QObject *parent)
auto PackCompiler::reset() -> void auto PackCompiler::reset() -> void
{ {
setError({}, {});
setProgress(std::numeric_limits<qreal>::infinity()); setProgress(std::numeric_limits<qreal>::infinity());
setTotalSteps(0); setTotalSteps(0);
setCurrentStep(0); setCurrentStep(0);
setCompilerOutput({});
setStatus({});
setState(Idle); setState(Idle);
} }
auto PackCompiler::build(const QUrl &uri) -> QUrl auto PackCompiler::build(const QUrl &uri) -> QUrl
{ {
setState(Compiling);
setStatus(QStringLiteral("Preparing Komplex Pack For Building"));
BuildContext *context = new BuildContext; BuildContext *context = new BuildContext;
QUrl extractedUri = extract(uri); QUrl extractedUri = extract(uri);
@@ -42,6 +42,8 @@ auto PackCompiler::build(const QUrl &uri) -> QUrl
context->commonData = loadCommonData(extractedUri); context->commonData = loadCommonData(extractedUri);
processShaders(extractedUri, context); processShaders(extractedUri, context);
setState(Complete);
setStatus(QStringLiteral("Complete"));
delete context; delete context;
return extractedUri; return extractedUri;
@@ -50,6 +52,7 @@ auto PackCompiler::build(const QUrl &uri) -> QUrl
auto PackCompiler::extract(const QUrl &sourceUri) noexcept(false) -> const QUrl auto PackCompiler::extract(const QUrl &sourceUri) noexcept(false) -> const QUrl
{ {
validateUri(sourceUri); validateUri(sourceUri);
setStatus(QStringLiteral("Extracting Komplex Pack"));
QFileInfo info(sourceUri.toLocalFile()); QFileInfo info(sourceUri.toLocalFile());
@@ -77,7 +80,6 @@ auto PackCompiler::extract(const QUrl &sourceUri) noexcept(false) -> const QUrl
} }
run(QStringLiteral("tar"), arguments); run(QStringLiteral("tar"), arguments);
QFile::remove(sourceUri.toLocalFile()); QFile::remove(sourceUri.toLocalFile());
return std::move(outputUri); return std::move(outputUri);
@@ -101,6 +103,7 @@ auto PackCompiler::validatePack(const QUrl &uri) const noexcept(false) -> void
auto PackCompiler::loadCommonData(const QUrl &uri) -> QMap<QByteArray,QByteArray> auto PackCompiler::loadCommonData(const QUrl &uri) -> QMap<QByteArray,QByteArray>
{ {
validateUri(uri); validateUri(uri);
setStatus(QStringLiteral("Loading Common Data"));
QMap<QByteArray,QByteArray> commonData; QMap<QByteArray,QByteArray> commonData;
@@ -166,18 +169,21 @@ auto PackCompiler::processShaders(const QUrl &uri, BuildContext *context) -> voi
const QStringList entries = shaderDirectory.entryList(); const QStringList entries = shaderDirectory.entryList();
setTotalSteps(entries.count());
setProgress(0);
for(const QString &entry : entries) for(const QString &entry : entries)
{ {
QFileInfo entryInfo(shaderDirectory.absoluteFilePath(entry)); QFileInfo entryInfo(shaderDirectory.absoluteFilePath(entry));
QByteArray shaderData;
QUrl entryUri = QStringLiteral("file://%1").arg QUrl entryUri = QStringLiteral("file://%1").arg
( (
entryInfo.absoluteFilePath() entryInfo.absoluteFilePath()
); );
shaderData += readFile(entryUri); setStatus(QStringLiteral("Compiling: %1").arg(entry));
QShader::Stage stage = getStageFromSuffix(entryInfo.suffix()); QShader::Stage stage = getStageFromSuffix(entryInfo.suffix());
QByteArray shaderData = readFile(entryUri);
appendCommonData(&shaderData, entryInfo.suffix().toUtf8(), context); appendCommonData(&shaderData, entryInfo.suffix().toUtf8(), context);
replaceUniformVariables(&shaderData); replaceUniformVariables(&shaderData);
@@ -195,6 +201,7 @@ auto PackCompiler::processShaders(const QUrl &uri, BuildContext *context) -> voi
save(outputUri, shader); save(outputUri, shader);
QFile::remove(entryUri.toLocalFile()); QFile::remove(entryUri.toLocalFile());
incrementCompileStep();
} }
} }
@@ -237,13 +244,6 @@ auto PackCompiler::compile(const QByteArray &data, const QString &filename, cons
if(!shader.isValid()) if(!shader.isValid())
{ {
QUrl errorUri
(
QStringLiteral("file://tmp/_err")
);
writeFile(errorUri, data);
throw shader::logic_error throw shader::logic_error
( (
std::string("Compiler Error"), std::string("Compiler Error"),
@@ -541,42 +541,6 @@ auto PackCompiler::setProgress(qreal progress) -> void
Q_EMIT progressChanged(); Q_EMIT progressChanged();
} }
void PackCompiler::setCompilerOutput(const QString &compilerOutput)
{
if (m_compilerOutput == compilerOutput)
{
return;
}
m_compilerOutput = compilerOutput;
emit compilerOutputChanged();
}
auto PackCompiler::setError(const QString &title, const QString &message, const QUrl &uri) -> void
{
if(title == m_errorTitle && message == m_errorMessage)
{
return;
}
m_errorMessage = std::move(message);
m_errorTitle = std::move(title);
if(uri.isValid() && uri.isLocalFile())
{
QFile errorFile(uri.toLocalFile());
if(errorFile.open(QFile::ReadWrite | QFile::Append))
{
errorFile.write(message.toLocal8Bit() + QByteArray("\n"));
}
}
Q_EMIT errorTitleChanged();
Q_EMIT errorMessageChanged();
Q_EMIT errorOcurred();
}
auto PackCompiler::setState(State state) -> void auto PackCompiler::setState(State state) -> void
{ {
if(state == m_state) if(state == m_state)
+201 -28
View File
@@ -59,7 +59,6 @@
struct KOMPLEX_EXPORT BuildContext struct KOMPLEX_EXPORT BuildContext
{ {
QMap<QByteArray, QByteArray> commonData; QMap<QByteArray, QByteArray> commonData;
QPromise<QUrl> promise;
}; };
/** /**
@@ -83,6 +82,10 @@ class PackCompiler : public QObject
Q_OBJECT Q_OBJECT
public: public:
/**
* @brief The State enum
* Enum of the possible states of the compiler
*/
enum State enum State
{ {
Idle, Idle,
@@ -94,23 +97,59 @@ public:
explicit PackCompiler(QObject *parent = nullptr); explicit PackCompiler(QObject *parent = nullptr);
auto compilerOutput() const -> const QString & { return m_compilerOutput; } /**
* @brief progress
* Current compiler progress
* @return
*/
auto progress() -> qreal { return m_progress; } auto progress() -> qreal { return m_progress; }
/**
* @brief currentStep
* Current compiler step
* @return
*/
auto currentStep() -> qint64 { return m_currentStep; } auto currentStep() -> qint64 { return m_currentStep; }
/**
* @brief totalSteps
* Total steps in the current compile
* @return
*/
auto totalSteps() -> qint64 { return m_totalSteps; } auto totalSteps() -> qint64 { return m_totalSteps; }
auto errorTitle() const -> const QString & { return m_errorTitle; }
auto errorMessage() const -> const QString & { return m_errorMessage; } /**
* @brief status
* Current status message
* @return
*/
auto status() const -> const QString & { return m_status; } auto status() const -> const QString & { return m_status; }
/**
* @brief state
* Current compiler state
* @return
*/
auto state() const -> State { return m_state; } auto state() const -> State { return m_state; }
/**
* @brief reset
* Resets the compiler state
*/
auto reset() -> void; auto reset() -> void;
/**
* @brief build
* Builds a Komplex pack from a tar.gz file
* @param uri
* Uri of the tar.gz
* @return
* Uri of the built pack
*/
auto build(const QUrl &uri) -> QUrl; auto build(const QUrl &uri) -> QUrl;
signals: signals:
auto compilerOutputChanged() -> void; auto compilerOutputChanged() -> void;
auto errorOcurred() -> void;
auto errorTitleChanged() -> void;
auto errorMessageChanged() -> void;
auto stateChanged() -> void; auto stateChanged() -> void;
auto progressChanged() -> void; auto progressChanged() -> void;
auto currentStepChanged() -> void; auto currentStepChanged() -> void;
@@ -230,36 +269,161 @@ private:
auto compile(const QByteArray &data, const QString &filename, const QShader::Stage stage) noexcept(false) -> QShader; auto compile(const QByteArray &data, const QString &filename, const QShader::Stage stage) noexcept(false) -> QShader;
//[13] //[13]
/**
* @brief save
* Saves a serialized version of the shader to the specified uri
* @param uri
* Uri of the file to create
* @param shader
* The compiled shader
*/
auto save(const QUrl &uri, const QShader &shader) noexcept(false) -> void; auto save(const QUrl &uri, const QShader &shader) noexcept(false) -> void;
//helpers //@BEGIN helpers
/**
* @brief validateUri
* Validates that the uri is a local file or direcotry
* @param uri
*/
auto validateUri(const QUrl &uri) const noexcept(false) -> void; auto validateUri(const QUrl &uri) const noexcept(false) -> void;
/**
* @brief run
* Runs the supplied command with the given arguments as a QProcess. If
* data is supplied, it is written to the standard input channel after the
* process has started
* @param command
* System command or program to run
* @param arguments
* QStringList of the given arguments. Minimal wildcard expansion available.
* @param data
* Optional data to write
* @return
* Standard non-error output
*/
auto run(const QString &command, const QStringList &arguments, const QByteArray &data = {}) noexcept(false) -> QByteArray; auto run(const QString &command, const QStringList &arguments, const QByteArray &data = {}) noexcept(false) -> QByteArray;
/**
* @brief readFile
* Reads the file at the given uri and returns its data
* @param uri
* Uri of the file
* @return
* File contents
*/
auto readFile(const QUrl &uri) noexcept(false) -> QByteArray; auto readFile(const QUrl &uri) noexcept(false) -> QByteArray;
/**
* @brief writeFile
* Writes the supplied data to the given uri
* @param uri
* Uri of the file
* @param data
* Data to write
*/
auto writeFile(const QUrl &uri, const QByteArray &data) noexcept(false) -> void; auto writeFile(const QUrl &uri, const QByteArray &data) noexcept(false) -> void;
/**
* @brief copyFile
* Copys file to new uri
* @param sourceUri
* File to copy
* @param destinationUri
* New file location/name
*/
auto copyFile(const QUrl &sourceUri, const QUrl &destinationUri) noexcept(false) -> void; auto copyFile(const QUrl &sourceUri, const QUrl &destinationUri) noexcept(false) -> void;
/**
* @brief createDirectory
* QDir::mkpath was failing, so this helper function calls mkdir -p
* @param uri
* Directory path to create
*/
auto createDirectory(const QUrl &uri) noexcept(false) -> void; auto createDirectory(const QUrl &uri) noexcept(false) -> void;
/**
* @brief removeDirectory
* Calls rm -rf, but should be replaced with an agnostic solution
* @param uri
* Directory to remove
*/
auto removeDirectory(const QUrl &uri) noexcept(false) -> void; auto removeDirectory(const QUrl &uri) noexcept(false) -> void;
/**
* @brief getStageFromSuffix
* Supplies the stage/type of shader based on the shaders file extension
* @param suffix
* @return
*/
auto getStageFromSuffix(const QString &suffix) const -> QShader::Stage; auto getStageFromSuffix(const QString &suffix) const -> QShader::Stage;
auto setError(const QString &title, const QString &message, const QUrl &uri = {}) -> void; /**
auto setCompilerOutput(const QString &compilerOutput) -> void; * @brief setState
* Sets the current state of the compiler
* @param state
*/
auto setState(State state) -> void; auto setState(State state) -> void;
/**
* @brief setProgress
* Sets the current progress of the compiler
* @param progress
*/
auto setProgress(qreal progress) -> void; auto setProgress(qreal progress) -> void;
/**
* @brief setTotalSteps
* Sets the total steps pack will take to build
* @param steps
*/
auto setTotalSteps(qint64 steps) -> void; auto setTotalSteps(qint64 steps) -> void;
/**
* @brief setCurrentStep
* Sets the current step
* @param step
*/
auto setCurrentStep(qint64 step) -> void; auto setCurrentStep(qint64 step) -> void;
/**
* @brief setStatus
* Sets the current status message
* @param status
*/
auto setStatus(const QString &status) -> void; auto setStatus(const QString &status) -> void;
/**
* @brief incrementCompileStep
* Increments the current step and updates progress
*/
auto incrementCompileStep() -> void; auto incrementCompileStep() -> void;
//@END helpers
#ifdef HAS_VULKAN #ifdef HAS_VULKAN
/**
* @brief vulkanVersion
* Returns the current version reported by the vulkan api
* @return
*/
auto vulkanVersion() const -> qint32; auto vulkanVersion() const -> qint32;
#endif #endif
#ifdef HAS_OPENGL #ifdef HAS_OPENGL
/**
* @brief openGlVersion
* Returns the current version reported by the opengl api
* @return
*/
auto openGlVersion() const -> qint32; auto openGlVersion() const -> qint32;
#endif #endif
//members //members
/**
* @brief m_updateVariables
* Standard variables expected by most online shaders, mainly
* shadertoy and similar.
*/
static inline const QStringList m_updateVariables static inline const QStringList m_updateVariables
{ {
QStringLiteral("iTime"), QStringLiteral("iTime"),
@@ -275,6 +439,16 @@ private:
QStringLiteral("iChannelResolution") QStringLiteral("iChannelResolution")
}; };
/**
* @brief m_variableExpressions
* Regular expressions of standardized variables. Built at runtime
*/
static inline QList<QRegularExpression> m_variableExpressions;
/**
* @brief m_shaderNameFilters
* Name filters for supported shader types
*/
static inline const QStringList m_shaderNameFilters static inline const QStringList m_shaderNameFilters
{ {
QStringLiteral("*.frag"), QStringLiteral("*.frag"),
@@ -286,6 +460,10 @@ private:
QStringLiteral("*.glsl") QStringLiteral("*.glsl")
}; };
/**
* @brief m_shaderStages
* Map of supported file suffix to their QShader::Stage
*/
static inline const QMap<QString, QShader::Stage> m_shaderStages static inline const QMap<QString, QShader::Stage> m_shaderStages
{ {
{ {
@@ -314,11 +492,19 @@ private:
} }
}; };
/**
* @brief m_version
* Version to be appended to the shader before build
*/
static inline const QByteArray m_version static inline const QByteArray m_version
{ {
R"(#version 450)" R"(#version 450)"
}; };
/**
* @brief m_header
* Header to be appended to the shader before build
*/
static inline const QByteArray m_header static inline const QByteArray m_header
{ {
R"(layout(location = 0) in vec2 qt_TexCoord0; R"(layout(location = 0) in vec2 qt_TexCoord0;
@@ -348,6 +534,10 @@ layout(binding = 4) uniform sampler2D iChannel3;
vec2 fragCoord = vec2(qt_TexCoord0.x, 1.0 - qt_TexCoord0.y) * ubuf.iResolution.xy;)" vec2 fragCoord = vec2(qt_TexCoord0.x, 1.0 - qt_TexCoord0.y) * ubuf.iResolution.xy;)"
}; };
/**
* @brief m_footer
* Footer to be appended to the shader before build
*/
static inline const QByteArray m_footer static inline const QByteArray m_footer
{ {
R"( R"(
@@ -358,29 +548,12 @@ void main() {
})" })"
}; };
QMap<QByteArray, QByteArray> m_commonData;
QMap<QByteArray, QShaderBaker> m_shaders;
QString m_compilerOutput;
QString m_errorMessage;
QString m_errorTitle;
QString m_status;
State m_state; State m_state;
qreal m_currentStep = 0; qreal m_currentStep = 0;
qreal m_progress = 0; qreal m_progress = 0;
qreal m_totalSteps = 0; qreal m_totalSteps = 0;
QString m_status;
QMutex m_downloadMutex;
QFuture<QUrl> m_buildFuture;
static inline QList<QRegularExpression> m_variableExpressions;
Q_PROPERTY(QString compilerOutput READ compilerOutput WRITE setCompilerOutput NOTIFY compilerOutputChanged FINAL)
Q_PROPERTY(QString errorTitle READ errorTitle NOTIFY errorTitleChanged FINAL)
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged FINAL)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged FINAL) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged FINAL)
Q_PROPERTY(qint64 totalSteps READ totalSteps NOTIFY totalStepsChanged FINAL) Q_PROPERTY(qint64 totalSteps READ totalSteps NOTIFY totalStepsChanged FINAL)
Q_PROPERTY(qint64 currentStep READ currentStep NOTIFY currentStepChanged FINAL) Q_PROPERTY(qint64 currentStep READ currentStep NOTIFY currentStepChanged FINAL)