Skip to content

Commit 3b66f49

Browse files
committed
Improve CNZSL
1 parent 0b1a27e commit 3b66f49

31 files changed

+857
-588
lines changed

include/CNZSL/CNZSL.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
// Copyright (C) 2024 REMqb (remqb at remqb dot fr)
2-
// This file is part of the "Nazara Shading Language" project
3-
// For conditions of distribution and use, see copyright notice in Config.hpp
1+
/*
2+
Copyright (C) 2024 REMqb (remqb at remqb dot fr)
3+
This file is part of the "Nazara Shading Language - C Binding" project
4+
For conditions of distribution and use, see copyright notice in Config.hpp
5+
*/
46

57
#pragma once
68

79
#ifndef CNZSL_CNZSL_H
810
#define CNZSL_CNZSL_H
911

10-
#include <CNZSL/Error.h>
1112
#include <CNZSL/GlslWriter.h>
13+
#include <CNZSL/LangWriter.h>
1214
#include <CNZSL/Module.h>
1315
#include <CNZSL/Parser.h>
1416
#include <CNZSL/SpirvWriter.h>
1517

16-
#endif //CNZSL_CNZSL_H
18+
#endif /* CNZSL_CNZSL_H */

include/CNZSL/Config.h

+39-96
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,50 @@
1-
// Copyright (C) 2024 REMqb (remqb at remqb dot fr)
2-
// This file is part of the "Nazara Shading Language" project
3-
// For conditions of distribution and use, see copyright notice in Config.hpp
1+
/*
2+
Nazara Shading Language - C Binding (CNZSL)
3+
4+
Copyright (C) 2024 Jérôme "SirLynix" Leclercq ([email protected])
5+
2024 REMqb (remqb at remqb dot fr)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
this software and associated documentation files (the "Software"), to deal in
9+
the Software without restriction, including without limitation the rights to
10+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11+
of the Software, and to permit persons to whom the Software is furnished to do
12+
so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
*/
425

526
#pragma once
627

7-
#ifndef CNZSL_CNZSL_H
8-
#define CNZSL_CNZSL_H
28+
#ifndef CNZSL_CONFIG_H
29+
#define CNZSL_CONFIG_H
930

10-
// #include <NazaraUtils/Prerequisites.hpp> // I don't want the C++ things
31+
/* CNZSL version macro */
32+
#define CNZSL_VERSION_MAJOR 0
33+
#define CNZSL_VERSION_MINOR 1
34+
#define CNZSL_VERSION_PATCH 0
1135

