mirror of
https://github.com/Yours3lf/rpi-vk-driver.git
synced 2025-01-19 11:52:16 +01:00
fixed clear test
This commit is contained in:
parent
3df04a2423
commit
3a16211893
@ -145,6 +145,7 @@ typedef struct VkDevice_T
|
|||||||
VkShaderModule emulTextureToBufferShaderModule; //TODO
|
VkShaderModule emulTextureToBufferShaderModule; //TODO
|
||||||
VkShaderModule emulBufferToBufferShaderModule; //TODO
|
VkShaderModule emulBufferToBufferShaderModule; //TODO
|
||||||
VkShaderModule emulClearShaderModule;
|
VkShaderModule emulClearShaderModule;
|
||||||
|
VkShaderModule emulClearNoColorShaderModule;
|
||||||
} _device;
|
} _device;
|
||||||
|
|
||||||
typedef struct VkRenderPass_T
|
typedef struct VkRenderPass_T
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "QPUassembler/qpu_assembler.h"
|
#include "QPUassembler/qpu_assembler.h"
|
||||||
|
|
||||||
void createClearShaderModule(VkDevice device, VkShaderModule* blitShaderModule)
|
void createClearShaderModule(VkDevice device, VkShaderModule* blitShaderModule, VkShaderModule* blitShaderModuleNoColor)
|
||||||
{
|
{
|
||||||
char vs_asm_code[] =
|
char vs_asm_code[] =
|
||||||
///0x40000000 = 2.0
|
///0x40000000 = 2.0
|
||||||
@ -118,10 +118,17 @@ void createClearShaderModule(VkDevice device, VkShaderModule* blitShaderModule)
|
|||||||
"sig_unlock_score ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"
|
"sig_unlock_score ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"
|
||||||
"\0";
|
"\0";
|
||||||
|
|
||||||
char* blit_asm_strings[] =
|
char fs_asm_code_no_color[] =
|
||||||
{
|
"sig_none ; r0 = or.always(a, a, uni, nop) ; nop = nop(r0, r0) ;" //clear color value
|
||||||
(char*)cs_asm_code, (char*)vs_asm_code, (char*)fs_asm_code, 0
|
"sig_none ; r1 = or.always(a, a, uni, nop) ; nop = nop(r0, r0) ;" //stencil setup
|
||||||
};
|
"sig_none ; r2 = or.always(a, a, uni, nop) ; nop = nop(r0, r0) ;" //depth clear value
|
||||||
|
"sig_none ; tlb_stencil_setup = or.always(r1, r1) ; nop = nop(r0, r0) ;"
|
||||||
|
"sig_none ; tlb_z = or.always(r2, r2) ; nop = nop(r0, r0) ;"
|
||||||
|
///"sig_none ; tlb_color_all = or.always(r0, r0) ; nop = nop(r0, r0) ;"
|
||||||
|
"sig_end ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"
|
||||||
|
"sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"
|
||||||
|
"sig_unlock_score ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"
|
||||||
|
"\0";
|
||||||
|
|
||||||
VkRpiAssemblyMappingEXT vertexMappings[] = {
|
VkRpiAssemblyMappingEXT vertexMappings[] = {
|
||||||
//vertex shader uniforms
|
//vertex shader uniforms
|
||||||
@ -254,6 +261,20 @@ void createClearShaderModule(VkDevice device, VkShaderModule* blitShaderModule)
|
|||||||
rpi_vkCreateShaderModule(device, &smci, 0, blitShaderModule);
|
rpi_vkCreateShaderModule(device, &smci, 0, blitShaderModule);
|
||||||
assert(*blitShaderModule);
|
assert(*blitShaderModule);
|
||||||
|
|
||||||
|
{ //assemble fs code
|
||||||
|
asm_sizes[2] = get_num_instructions(fs_asm_code_no_color);
|
||||||
|
uint32_t size = sizeof(uint64_t)*asm_sizes[2];
|
||||||
|
//TODO this alloc feels kinda useless, we just copy the data anyway to kernel space
|
||||||
|
//why not map kernel space mem to user space instead?
|
||||||
|
free(asm_ptrs[2]);
|
||||||
|
asm_ptrs[2] = (uint64_t*)malloc(size);
|
||||||
|
assemble_qpu_asm(fs_asm_code_no_color, asm_ptrs[2]);
|
||||||
|
assert(asm_ptrs[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpi_vkCreateShaderModule(device, &smci, 0, blitShaderModuleNoColor);
|
||||||
|
assert(*blitShaderModuleNoColor);
|
||||||
|
|
||||||
// _shaderModule* s = *blitShaderModule;
|
// _shaderModule* s = *blitShaderModule;
|
||||||
// fprintf(stderr, "=================\n");
|
// fprintf(stderr, "=================\n");
|
||||||
// fprintf(stderr, "pixel shader bo %i\n", s->bos[2]);
|
// fprintf(stderr, "pixel shader bo %i\n", s->bos[2]);
|
||||||
@ -392,7 +413,7 @@ void setupClearEmulationResources(VkDevice device)
|
|||||||
//create resources that won't change
|
//create resources that won't change
|
||||||
_device* dev = device;
|
_device* dev = device;
|
||||||
|
|
||||||
createClearShaderModule(device, &dev->emulClearShaderModule);
|
createClearShaderModule(device, &dev->emulClearShaderModule, &dev->emulClearNoColorShaderModule);
|
||||||
createClearDescriptorSetLayouts(device, &dev->emulClearDsl);
|
createClearDescriptorSetLayouts(device, &dev->emulClearDsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,6 +597,19 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkCmdClearAttachments(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_pipeline* oldPipeline;
|
||||||
|
uint32_t oldVertexBufferOffsets[8];
|
||||||
|
_buffer* oldVertexBuffers[8];
|
||||||
|
char oldPushConstantBufferVertex[256];
|
||||||
|
char oldPushConstantBufferPixel[256];
|
||||||
|
|
||||||
|
//save the state that we'll modify
|
||||||
|
oldPipeline = cmdBuf->graphicsPipeline;
|
||||||
|
memcpy(oldVertexBufferOffsets, cmdBuf->vertexBufferOffsets, sizeof(oldVertexBufferOffsets));
|
||||||
|
memcpy(oldVertexBuffers, cmdBuf->vertexBuffers, sizeof(oldVertexBuffers));
|
||||||
|
memcpy(oldPushConstantBufferVertex, cmdBuf->pushConstantBufferVertex, sizeof(oldPushConstantBufferVertex));
|
||||||
|
memcpy(oldPushConstantBufferPixel, cmdBuf->pushConstantBufferPixel, sizeof(oldPushConstantBufferPixel));
|
||||||
|
|
||||||
for(uint32_t c = 0; c < attachmentCount; ++c)
|
for(uint32_t c = 0; c < attachmentCount; ++c)
|
||||||
{
|
{
|
||||||
uint32_t clearColor = 0, clearDepth = 0, clearStencil = 0;
|
uint32_t clearColor = 0, clearDepth = 0, clearStencil = 0;
|
||||||
@ -613,7 +647,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkCmdClearAttachments(
|
|||||||
dsci.front.passOp = VK_STENCIL_OP_REPLACE;
|
dsci.front.passOp = VK_STENCIL_OP_REPLACE;
|
||||||
dsci.back = dsci.front;
|
dsci.back = dsci.front;
|
||||||
|
|
||||||
createClearPipeline(device, &dsci, device->emulClearShaderModule, device->emulClearDsl, &blitPipelineLayout, cmdBuf->currRenderPass, &blitPipeline);
|
createClearPipeline(device, &dsci, clearColor ? device->emulClearShaderModule : device->emulClearNoColorShaderModule, device->emulClearDsl, &blitPipelineLayout, cmdBuf->currRenderPass, &blitPipeline);
|
||||||
|
|
||||||
// _shaderModule* s = device->emulClearShaderModule;
|
// _shaderModule* s = device->emulClearShaderModule;
|
||||||
// fprintf(stderr, "=================\n");
|
// fprintf(stderr, "=================\n");
|
||||||
@ -629,7 +663,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkCmdClearAttachments(
|
|||||||
uint32_t clearColorValue = 0, stencilSetup = 0, depthClearValue = 0;
|
uint32_t clearColorValue = 0, stencilSetup = 0, depthClearValue = 0;
|
||||||
|
|
||||||
clearColorValue = packVec4IntoABGR8(&pAttachments[c].clearValue.color.float32[0]);
|
clearColorValue = packVec4IntoABGR8(&pAttachments[c].clearValue.color.float32[0]);
|
||||||
depthClearValue = (uint32_t)(pAttachments[c].clearValue.depthStencil.depth * 0xffffff) & 0xffffff;
|
depthClearValue = (uint32_t)(pAttachments[c].clearValue.depthStencil.depth * 0xffffffu) & 0xffffffu;
|
||||||
uint32_t numValues = 1;
|
uint32_t numValues = 1;
|
||||||
encodeStencilValue(&stencilSetup, &numValues, dsci.front, dsci.back, clearStencil);
|
encodeStencilValue(&stencilSetup, &numValues, dsci.front, dsci.back, clearStencil);
|
||||||
|
|
||||||
@ -673,6 +707,13 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkCmdClearAttachments(
|
|||||||
rpi_vkDestroyPipelineLayout(device, blitPipelineLayout, 0);
|
rpi_vkDestroyPipelineLayout(device, blitPipelineLayout, 0);
|
||||||
rpi_vkDestroyPipeline(device, blitPipeline, 0);
|
rpi_vkDestroyPipeline(device, blitPipeline, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//restore state
|
||||||
|
cmdBuf->graphicsPipeline = oldPipeline;
|
||||||
|
memcpy(cmdBuf->vertexBufferOffsets, oldVertexBufferOffsets, sizeof(oldVertexBufferOffsets));
|
||||||
|
memcpy(cmdBuf->vertexBuffers, oldVertexBuffers, sizeof(oldVertexBuffers));
|
||||||
|
memcpy(cmdBuf->pushConstantBufferVertex, oldPushConstantBufferVertex, sizeof(oldPushConstantBufferVertex));
|
||||||
|
memcpy(cmdBuf->pushConstantBufferPixel, oldPushConstantBufferPixel, sizeof(oldPushConstantBufferPixel));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -825,19 +825,25 @@ void recordCommandBuffers()
|
|||||||
uint32_t fragColor = 0xffa14ccc; //purple
|
uint32_t fragColor = 0xffa14ccc; //purple
|
||||||
vkCmdPushConstants(presentCommandBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragColor), &fragColor);
|
vkCmdPushConstants(presentCommandBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragColor), &fragColor);
|
||||||
|
|
||||||
VkDeviceSize offsets = 0;
|
VkClearAttachment clearAttachment[2] = {};
|
||||||
vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &vertexBuffer1, &offsets );
|
clearAttachment[0].aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||||
vkCmdDraw(presentCommandBuffers[i], 3, 1, 0, 0);
|
clearAttachment[0].clearValue.depthStencil.depth = 0.3f;
|
||||||
|
|
||||||
VkClearAttachment clearAttachment = {};
|
clearAttachment[1].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
clearAttachment[1].clearValue.color.float32[0] = 1.0f;
|
||||||
clearAttachment.clearValue.depthStencil.depth = 0.0f;
|
clearAttachment[1].clearValue.color.float32[1] = 1.0f;
|
||||||
|
clearAttachment[1].clearValue.color.float32[2] = 1.0f;
|
||||||
|
clearAttachment[1].clearValue.color.float32[3] = 1.0f;
|
||||||
VkClearRect clearRect = {};
|
VkClearRect clearRect = {};
|
||||||
clearRect.rect.offset.x = 0;
|
clearRect.rect.offset.x = 0;
|
||||||
clearRect.rect.offset.y = 0;
|
clearRect.rect.offset.y = 0;
|
||||||
clearRect.rect.extent.width = swapChainExtent.width;
|
clearRect.rect.extent.width = swapChainExtent.width;
|
||||||
clearRect.rect.extent.height = swapChainExtent.height;
|
clearRect.rect.extent.height = swapChainExtent.height;
|
||||||
vkCmdClearAttachments(presentCommandBuffers[i], 1, &clearAttachment, 1, &clearRect);
|
vkCmdClearAttachments(presentCommandBuffers[i], 2, clearAttachment, 1, &clearRect);
|
||||||
|
|
||||||
|
VkDeviceSize offsets = 0;
|
||||||
|
vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &vertexBuffer1, &offsets );
|
||||||
|
vkCmdDraw(presentCommandBuffers[i], 3, 1, 0, 0);
|
||||||
|
|
||||||
fragColor = 0xffafcd02; //yellow
|
fragColor = 0xffafcd02; //yellow
|
||||||
vkCmdPushConstants(presentCommandBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragColor), &fragColor);
|
vkCmdPushConstants(presentCommandBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragColor), &fragColor);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user