Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ docs/traces/
.vimspector.json
subprojects/.wraplock
subprojects/pml.wrap
.launch
2 changes: 0 additions & 2 deletions .launch

This file was deleted.

7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ dep_nytl = subproject('nytl', default_options: dopts).get_variable('nytl_dep')
dep_imgio = subproject('imgio', default_options: dopts).get_variable('imgio_dep')
dep_spc = subproject('spc', default_options: dopts).get_variable('spc_dep')

dep_spirv_tools = dependency('SPIRV-Tools', required: false)

layer_args += '-DDLG_DEFAULT_TAGS="vil"'

if disable_dlg
Expand Down Expand Up @@ -414,6 +416,11 @@ if with_window or with_x11_hook or with_win32 or with_example
endif
endif

if dep_spirv_tools.found()
deps += [dep_spirv_tools]
layer_args += '-DVIL_WITH_SPIRV_TOOLS=1'
endif

with_unit_tests = get_option('unit-tests')
if with_unit_tests
src += files(
Expand Down
2 changes: 2 additions & 0 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ std::unique_ptr<DisplayWindow> tryCreateWindow(Instance& ini,
// swa whether it should use x11 or wayland; but also have to tell
// it whether to use xcb or xlib for window creation).
if(standaloneMode) {
window->ini = &ini;
if(!window->doCreateDisplay()) {
return nullptr;
}
Expand Down Expand Up @@ -1251,6 +1252,7 @@ VkResult doCreateDevice(

if(standaloneMode) {
dev.window->dev = &dev;
dev.window->doCreateWindow();
dev.window->doInitSwapchain();
}
}
Expand Down
36 changes: 34 additions & 2 deletions src/gui/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <device.hpp>
#include <queue.hpp>
#include <pipe.hpp>
#include <shader.hpp>
#include <memory.hpp>
#include <threadContext.hpp>
#include <image.hpp>
Expand All @@ -30,8 +31,13 @@
#include <imgui/imgui_internal.h>
#include <vkutil/enumString.hpp>
#include <vk/format_utils.h>
#include <spirv_cross.hpp>
#include <map>

#ifdef VIL_WITH_SPIRV_TOOLS
#include <spirv-tools/libspirv.h>
#endif // VIL_WITH_SPIRV_TOOLS

namespace vil {

// NOTE: use something like this? But this actively hides information,
Expand Down Expand Up @@ -1175,8 +1181,33 @@ void ResourceGui::drawDesc(Draw&, ImageView& view) {
}
}

void ResourceGui::drawDesc(Draw&, ShaderModule&) {
ImGui::Text("TODO");
void ResourceGui::drawDesc(Draw&, ShaderModule& mod) {
(void) mod;
#ifdef VIL_WITH_SPIRV_TOOLS
if (spirvDisassembly_.empty()) {
auto context = spvContextCreate(SPV_ENV_UNIVERSAL_1_6);
auto& spirv = mod.compiled->get_ir().spirv;
spv_text text;
spv_diagnostic diagnostic;
auto opts = SPV_BINARY_TO_TEXT_OPTION_INDENT |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
spvBinaryToText(context, spirv.data(), spirv.size(),
opts, &text, &diagnostic);

dlg_assert(!diagnostic);
spirvDisassembly_ = {text->str, text->length};

spirvEdit_.SetReadOnly(true);
spirvEdit_.SetText(spirvDisassembly_);
spirvEdit_.SetShowWhitespaces(false);
spirvEdit_.SetTabSize(4);
spirvEdit_.SetLanguageDefinition(igt::TextEditor::LanguageDefinition::SPIRV());
}

ImGui::PushFont(gui_->monoFont);
spirvEdit_.Render("SPIR-V");
ImGui::PopFont();
#endif // VIL_WITH_SPIRV_TOOLS
}

void ResourceGui::drawDesc(Draw&, Framebuffer& fb) {
Expand Down Expand Up @@ -1651,6 +1682,7 @@ void ResourceGui::clearSelection() {
ds_.selected = {};
image_.object = {};
buffer_.handle = {};
spirvDisassembly_ = {};
}

void ResourceGui::draw(Draw& draw) {
Expand Down
3 changes: 3 additions & 0 deletions src/gui/resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class ResourceGui {
Handle* handle_ {};
bool editName_ {false};

std::string spirvDisassembly_;
igt::TextEditor spirvEdit_;

struct {
Image* object {};
ImageViewer viewer {};
Expand Down
3 changes: 3 additions & 0 deletions src/handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const char* name(VkObjectType objectType) {
case VK_OBJECT_TYPE_FRAMEBUFFER: return "Framebuffer";
case VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE: return "DescriptorUpdateTemplate";
case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR: return "AccelerationStructure";
case VK_OBJECT_TYPE_SHADER_EXT: return "Shader";
case VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_EXT: return "IndirectCommandsLayout";
case VK_OBJECT_TYPE_INDIRECT_EXECUTION_SET_EXT: return "IndirectExecutionSet";
default: return "?";
}
}
Expand Down
48 changes: 48 additions & 0 deletions src/imgui/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2907,6 +2907,54 @@ const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::HLSL()
return langDef;
}

const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::SPIRV()
{
// From SHADERed
// Copyright (c) 2018 - 2021 dfranx
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

static bool inited = false;
static LanguageDefinition langDef;
if (!inited) {
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>("L?\\\"(\\\\.|[^\\\"])*\\\"", PaletteIndex::String));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>("[ =\\t]Op[a-zA-Z]*", PaletteIndex::Keyword));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>("%[_a-zA-Z0-9]*", PaletteIndex::Identifier));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?", PaletteIndex::Number));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::Number));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::Number));
langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::Number));

langDef.mCommentStart = "/*";
langDef.mCommentEnd = "*/";
langDef.mSingleLineComment = ";";

langDef.mCaseSensitive = true;
langDef.mAutoIndentation = false;

langDef.mName = "SPIR-V";

inited = true;
}
return langDef;
}

const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::GLSLFast()
{
static bool inited = false;
Expand Down
1 change: 1 addition & 0 deletions src/imgui/textedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class TextEditor
static const LanguageDefinition& CPlusPlus();
static const LanguageDefinition& HLSL();
static const LanguageDefinition& GLSLFast();
static const LanguageDefinition& SPIRV();
static const LanguageDefinition& GLSL();
static const LanguageDefinition& C();
static const LanguageDefinition& SQL();
Expand Down
2 changes: 2 additions & 0 deletions src/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateShadersEXT(
mod.handle = pShaders[i];
mod.dsLayouts = std::move(layoutVecs[i]);

// TODO: store code!

pShaders[i] = castDispatch<VkShaderEXT>(mod);
dev.shaderObjects.mustEmplace(pShaders[i], std::move(modPtr));
}
Expand Down