mirror of
https://github.com/Yours3lf/rpi-vk-driver.git
synced 2024-11-29 11:24:14 +01:00
now the multipass texturing example works!
This commit is contained in:
parent
1e5a5c965a
commit
d0ce9e79a5
@ -18,7 +18,7 @@ uint32_t clHasEnoughSpace(ControlList* cl, uint32_t size)
|
||||
assert(cl);
|
||||
assert(cl->buffer);
|
||||
assert(cl->nextFreeByte);
|
||||
uint32_t currSize = cl->nextFreeByte - cl->buffer;;
|
||||
uint32_t currSize = cl->nextFreeByte - cl->buffer;
|
||||
if(currSize + size < CONTROL_LIST_SIZE)
|
||||
{
|
||||
return 1; //fits!
|
||||
@ -39,7 +39,7 @@ void clInit(ControlList* cl, void* buffer)
|
||||
cl->currMarker = 0;
|
||||
}
|
||||
|
||||
void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, ControlList* uniformsCL, void* imagePtr)
|
||||
void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL, void* imagePtr)
|
||||
{
|
||||
//to be inserted when you'd insert tile binning mode config
|
||||
assert(cl);
|
||||
@ -52,19 +52,53 @@ void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* s
|
||||
marker.nextMarker = 0;
|
||||
marker.size = 0;
|
||||
marker.image = imagePtr;
|
||||
marker.handles = cl->currMarker ? cl->currMarker->handles + cl->currMarker->handlesSize : handlesCL;
|
||||
marker.handlesSize = 0;
|
||||
marker.shaderRec = cl->currMarker ? cl->currMarker->shaderRec + cl->currMarker->shaderRecSize : shaderRecCL;
|
||||
marker.shaderRecSize = 0;
|
||||
marker.shaderRecCount = 0;
|
||||
marker.uniforms = cl->currMarker ? cl->currMarker->uniforms + cl->currMarker->uniformsSize : uniformsCL;
|
||||
marker.uniformsSize = 0;
|
||||
marker.shaderRecCount = 0;
|
||||
marker.flags = 0;
|
||||
marker.handlesBuf = handlesCL->buffer;
|
||||
marker.shaderRecBuf = shaderRecCL->buffer;
|
||||
marker.uniformsBuf = uniformsCL->buffer;
|
||||
|
||||
//close current marker
|
||||
if(cl->currMarker && !cl->currMarker->size)
|
||||
{
|
||||
clCloseCurrentMarker(cl, handlesCL, shaderRecCL, shaderRecCount, uniformsCL);
|
||||
}
|
||||
|
||||
//if this is not the first marker
|
||||
if(cl->currMarker)
|
||||
{
|
||||
marker.handlesBuf = cl->currMarker->handlesBuf + cl->currMarker->handlesSize;
|
||||
marker.shaderRecBuf = cl->currMarker->shaderRecBuf + cl->currMarker->shaderRecSize;
|
||||
marker.uniformsBuf = cl->currMarker->uniformsBuf + cl->currMarker->uniformsSize;
|
||||
marker.shaderRecCount = cl->currMarker->shaderRecCount; //initialize with previous marker's data
|
||||
}
|
||||
|
||||
*(CLMarker*)cl->nextFreeByte = marker;
|
||||
if(cl->currMarker)
|
||||
{
|
||||
cl->currMarker->nextMarker = cl->nextFreeByte;
|
||||
}
|
||||
cl->currMarker = cl->nextFreeByte;
|
||||
cl->nextFreeByte += sizeof(CLMarker);
|
||||
}
|
||||
|
||||
void clCloseCurrentMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL)
|
||||
{
|
||||
assert(cl);
|
||||
assert(handlesCL);
|
||||
assert(shaderRecCL);
|
||||
assert(uniformsCL);
|
||||
assert(cl->currMarker);
|
||||
cl->currMarker->size = cl->nextFreeByte - ((uint8_t*)cl->currMarker + sizeof(CLMarker));
|
||||
cl->currMarker->handlesSize = handlesCL->nextFreeByte - cl->currMarker->handlesBuf;
|
||||
cl->currMarker->shaderRecSize = shaderRecCL->nextFreeByte - cl->currMarker->shaderRecBuf;
|
||||
cl->currMarker->uniformsSize = uniformsCL->nextFreeByte - cl->currMarker->uniformsBuf;
|
||||
cl->currMarker->shaderRecCount = shaderRecCount - cl->currMarker->shaderRecCount; //update shader rec count to reflect added shader recs
|
||||
}
|
||||
|
||||
void clInsertData(ControlList* cl, uint32_t size, uint8_t* data)
|
||||
{
|
||||
assert(cl);
|
||||
@ -667,6 +701,7 @@ void clInsertGEMRelocations(ControlList* cl,
|
||||
void clInsertShaderRecord(ControlList* cls,
|
||||
ControlList* relocCl,
|
||||
ControlList* handlesCl,
|
||||
uint8_t* handlesBuf, uint32_t handlesSize,
|
||||
uint32_t fragmentShaderIsSingleThreaded, //0/1
|
||||
uint32_t pointSizeIncludedInShadedVertexData, //0/1
|
||||
uint32_t enableClipping, //0/1
|
||||
@ -696,14 +731,14 @@ void clInsertShaderRecord(ControlList* cls,
|
||||
*cls->nextFreeByte = 0; cls->nextFreeByte++;
|
||||
*(uint16_t*)cls->nextFreeByte = moveBits(fragmentNumberOfUnusedUniforms, 16, 0); cls->nextFreeByte++;
|
||||
*cls->nextFreeByte |= fragmentNumberOfVaryings; cls->nextFreeByte++;
|
||||
clEmitShaderRelocation(relocCl, handlesCl, &fragmentCodeAddress);
|
||||
clEmitShaderRelocation(relocCl, handlesCl, handlesBuf, handlesSize, &fragmentCodeAddress);
|
||||
*(uint32_t*)cls->nextFreeByte = fragmentCodeAddress.offset; cls->nextFreeByte += 4;
|
||||
*(uint32_t*)cls->nextFreeByte = fragmentUniformsAddress; cls->nextFreeByte += 4;
|
||||
|
||||
*(uint16_t*)cls->nextFreeByte = moveBits(vertexNumberOfUnusedUniforms, 16, 0); cls->nextFreeByte += 2;
|
||||
*cls->nextFreeByte = vertexAttributeArraySelectBits; cls->nextFreeByte++;
|
||||
*cls->nextFreeByte = vertexTotalAttributesSize; cls->nextFreeByte++;
|
||||
clEmitShaderRelocation(relocCl, handlesCl, &vertexCodeAddress);
|
||||
clEmitShaderRelocation(relocCl, handlesCl, handlesBuf, handlesSize, &vertexCodeAddress);
|
||||
//TODO wtf???
|
||||
uint32_t offset = moveBits(vertexCodeAddress.offset, 32, 0) | moveBits(vertexUniformsAddress, 32, 0);
|
||||
*(uint32_t*)cls->nextFreeByte = offset; cls->nextFreeByte += 4;
|
||||
@ -712,7 +747,7 @@ void clInsertShaderRecord(ControlList* cls,
|
||||
*(uint16_t*)cls->nextFreeByte = moveBits(coordinateNumberOfUnusedUniforms, 16, 0); cls->nextFreeByte += 2;
|
||||
*cls->nextFreeByte = coordinateAttributeArraySelectBits; cls->nextFreeByte++;
|
||||
*cls->nextFreeByte = coordinateTotalAttributesSize; cls->nextFreeByte++;
|
||||
clEmitShaderRelocation(relocCl, handlesCl, &coordinateCodeAddress);
|
||||
clEmitShaderRelocation(relocCl, handlesCl, handlesBuf, handlesSize, &coordinateCodeAddress);
|
||||
*(uint32_t*)cls->nextFreeByte = coordinateCodeAddress.offset; cls->nextFreeByte += 4;
|
||||
*(uint32_t*)cls->nextFreeByte = coordinateUniformsAddress; cls->nextFreeByte += 4;
|
||||
}
|
||||
@ -721,6 +756,7 @@ void clInsertShaderRecord(ControlList* cls,
|
||||
void clInsertAttributeRecord(ControlList* cls,
|
||||
ControlList* relocCl,
|
||||
ControlList* handlesCl,
|
||||
uint8_t* handlesBuf, uint32_t handlesSize,
|
||||
ControlListAddress address,
|
||||
uint32_t sizeBytes,
|
||||
uint32_t stride,
|
||||
@ -732,7 +768,7 @@ void clInsertAttributeRecord(ControlList* cls,
|
||||
assert(cls->nextFreeByte);
|
||||
uint32_t sizeBytesMinusOne = sizeBytes - 1;
|
||||
//TODO is this correct?
|
||||
clEmitShaderRelocation(relocCl, handlesCl, &address);
|
||||
clEmitShaderRelocation(relocCl, handlesCl, handlesBuf, handlesSize, &address);
|
||||
*(uint32_t*)cls->nextFreeByte = address.offset; cls->nextFreeByte += 4;
|
||||
*cls->nextFreeByte = sizeBytesMinusOne; cls->nextFreeByte++;
|
||||
*cls->nextFreeByte = stride; cls->nextFreeByte++;
|
||||
@ -740,15 +776,16 @@ void clInsertAttributeRecord(ControlList* cls,
|
||||
*cls->nextFreeByte = coordinateVPMOffset; cls->nextFreeByte++;
|
||||
}
|
||||
|
||||
uint32_t clGetHandleIndex(ControlList* handlesCl, uint32_t handle)
|
||||
uint32_t clGetHandleIndex(ControlList* handlesCl, uint8_t* handlesBuf, uint32_t handlesSize, uint32_t handle)
|
||||
{
|
||||
uint32_t c = 0;
|
||||
|
||||
uint32_t numHandles = clSize(handlesCl) / 4;
|
||||
//if curr marker is closed already we need to work with the stored size
|
||||
uint32_t numHandles = (handlesSize ? handlesSize : (handlesCl->nextFreeByte - handlesBuf)) / 4;
|
||||
|
||||
for(; c < numHandles; ++c)
|
||||
{
|
||||
if(((uint32_t*)handlesCl->buffer)[c] == handle)
|
||||
if(((uint32_t*)handlesBuf)[c] == handle)
|
||||
{
|
||||
//found
|
||||
return c;
|
||||
@ -763,7 +800,7 @@ uint32_t clGetHandleIndex(ControlList* handlesCl, uint32_t handle)
|
||||
}
|
||||
|
||||
//input: 2 cls (cl + handles cl)
|
||||
inline void clEmitShaderRelocation(ControlList* relocCl, ControlList* handlesCl, const ControlListAddress* address)
|
||||
inline void clEmitShaderRelocation(ControlList* relocCl, ControlList* handlesCl, uint8_t* handlesBuf, uint32_t handlesSize, const ControlListAddress* address)
|
||||
{
|
||||
assert(relocCl);
|
||||
assert(relocCl->buffer);
|
||||
@ -775,7 +812,7 @@ inline void clEmitShaderRelocation(ControlList* relocCl, ControlList* handlesCl,
|
||||
assert(address->handle);
|
||||
|
||||
//store offset within handles in cl
|
||||
*(uint32_t*)relocCl->nextFreeByte = clGetHandleIndex(handlesCl, address->handle);
|
||||
*(uint32_t*)relocCl->nextFreeByte = clGetHandleIndex(handlesCl, handlesBuf, handlesSize, address->handle);
|
||||
relocCl->nextFreeByte += 4;
|
||||
}
|
||||
|
||||
|
@ -14,17 +14,21 @@ typedef struct ControlListAddress
|
||||
|
||||
typedef struct CLMarker
|
||||
{
|
||||
//current binning cl buf position is this struct in the CL plus sizeof(this struct)
|
||||
struct CLMarker* nextMarker;
|
||||
uint32_t size; //in bytes
|
||||
void* image; //_image* to render to
|
||||
uint8_t* handles;
|
||||
uint32_t flags; //used to store clear flag etc.
|
||||
|
||||
//pointers that point to where all the other CL data is
|
||||
//plus sizes
|
||||
uint8_t* handlesBuf;
|
||||
uint32_t handlesSize;
|
||||
uint8_t* shaderRec;
|
||||
uint8_t* shaderRecBuf;
|
||||
uint32_t shaderRecSize;
|
||||
uint32_t shaderRecCount;
|
||||
uint8_t* uniforms;
|
||||
uint8_t* uniformsBuf;
|
||||
uint32_t uniformsSize;
|
||||
uint32_t flags; //used to store clear flag etc.
|
||||
} CLMarker;
|
||||
|
||||
#define CONTROL_LIST_SIZE 4096
|
||||
@ -37,7 +41,7 @@ typedef struct ControlList
|
||||
CLMarker* currMarker;
|
||||
} ControlList;
|
||||
|
||||
void clEmitShaderRelocation(ControlList* relocCl, ControlList* handlesCl, const ControlListAddress* address);
|
||||
void clEmitShaderRelocation(ControlList* relocCl, ControlList* handlesCl, uint8_t* handlesBuf, uint32_t handlesSize, const ControlListAddress* address);
|
||||
void clDummyRelocation(ControlList* relocCl, const ControlListAddress* address);
|
||||
|
||||
#define __gen_user_data struct ControlList
|
||||
@ -53,7 +57,8 @@ uint32_t divRoundUp(uint32_t n, uint32_t d);
|
||||
uint32_t moveBits(uint32_t d, uint32_t bits, uint32_t offset);
|
||||
uint32_t clHasEnoughSpace(ControlList* cl, uint32_t size);
|
||||
void clInit(ControlList* cl, void* buffer);
|
||||
void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, ControlList* uniformsCL, void* imagePtr);
|
||||
void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL, void* imagePtr);
|
||||
void clCloseCurrentMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL);
|
||||
void clInsertData(ControlList* cl, uint32_t size, uint8_t* data);
|
||||
void clInsertUniformConstant(ControlList* cl, uint32_t data);
|
||||
void clInsertUniformXYScale(ControlList* cl, float data);
|
||||
@ -152,6 +157,7 @@ void clInsertGEMRelocations(ControlList* cl,
|
||||
void clInsertShaderRecord(ControlList* cls,
|
||||
ControlList* relocCl,
|
||||
ControlList* handlesCl,
|
||||
uint8_t* handlesBuf, uint32_t handlesSize,
|
||||
uint32_t fragmentShaderIsSingleThreaded, //0/1
|
||||
uint32_t pointSizeIncludedInShadedVertexData, //0/1
|
||||
uint32_t enableClipping, //0/1
|
||||
@ -172,12 +178,13 @@ void clInsertShaderRecord(ControlList* cls,
|
||||
void clInsertAttributeRecord(ControlList* cls,
|
||||
ControlList* relocCl,
|
||||
ControlList* handlesCl,
|
||||
uint8_t* handlesBuf, uint32_t handlesSize,
|
||||
ControlListAddress address,
|
||||
uint32_t sizeBytes,
|
||||
uint32_t stride,
|
||||
uint32_t vertexVPMOffset,
|
||||
uint32_t coordinateVPMOffset);
|
||||
uint32_t clGetHandleIndex(ControlList* handlesCl, uint32_t handle);
|
||||
uint32_t clGetHandleIndex(ControlList* handlesCl, uint8_t* handlesBuf, uint32_t handlesSize, uint32_t handle);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
@ -212,21 +212,8 @@ VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(
|
||||
|
||||
//When a command buffer begins recording, all state in that command buffer is undefined
|
||||
|
||||
struct drm_vc4_submit_cl submitCl =
|
||||
{
|
||||
.color_read.hindex = ~0,
|
||||
.zs_read.hindex = ~0,
|
||||
.color_write.hindex = ~0,
|
||||
.msaa_color_write.hindex = ~0,
|
||||
.zs_write.hindex = ~0,
|
||||
.msaa_zs_write.hindex = ~0,
|
||||
};
|
||||
|
||||
commandBuffer->usageFlags = pBeginInfo->flags;
|
||||
commandBuffer->shaderRecCount = 0;
|
||||
commandBuffer->state = CMDBUF_STATE_RECORDING;
|
||||
commandBuffer->submitCl = submitCl;
|
||||
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@ -242,16 +229,6 @@ VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(
|
||||
{
|
||||
assert(commandBuffer);
|
||||
|
||||
//Increment the semaphore indicating that binning is done and
|
||||
//unblocking the render thread. Note that this doesn't act
|
||||
//until the FLUSH completes.
|
||||
//The FLUSH caps all of our bin lists with a
|
||||
//VC4_PACKET_RETURN.
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_INCREMENT_SEMAPHORE_length);
|
||||
clInsertIncrementSemaphore(&commandBuffer->binCl);
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLUSH_length);
|
||||
clInsertFlush(&commandBuffer->binCl);
|
||||
|
||||
commandBuffer->state = CMDBUF_STATE_EXECUTABLE;
|
||||
|
||||
return VK_SUCCESS;
|
||||
@ -305,7 +282,11 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(
|
||||
//first entry is assumed to be a marker
|
||||
CLMarker* marker = cmdbuf->binCl.buffer;
|
||||
|
||||
//submit each separate job
|
||||
//a command buffer may contain multiple render passes
|
||||
//and commands outside render passes such as clear commands
|
||||
//each of these corresponds to a control list submit
|
||||
|
||||
//submit each separate control list
|
||||
while(marker)
|
||||
{
|
||||
struct drm_vc4_submit_cl submitCl =
|
||||
@ -318,12 +299,10 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(
|
||||
.msaa_zs_write.hindex = ~0,
|
||||
};
|
||||
|
||||
ControlList* handles = marker->handles;
|
||||
_image* i = marker->image;
|
||||
|
||||
//Insert image handle index
|
||||
clFit(cmdbuf, handles, 4);
|
||||
uint32_t imageIdx = clGetHandleIndex(handles, i->boundMem->bo);
|
||||
//This should not result in an insertion!
|
||||
uint32_t imageIdx = clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBuf, marker->handlesSize, i->boundMem->bo);
|
||||
|
||||
//fill out submit cl fields
|
||||
submitCl.color_write.hindex = imageIdx;
|
||||
@ -360,18 +339,26 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(
|
||||
submitCl.max_y_tile = heightInTiles - 1;
|
||||
submitCl.width = i->width;
|
||||
submitCl.height = i->height;
|
||||
submitCl.flags |= marker->flags;//VC4_SUBMIT_CL_USE_CLEAR_COLOR;
|
||||
submitCl.flags |= marker->flags;
|
||||
submitCl.clear_z = 0; //TODO
|
||||
submitCl.clear_s = 0;
|
||||
|
||||
submitCl.bo_handles = marker->handles;
|
||||
submitCl.bo_handle_count = marker->handlesSize / 4;
|
||||
submitCl.bo_handles = marker->handlesBuf;
|
||||
submitCl.bin_cl = ((uint8_t*)marker) + sizeof(CLMarker);
|
||||
submitCl.shader_rec = marker->shaderRecBuf;
|
||||
submitCl.uniforms = marker->uniformsBuf;
|
||||
|
||||
//marker not closed yet
|
||||
//close here
|
||||
if(!marker->size)
|
||||
{
|
||||
clCloseCurrentMarker(&cmdbuf->binCl, &cmdbuf->handlesCl, &cmdbuf->shaderRecCl, cmdbuf->shaderRecCount, &cmdbuf->uniformsCl);
|
||||
}
|
||||
|
||||
submitCl.bo_handle_count = marker->handlesSize / 4;
|
||||
submitCl.bin_cl_size = marker->size;
|
||||
submitCl.shader_rec = marker->shaderRec;
|
||||
submitCl.shader_rec_size = marker->shaderRecSize;
|
||||
submitCl.shader_rec_count = marker->shaderRecCount;
|
||||
submitCl.uniforms = marker->uniforms;
|
||||
submitCl.uniforms_size = marker->uniformsSize;
|
||||
|
||||
/**/
|
||||
@ -380,12 +367,12 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(
|
||||
printf("BO handles: ");
|
||||
for(int d = 0; d < marker->handlesSize / 4; ++d)
|
||||
{
|
||||
printf("%u ", *((uint32_t*)(marker->handles)+d));
|
||||
printf("%u ", *((uint32_t*)(marker->handlesBuf)+d));
|
||||
}
|
||||
printf("\nUniforms: ");
|
||||
for(int d = 0; d < marker->uniformsSize / 4; ++d)
|
||||
{
|
||||
printf("%u ", *((uint32_t*)(marker->uniforms)+d));
|
||||
printf("%u ", *((uint32_t*)(marker->uniformsBuf)+d));
|
||||
}
|
||||
printf("\nwidth height: %u, %u\n", submitCl.width, submitCl.height);
|
||||
printf("tile min/max: %u,%u %u,%u\n", submitCl.min_x_tile, submitCl.min_y_tile, submitCl.max_x_tile, submitCl.max_y_tile);
|
||||
|
@ -500,7 +500,7 @@ void clFit(VkCommandBuffer cb, ControlList* cl, uint32_t commandSize)
|
||||
{
|
||||
if(!clHasEnoughSpace(cl, commandSize))
|
||||
{
|
||||
uint32_t currSize = clSize(cl);
|
||||
uint32_t currSize = cl->nextFreeByte - cl->buffer;
|
||||
cl->buffer = consecutivePoolReAllocate(&cb->cp->cpa, cl->buffer, cl->numBlocks); assert(cl->buffer);
|
||||
cl->nextFreeByte = cl->buffer + currSize;
|
||||
}
|
||||
|
@ -401,6 +401,8 @@ VKAPI_ATTR void VKAPI_CALL vkCmdBindDescriptorSets(
|
||||
{
|
||||
setMapElement(&pl->descriptorSetBindingMap, c, pDescriptorSets[c]);
|
||||
}
|
||||
|
||||
cb->descriptorSetDirty = 1;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(
|
||||
|
226
driver/draw.c
226
driver/draw.c
@ -20,28 +20,106 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
//TODO handle multiple attachments etc.
|
||||
_image* i = fb->attachmentViews[rp->subpasses[cb->currentSubpass].pColorAttachments[0].attachment].image;
|
||||
|
||||
//TODO when doing multiple draw calls (well multipass now)
|
||||
//kernel side expects one Tile Binning Mode Config field per submit
|
||||
//sounds like for each renderpass we'll have to submit one submit, one of these config fields
|
||||
//uint32_t vertexBufferDirty;
|
||||
//uint32_t indexBufferDirty;
|
||||
///uint32_t viewportDirty;
|
||||
///uint32_t lineWidthDirty;
|
||||
///uint32_t depthBiasDirty;
|
||||
///uint32_t depthBoundsDirty;
|
||||
//uint32_t graphicsPipelineDirty;
|
||||
//uint32_t computePipelineDirty;
|
||||
//uint32_t subpassDirty;
|
||||
//uint32_t blendConstantsDirty;
|
||||
//uint32_t scissorDirty;
|
||||
//uint32_t stencilCompareMaskDirty;
|
||||
//uint32_t stencilWriteMaskDirty;
|
||||
//uint32_t stencilReferenceDirty;
|
||||
//uint32_t descriptorSetDirty;
|
||||
//uint32_t pushConstantDirty;
|
||||
|
||||
//if(cb->lineWidthDirty)
|
||||
{
|
||||
//Line width
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_LINE_WIDTH_length);
|
||||
clInsertLineWidth(&commandBuffer->binCl, cb->graphicsPipeline->lineWidth);
|
||||
|
||||
cb->lineWidthDirty = 0;
|
||||
}
|
||||
|
||||
//if(cb->viewportDirty)
|
||||
{
|
||||
//Clip Window
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIP_WINDOW_length);
|
||||
clInsertClipWindow(&commandBuffer->binCl,
|
||||
i->width,
|
||||
i->height,
|
||||
0, //bottom pixel coord
|
||||
0); //left pixel coord
|
||||
|
||||
//TODO why flipped???
|
||||
//Clipper XY Scaling
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIPPER_XY_SCALING_length);
|
||||
clInsertClipperXYScaling(&commandBuffer->binCl, (float)(i->width) * 0.5f * 16.0f, -1.0f * (float)(i->height) * 0.5f * 16.0f);
|
||||
|
||||
//Viewport Offset
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_VIEWPORT_OFFSET_length);
|
||||
clInsertViewPortOffset(&commandBuffer->binCl, i->width >> 1, i->height >> 1);
|
||||
|
||||
cb->viewportDirty = 0;
|
||||
}
|
||||
|
||||
//if(cb->depthBiasDirty || cb->depthBoundsDirty)
|
||||
{
|
||||
//Configuration Bits
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CONFIGURATION_BITS_length);
|
||||
clInsertConfigurationBits(&commandBuffer->binCl,
|
||||
1, //TODO earlyz updates enable
|
||||
0, //TODO earlyz enable
|
||||
0, //TODO z updates enable
|
||||
cb->graphicsPipeline->depthTestEnable ? getDepthCompareOp(cb->graphicsPipeline->depthCompareOp) : V3D_COMPARE_FUNC_ALWAYS, //depth compare func
|
||||
0, //coverage read mode
|
||||
0, //coverage pipe select
|
||||
0, //coverage update mode
|
||||
0, //coverage read type
|
||||
0, //rasterizer oversample mode
|
||||
cb->graphicsPipeline->depthBiasEnable, //depth offset enable
|
||||
cb->graphicsPipeline->frontFace == VK_FRONT_FACE_CLOCKWISE, //clockwise
|
||||
!(cb->graphicsPipeline->cullMode & VK_CULL_MODE_BACK_BIT), //enable back facing primitives
|
||||
!(cb->graphicsPipeline->cullMode & VK_CULL_MODE_FRONT_BIT)); //enable front facing primitives
|
||||
|
||||
//TODO Depth Offset
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_DEPTH_OFFSET_length);
|
||||
clInsertDepthOffset(&commandBuffer->binCl, cb->graphicsPipeline->depthBiasConstantFactor, cb->graphicsPipeline->depthBiasSlopeFactor);
|
||||
|
||||
//TODO how is this calculated?
|
||||
//it's Zc to Zs scale and bias
|
||||
//seems to go from -1.0 .. 1.0 to 0.0 .. 1.0
|
||||
//eg. x * 0.5 + 0.5
|
||||
//cb->graphicsPipeline->minDepthBounds;
|
||||
//Clipper Z Scale and Offset
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIPPER_Z_SCALE_AND_OFFSET_length);
|
||||
clInsertClipperZScaleOffset(&commandBuffer->binCl, 0.5f, 0.5f);
|
||||
|
||||
cb->vertexBufferDirty = 0;
|
||||
cb->depthBoundsDirty = 0;
|
||||
}
|
||||
|
||||
//Point size
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_POINT_SIZE_length);
|
||||
clInsertPointSize(&commandBuffer->binCl, 1.0f);
|
||||
|
||||
//TODO?
|
||||
//Flat Shade Flags
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLAT_SHADE_FLAGS_length);
|
||||
clInsertFlatShadeFlags(&commandBuffer->binCl, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//stuff needed to submit a draw call:
|
||||
//Tile Binning Mode Configuration
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length);
|
||||
clInsertTileBinningModeConfiguration(&commandBuffer->binCl,
|
||||
0, //double buffer in non ms mode
|
||||
0, //tile allocation block size
|
||||
0, //tile allocation initial block size
|
||||
0, //auto initialize tile state data array
|
||||
getFormatBpp(i->format) == 64, //64 bit color mode
|
||||
i->samples > 1, //msaa
|
||||
i->width, i->height,
|
||||
0, //tile state data array address
|
||||
0, //tile allocation memory size
|
||||
0); //tile allocation memory address
|
||||
|
||||
//Start Tile Binning
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_START_TILE_BINNING_length);
|
||||
clInsertStartTileBinning(&commandBuffer->binCl);
|
||||
|
||||
//Primitive List Format
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_PRIMITIVE_LIST_FORMAT_length);
|
||||
@ -49,66 +127,6 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
1, //16 bit
|
||||
getTopology(cb->graphicsPipeline->topology)); //tris
|
||||
|
||||
//Clip Window
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIP_WINDOW_length);
|
||||
clInsertClipWindow(&commandBuffer->binCl,
|
||||
i->width,
|
||||
i->height,
|
||||
0, //bottom pixel coord
|
||||
0); //left pixel coord
|
||||
|
||||
//Configuration Bits
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CONFIGURATION_BITS_length);
|
||||
clInsertConfigurationBits(&commandBuffer->binCl,
|
||||
1, //TODO earlyz updates enable
|
||||
0, //TODO earlyz enable
|
||||
0, //TODO z updates enable
|
||||
cb->graphicsPipeline->depthTestEnable ? getDepthCompareOp(cb->graphicsPipeline->depthCompareOp) : V3D_COMPARE_FUNC_ALWAYS, //depth compare func
|
||||
0, //coverage read mode
|
||||
0, //coverage pipe select
|
||||
0, //coverage update mode
|
||||
0, //coverage read type
|
||||
0, //rasterizer oversample mode
|
||||
cb->graphicsPipeline->depthBiasEnable, //depth offset enable
|
||||
cb->graphicsPipeline->frontFace == VK_FRONT_FACE_CLOCKWISE, //clockwise
|
||||
!(cb->graphicsPipeline->cullMode & VK_CULL_MODE_BACK_BIT), //enable back facing primitives
|
||||
!(cb->graphicsPipeline->cullMode & VK_CULL_MODE_FRONT_BIT)); //enable front facing primitives
|
||||
|
||||
//TODO Depth Offset
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_DEPTH_OFFSET_length);
|
||||
clInsertDepthOffset(&commandBuffer->binCl, cb->graphicsPipeline->depthBiasConstantFactor, cb->graphicsPipeline->depthBiasSlopeFactor);
|
||||
|
||||
//Point size
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_POINT_SIZE_length);
|
||||
clInsertPointSize(&commandBuffer->binCl, 1.0f);
|
||||
|
||||
//Line width
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_LINE_WIDTH_length);
|
||||
clInsertLineWidth(&commandBuffer->binCl, cb->graphicsPipeline->lineWidth);
|
||||
|
||||
//TODO why flipped???
|
||||
//Clipper XY Scaling
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIPPER_XY_SCALING_length);
|
||||
clInsertClipperXYScaling(&commandBuffer->binCl, (float)(i->width) * 0.5f * 16.0f, -1.0f * (float)(i->height) * 0.5f * 16.0f);
|
||||
|
||||
//TODO how is this calculated?
|
||||
//it's Zc to Zs scale and bias
|
||||
//seems to go from -1.0 .. 1.0 to 0.0 .. 1.0
|
||||
//eg. x * 0.5 + 0.5
|
||||
//cb->graphicsPipeline->minDepthBounds;
|
||||
//Clipper Z Scale and Offset
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIPPER_Z_SCALE_AND_OFFSET_length);
|
||||
clInsertClipperZScaleOffset(&commandBuffer->binCl, 0.5f, 0.5f);
|
||||
|
||||
//Viewport Offset
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_VIEWPORT_OFFSET_length);
|
||||
clInsertViewPortOffset(&commandBuffer->binCl, i->width >> 1, i->height >> 1);
|
||||
|
||||
//TODO?
|
||||
//Flat Shade Flags
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLAT_SHADE_FLAGS_length);
|
||||
clInsertFlatShadeFlags(&commandBuffer->binCl, 0);
|
||||
|
||||
//TODO how to get address?
|
||||
//GL Shader State
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_GL_SHADER_STATE_length);
|
||||
@ -151,6 +169,8 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
clInsertShaderRecord(&commandBuffer->shaderRecCl,
|
||||
&relocCl,
|
||||
&commandBuffer->handlesCl,
|
||||
cb->binCl.currMarker->handlesBuf,
|
||||
cb->binCl.currMarker->handlesSize,
|
||||
!cb->graphicsPipeline->modules[ulog2(VK_SHADER_STAGE_FRAGMENT_BIT)]->hasThreadSwitch,
|
||||
0, //TODO point size included in shaded vertex data?
|
||||
1, //TODO enable clipping?
|
||||
@ -179,6 +199,8 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
clInsertAttributeRecord(&commandBuffer->shaderRecCl,
|
||||
&relocCl,
|
||||
&commandBuffer->handlesCl,
|
||||
cb->binCl.currMarker->handlesBuf,
|
||||
cb->binCl.currMarker->handlesSize,
|
||||
vertexBuffer, //reloc address
|
||||
getFormatByteSize(cb->graphicsPipeline->vertexAttributeDescriptions[0].format),
|
||||
cb->graphicsPipeline->vertexBindingDescriptions[0].stride, //stride
|
||||
@ -186,49 +208,11 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
0 //TODO coordinte vpm offset
|
||||
);
|
||||
|
||||
//Insert image handle index
|
||||
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
||||
uint32_t imageIdx = clGetHandleIndex(&commandBuffer->handlesCl, i->boundMem->bo);
|
||||
|
||||
//fill out submit cl fields
|
||||
commandBuffer->submitCl.color_write.hindex = imageIdx;
|
||||
commandBuffer->submitCl.color_write.offset = 0;
|
||||
commandBuffer->submitCl.color_write.flags = 0;
|
||||
//TODO format
|
||||
commandBuffer->submitCl.color_write.bits =
|
||||
VC4_SET_FIELD(VC4_RENDER_CONFIG_FORMAT_RGBA8888, VC4_RENDER_CONFIG_FORMAT) |
|
||||
VC4_SET_FIELD(i->tiling, VC4_RENDER_CONFIG_MEMORY_FORMAT);
|
||||
|
||||
commandBuffer->submitCl.clear_color[0] = i->clearColor[0];
|
||||
commandBuffer->submitCl.clear_color[1] = i->clearColor[1];
|
||||
|
||||
commandBuffer->submitCl.min_x_tile = 0;
|
||||
commandBuffer->submitCl.min_y_tile = 0;
|
||||
|
||||
uint32_t tileSizeW = 64;
|
||||
uint32_t tileSizeH = 64;
|
||||
|
||||
if(i->samples > 1)
|
||||
{
|
||||
tileSizeW >>= 1;
|
||||
tileSizeH >>= 1;
|
||||
}
|
||||
|
||||
if(getFormatBpp(i->format) == 64)
|
||||
{
|
||||
tileSizeH >>= 1;
|
||||
}
|
||||
|
||||
uint32_t widthInTiles = divRoundUp(i->width, tileSizeW);
|
||||
uint32_t heightInTiles = divRoundUp(i->height, tileSizeH);
|
||||
|
||||
commandBuffer->submitCl.max_x_tile = widthInTiles - 1;
|
||||
commandBuffer->submitCl.max_y_tile = heightInTiles - 1;
|
||||
commandBuffer->submitCl.width = i->width;
|
||||
commandBuffer->submitCl.height = i->height;
|
||||
commandBuffer->submitCl.flags |= VC4_SUBMIT_CL_USE_CLEAR_COLOR;
|
||||
commandBuffer->submitCl.clear_z = 0; //TODO
|
||||
commandBuffer->submitCl.clear_s = 0;
|
||||
|
||||
//write uniforms
|
||||
_pipelineLayout* pl = cb->graphicsPipeline->layout;
|
||||
@ -252,7 +236,7 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
|
||||
//emit reloc for texture BO
|
||||
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
||||
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, di->imageView->image->boundMem->bo);
|
||||
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, cb->binCl.currMarker->handlesBuf, cb->binCl.currMarker->handlesSize, di->imageView->image->boundMem->bo);
|
||||
|
||||
//emit tex bo reloc index
|
||||
clFit(commandBuffer, &commandBuffer->uniformsCl, 4);
|
||||
@ -269,7 +253,7 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
|
||||
//emit reloc for BO
|
||||
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
||||
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, db->buffer->boundMem->bo);
|
||||
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, cb->binCl.currMarker->handlesBuf, cb->binCl.currMarker->handlesSize, db->buffer->boundMem->bo);
|
||||
|
||||
//emit bo reloc index
|
||||
clFit(commandBuffer, &commandBuffer->uniformsCl, 4);
|
||||
@ -284,7 +268,7 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
|
||||
|
||||
//emit reloc for BO
|
||||
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
||||
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, dtb->bufferView->buffer->boundMem->bo);
|
||||
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, cb->binCl.currMarker->handlesBuf, cb->binCl.currMarker->handlesSize, dtb->bufferView->buffer->boundMem->bo);
|
||||
|
||||
//emit bo reloc index
|
||||
clFit(commandBuffer, &commandBuffer->uniformsCl, 4);
|
||||
|
@ -24,7 +24,6 @@ void vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBegin
|
||||
{
|
||||
if(cb->renderpass->attachments[c].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
{
|
||||
cb->fbo->attachmentViews[c].image->needToClear = 1;
|
||||
cb->fbo->attachmentViews[c].image->clearColor[0] = cb->fbo->attachmentViews[c].image->clearColor[1] = packVec4IntoABGR8(pRenderPassBegin->pClearValues->color.float32);
|
||||
}
|
||||
else if(isDepthStencilFormat(cb->renderpass->attachments[c].format) && cb->renderpass->attachments[c].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
@ -36,6 +35,42 @@ void vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBegin
|
||||
}
|
||||
|
||||
cb->currentSubpass = 0;
|
||||
|
||||
//TODO handle multiple attachments
|
||||
_image* i = cb->fbo->attachmentViews[0].image;
|
||||
|
||||
clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker));
|
||||
clInsertNewCLMarker(&commandBuffer->binCl, &cb->handlesCl, &cb->shaderRecCl, cb->shaderRecCount, &cb->uniformsCl, i);
|
||||
|
||||
//insert reloc for render target
|
||||
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
||||
clGetHandleIndex(&commandBuffer->handlesCl, commandBuffer->binCl.currMarker->handlesBuf, commandBuffer->binCl.currMarker->handlesSize, i->boundMem->bo);
|
||||
|
||||
//TODO handle multiple attachments
|
||||
if(cb->renderpass->attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
{
|
||||
cb->binCl.currMarker->flags |= VC4_SUBMIT_CL_USE_CLEAR_COLOR;
|
||||
}
|
||||
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length);
|
||||
clInsertTileBinningModeConfiguration(&commandBuffer->binCl,
|
||||
0, //double buffer in non ms mode
|
||||
0, //tile allocation block size
|
||||
0, //tile allocation initial block size
|
||||
0, //auto initialize tile state data array
|
||||
getFormatBpp(i->format) == 64, //64 bit color mode
|
||||
i->samples > 1, //msaa
|
||||
i->width, i->height,
|
||||
0, //tile state data array address
|
||||
0, //tile allocation memory size
|
||||
0); //tile allocation memory address
|
||||
|
||||
//START_TILE_BINNING resets the statechange counters in the hardware,
|
||||
//which are what is used when a primitive is binned to a tile to
|
||||
//figure out what new state packets need to be written to that tile's
|
||||
//command list.
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_START_TILE_BINNING_length);
|
||||
clInsertStartTileBinning(&commandBuffer->binCl);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -45,8 +80,19 @@ void vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
|
||||
{
|
||||
assert(commandBuffer);
|
||||
|
||||
//TODO switch command buffer to next control record stream?
|
||||
_commandBuffer* cb = commandBuffer;
|
||||
|
||||
//Ending a render pass instance performs any multisample resolve operations on the final subpass
|
||||
|
||||
//Increment the semaphore indicating that binning is done and
|
||||
//unblocking the render thread. Note that this doesn't act
|
||||
//until the FLUSH completes.
|
||||
//The FLUSH caps all of our bin lists with a
|
||||
//VC4_PACKET_RETURN.
|
||||
clFit(commandBuffer, &cb->binCl, V3D21_INCREMENT_SEMAPHORE_length);
|
||||
clInsertIncrementSemaphore(&cb->binCl);
|
||||
clFit(commandBuffer, &cb->binCl, V3D21_FLUSH_length);
|
||||
clInsertFlush(&cb->binCl);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -371,6 +371,8 @@ VKAPI_ATTR void VKAPI_CALL vkCmdPushConstants(
|
||||
{
|
||||
memcpy(cb->pushConstantBufferPixel + offset, pValues, size);
|
||||
}
|
||||
|
||||
cb->pushConstantDirty = 1;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout(
|
||||
|
@ -96,11 +96,14 @@ VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
|
||||
|
||||
//TODO externally sync cmdbuf, cmdpool
|
||||
|
||||
//i->needToClear = 1;
|
||||
//i->clearColor[0] = i->clearColor[1] = packVec4IntoABGR8(pColor->float32);
|
||||
|
||||
|
||||
{ //Simplest case: just submit a job to clear the image
|
||||
clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker));
|
||||
clInsertNewCLMarker(&commandBuffer->binCl, &commandBuffer->handlesCl, &commandBuffer->shaderRecCl, commandBuffer->shaderRecCount, &commandBuffer->uniformsCl, i);
|
||||
|
||||
//insert reloc for render target
|
||||
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
||||
clGetHandleIndex(&commandBuffer->handlesCl, commandBuffer->binCl.currMarker->handlesBuf, commandBuffer->binCl.currMarker->handlesSize, i->boundMem->bo);
|
||||
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length);
|
||||
clInsertTileBinningModeConfiguration(&commandBuffer->binCl,
|
||||
0, //double buffer in non ms mode
|
||||
@ -121,19 +124,18 @@ VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_START_TILE_BINNING_length);
|
||||
clInsertStartTileBinning(&commandBuffer->binCl);
|
||||
|
||||
//Reset the current compressed primitives format. This gets modified
|
||||
//by VC4_PACKET_GL_INDEXED_PRIMITIVE and
|
||||
//VC4_PACKET_GL_ARRAY_PRIMITIVE, so it needs to be reset at the start
|
||||
//of every tile.
|
||||
//clFit(commandBuffer, &commandBuffer->binCl, V3D21_PRIMITIVE_LIST_FORMAT_length);
|
||||
//clInsertPrimitiveListFormat(&commandBuffer->binCl,
|
||||
// 1, //16 bit
|
||||
// 2); //tris
|
||||
|
||||
//Increment the semaphore indicating that binning is done and
|
||||
//unblocking the render thread. Note that this doesn't act
|
||||
//until the FLUSH completes.
|
||||
//The FLUSH caps all of our bin lists with a
|
||||
//VC4_PACKET_RETURN.
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_INCREMENT_SEMAPHORE_length);
|
||||
clInsertIncrementSemaphore(&commandBuffer->binCl);
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLUSH_length);
|
||||
clInsertFlush(&commandBuffer->binCl);
|
||||
|
||||
i->clearColor[0] = i->clearColor[1] = packVec4IntoABGR8(pColor->float32);
|
||||
commandBuffer->binCl.currMarker->flags |= VC4_SUBMIT_CL_USE_CLEAR_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,80 +148,11 @@ VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
|
||||
{
|
||||
_image* i = pImageMemoryBarriers[c].image;
|
||||
|
||||
//assert(i->layout == pImageMemoryBarriers[c].oldLayout || i->layout == VK_IMAGE_LAYOUT_UNDEFINED);
|
||||
|
||||
if(srcStageMask & VK_PIPELINE_STAGE_TRANSFER_BIT &&
|
||||
pImageMemoryBarriers[c].srcAccessMask & VK_ACCESS_TRANSFER_WRITE_BIT &&
|
||||
i->needToClear)
|
||||
{
|
||||
//insert CRs to clear the image
|
||||
|
||||
assert(i->layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length);
|
||||
clInsertTileBinningModeConfiguration(&commandBuffer->binCl,
|
||||
0, 0, 0, 0,
|
||||
getFormatBpp(i->format) == 64, //64 bit color mode
|
||||
i->samples > 1, //msaa
|
||||
i->width, i->height, 0, 0, 0);
|
||||
|
||||
//START_TILE_BINNING resets the statechange counters in the hardware,
|
||||
//which are what is used when a primitive is binned to a tile to
|
||||
//figure out what new state packets need to be written to that tile's
|
||||
//command list.
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_START_TILE_BINNING_length);
|
||||
clInsertStartTileBinning(&commandBuffer->binCl);
|
||||
|
||||
//Reset the current compressed primitives format. This gets modified
|
||||
//by VC4_PACKET_GL_INDEXED_PRIMITIVE and
|
||||
//VC4_PACKET_GL_ARRAY_PRIMITIVE, so it needs to be reset at the start
|
||||
//of every tile.
|
||||
clFit(commandBuffer, &commandBuffer->binCl, V3D21_PRIMITIVE_LIST_FORMAT_length);
|
||||
clInsertPrimitiveListFormat(&commandBuffer->binCl,
|
||||
1, //16 bit
|
||||
2); //tris
|
||||
|
||||
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
||||
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, i->boundMem->bo);
|
||||
commandBuffer->submitCl.color_write.hindex = idx;
|
||||
commandBuffer->submitCl.color_write.offset = 0;
|
||||
commandBuffer->submitCl.color_write.flags = 0;
|
||||
//TODO format
|
||||
commandBuffer->submitCl.color_write.bits =
|
||||
VC4_SET_FIELD(VC4_RENDER_CONFIG_FORMAT_RGBA8888, VC4_RENDER_CONFIG_FORMAT) |
|
||||
VC4_SET_FIELD(i->tiling, VC4_RENDER_CONFIG_MEMORY_FORMAT);
|
||||
|
||||
commandBuffer->submitCl.clear_color[0] = i->clearColor[0];
|
||||
commandBuffer->submitCl.clear_color[1] = i->clearColor[1];
|
||||
|
||||
//TODO ranges
|
||||
commandBuffer->submitCl.min_x_tile = 0;
|
||||
commandBuffer->submitCl.min_y_tile = 0;
|
||||
|
||||
uint32_t tileSizeW = 64;
|
||||
uint32_t tileSizeH = 64;
|
||||
|
||||
if(i->samples > 1)
|
||||
{
|
||||
tileSizeW >>= 1;
|
||||
tileSizeH >>= 1;
|
||||
}
|
||||
|
||||
if(getFormatBpp(i->format) == 64)
|
||||
{
|
||||
tileSizeH >>= 1;
|
||||
}
|
||||
|
||||
uint32_t widthInTiles = divRoundUp(i->width, tileSizeW);
|
||||
uint32_t heightInTiles = divRoundUp(i->height, tileSizeH);
|
||||
|
||||
commandBuffer->submitCl.max_x_tile = widthInTiles - 1;
|
||||
commandBuffer->submitCl.max_y_tile = heightInTiles - 1;
|
||||
commandBuffer->submitCl.width = i->width;
|
||||
commandBuffer->submitCl.height = i->height;
|
||||
commandBuffer->submitCl.flags |= VC4_SUBMIT_CL_USE_CLEAR_COLOR;
|
||||
commandBuffer->submitCl.clear_z = 0; //TODO
|
||||
commandBuffer->submitCl.clear_s = 0;
|
||||
}
|
||||
|
||||
//transition to new layout
|
||||
|
@ -72,6 +72,8 @@ typedef struct VkRpiShaderModuleAssemblyCreateInfoEXT {
|
||||
uint32_t numMappings;
|
||||
} VkRpiShaderModuleAssemblyCreateInfoEXT;
|
||||
|
||||
//TODO could use this extension https://vulkan.lunarg.com/doc/view/1.0.30.0/windows/vkspec.chunked/ch29s03.html
|
||||
|
||||
//extension name something like: VK_KHR_rpi_surface
|
||||
//extension that allows developers to create a surface to render to on Raspbian Stretch Lite
|
||||
VkResult vkCreateRpiSurfaceEXT(
|
||||
|
@ -68,8 +68,10 @@ VkPipeline blitPipeline; //
|
||||
VkPipeline samplePipeline; //
|
||||
VkQueue graphicsQueue;
|
||||
VkQueue presentQueue;
|
||||
VkBuffer vertexBuffer;
|
||||
VkDeviceMemory vertexBufferMemory;
|
||||
VkBuffer fsqVertexBuffer;
|
||||
VkDeviceMemory fsqVertexBufferMemory;
|
||||
VkBuffer triangleVertexBuffer;
|
||||
VkDeviceMemory triangleVertexBufferMemory;
|
||||
VkPhysicalDeviceMemoryProperties pdmp;
|
||||
std::vector<VkImageView> views; //?
|
||||
VkSurfaceFormatKHR swapchainFormat;
|
||||
@ -727,7 +729,7 @@ void recordCommandBuffers()
|
||||
vkCmdBindPipeline(presentCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, blitPipeline);
|
||||
|
||||
VkDeviceSize offsets = 0;
|
||||
vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &vertexBuffer, &offsets );
|
||||
vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &fsqVertexBuffer, &offsets );
|
||||
|
||||
vkCmdBindDescriptorSets(presentCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, blitPipelineLayout, 0, 1, &blitDescriptorSet, 0, 0);
|
||||
|
||||
@ -759,7 +761,7 @@ void recordCommandBuffers()
|
||||
{ //render to screen
|
||||
renderPassInfo.framebuffer = fbs[i];
|
||||
renderPassInfo.renderPass = renderPass;
|
||||
renderPassInfo.clearValueCount = 2;
|
||||
renderPassInfo.clearValueCount = 1;
|
||||
renderPassInfo.pClearValues = &clearValue;
|
||||
|
||||
vkCmdBeginRenderPass(presentCommandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
@ -767,7 +769,7 @@ void recordCommandBuffers()
|
||||
vkCmdBindPipeline(presentCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, samplePipeline);
|
||||
|
||||
VkDeviceSize offsets = 0;
|
||||
vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &vertexBuffer, &offsets );
|
||||
vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &triangleVertexBuffer, &offsets );
|
||||
|
||||
vkCmdBindDescriptorSets(presentCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, samplePipelineLayout, 0, 1, &sampleDescriptorSet, 0, 0);
|
||||
|
||||
@ -1688,22 +1690,24 @@ void CreateVertexBuffer()
|
||||
|
||||
VkMemoryRequirements mr;
|
||||
|
||||
{ //create staging buffer
|
||||
{ //create fsq vertex buffer
|
||||
unsigned vboSize = sizeof(float) * 2 * 3 * 2; //2 * 3 x vec2
|
||||
|
||||
VkBufferCreateInfo ci = {};
|
||||
ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
ci.size = vboSize;
|
||||
ci.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
|
||||
|
||||
VkResult res = vkCreateBuffer(device, &ci, 0, &vertexBuffer);
|
||||
VkResult res = vkCreateBuffer(device, &ci, 0, &fsqVertexBuffer);
|
||||
|
||||
vkGetBufferMemoryRequirements(device, vertexBuffer, &mr);
|
||||
vkGetBufferMemoryRequirements(device, fsqVertexBuffer, &mr);
|
||||
|
||||
VkMemoryAllocateInfo mai = {};
|
||||
mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
mai.allocationSize = mr.size;
|
||||
mai.memoryTypeIndex = getMemoryTypeIndex(pdmp, mr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
|
||||
res = vkAllocateMemory(device, &mai, 0, &vertexBufferMemory);
|
||||
res = vkAllocateMemory(device, &mai, 0, &fsqVertexBufferMemory);
|
||||
|
||||
float vertices[] =
|
||||
{
|
||||
@ -1717,11 +1721,45 @@ void CreateVertexBuffer()
|
||||
};
|
||||
|
||||
void* data;
|
||||
res = vkMapMemory(device, vertexBufferMemory, 0, mr.size, 0, &data);
|
||||
res = vkMapMemory(device, fsqVertexBufferMemory, 0, mr.size, 0, &data);
|
||||
memcpy(data, vertices, vboSize);
|
||||
vkUnmapMemory(device, vertexBufferMemory);
|
||||
vkUnmapMemory(device, fsqVertexBufferMemory);
|
||||
|
||||
res = vkBindBufferMemory(device, vertexBuffer, vertexBufferMemory, 0);
|
||||
res = vkBindBufferMemory(device, fsqVertexBuffer, fsqVertexBufferMemory, 0);
|
||||
}
|
||||
|
||||
{ //create triangle vertex buffer
|
||||
unsigned vboSize = sizeof(float) * 1 * 3 * 2; //1 * 3 x vec2
|
||||
|
||||
VkBufferCreateInfo ci = {};
|
||||
ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
ci.size = vboSize;
|
||||
ci.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
|
||||
|
||||
VkResult res = vkCreateBuffer(device, &ci, 0, &triangleVertexBuffer);
|
||||
|
||||
vkGetBufferMemoryRequirements(device, triangleVertexBuffer, &mr);
|
||||
|
||||
VkMemoryAllocateInfo mai = {};
|
||||
mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
mai.allocationSize = mr.size;
|
||||
mai.memoryTypeIndex = getMemoryTypeIndex(pdmp, mr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
|
||||
res = vkAllocateMemory(device, &mai, 0, &triangleVertexBufferMemory);
|
||||
|
||||
float vertices[] =
|
||||
{
|
||||
-1, -1,
|
||||
1, -1,
|
||||
0, 1
|
||||
};
|
||||
|
||||
void* data;
|
||||
res = vkMapMemory(device, triangleVertexBufferMemory, 0, mr.size, 0, &data);
|
||||
memcpy(data, vertices, vboSize);
|
||||
vkUnmapMemory(device, triangleVertexBufferMemory);
|
||||
|
||||
res = vkBindBufferMemory(device, triangleVertexBuffer, triangleVertexBufferMemory, 0);
|
||||
}
|
||||
|
||||
printf("Vertex buffer created\n");
|
||||
|
Loading…
Reference in New Issue
Block a user