12-
// Try to identify the compiler
13-
#if defined(__clang__)
14-
#define NAZARA_COMPILER_CLANG
15-
#define NAZARA_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
16-
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
17-
#define NAZARA_PRETTY_FUNCTION __PRETTY_FUNCTION__
18-
19-
#define NAZARA_CHECK_CLANG_VER(ver) (NAZARA_COMPILER_CLANG_VER >= ver)
20-
21-
#define NAZARA_PRAGMA(x) _Pragma(#x)
22-
23-
#define NAZARA_WARNING_CLANG_DISABLE(warn) NAZARA_PRAGMA(clang diagnostic ignored warn)
24-
#define NAZARA_WARNING_CLANG_GCC_DISABLE(warn) NAZARA_PRAGMA(clang diagnostic ignored warn)
25-
#define NAZARA_WARNING_POP() NAZARA_PRAGMA(clang diagnostic pop)
26-
#define NAZARA_WARNING_PUSH() NAZARA_PRAGMA(clang diagnostic push)
27-
28-
#ifdef __MINGW32__
29-
#define NAZARA_COMPILER_MINGW
30-
#ifdef __MINGW64_VERSION_MAJOR
31-
#define NAZARA_COMPILER_MINGW_W64
32-
#endif
33-
#endif
34-
#elif defined(__GNUC__) || defined(__MINGW32__)
35-
#define NAZARA_COMPILER_GCC
36-
#define NAZARA_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
37-
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
38-
#define NAZARA_PRETTY_FUNCTION __PRETTY_FUNCTION__
39-
40-
#define NAZARA_CHECK_GCC_VER(ver) (NAZARA_COMPILER_GCC_VER >= ver)
41-
42-
#define NAZARA_PRAGMA(x) _Pragma(#x)
43-
44-
#define NAZARA_WARNING_CLANG_GCC_DISABLE(warn) NAZARA_PRAGMA(GCC diagnostic ignored warn)
45-
#define NAZARA_WARNING_GCC_DISABLE(warn) NAZARA_PRAGMA(GCC diagnostic ignored warn)
46-
#define NAZARA_WARNING_POP() NAZARA_PRAGMA(GCC diagnostic pop)
47-
#define NAZARA_WARNING_PUSH() NAZARA_PRAGMA(GCC diagnostic push)
48-
49-
#ifdef __MINGW32__
50-
#define NAZARA_COMPILER_MINGW
51-
#ifdef __MINGW64_VERSION_MAJOR
52-
#define NAZARA_COMPILER_MINGW_W64
36+
#if !defined(CNZSL_STATIC)
37+
#ifdef _WIN32
38+
#ifdef CNZSL_BUILD
39+
#define CNZSL_API __declspec(dllexport)
40+
#else
41+
#define CNZSL_API __declspec(dllimport)
5342
#endif
54-
#endif
55-
#elif defined(__INTEL_COMPILER) || defined(__ICL)
56-
#define NAZARA_COMPILER_ICC
57-
#define NAZARA_COMPILER_ICC_VER __INTEL_COMPILER
58-
#define NAZARA_DEPRECATED(txt) [[deprecated(txt)]]
59-
#define NAZARA_PRETTY_FUNCTION __FUNCTION__
60-
61-
#define NAZARA_CHECK_ICC_VER(ver) (NAZARA_COMPILER_ICC_VER >= ver)
62-
63-
#define NAZARA_PRAGMA(x) _Pragma(x)
64-
65-
#define NAZARA_WARNING_ICC_DISABLE(...) NAZARA_PRAGMA(warning(disable: __VA_ARGS__))
66-
#define NAZARA_WARNING_POP() NAZARA_PRAGMA(warning(pop))
67-
#define NAZARA_WARNING_PUSH() NAZARA_PRAGMA(warning(push))
68-
#elif defined(_MSC_VER)
69-
#define NAZARA_COMPILER_MSVC
70-
#define NAZARA_COMPILER_MSVC_VER _MSC_VER
71-
#define NAZARA_DEPRECATED(txt) __declspec(deprecated(txt))
72-
#define NAZARA_PRETTY_FUNCTION __FUNCSIG__
73-
74-
#define NAZARA_CHECK_MSVC_VER(ver) (NAZARA_COMPILER_MSVC_VER >= ver)
75-
76-
#define NAZARA_PRAGMA(x) __pragma(x)
77-
78-
#define NAZARA_WARNING_MSVC_DISABLE(...) NAZARA_PRAGMA(warning(disable: __VA_ARGS__))
79-
#define NAZARA_WARNING_POP() NAZARA_PRAGMA(warning(pop))
80-
#define NAZARA_WARNING_PUSH() NAZARA_PRAGMA(warning(push))
81-
82-
// __cplusplus isn't respected on MSVC without /Zc:__cplusplus flag
83-
#define NAZARA_CPP_VER _MSVC_LANG
84-
#else
85-
#define NAZARA_COMPILER_UNKNOWN
86-
#define NAZARA_DEPRECATED(txt)
87-
#define NAZARA_PRETTY_FUNCTION __func__ // __func__ has been standardized in C++ 2011
88-
89-
#pragma message This compiler is not fully supported
90-
#endif
91-
92-
// Nazara version macro
93-
#define NZSL_VERSION_MAJOR 0
94-
#define NZSL_VERSION_MINOR 1
95-
#define NZSL_VERSION_PATCH 0
96-
97-
#if !defined(NZSL_STATIC)
98-
#ifdef NZSL_BUILD
99-
#define NZSL_API NAZARA_EXPORT
10043
#else
101-
#define NZSL_API NAZARA_IMPORT
44+
#define CNZSL_API __attribute__((visibility("default")))
10245
#endif
10346
#else
104-
#define NZSL_API
47+
#define CNZSL_API extern
10548
#endif
10649

