diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 1d3407a6..48e33a9c 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -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/ccache-action@v1.2 + - 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/* diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..301e2019 --- /dev/null +++ b/.github/workflows/windows.yml @@ -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/ccache-action@v1.2 + - 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/* diff --git a/.gitmodules b/.gitmodules index 961ce159..83efd3de 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 55eb05c7..e69f061e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,6 +133,10 @@ if(WIN32) ) endif() +if(MSVC) + add_compile_options(-wd4996) +endif() + # cmake toolchain if(CMAKE_TOOLCHAIN_FILE) include(${CMAKE_TOOLCHAIN_FILE}) diff --git a/libs/SPIRV-VM b/libs/SPIRV-VM index 439434fc..ff8c006f 160000 --- a/libs/SPIRV-VM +++ b/libs/SPIRV-VM @@ -1 +1 @@ -Subproject commit 439434fce991ea9c5e9c1b78ebcbcb22bb27feaf +Subproject commit ff8c006ff7daf57ac503b82a3a8a58c35703e4f3 diff --git a/libs/SpvGenTwo b/libs/SpvGenTwo index 5fba6bd5..f24376fd 160000 --- a/libs/SpvGenTwo +++ b/libs/SpvGenTwo @@ -1 +1 @@ -Subproject commit 5fba6bd5411a8515a682f49111546ae4c81c5237 +Subproject commit f24376fd9d4a8f097355340c57fa56f1c2e2b016 diff --git a/src/SHADERed/Objects/DebugAdapterProtocol.cpp b/src/SHADERed/Objects/DebugAdapterProtocol.cpp index df378e49..a5c772ab 100644 --- a/src/SHADERed/Objects/DebugAdapterProtocol.cpp +++ b/src/SHADERed/Objects/DebugAdapterProtocol.cpp @@ -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); @@ -469,7 +469,7 @@ namespace ed { else line = lines[i]; - if (vm->owner->language == SpvSourceLanguageHLSL) + if (vm->owner->files[0].language == SpvSourceLanguageHLSL) line--; @@ -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"; diff --git a/src/SHADERed/Objects/DebugInformation.cpp b/src/SHADERed/Objects/DebugInformation.cpp index 24d48402..c7c64ea7 100644 --- a/src/SHADERed/Objects/DebugInformation.cpp +++ b/src/SHADERed/Objects/DebugInformation.cpp @@ -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--; } @@ -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]; @@ -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); } @@ -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); @@ -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]; @@ -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; + //} } } } @@ -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); diff --git a/src/SHADERed/Objects/DebugInformation.h b/src/SHADERed/Objects/DebugInformation.h index fbad4e96..5e0cb92c 100644 --- a/src/SHADERed/Objects/DebugInformation.h +++ b/src/SHADERed/Objects/DebugInformation.h @@ -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; } @@ -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 m_images; // TODO: clear these + smart cache + std::vector m_images; // TODO: clear these + smart cache spvm_context_t m_vmContext; spvm_ext_opcode_func* m_vmGLSL; diff --git a/src/SHADERed/UI/Debug/FunctionStackUI.cpp b/src/SHADERed/UI/Debug/FunctionStackUI.cpp index 6fe65ae4..99a43995 100644 --- a/src/SHADERed/UI/Debug/FunctionStackUI.cpp +++ b/src/SHADERed/UI/Debug/FunctionStackUI.cpp @@ -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); @@ -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)); diff --git a/src/SHADERed/UI/ObjectPreviewUI.cpp b/src/SHADERed/UI/ObjectPreviewUI.cpp index c355e403..b6736819 100644 --- a/src/SHADERed/UI/ObjectPreviewUI.cpp +++ b/src/SHADERed/UI/ObjectPreviewUI.cpp @@ -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); diff --git a/src/SHADERed/UI/PixelInspectUI.cpp b/src/SHADERed/UI/PixelInspectUI.cpp index a44f4003..b6ac427b 100644 --- a/src/SHADERed/UI/PixelInspectUI.cpp +++ b/src/SHADERed/UI/PixelInspectUI.cpp @@ -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) { diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..26462bea --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,9 @@ +{ + "name": "shadered", + "version-string": "latest", + "dependencies": [ + "sdl2", + "glew", + "glm" + ] +}