SHADERed
SHADERed copied to clipboard
Unknown identifier 'binding' in layout - when trying to use a texture
I have a very basic shader. After I bind the texture and add the uniform, I get an error:
ERROR: 0:7: Unknown identifier 'binding' in layout
ERROR: 0:14: Use of undeclared identifier 'tex'
Failed to compile the shader
Any help would be appreciated since I cannot use SHADERed right now without the ability to use textures. If there's more info I can provide, please let me know. I am running on a macOS Big Sur 11.6 (20G165). I was able to compile it by following the instructions in the README, without any problems.
I was able to work around this by modifying libs/SPIRVCross/spirv_glsl.hpp and changing enable_420pack_extension
to false
:
// bool enable_420pack_extension = true;
bool enable_420pack_extension = false;
For reference, these are all the commands I used to compile SHADERed on macOS Big Sur 11.6 (20G165), Xcode 13.0.
git clone https://github.com/dfranx/SHADERed.git
cd SHADERed
git submodule update --init --recursive
brew install sdl2 glew glm
brew install minizip
vim libs/SPIRVCross/spirv_glsl.hpp # change `enable_420pack_extension` to `false`
mkdir build
cd build
cmake ../
cp -r ../bin/* ./bin/
make -j8
./bin/SHADERed
There are still things that don't work, like the Watches or the Immediate window. As soon as you enter something in either of them, you get a "Segmentation fault: 11" and the IDE crashes.
Can you clone a clean version of SHADERed and then try opening the project file in the examples/Eroded
directory? Report to me if it works.
The Watches and Immediate window also shouldn't crash with one of the latest commits...
Though, just a disclaimer that SHADERed doesn't officially support macOS (don't have a macOS device so I can't develop and test for it), so I can't help much (I didn't experience these problems on any of my Windows and Linux machines).
Opening examples/Eroded
works, but the same "Segmentation fault: 11" error happens when starting the debugger and adding a Watch, adding something into the Immediate window, or also if trying to focus the Auto window.
I also noticed that I get a "Segmentation fault: 11" error if I:
- start the debugger
- debug the code normally, don't use any Watches, Immediate or Auto windows
- hit Continue and the debugger stops
- when I start the debugger a second time, the IDE crashes immediately
Kind of a tedious process but at least I can use shader debugging.
I do have the latest code cloned (I cloned and built everything from scratch today).
$ git show-ref HEAD
d118369cbc5f18db3596e318c92557760ef0b466 refs/remotes/origin/HEAD
I will include here part from the stack trace of the crash report, maybe it is useful. The complete crash report can be found here: https://gist.github.com/clns/dd47d302c91af6584038cdea9996adfc. I know SHADERed is not officially supported on macOS, that's why I posted this here, maybe it will be useful to other people trying to use it on a mac.
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_platform.dylib 0x00007fff20394552 _platform_strlen + 18
1 SHADERed 0x0000000102dc2e65 std::__1::char_traits<char>::length(char const*) + 21
2 SHADERed 0x0000000102e9e8b6 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string<std::nullptr_t>(char const*) + 54
3 SHADERed 0x0000000102e8c3dd std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string<std::nullptr_t>(char const*) + 29
4 SHADERed 0x0000000102e8b769 ed::ExpressionCompiler::Compile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 2249
5 SHADERed 0x0000000102ec6f6c ed::DebugInformation::Immediate(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, spvm_result*&) + 732
6 SHADERed 0x0000000103191b82 ed::DebugAutoUI::Update(float) + 226
7 SHADERed 0x0000000102ddc763 ed::GUIManager::Update(float) + 24483
8 SHADERed 0x0000000102dc7240 ed::EditorEngine::Update(float) + 64
9 SHADERed 0x0000000102dbe59b main + 9243
10 libdyld.dylib 0x00007fff2036cf3d start + 1
Thread 1:: SDLTimer
0 libsystem_kernel.dylib 0x00007fff2031ecde __psynch_cvwait + 10
1 libsystem_pthread.dylib 0x00007fff20351e49 _pthread_cond_wait + 1298
2 libSDL2-2.0.0.dylib 0x0000000107e74584 SDL_CondWaitTimeout_REAL + 144
3 libSDL2-2.0.0.dylib 0x0000000107e74202 SDL_SemWaitTimeout_REAL + 78
I would be willing to give it a try and fix this, but I am not sure I will be able to. If you have any pointers based on this crash report, would be appreciated.
More info... it seems that what is causing the "Segmentation fault: 11" crash is the func.getName()
call in ExpressionCompiler.cpp#L78, on the result from calling auto& func : m_module->getFunctions()
from ExpressionCompiler::Compile()
:
// search for local variables first
for (auto& func : m_module->getFunctions()) {
spvgentwo::BasicBlock& bb = *func;
if (curFunction == std::string(func.getName())) {
const spvgentwo::List<spvgentwo::Instruction>& params = func.getParameters();
// first local variables
for (auto& inst : bb) {
const char* iName = inst.getName();
if (iName != nullptr && m_vars.count(iName) && m_vars[iName] == nullptr)
m_vars[iName] = &inst;
}
// then parameters
for (auto& param : params) {
const char* iName = param.getName();
if (iName != nullptr && m_vars.count(iName) && m_vars[iName] == nullptr)
m_vars[iName] = ¶m;
}
}
}
Also, the Compile() function is called with the arguments expr
= outColor
and curFunction
= main
- while running the starter project GLSL:
ExpressionCompiler::Compile("outColor", "main");
I don't know how to proceed forward. If you have any suggestions please feel free to let me know. Thanks!
So inside ExpressionCompiler::SetSPIRV()
, right after the addFunction()
call, if I do the same loop over the getFunctions()
list, and inside the loop I call func.getName()
, I get the Segmentation fault error. Looks like the function that was just added is an invalid pointer when you loop over the list. Not sure why is this happening.
void ExpressionCompiler::SetSPIRV(const std::vector<unsigned int>& spv)
{
BinaryVectorReader reader(spv);
m_module->reset();
m_module->read(reader, *m_grammar);
m_module->resolveIDs();
m_module->reconstructTypeAndConstantInfo();
m_module->reconstructNames();
m_func = &m_module->addFunction("$$_shadered_immediate", spvgentwo::spv::FunctionControlMask::Const);
for (auto& func : m_module->getFunctions()) {
Logger::Get().Log("=== func.getName(): " + std::string(func.getName())); // <- Segmentation fault
}
}
The problem is when doing std::string(func.getName())
, since func.getName()
apparently returns a nullptr
.
I have opened an issue here: https://github.com/rAzoR8/SpvGenTwo/issues/40