107-
#endif //CNZSL_CNZSL_H
50+
#endif /* CNZSL_CONFIG_H */

include/CNZSL/DebugLevel.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright (C) 2024 REMqb (remqb at remqb dot fr)
3+
This file is part of the "Nazara Shading Language - C Binding" project
4+
For conditions of distribution and use, see copyright notice in Config.hpp
5+
*/
6+
7+
#pragma once
8+
9+
#ifndef CNZSL_DEBUGLEVEL_H
10+
#define CNZSL_DEBUGLEVEL_H
11+
12+
enum nzslDebugLevel
13+
{
14+
NZSL_DEBUG_NONE,
15+
16+
NZSL_DEBUG_FULL,
17+
NZSL_DEBUG_MINIMAL,
18+
NZSL_DEBUG_REGULAR,
19+
20+
NZSL_DEBUG_MAX_ENUM = 0x7FFFFFFF
21+
};
22+
23+
#endif /* CNZSL_DEBUGLEVEL_H */

include/CNZSL/Error.h

-30
This file was deleted.

include/CNZSL/Error.hpp

-22
This file was deleted.

include/CNZSL/GlslWriter.h

+42-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Copyright (C) 2024 REMqb (remqb at remqb dot fr)
2-
// This file is part of the "Nazara Shading Language" project
3-
// For conditions of distribution and use, see copyright notice in Config.hpp
1+
/*
2+
Copyright (C) 2024 REMqb (remqb at remqb dot fr)
3+
This file is part of the "Nazara Shading Glsluage - C Binding" project
4+
For conditions of distribution and use, see copyright notice in Config.hpp
5+
*/
46

57
#pragma once
68

@@ -9,69 +11,77 @@
911

1012
#include <CNZSL/Config.h>
1113
#include <CNZSL/Module.h>
14+
#include <CNZSL/ShaderStageType.h>
15+
#include <CNZSL/WriterStates.h>
16+
#include <stddef.h>
1217

