Open aleiby opened 2 years ago
I have not gone through all of these to verify correctness, so I was wondering if you originally just did this by hand and maybe these got missed, or if something else is going on.
Yes, I did this by hand.
Table is here: https://github.com/bkaradzic/bgfx/blob/a2ad0667397d82b921907870de45ca47d3e2526d/src/shader_dxbc.cpp#L116
If you have test, you could fix this and send PR.
I meet a problem with direct11 which may related with the problem @aleiby have found.
OS: Windows11 x64
Driver: Direct11
GPU: AMD RX 6600XT
bgfx: 36be8a72cc87e72bc640947e18f81c5d8635ce25
bx: bd53db48618e602dbe241fbeadf207bd262dc7be
bimg: 663f724186e26caf46494e389ed82409106205fb
using CMake
Use shaderc.exe to compile the shader
varying.def.sc
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
vec3 a_position : POSITION; vec4 a_color0 : COLOR0;
- v_simple.sc
$input a_position, a_color0 $output v_color0
void main() { gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); v_color0 = a_color0; }
- f_simple.sc
$input v_color0
void main() { gl_FragColor = v_color0; }
- LoadShader
```cpp
bgfx::ShaderHandle loadShader(const char* _name) {
char* data = new char[2048];
std::ifstream file;
size_t fileSize = 0;
if (!std::filesystem::exists(_name)) {
std::filesystem::path cwd = std::filesystem::current_path();
std::cout << "Current dir is: " << cwd << ". Cannot find file: " << _name << std::endl;
return bgfx::ShaderHandle{ bgfx::kInvalidHandle };
}
file.open(_name);
if(file.is_open()) {
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(0, std::ios::beg);
file.read(data, fileSize);
file.close();
}
const bgfx::Memory* mem = bgfx::copy(data, fileSize+1);
mem->data[mem->size - 1] = '\0';
bgfx::ShaderHandle handle = bgfx::createShader(mem);
bgfx::setName(handle, _name);
return handle;
}
@REM DirectX
..\..\.Build\bgfx.cmake\Debug\shaderc.exe -f v_simple.sc -o v_simple.bin --stdout --varyingdef varying.def.sc --platform windows -p vs_5_0 --type vertex --verbose -i ..\..\3rdparty\bgfx.cmake\bgfx\src
..\..\.Build\bgfx.cmake\Debug\shaderc.exe -f f_simple.sc -o f_simple.bin --stdout --varyingdef varying.def.sc --platform windows -p ps_5_0 --type fragment --verbose -i ..\..\3rdparty\bgfx.cmake\bgfx\src
As the debugger shows: instruction.length = 8, but read size is 28. read size/4 =7, not equals to instruction.length. I have no idea about this error. Would you have some time to check this?
@REM OpenGL
..\..\.Build\bgfx.cmake\Debug\shaderc.exe -f v_simple.sc -o v_simple.bin --varyingdef varying.def.sc --platform windows --type vertex --verbose -i ..\..\3rdparty\bgfx.cmake\bgfx\src
..\..\.Build\bgfx.cmake\Debug\shaderc.exe -f f_simple.sc -o f_simple.bin --varyingdef varying.def.sc --platform windows --type fragment --verbose -i ..\..\3rdparty\bgfx.cmake\bgfx\src
@zeroxer You should read shader .bin files as binary, they're not text files:
file.open(_name, std::ifstream::in|std::ifstream::binary)
Thanks. It works now.
Testing bgfx's dxbc parsing I ran into an issue which appears to be due to incorrect
DxbcOpcodeInfo
entries. How were these generated?Specifically,
DCL_INPUT_SIV
which hasnumOperands=1
, butnumValues=0
.Digging into d3d11TokenizedProgramFormat.hpp:
It looks like
numValues
should be 1. This would also match the existing entry forDCL_INPUT_SGV
.I was getting
instruction.length=5
but thenread
was only parsing 4 DWORDs.Similarly, it looks like
DCL_OUTPUT_SGV
also needsnumValues=1
. The other DCL INPUT/OUTPUT entries look good.I have not gone through all of these to verify correctness, so I was wondering if you originally just did this by hand and maybe these got missed, or if something else is going on.