suppose I have some code in a library where I can’t modify when I link it later on.
in the library, There’s an image with undefined data, uninitialized, and without any “copy raw pixels from a staging buffer to image”. so data in the image is basically junk.
but I still want it to be runnable. in the shader there’s a sampler 2D referencing this image. so the descriptor need this image in its proper form.
it seems I need to first enforce the layout for this empty image(the junk image).
//(not yet tested, draft code)
transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
or maybe cheat a bit by telling the driver all the junk are preinitialized data?
transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_PREINITIALIZED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
That’s my question,I’m not sure if this will work, can i have something like this? and later on (after linking the library) I modify the data in the image, then the sampler2D will have correct image data.
in the library, all i want is a placeholder image for this sampler2D to work (bare minimum, bootstrap code), and then I can initialize it later in my application. by using a staging buffer and do a transition
// copied code from vulkan tutorial, 1st line is modified , old layout is no longer layout_undefined, but SHADER_READ_ONLY_OPTIMAL transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); copyBufferToImage(stagingBuffer, textureImage, static_cast<uint32_t>(texWidth), static_cast<uint32_t>(texHeight)); transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
is this ok to think way? or should I always initialize it from the very begining?