1318
#ifdef __cplusplus
14-
extern "C" {
19+
extern "C"
20+
{
1521
#endif
1622

17-
18-
/// Opaque pointer on nzsl::GlslWriter
19-
typedef struct NZSLGlslWriter_s* NZSLGlslWriter;
23+
typedef struct nzslGlslWriter nzslGlslWriter;
24+
typedef struct nzslGlslBindingMapping nzslGlslBindingMapping;
25+
typedef struct nzslGlslOutput nzslGlslOutput;
2026

2127
typedef struct
2228
{
23-
// ExtSupportCallback extCallback;
2429
unsigned int glMajorVersion;
2530
unsigned int glMinorVersion;
2631
int glES;
2732
int flipYPosition;
2833
int remapZPosition;
2934
int allowDrawParametersUniformsFallback;
30-
} NZSLGlslWriterEnvironment;
35+
} nzslGlslWriterEnvironment;
3136

32-
typedef struct NZSLGlslWriterOutputInternal_s* NZSLGlslWriterOutputInternal;
37+
CNZSL_API nzslGlslBindingMapping* nzslGlslBindingMappingCreate(void);
38+
CNZSL_API void nzslGlslBindingMappingDestroy(nzslGlslBindingMapping* bindingMappingPtr);
3339

34-
typedef struct
35-
{
36-
NZSLGlslWriterOutputInternal internal;
37-
const char* code;
38-
size_t codeLen;
39-
int usesDrawParameterBaseInstanceUniform;
40-
int usesDrawParameterBaseVertexUniform;
41-
int usesDrawParameterDrawIndexUniform;
42-
} NZSLGlslWriterOutput_s;
40+
CNZSL_API void nzslGlslBindingMappingSetBinding(nzslGlslBindingMapping* bindingMappingPtr, uint32_t setIndex, uint32_t bindingIndex, unsigned int glBinding);
4341

44-
typedef NZSLGlslWriterOutput_s* NZSLGlslWriterOutput;
42+
CNZSL_API nzslGlslWriter* nzslGlslWriterCreate(void);
43+
CNZSL_API void nzslGlslWriterDestroy(nzslGlslWriter* writerPtr);
4544

46-
NZSLGlslWriter NZSL_API nzslGlslWriterCreate(void);
45+
CNZSL_API nzslGlslOutput* nzslGlslWriterGenerate(nzslGlslWriter* writerPtr, const nzslModule* modulePtr, const nzslGlslBindingMapping* bindingMapping, const nzslWriterStates* statesPtr);
46+
CNZSL_API nzslGlslOutput* nzslGlslWriterGenerateStage(nzslShaderStageType stage, nzslGlslWriter* writerPtr, const nzslModule* modulePtr, const nzslGlslBindingMapping* bindingMapping, const nzslWriterStates* statesPtr);
4747

48-
int NZSL_API nzslGlslWriterSetEnv(NZSLGlslWriter writer, NZSLGlslWriterEnvironment env);
48+
/**
49+
** Gets the last error message set by the last operation to this writer
50+
**
51+
** @param writerPtr
52+
** @returns null-terminated error string
53+
**/
54+
CNZSL_API const char* nzslGlslWriterGetLastError(const nzslGlslWriter* writerPtr);
4955

50-
NZSLGlslWriterOutput NZSL_API nzslGlslWriterGenerate(NZSLGlslWriter writer, NZSLModule module);
56+
CNZSL_API void nzslGlslWriterSetEnv(nzslGlslWriter* writerPtr, const nzslGlslWriterEnvironment* env);
5157

52-
/**Return texture binding in output or -1 if binding doesn't exists
58+
CNZSL_API void nzslGlslOutputDestroy(nzslGlslOutput* outputPtr);
59+
CNZSL_API const char* nzslGlslOutputGetCode(const nzslGlslOutput* outputPtr, size_t* length);
60+
61+
/**
62+
* Return texture binding in output or -1 if binding doesn't exists
5363
*
5464
* @param output
5565
* @param bindingName
5666
* @return
5767
*/
58-
int NZSL_API nzslGlslWriterOutputGetExplicitTextureBinding(NZSLGlslWriterOutput output, const char* bindingName);
68+
CNZSL_API int nzslGlslOutputGetExplicitTextureBinding(const nzslGlslOutput* outputPtr, const char* bindingName);
5969

60-
/**Return uniform binding in output or -1 if binding doesn't exists
70+
/**
71+
* Return uniform binding in output or -1 if binding doesn't exists
6172
*
6273
* @param output
6374
* @param bindingName
6475
* @return
6576
*/
66-
int NZSL_API nzslGlslWriterOutputGetExplicitUniformBlockBinding(NZSLGlslWriterOutput output, const char* bindingName);
67-
68-
void NZSL_API nzslGlslWriterOutputDestroy(NZSLGlslWriterOutput output);
77+
CNZSL_API int nzslGlslOutputGetExplicitUniformBlockBinding(const nzslGlslOutput* outputPtr, const char* bindingName);
6978

70-
void NZSL_API nzslGlslWriterDestroy(NZSLGlslWriter writer);
79+
CNZSL_API int nzslGlslOutputGetUsesDrawParameterBaseInstanceUniform(const nzslGlslOutput* outputPtr);
80+
CNZSL_API int nzslGlslOutputGetUsesDrawParameterBaseVertexUniform(const nzslGlslOutput* outputPtr);
81+
CNZSL_API int nzslGlslOutputGetUsesDrawParameterDrawIndexUniform(const nzslGlslOutput* outputPtr);
7182

7283
#ifdef __cplusplus
7384
}
7485
#endif
7586

76-
77-
#endif //CNZSL_GLSLWRITER_H
87+
#endif /* CNZSL_GLSLWRITER_H */

0 commit comments

Comments
 (0)