#Can't get size of Vertex shader and Fragment shader

45 messages · Page 1 of 1 (latest)

slate plank
#

(C code) I have some vertex and fragment shader codes(that i got with glslc compiler from google using -mfmt=c tag) that i put into a uint32_t variables like this:

uint32_t VertexCode[] = {
...
};
uint32_t FragmentCode[] = {
...
};

and i want to pass these arguments to a function that creates shader modules:

void CreateShaderModules(Program *ProgramState, uint32_t VertexCode[], uint32_t FragmentCode[]) {
    size_t VertexCodeSize = sizeof(VertexCode) / sizeof(VertexCode[0]);
    VkResult VertexResult = vkCreateShaderModule(
        ProgramState->initialize.Device,
        &(VkShaderModuleCreateInfo)
        {
            .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
            .codeSize = VertexCodeSize,
            .pCode = VertexCode,
        },
        ProgramState->Allocator,
        &ProgramState->graphics.VertexModule
    );

     size_t FragmentCodeSize = sizeof(FragmentCode) / sizeof(FragmentCode[0]);
    VkResult FragmentResult = vkCreateShaderModule(
        ProgramState->initialize.Device,
        &(VkShaderModuleCreateInfo)
        {
            .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
            .codeSize = FragmentCodeSize,
            .pCode = FragmentCode,
        },
        ProgramState->Allocator,
        &ProgramState->graphics.FragmentModule
    );
};

when i try to get size, i get this error:

'sizeo 
' on array function parameter 'FragmentCode' will return size of 'uint32_t *' {aka 'unsigned int *'} [-Wsizeof-array-argument]
   59 |      size_t FragmentCodeSize = sizeof(FragmentCode) / sizeof(FragmentCode[0]);
      | 
``` same for vertex shader
flint inlet
#

Yeah sizeof will return the size of a uint32_t* here

#

(so 64 bits)

#

Because you are sending it as a parameter

#

You can try to send the size as a parameter too

#

(so doing sizeof(VertexCode) where you declare VertexCode, and sending this value to the function)

slate plank
#

oh, okey, let me try

#

but how should i better like call the function, i use CreateShaderModule(ProgramState, ShaderVert, will initialize size here, ShaderFrag, same with fragment); ?

#

also, tried and got this

  • Executing task: C:\Users\Nazar\Documents\Programming\Trying something new\Vulkan Game Engine\Dev-Windows/start.bat

C:\Users\Nazar\Documents\Programming\Trying something new\Vulkan Game Engine\Dev-Windows>chcp 65001 && gcc -Wall "Engine/Engine.c" -I"Engine" -I "Libraries/GLFW/include" -I "Libraries/Vulkan/Include" -I "Libraries/CGLM" -L"Libraries/GLFW/lib-mingw-w64" -L"Libraries/Vulkan/Lib" -lvulkan-1 -lglfw3 -lgdi32 -o Compiled/HEAT.exe && "Compiled\HEAT.exe"
Active code page: 65001

  • The terminal process "C:\Users\Nazar\Documents\Programming\Trying something new\Vulkan Game Engine\Dev-Windows\start.bat" terminated with exit code: -1073741571.
  • Terminal will be reused by tasks, press any key to close it.
ocean wigeon
slate plank
#

also, i checked that even if i don't make modules it still crashes with the same error

#

so maybe the problem isn't even with modules...

#

brih

#

i can give you my main files that initialize it all

#

so you can check if the error is even in the function

ocean wigeon
#

use the debugger and it will tell you

#

btw you are getting STATUS_STACK_OVERFLOW

slate plank
#

yes, i think that is because of dynamic stats:
i intilialize it in my Program struct:

#

VkDynamicState Dynamics[VK_DYNAMIC_STATE_MAX_ENUM];

ocean wigeon
#

why are you doing that

slate plank
#

Sorry, electricity went off, i'll write my initialization by hand

ocean wigeon
#

fyi MAX_ENUM is 2147483647

slate plank
#
Program program = {
.window = {
.Title = "Vulkan engine",
.Width = 1280, 
.Height = 720,
},
.graphics.Dynamic = {
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR,
},
.ApiVersion = VK_API_VERSION_1_3,
}
ocean wigeon
#

why is dynamic states part of program

#

dynamic states is static as it requires you to program specifically to handle it

slate plank
#

I wanted it to be configurable from any other user and not getting right into code, seaking for it

ocean wigeon
#

just change it to be a static const array inside the function you use to create the pipeline

#

if you are making this as a lib, there is still no reason to put it in program, dynamic states is per pipeline so just make it a struct with a pointer and count that they pass to create pipeline

slate plank
#

I have everything in program struct, allocator, swapchain, window, vulkan things like device and instance

#

And also graphics pipeline

ocean wigeon
#

those make sense to be in program

#

dynamic states and pipeline does not

slate plank
#

Okey, so what should i do with it?

ocean wigeon
#

as I've said, make a create pipeline function

slate plank
#

I do have

#

Also pipelinelayout and shadermodules

ocean wigeon
#

then change it to take a create info rather than reading from program

slate plank
#

Okey, thanks you

#

How to close a forum?

#

Because my problem with size also solved

ocean wigeon
#

idk try clicking the 3 dots

slate plank
#

and then i give it parameters(with other program parameters):

Program program = {
        .window = {
            .Title = "Vulkan Engine",
            .Width = 1280,
            .Height = 720,
            .swapchain = {
                .Buffering = 2,
            }
        },
        .graphics.Dynamics = {
            VK_DYNAMIC_STATE_VIEWPORT,
            VK_DYNAMIC_STATE_SCISSOR,
        },
        .ApiVersion = VK_API_VERSION_1_3
    };

slate plank
ocean wigeon
#

either is fine