Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC #290

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

RFC #290

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-22.04

runs-on: ubuntu-latest

steps:
- name: Checkout submodules
uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
submodules: true
- name: Install libs
run: sudo apt install libsdl2-dev libglew-dev libglm-dev libgtk-3-dev
- name: cmake
run: sudo cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++-9 -DCMAKE_C_COMPILER=/usr/bin/gcc-9 .
- name: make
run: sudo make
- run: sudo apt install -y ccache ninja-build libsdl2-dev libglew-dev libglm-dev libgtk-3-dev
- uses: hendrikmuhs/[email protected]
- uses: Trass3r/setup-cpp@master
- run: cmake -GNinja -DCMAKE_BUILD_TYPE=Release .
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
- run: ninja -k0
env:
CCACHE_NOCOMPRESS: 1 # cache action will also compress
- uses: actions/upload-artifact@v3
with:
name: linuxbuild
path: bin/*
37 changes: 37 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Windows

on: [push, pull_request]

jobs:
build:
defaults:
run:
shell: bash
runs-on: windows-latest

steps:
- name: Checkout submodules
uses: actions/checkout@v2
with:
submodules: true
- uses: lukka/get-cmake@latest
- uses: lukka/run-vcpkg@v10
with:
vcpkgGitCommitId: '83eb3d3d136f751b0562e1219d391575fdf9fe73'
- uses: hendrikmuhs/[email protected]
- uses: Trass3r/setup-cpp@master
- uses: ilammy/msvc-dev-cmd@v1
- name: configure
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
run: |
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" .
- name: build
env:
UseMultiToolTask: 1
run: ninja
- uses: actions/upload-artifact@v3
with:
name: windowsbuild
path: bin/*
8 changes: 6 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
path = libs/imgui
url = https://github.com/dfranx/imgui.git
branch = docking
shallow = true
[submodule "libs/glslang"]
path = libs/glslang
url = https://github.com/KhronosGroup/glslang
ignore = dirty
shallow = true
[submodule "libs/assimp"]
path = libs/assimp
url = https://github.com/dfranx/assimp.git
shallow = true
[submodule "libs/SPIRV-VM"]
path = libs/SPIRV-VM
url = https://github.com/dfranx/SPIRV-VM.git
url = https://github.com/Trass3r/SPIRV-VM.git
ignore = dirty
shallow = true
[submodule "libs/ShaderExpressionParser"]
path = libs/ShaderExpressionParser
url = https://github.com/dfranx/ShaderExpressionParser
[submodule "libs/SpvGenTwo"]
path = libs/SpvGenTwo
url = https://github.com/dfranx/SpvGenTwo
url = https://github.com/rAzoR8/SpvGenTwo.git
ignore = dirty
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ if(WIN32)
)
endif()

if(MSVC)
add_compile_options(-wd4996)
endif()

# cmake toolchain
if(CMAKE_TOOLCHAIN_FILE)
include(${CMAKE_TOOLCHAIN_FILE})
Expand Down
2 changes: 1 addition & 1 deletion libs/SpvGenTwo
Submodule SpvGenTwo updated 88 files
+42 −0 .github/workflows/CI.yml
+2 −1 .gitignore
+92 −19 CMakeLists.txt
+113 −8 DOCUMENTATION.md
+3 −1 LINKER.md
+99 −92 README.md
+29 −1 common/include/common/Algorithms.h
+1 −1 common/include/common/BinaryVectorWriter.h
+1 −1 common/include/common/Callable.h
+1 −4 common/include/common/ConsoleLogger.h
+2 −2 common/include/common/ExprGraph.h
+5 −5 common/include/common/ExternalMemoryAllocator.h
+6 −17 common/include/common/HeapAllocator.h
+1 −1 common/include/common/HeapString.h
+7 −6 common/include/common/LinkerHelper.h
+1 −1 common/include/common/ReflectionHelper.h
+26 −23 common/source/ConsoleLogger.cpp
+2 −2 common/source/ExternalMemoryAllocator.cpp
+1 −1 common/source/FunctionCallGraph.cpp
+13 −64 common/source/HeapAllocator.cpp
+93 −67 common/source/LinkerHelper.cpp
+2 −2 common/source/ModulePrinter.cpp
+2 −2 common/source/ReflectionHelper.cpp
+0 −8 example/include/example/Constants.h
+0 −8 example/include/example/ControlFlow.h
+0 −8 example/include/example/ExpressionGraph.h
+0 −8 example/include/example/Extensions.h
+0 −8 example/include/example/FragmentShader.h
+0 −8 example/include/example/FunctionCall.h
+0 −8 example/include/example/GeometryShader.h
+0 −14 example/include/example/Linkage.h
+0 −8 example/include/example/OldInstrTest.h
+0 −8 example/include/example/Types.h
+0 −45 example/source/FragmentShader.cpp
+0 −205 example/source/example.cpp
+5 −4 lib/include/spvgentwo/Allocator.h
+4 −0 lib/include/spvgentwo/BasicBlock.h
+2 −2 lib/include/spvgentwo/EntryPointTemplate.inl
+22 −0 lib/include/spvgentwo/Flag.h
+50 −40 lib/include/spvgentwo/GLSL450Instruction.h
+29 −26 lib/include/spvgentwo/Grammar.h
+20 −12 lib/include/spvgentwo/HashMap.h
+121 −70 lib/include/spvgentwo/Instruction.h
+253 −87 lib/include/spvgentwo/InstructionTemplate.inl
+17 −10 lib/include/spvgentwo/Logger.h
+13 −8 lib/include/spvgentwo/Module.h
+4 −4 lib/include/spvgentwo/ModuleTemplate.inl
+49 −24 lib/include/spvgentwo/Operand.h
+361 −73 lib/include/spvgentwo/Spv.h
+86 −2 lib/include/spvgentwo/SpvDefines.h
+116 −73 lib/include/spvgentwo/Type.h
+2 −27 lib/include/spvgentwo/TypeInferenceAndValiation.h
+58 −55 lib/include/spvgentwo/Vector.h
+3 −0 lib/include/spvgentwo/stdreplacement.h
+1 −1 lib/source/Allocator.cpp
+8 −2 lib/source/BasicBlock.cpp
+1 −1 lib/source/Function.cpp
+199 −40 lib/source/GLSL450Instruction.cpp
+1,683 −599 lib/source/Grammar.cpp
+345 −52 lib/source/Instruction.cpp
+93 −29 lib/source/Module.cpp
+174 −24 lib/source/Type.cpp
+200 −141 lib/source/TypeInferenceAndValiation.cpp
+2 −1 link/source/link.cpp
+31 −0 misc/spvgentwo.cppcheck
+27 −0 test/catch2.runsettings
+0 −0 test/include/test/.gitkeep
+26 −0 test/include/test/Modules.h
+16 −0 test/include/test/SpvValidator.h
+12 −0 test/include/test/TestLogger.h
+23 −0 test/source/AllocatorTests.cpp
+73 −0 test/source/ComputeShader.cpp
+89 −0 test/source/ConstantFundamentals.cpp
+3 −3 test/source/Constants.cpp
+2 −2 test/source/ControlFlow.cpp
+53 −48 test/source/ExpressionGraph.cpp
+62 −12 test/source/Extensions.cpp
+111 −0 test/source/FragmentShader.cpp
+2 −2 test/source/FunctionCall.cpp
+2 −2 test/source/GeometryShader.cpp
+41 −0 test/source/ImageRead.cpp
+6 −6 test/source/Linkage.cpp
+122 −0 test/source/ModuleTests.cpp
+11 −6 test/source/OldInstrTest.cpp
+78 −0 test/source/PhysicalStorageTest.cpp
+71 −0 test/source/SpvValidator.cpp
+41 −0 test/source/TestLogger.cpp
+7 −2 test/source/Types.cpp
6 changes: 3 additions & 3 deletions src/SHADERed/Objects/DebugAdapterProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ namespace ed {

for (int i = vm->function_stack_current; i >= 0; i--) {
spvm_result_t func = vm->function_stack_info[i];
if (!(vm->owner->language == SpvSourceLanguageHLSL && i == 0)) {
if (!(vm->owner->files[0].language == SpvSourceLanguageHLSL && i == 0)) {
std::string fname(func->name);
if (fname.size() > 0 && fname[0] == '@') // clean up the @main(
fname = fname.substr(1);
Expand All @@ -469,7 +469,7 @@ namespace ed {
else
line = lines[i];

if (vm->owner->language == SpvSourceLanguageHLSL)
if (vm->owner->files[0].language == SpvSourceLanguageHLSL)
line--;


Expand Down Expand Up @@ -599,7 +599,7 @@ namespace ed {
std::string DebugAdapterProtocol::m_getTypeString(spvm_result_t type, bool returnEmpty)
{
spvm_state_t vm = m_debugger->GetVM();
if (vm && vm->owner->language == SpvSourceLanguageHLSL) {
if (vm && vm->owner->files[0].language == SpvSourceLanguageHLSL) {
// HLSL names
if (type->value_type == spvm_value_type_vector && !returnEmpty) {
std::string ret = "float";
Expand Down
40 changes: 20 additions & 20 deletions src/SHADERed/Objects/DebugInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ void writeWorkgroupMemory(struct spvm_state* state, spvm_word result_id, spvm_wo
spvm_word index_id = SPVM_READ_WORD(code);
spvm_word index = state->results[index_id].members[0].value.s;

spvm_member_t result = sharedData->members + MIN(index, sharedData->member_count - 1);
spvm_member_t result = sharedData->members + SPVM_MIN(index, sharedData->member_count - 1);

while (index_count) {
index_id = SPVM_READ_WORD(code);
index = state->results[index_id].members[0].value.s;

result = result->members + MIN(index, result->member_count - 1);
result = result->members + SPVM_MIN(index, result->member_count - 1);

index_count--;
}
Expand Down Expand Up @@ -165,25 +165,25 @@ void atomicOperation(spvm_word inst, spvm_word word_count, struct spvm_state* st
spvm_result_t value = &state->results[value_id];

for (int i = 0; i < data->member_count; i++)
data->members[i].value.s = MIN(value->members[i].value.s, data->members[i].value.s);
data->members[i].value.s = SPVM_MIN(value->members[i].value.s, data->members[i].value.s);
} else if (inst == SpvOpAtomicUMin) {
spvm_word value_id = SPVM_READ_WORD(state->code_current);
spvm_result_t value = &state->results[value_id];

for (int i = 0; i < data->member_count; i++)
data->members[i].value.u = MIN(value->members[i].value.u, data->members[i].value.u);
data->members[i].value.u = SPVM_MIN(value->members[i].value.u, data->members[i].value.u);
} else if (inst == SpvOpAtomicSMax) {
spvm_word value_id = SPVM_READ_WORD(state->code_current);
spvm_result_t value = &state->results[value_id];

for (int i = 0; i < data->member_count; i++)
data->members[i].value.s = MAX(value->members[i].value.s, data->members[i].value.s);
data->members[i].value.s = SPVM_MAX(value->members[i].value.s, data->members[i].value.s);
} else if (inst == SpvOpAtomicUMax) {
spvm_word value_id = SPVM_READ_WORD(state->code_current);
spvm_result_t value = &state->results[value_id];

for (int i = 0; i < data->member_count; i++)
data->members[i].value.u = MAX(value->members[i].value.u, data->members[i].value.u);
data->members[i].value.u = SPVM_MAX(value->members[i].value.u, data->members[i].value.u);
} else if (inst == SpvOpAtomicAnd) {
spvm_word value_id = SPVM_READ_WORD(state->code_current);
spvm_result_t value = &state->results[value_id];
Expand Down Expand Up @@ -367,7 +367,7 @@ namespace ed {
{
ed::Logger::Get().Log("Resetting the debugger");

for (spvm_image_t img : m_images) {
for (spvm_image_data* img : m_images) {
free(img->data);
free(img);
}
Expand Down Expand Up @@ -967,18 +967,14 @@ namespace ed {
}

if ((wrongBind || textureID == 0) && !pluginUsesCustomTextures) {
spvm_image_t img = (spvm_image_t)malloc(sizeof(spvm_image));
auto img = (spvm_image_data*)calloc(1, sizeof(spvm_image_data));

// get texture size
glm::ivec2 size(1, 1);
float* imgData = (float*)calloc(1, sizeof(float) * size.x * size.y * 4);

img->user_data = nullptr;

spvm_image_create(img, imgData, size.x, size.y, 1);
free(imgData);

slot->members[0].image_data = img;
slot->members[0].value.image = (spvm_image*)img;

m_images.push_back(img);

Expand All @@ -988,8 +984,8 @@ namespace ed {
if (slot->members == nullptr) // if slot->members == nullptr it means that it's a pointer/function argument
continue;

spvm_image_t img = (spvm_image_t)malloc(sizeof(spvm_image));
auto img = (spvm_image_data*)calloc(1, sizeof(spvm_image_data));

if (type_info->image_info == NULL)
type_info = &m_vm->results[type_info->pointer];

Expand Down Expand Up @@ -1119,17 +1115,21 @@ namespace ed {

if (imgData != nullptr) {
spvm_image_create(img, imgData, imgSize.x, imgSize.y, imgSize.z);
free(imgData);
}

/*
if (pluginUsesCustomTextures)
img->user_data = (void*)pluginCustomTexture;
else
img->user_data = (void*)textureID;

slot->members[0].image_data = img;
*/
slot->members[0].value.image = (spvm_image*)img;
m_images.push_back(img);
sampler2Dloc++;
// oddly it's an image not a sampled_image
//if (type_info->value_type == spvm_value_type_sampled_image) {
auto sampler = (spvm_sampler*)calloc(1, sizeof(spvm_sampler));
slot->members[1].value.sampler = sampler;
//}
}
}
}
Expand Down Expand Up @@ -2426,7 +2426,7 @@ namespace ed {

// move to cursor to first line in the function
spvm_state_step_into(m_vm);
if (m_vm->owner->language == SpvSourceLanguageHLSL) {
if (m_vm->owner->files[0].language == SpvSourceLanguageHLSL) {
// since actual main is encapsulated into another main function
while (m_vm->code_current && m_vm->function_stack_current == 0)
spvm_state_step_into(m_vm);
Expand Down
4 changes: 2 additions & 2 deletions src/SHADERed/Objects/DebugInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ed {
inline spvm_state_t GetVMImmediate() { return m_vmImmediate; }
inline spvm_context_t GetVMContext() { return m_vmContext; }
inline spvm_ext_opcode_func* GetGLSLExtension() { return m_vmGLSL; }
inline int GetCurrentLine() { return m_shader->language == SpvSourceLanguageHLSL ? (m_vm->current_line - 1) : m_vm->current_line; }
inline int GetCurrentLine() { return m_shader->files[0].language == SpvSourceLanguageHLSL ? (m_vm->current_line - 1) : m_vm->current_line; }
inline bool IsVMRunning() { return m_vm != nullptr && m_vm->code_current != nullptr; }
inline void SetCurrentFile(const std::string& file) { m_file = file; }
inline const std::string& GetCurrentFile() { return m_file; }
Expand Down Expand Up @@ -169,7 +169,7 @@ namespace ed {
glm::vec3 m_processWeight(glm::ivec2 offset);
void m_interpolateValues(spvm_state_t state, glm::vec3 weights);

std::vector<spvm_image_t> m_images; // TODO: clear these + smart cache
std::vector<spvm_image_data*> m_images; // TODO: clear these + smart cache

spvm_context_t m_vmContext;
spvm_ext_opcode_func* m_vmGLSL;
Expand Down
4 changes: 2 additions & 2 deletions src/SHADERed/UI/Debug/FunctionStackUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ed {

for (int i = vm->function_stack_current; i >= 0; i--) {
spvm_result_t func = vm->function_stack_info[i];
if (!(vm->owner->language == SpvSourceLanguageHLSL && i == 0) && func->name != nullptr) {
if (!(vm->owner->files[0].language == SpvSourceLanguageHLSL && i == 0) && func->name != nullptr) {
std::string fname(func->name);
if (fname.size() > 0 && fname[0] == '@') // clean up the @main(
fname = fname.substr(1);
Expand All @@ -26,7 +26,7 @@ namespace ed {
if (i >= lines.size()) line = vm->current_line;
else line = lines[i];

if (vm->owner->language == SpvSourceLanguageHLSL)
if (vm->owner->files[0].language == SpvSourceLanguageHLSL)
line--;

m_stack.push_back(fname + " @ line " + std::to_string(line));
Expand Down
4 changes: 2 additions & 2 deletions src/SHADERed/UI/ObjectPreviewUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ namespace ed {
ImGui::Text("Slice: ");
ImGui::SameLine();
if (ImGui::Button("-", ImVec2(30, 0)))
m_cachedImgSlice[i] = MAX(m_cachedImgSlice[i] - 1, 0);
m_cachedImgSlice[i] = SPVM_MAX(m_cachedImgSlice[i] - 1, 0);
ImGui::SameLine();
ImGui::Text("%d", m_cachedImgSlice[i]);
ImGui::SameLine();
if (ImGui::Button("+", ImVec2(30, 0)))
m_cachedImgSlice[i] = MIN(m_cachedImgSlice[i] + 1, objSize.z - 1);
m_cachedImgSlice[i] = SPVM_MIN(m_cachedImgSlice[i] + 1, objSize.z - 1);
}
else if (item->Type == ObjectType::Audio) {
memset(&m_samplesTempBuffer, 0, sizeof(short) * 1024);
Expand Down
10 changes: 5 additions & 5 deletions src/SHADERed/UI/PixelInspectUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,18 +549,18 @@ namespace ed {
ImGui::Separator();

// Value:
if (isTex && res->image_data != nullptr) {
spvm_image_t tex = res->image_data;
if (isTex && res->value.image != nullptr) {
spvm_image* tex = res->value.image;

if (isCube) {
m_cubePrev.Draw((GLuint)((uintptr_t)tex->user_data));
m_cubePrev.Draw(/*(GLuint)((uintptr_t)tex->user_data)*/0);
ImGui::Image((ImTextureID)m_cubePrev.GetTexture(), ImVec2(128.0f, 128.0f * (375.0f / 512.0f)), ImVec2(0, 1), ImVec2(1, 0));
} else if (isTex3D) {
float imgWH = (tex->height / (float)tex->width);
m_tex3DPrev.Draw((GLuint)((uintptr_t)tex->user_data), 128.0f, 128.0f * (float)imgWH);
m_tex3DPrev.Draw(/*(GLuint)((uintptr_t)tex->user_data)*/0, 128.0f, 128.0f * (float)imgWH);
ImGui::Image((void*)(intptr_t)m_tex3DPrev.GetTexture(), ImVec2(128.0f, 128.0f * imgWH));
} else
ImGui::Image((ImTextureID)tex->user_data, ImVec2(128.0f, 128.0f * (tex->height / (float)tex->width)), ImVec2(0, 1), ImVec2(1, 0));
ImGui::Image(/*(ImTextureID)tex->user_data*/0, ImVec2(128.0f, 128.0f * (tex->height / (float)tex->width)), ImVec2(0, 1), ImVec2(1, 0));
} else {
// color preview
if (resType->value_type == spvm_value_type_vector && m_data->Debugger.GetVM()->results[resType->pointer].value_type == spvm_value_type_float) {
Expand Down
9 changes: 9 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "shadered",
"version-string": "latest",
"dependencies": [
"sdl2",
"glew",
"glm"
]
}