I am trying to create a pointer to an array of of two (2) VkClearValues using Java's Project Panama (JEP 434, JDK 20). One clear value is for the color attachment, one is for the depth buffer.
My attempt at that is the following:
var pClearValue = VkClearValue.allocate(arena);
VkClearValue.color$slice(pClearValue).setAtIndex(C_FLOAT, 0, 0.0f);
VkClearValue.color$slice(pClearValue).setAtIndex(C_FLOAT, 1, 1.0f);
VkClearValue.color$slice(pClearValue).setAtIndex(C_FLOAT, 2, 0.0f);
VkClearValue.color$slice(pClearValue).setAtIndex(C_FLOAT, 3, 0.0f);
var pDepthClearValue = VkClearValue.allocate(arena);
VkClearDepthStencilValue.depth$set(VkClearValue.depthStencil$slice(pDepthClearValue), 1f);
VkClearDepthStencilValue.stencil$set(VkClearValue.depthStencil$slice(pDepthClearValue), 0);
var pClearValues = arena.allocateArray(VkClearValue.$LAYOUT(), 2);
pClearValues.setAtIndex(C_POINTER, 0, pClearValue.get(C_POINTER, 0));
pClearValues.setAtIndex(C_POINTER, 1, pDepthClearValue.get(C_POINTER, 0));
VkRenderPassBeginInfo.pClearValues$set(pRenderPassBeginInfo, 0, pClearValues);
Using Renderdoc I see garbage clear values being sent to Vulkan.
If I just try and pass in the one color clear value:
VkRenderPassBeginInfo.pClearValues$set(pRenderPassBeginInfo, 0, pClearValue);
The data is sent correctly (but with no depth clear value (only color)).
I have tried many permutations to try and set up this Pointer array, but I can never succeed in sending two valid depth adjustments.
Thanks!
You are off by a level of indirection. The
VkRenderPassBeginInfo
struct has the fieldconst VkClearValue* pClearValues
, which is an array of structs. But, you seem to be trying to pass an array of pointers to it.Furthermore, you are reading a pointer from both
pClearValue
andpDepthClearValue
, which is incorrect since the struct doesn't contain pointers.It works when passing just a single pointer to a
VkClearValue
, since that can also act as a pointer to an array of a single struct.If you want to initialize the array correctly, you need to either copy your pre-allocated structs into the array:
Or allocate the array upfront and initialize it's contents directly (this is what I would recommend):