v icon indicating copy to clipboard operation
v copied to clipboard

sokol: shader v compiler error

Open JoeyShapiro opened this issue 1 year ago • 3 comments

Describe the bug

I was told to report this by the compiler:

C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,

Reproduction Steps

go to v/examples/sokol/07_simple_shader_glsl open simple_shader.v and go to line 132 change one of these lines, renaming the C value.

// something like this
pipeline_desc.layout.attrs[C.ATTR_vs_position].format = .float3
// to something like this
pipeline_desc.layout.attrs[C.ATTR_vs_aposition].format = .float3

compile the code. you should get the following error. (v run .)

Expected Behavior

compiled code

Current Behavior

==================
                                                            ~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v_501/simple_shader.01HX381VZ0CFX7SD21X4M8RFT9.tmp.c:21250:43: error: use of undeclared identifier 'ATTR_vs_aposition'
        pipeline_desc.layout.attrs[v_fixed_index(ATTR_vs_aposition, 16)].format = sokol__gfx__VertexFormat__float3;
                                                 ^
/tmp/v_501/simple_shader.01HX381VZ0CFX7SD21X4M8RFT9.tmp.c:21251:73: warning: implicit conversion from enumeration type 'sokol__gfx__VertexFormat' to different enumeration type 'sg_vertex_format' (aka 'enum sg_vertex_format') [-Wenum-conversion]
        pipeline_desc.layout.attrs[v_fixed_index(ATTR_vs_color0, 16)].format = sokol__gfx__VertexFormat__float4;
                                                                             ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 warnings and 1 error generated.
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

Possible Solution

it appears to be caused by the variable being misnamed.

Additional Information/Context

No response

V version

V 0.4.5 206c0e3

Environment details (OS name and version, etc.)

V full version: V 0.4.5 206c0e3
OS: macos, macOS, 14.4, 23E214
Processor: 14 cpus, 64bit, little endian, Apple M3 Max

getwd: /Users/oniichan/Downloads/v/examples/sokol/07_simple_shader_glsl
vexe: /Users/oniichan/Downloads/v/v
vexe mtime: 2024-04-26 00:31:07

vroot: OK, value: /Users/oniichan/Downloads/v
VMODULES: OK, value: /Users/oniichan/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.3 (Apple Git-146)
Git vroot status: Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present: false

CC version: Apple clang version 15.0.0 (clang-1500.3.9.4)
thirdparty/tcc status: thirdparty-macos-arm64 5c1d002f

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

JoeyShapiro avatar May 05 '24 02:05 JoeyShapiro

If you change one of the names there, you have to also change the corresponding name in simple_shader.glsl: in vec4 aposition;

spytheman avatar May 05 '24 14:05 spytheman

yeah, its a pretty simple fix, and didn't take long to notice. but the compiler said I should report it as a bug. granted this isn't pure v code. I just thought I should report it.

JoeyShapiro avatar May 05 '24 14:05 JoeyShapiro

Yes. Thank you for reporting it.

We should think of a way to handle those better (since V can know about the shader variables from its v shader tool, it should be able to offer more useful errors for that specific situation).

spytheman avatar May 05 '24 16:05 spytheman