2018-10-15 23:37:09 +02:00
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include "kernel/vc4_packet.h"
|
|
|
|
|
2020-05-08 14:06:45 +02:00
|
|
|
#include "declarations.h"
|
|
|
|
|
|
|
|
#include "QPUassembler/qpu_assembler.h"
|
|
|
|
|
2020-05-10 20:03:36 +02:00
|
|
|
void createClearShaderModule(VkDevice device, VkShaderModule* blitShaderModule, VkShaderModule* blitShaderModuleNoColor)
|
2020-05-08 14:06:45 +02:00
|
|
|
{
|
|
|
|
char vs_asm_code[] =
|
|
|
|
///0x40000000 = 2.0
|
|
|
|
///uni = 1.0
|
|
|
|
///rb0 = 2 - 1 = 1
|
|
|
|
"sig_small_imm ; rx0 = fsub.ws.always(b, a, uni, 0x40000000) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///set up VPM read for subsequent reads
|
|
|
|
///0x00201a00: 0000 0000 0010 0000 0001 1010 0000 0000
|
|
|
|
///addr: 0
|
|
|
|
///size: 32bit
|
|
|
|
///packed
|
|
|
|
///horizontal
|
|
|
|
///stride=1
|
|
|
|
///vectors to read = 2 (how many components)
|
|
|
|
"sig_load_imm ; vr_setup = load32.always(0x00201a00) ; nop = load32.always() ;\n"
|
|
|
|
///uni = viewportXScale
|
|
|
|
///r0 = vpm * uni
|
|
|
|
"sig_none ; nop = nop(r0, r0, vpm_read, uni) ; r0 = fmul.always(a, b) ;\n"
|
|
|
|
///r1 = r0 * rb0 (1)
|
|
|
|
"sig_none ; nop = nop(r0, r0, nop, rb0) ; r1 = fmul.always(r0, b) ;\n"
|
|
|
|
///uni = viewportYScale
|
|
|
|
///ra0.16a = int(r1), r2 = vpm * uni
|
|
|
|
"sig_none ; rx0.16a = ftoi.always(r1, r1, vpm_read, uni) ; r2 = fmul.always(a, b) ;\n"
|
|
|
|
///r3 = r2 * rb0
|
|
|
|
"sig_none ; nop = nop(r0, r0, nop, rb0) ; r3 = fmul.always(r2, b) ;\n"
|
|
|
|
///ra0.16b = int(r3)
|
|
|
|
"sig_none ; rx0.16b = ftoi.always(r3, r3) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///set up VPM write for subsequent writes
|
|
|
|
///0x00001a00: 0000 0000 0000 0000 0001 1010 0000 0000
|
|
|
|
///addr: 0
|
|
|
|
///size: 32bit
|
|
|
|
///horizontal
|
|
|
|
///stride = 1
|
|
|
|
"sig_load_imm ; vw_setup = load32.always.ws(0x00001a00) ; nop = load32.always() ;\n"
|
|
|
|
///shaded vertex format for PSE
|
|
|
|
/// Ys and Xs
|
|
|
|
///vpm = ra0
|
|
|
|
"sig_none ; vpm = or.always(a, a, ra0, nop) ; nop = nop(r0, r0);\n"
|
|
|
|
/// Zs
|
|
|
|
///uni = 0.5
|
|
|
|
///vpm = uni
|
|
|
|
"sig_none ; vpm = or.always(a, a, uni, nop) ; nop = nop(r0, r0);\n"
|
|
|
|
/// 1.0 / Wc
|
|
|
|
///vpm = rb0 (1)
|
|
|
|
"sig_none ; vpm = or.always(b, b, nop, rb0) ; nop = nop(r0, r0);\n"
|
|
|
|
///END
|
|
|
|
"sig_end ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;\n"
|
|
|
|
"sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;\n"
|
|
|
|
"sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;\n"
|
|
|
|
"\0";
|
|
|
|
|
|
|
|
char cs_asm_code[] =
|
|
|
|
///uni = 1.0
|
|
|
|
///r3 = 2.0 - uni
|
|
|
|
"sig_small_imm ; r3 = fsub.always(b, a, uni, 0x40000000) ; nop = nop(r0, r0);\n"
|
|
|
|
"sig_load_imm ; vr_setup = load32.always(0x00201a00) ; nop = load32.always() ;\n"
|
|
|
|
///r2 = vpm
|
|
|
|
"sig_none ; r2 = or.always(a, a, vpm_read, nop) ; nop = nop(r0, r0);\n"
|
|
|
|
"sig_load_imm ; vw_setup = load32.always.ws(0x00001a00) ; nop = load32.always() ;\n"
|
|
|
|
///shaded coordinates format for PTB
|
|
|
|
/// write Xc
|
|
|
|
///r1 = vpm, vpm = r2
|
|
|
|
"sig_none ; r1 = or.always(a, a, vpm_read, nop) ; vpm = v8min.always(r2, r2);\n"
|
|
|
|
/// write Yc
|
|
|
|
///uni = viewportXscale
|
|
|
|
///vpm = r1, r2 = r2 * uni
|
|
|
|
"sig_none ; vpm = or.always(r1, r1, uni, nop) ; r2 = fmul.always(r2, a);\n"
|
|
|
|
///uni = viewportYscale
|
|
|
|
///r1 = r1 * uni
|
|
|
|
"sig_none ; nop = nop(r0, r0, uni, nop) ; r1 = fmul.always(r1, a);\n"
|
|
|
|
///r0 = r2 * r3
|
|
|
|
"sig_none ; nop = nop(r0, r0) ; r0 = fmul.always(r2, r3);\n"
|
|
|
|
///ra0.16a = r0, r1 = r1 * r3
|
|
|
|
"sig_none ; rx0.16a = ftoi.always(r0, r0) ; r1 = fmul.always(r1, r3) ;\n"
|
|
|
|
///ra0.16b = r1
|
|
|
|
"sig_none ; rx0.16b = ftoi.always(r1, r1) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///write Zc
|
|
|
|
///vpm = 0
|
|
|
|
"sig_small_imm ; vpm = or.always(b, b, nop, 0) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///write Wc
|
|
|
|
///vpm = 1.0
|
|
|
|
"sig_small_imm ; vpm = or.always(b, b, nop, 0x3f800000) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///write Ys and Xs
|
|
|
|
///vpm = ra0
|
|
|
|
"sig_none ; vpm = or.always(a, a, ra0, nop) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///write Zs
|
|
|
|
///uni = 0.5
|
|
|
|
///vpm = uni
|
|
|
|
"sig_none ; vpm = or.always(a, a, uni, nop) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///write 1/Wc
|
|
|
|
///vpm = r3
|
|
|
|
"sig_none ; vpm = or.always(r3, r3) ; nop = nop(r0, r0) ;\n"
|
|
|
|
///END
|
|
|
|
"sig_end ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;\n"
|
|
|
|
"sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;\n"
|
|
|
|
"sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;\n"
|
|
|
|
"\0";
|
|
|
|
|
|
|
|
//sample texture
|
|
|
|
char fs_asm_code[] =
|
|
|
|
"sig_none ; r0 = or.always(a, a, uni, nop) ; nop = nop(r0, r0) ;" //clear color value
|
|
|
|
"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";
|
|
|
|
|
2020-05-10 20:03:36 +02:00
|
|
|
char fs_asm_code_no_color[] =
|
|
|
|
"sig_none ; r0 = or.always(a, a, uni, nop) ; nop = nop(r0, r0) ;" //clear color value
|
|
|
|
"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";
|
2020-05-08 14:06:45 +02:00
|
|
|
|
|
|
|
VkRpiAssemblyMappingEXT vertexMappings[] = {
|
|
|
|
//vertex shader uniforms
|
|
|
|
{
|
|
|
|
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
|
|
|
|
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
|
|
|
|
0, //descriptor set #
|
|
|
|
0, //descriptor binding #
|
|
|
|
0, //descriptor array element #
|
|
|
|
0, //resource offset
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
|
|
|
|
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
|
|
|
|
0, //descriptor set #
|
|
|
|
0, //descriptor binding #
|
|
|
|
0, //descriptor array element #
|
|
|
|
4, //resource offset
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
|
|
|
|
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
|
|
|
|
0, //descriptor set #
|
|
|
|
0, //descriptor binding #
|
|
|
|
0, //descriptor array element #
|
|
|
|
8, //resource offset
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
|
|
|
|
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
|
|
|
|
0, //descriptor set #
|
|
|
|
0, //descriptor binding #
|
|
|
|
0, //descriptor array element #
|
|
|
|
12, //resource offset
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
VkRpiAssemblyMappingEXT fragmentMappings[] = {
|
|
|
|
//fragment shader uniforms
|
|
|
|
{
|
|
|
|
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
|
|
|
|
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
|
|
|
|
0, //descriptor set #
|
|
|
|
0, //descriptor binding #
|
|
|
|
0, //descriptor array element #
|
|
|
|
0, //resource offset
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
|
|
|
|
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
|
|
|
|
0, //descriptor set #
|
|
|
|
0, //descriptor binding #
|
|
|
|
0, //descriptor array element #
|
|
|
|
4, //resource offset
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
|
|
|
|
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
|
|
|
|
0, //descriptor set #
|
|
|
|
0, //descriptor binding #
|
|
|
|
0, //descriptor array element #
|
|
|
|
8, //resource offset
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t spirv[6];
|
|
|
|
|
|
|
|
uint64_t* asm_ptrs[4] = {};
|
|
|
|
uint32_t asm_sizes[4] = {};
|
|
|
|
|
|
|
|
VkRpiAssemblyMappingEXT* asm_mappings[4] = {};
|
|
|
|
uint32_t asm_mappings_sizes[4] = {};
|
|
|
|
|
|
|
|
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
|
|
|
|
shaderModuleCreateInfo.instructions = asm_ptrs;
|
|
|
|
shaderModuleCreateInfo.numInstructions = asm_sizes;
|
|
|
|
shaderModuleCreateInfo.mappings = asm_mappings;
|
|
|
|
shaderModuleCreateInfo.numMappings = asm_mappings_sizes;
|
|
|
|
|
|
|
|
asm_mappings[VK_RPI_ASSEMBLY_TYPE_VERTEX] = vertexMappings;
|
|
|
|
asm_mappings_sizes[VK_RPI_ASSEMBLY_TYPE_VERTEX] = sizeof(vertexMappings) / sizeof(VkRpiAssemblyMappingEXT);
|
|
|
|
asm_mappings[VK_RPI_ASSEMBLY_TYPE_FRAGMENT] = fragmentMappings;
|
|
|
|
asm_mappings_sizes[VK_RPI_ASSEMBLY_TYPE_FRAGMENT] = sizeof(fragmentMappings) / sizeof(VkRpiAssemblyMappingEXT);
|
|
|
|
|
|
|
|
//TODO use allocator
|
|
|
|
|
|
|
|
{ //assemble cs code
|
|
|
|
asm_sizes[0] = get_num_instructions(cs_asm_code);
|
|
|
|
uint32_t size = sizeof(uint64_t)*asm_sizes[0];
|
|
|
|
//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?
|
|
|
|
asm_ptrs[0] = (uint64_t*)malloc(size);
|
|
|
|
assemble_qpu_asm(cs_asm_code, asm_ptrs[0]);
|
|
|
|
assert(asm_ptrs[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ //assemble vs code
|
|
|
|
asm_sizes[1] = get_num_instructions(vs_asm_code);
|
|
|
|
uint32_t size = sizeof(uint64_t)*asm_sizes[1];
|
|
|
|
//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?
|
|
|
|
asm_ptrs[1] = (uint64_t*)malloc(size);
|
|
|
|
assemble_qpu_asm(vs_asm_code, asm_ptrs[1]);
|
|
|
|
assert(asm_ptrs[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ //assemble fs code
|
|
|
|
asm_sizes[2] = get_num_instructions(fs_asm_code);
|
|
|
|
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?
|
|
|
|
asm_ptrs[2] = (uint64_t*)malloc(size);
|
|
|
|
assemble_qpu_asm(fs_asm_code, asm_ptrs[2]);
|
|
|
|
assert(asm_ptrs[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
spirv[0] = 0x07230203;
|
|
|
|
spirv[1] = 0x00010000;
|
|
|
|
spirv[2] = 0x14E45250;
|
|
|
|
spirv[3] = 1;
|
|
|
|
spirv[4] = (uint32_t)&shaderModuleCreateInfo;
|
|
|
|
//words start here
|
|
|
|
spirv[5] = 1 << 16;
|
|
|
|
|
|
|
|
VkShaderModuleCreateInfo smci = {};
|
|
|
|
smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
|
|
|
smci.codeSize = sizeof(uint32_t)*6;
|
|
|
|
smci.pCode = spirv;
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCreateShaderModule)(device, &smci, 0, blitShaderModule);
|
2020-05-08 14:06:45 +02:00
|
|
|
assert(*blitShaderModule);
|
|
|
|
|
2020-05-10 20:03:36 +02:00
|
|
|
{ //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]);
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCreateShaderModule)(device, &smci, 0, blitShaderModuleNoColor);
|
2020-05-10 20:03:36 +02:00
|
|
|
assert(*blitShaderModuleNoColor);
|
|
|
|
|
2020-05-08 14:06:45 +02:00
|
|
|
for(uint32_t c = 0; c < 4; ++c)
|
|
|
|
{
|
|
|
|
free(asm_ptrs[c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void createClearPipeline(VkDevice device, VkPipelineDepthStencilStateCreateInfo* dsState, VkShaderModule blitShaderModule, VkDescriptorSetLayout blitDsl, VkPipelineLayout* blitPipelineLayout, VkRenderPass offscreenRenderPass, VkPipeline* blitPipeline)
|
|
|
|
{
|
|
|
|
VkVertexInputBindingDescription vertexInputBindingDescription =
|
|
|
|
{
|
|
|
|
0,
|
|
|
|
sizeof(float) * 2 * 2,
|
|
|
|
VK_VERTEX_INPUT_RATE_VERTEX
|
|
|
|
};
|
|
|
|
|
|
|
|
VkVertexInputAttributeDescription vertexInputAttributeDescription[2];
|
|
|
|
|
|
|
|
{
|
|
|
|
vertexInputAttributeDescription[0].binding = 0;
|
|
|
|
vertexInputAttributeDescription[0].location = 0;
|
|
|
|
vertexInputAttributeDescription[0].offset = 0;
|
|
|
|
vertexInputAttributeDescription[0].format = VK_FORMAT_R32G32_SFLOAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
|
|
|
|
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
|
|
|
vertexInputInfo.vertexAttributeDescriptionCount = 1;
|
|
|
|
vertexInputInfo.pVertexAttributeDescriptions = vertexInputAttributeDescription;
|
|
|
|
vertexInputInfo.vertexBindingDescriptionCount = 1;
|
|
|
|
vertexInputInfo.pVertexBindingDescriptions = &vertexInputBindingDescription;
|
|
|
|
|
|
|
|
VkPipelineInputAssemblyStateCreateInfo pipelineIACreateInfo = {};
|
|
|
|
pipelineIACreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
|
|
|
pipelineIACreateInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
|
|
|
|
|
|
|
VkPipelineRasterizationStateCreateInfo rastCreateInfo = {};
|
|
|
|
rastCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
|
|
|
rastCreateInfo.polygonMode = VK_POLYGON_MODE_FILL;
|
|
|
|
rastCreateInfo.cullMode = VK_CULL_MODE_NONE;
|
|
|
|
rastCreateInfo.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
|
|
|
rastCreateInfo.lineWidth = 1.0f;
|
|
|
|
|
|
|
|
VkPipelineMultisampleStateCreateInfo pipelineMSCreateInfo = {};
|
|
|
|
pipelineMSCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
|
|
|
|
|
|
|
VkPipelineColorBlendAttachmentState blendAttachState = {};
|
|
|
|
blendAttachState.colorWriteMask = 0xf;
|
|
|
|
blendAttachState.blendEnable = false;
|
|
|
|
|
|
|
|
VkPipelineColorBlendStateCreateInfo blendCreateInfo = {};
|
|
|
|
blendCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
|
|
|
blendCreateInfo.attachmentCount = 1;
|
|
|
|
blendCreateInfo.pAttachments = &blendAttachState;
|
|
|
|
|
|
|
|
//create blit pipeline
|
|
|
|
VkPushConstantRange pushConstantRanges[2];
|
|
|
|
pushConstantRanges[0].offset = 0;
|
|
|
|
pushConstantRanges[0].size = 4 * 4; //n * 32bits
|
|
|
|
pushConstantRanges[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
|
|
|
|
|
|
|
pushConstantRanges[1].offset = 0;
|
|
|
|
pushConstantRanges[1].size = 3 * 4; //n * 32bits
|
|
|
|
pushConstantRanges[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
|
|
|
|
|
|
|
VkPipelineShaderStageCreateInfo shaderStageCreateInfo[2] = {};
|
|
|
|
|
|
|
|
shaderStageCreateInfo[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
|
|
|
shaderStageCreateInfo[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
|
|
|
|
shaderStageCreateInfo[0].module = blitShaderModule;
|
|
|
|
shaderStageCreateInfo[0].pName = "main";
|
|
|
|
shaderStageCreateInfo[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
|
|
|
shaderStageCreateInfo[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
|
|
|
shaderStageCreateInfo[1].module = blitShaderModule;
|
|
|
|
shaderStageCreateInfo[1].pName = "main";
|
|
|
|
|
|
|
|
VkPipelineLayoutCreateInfo pipelineLayoutCI = {};
|
|
|
|
pipelineLayoutCI.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
|
|
|
pipelineLayoutCI.setLayoutCount = 1;
|
|
|
|
pipelineLayoutCI.pSetLayouts = &blitDsl;
|
|
|
|
pipelineLayoutCI.pushConstantRangeCount = 2;
|
|
|
|
pipelineLayoutCI.pPushConstantRanges = &pushConstantRanges[0];
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCreatePipelineLayout)(device, &pipelineLayoutCI, 0, blitPipelineLayout);
|
2020-05-08 14:06:45 +02:00
|
|
|
|
|
|
|
VkDynamicState dynState = VK_DYNAMIC_STATE_VIEWPORT;
|
|
|
|
|
|
|
|
VkPipelineDynamicStateCreateInfo pdsci = {};
|
|
|
|
pdsci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
|
|
|
pdsci.dynamicStateCount = 1;
|
|
|
|
pdsci.pDynamicStates = &dynState;
|
|
|
|
|
|
|
|
VkPipelineViewportStateCreateInfo pvsci = {};
|
|
|
|
pvsci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
|
|
|
pvsci.viewportCount = 0;
|
|
|
|
pvsci.scissorCount = 0;
|
|
|
|
|
|
|
|
VkGraphicsPipelineCreateInfo pipelineInfo = {};
|
|
|
|
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
|
|
|
pipelineInfo.stageCount = 2;
|
|
|
|
pipelineInfo.pStages = &shaderStageCreateInfo[0];
|
|
|
|
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
|
|
|
pipelineInfo.pInputAssemblyState = &pipelineIACreateInfo;
|
|
|
|
pipelineInfo.pViewportState = &pvsci;
|
|
|
|
pipelineInfo.pDynamicState = &pdsci;
|
|
|
|
pipelineInfo.pRasterizationState = &rastCreateInfo;
|
|
|
|
pipelineInfo.pMultisampleState = &pipelineMSCreateInfo;
|
|
|
|
pipelineInfo.pColorBlendState = &blendCreateInfo;
|
|
|
|
pipelineInfo.renderPass = offscreenRenderPass;
|
|
|
|
pipelineInfo.basePipelineIndex = -1;
|
|
|
|
pipelineInfo.pDepthStencilState = dsState;
|
|
|
|
pipelineInfo.layout = *blitPipelineLayout;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
VkResult res = RPIFUNC(vkCreateGraphicsPipelines)(device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, blitPipeline);
|
2020-05-08 14:06:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void createClearDescriptorSetLayouts(VkDevice device, VkDescriptorSetLayout* bufferDsl)
|
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
assert(bufferDsl);
|
|
|
|
|
|
|
|
VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = {};
|
|
|
|
descriptorLayoutCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
|
|
|
descriptorLayoutCI.bindingCount = 0;
|
|
|
|
descriptorLayoutCI.pBindings = 0;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCreateDescriptorSetLayout)(device, &descriptorLayoutCI, 0, bufferDsl);
|
2020-05-08 14:06:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setupClearEmulationResources(VkDevice device)
|
|
|
|
{
|
|
|
|
//create resources that won't change
|
|
|
|
_device* dev = device;
|
|
|
|
|
2020-05-10 20:03:36 +02:00
|
|
|
createClearShaderModule(device, &dev->emulClearShaderModule, &dev->emulClearNoColorShaderModule);
|
2020-05-08 14:06:45 +02:00
|
|
|
createClearDescriptorSetLayouts(device, &dev->emulClearDsl);
|
|
|
|
}
|
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetViewport
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
void RPIFUNC(vkCmdSetViewport)(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport* pViewports)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetViewport));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
assert(firstViewport == 0);
|
|
|
|
assert(viewportCount == 1);
|
|
|
|
assert(pViewports);
|
|
|
|
|
|
|
|
//only 1 viewport is supported
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
cb->viewport = pViewports[0];
|
|
|
|
|
|
|
|
cb->viewportDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetViewport));
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetScissor
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
void RPIFUNC(vkCmdSetScissor)(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D* pScissors)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetScissor));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
assert(firstScissor == 0);
|
|
|
|
assert(scissorCount == 1);
|
|
|
|
assert(pScissors);
|
|
|
|
|
|
|
|
//only 1 scissor supported
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
cb->scissor = pScissors[0];
|
|
|
|
|
|
|
|
cb->scissorDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetScissor));
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdBindVertexBuffers
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
void RPIFUNC(vkCmdBindVertexBuffers)(VkCommandBuffer commandBuffer, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdBindVertexBuffers));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
|
|
|
|
for(int c = 0; c < bindingCount; ++c)
|
|
|
|
{
|
|
|
|
cb->vertexBuffers[firstBinding + c] = pBuffers[c];
|
|
|
|
cb->vertexBufferOffsets[firstBinding + c] = pOffsets[c];
|
|
|
|
}
|
2018-10-21 14:33:02 +02:00
|
|
|
|
|
|
|
cb->vertexBufferDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdBindVertexBuffers));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdClearColorImage
|
|
|
|
* Color and depth/stencil images can be cleared outside a render pass instance using vkCmdClearColorImage or vkCmdClearDepthStencilImage, respectively.
|
|
|
|
* These commands are only allowed outside of a render pass instance.
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearColorImage)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkImage image,
|
|
|
|
VkImageLayout imageLayout,
|
|
|
|
const VkClearColorValue* pColor,
|
|
|
|
uint32_t rangeCount,
|
|
|
|
const VkImageSubresourceRange* pRanges)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdClearColorImage));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
assert(image);
|
|
|
|
assert(pColor);
|
|
|
|
|
|
|
|
//TODO this should only flag an image for clearing. This can only be called outside a renderpass
|
|
|
|
//actual clearing would only happen:
|
|
|
|
// -if image is rendered to (insert clear before first draw call)
|
|
|
|
// -if the image is bound for sampling (submit a CL with a clear)
|
|
|
|
// -if a command buffer is submitted without any rendering (insert clear)
|
|
|
|
// -etc.
|
|
|
|
//we shouldn't clear an image if noone uses it
|
|
|
|
|
|
|
|
//TODO ranges support
|
|
|
|
|
|
|
|
assert(imageLayout == VK_IMAGE_LAYOUT_GENERAL ||
|
|
|
|
imageLayout == VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR ||
|
|
|
|
imageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
|
|
|
|
assert(commandBuffer->state == CMDBUF_STATE_RECORDING);
|
|
|
|
assert(_queueFamilyProperties[commandBuffer->cp->queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT || _queueFamilyProperties[commandBuffer->cp->queueFamilyIndex].queueFlags & VK_QUEUE_COMPUTE_BIT);
|
|
|
|
|
|
|
|
_image* i = image;
|
|
|
|
|
|
|
|
assert(i->usageBits & VK_IMAGE_USAGE_TRANSFER_DST_BIT);
|
|
|
|
|
2019-09-02 23:37:42 +02:00
|
|
|
{ //Simplest case: just submit a job to clear the image
|
|
|
|
clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker));
|
2020-03-01 20:11:31 +01:00
|
|
|
clInsertNewCLMarker(&commandBuffer->binCl, &commandBuffer->handlesCl, &commandBuffer->shaderRecCl, commandBuffer->shaderRecCount, &commandBuffer->uniformsCl);
|
2020-05-16 14:17:03 +02:00
|
|
|
|
2020-05-16 23:31:07 +02:00
|
|
|
((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->writeImage = i;
|
2019-09-01 20:14:47 +02:00
|
|
|
|
2019-09-02 23:37:42 +02:00
|
|
|
//insert reloc for render target
|
|
|
|
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
|
2020-05-17 11:47:23 +02:00
|
|
|
clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->handlesBufOffset + commandBuffer->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->handlesSize, i->boundMem->bo);
|
2019-09-01 20:14:47 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-09-02 23:37:42 +02:00
|
|
|
//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.
|
2019-09-01 20:14:47 +02:00
|
|
|
clFit(commandBuffer, &commandBuffer->binCl, V3D21_INCREMENT_SEMAPHORE_length);
|
|
|
|
clInsertIncrementSemaphore(&commandBuffer->binCl);
|
|
|
|
clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLUSH_length);
|
|
|
|
clInsertFlush(&commandBuffer->binCl);
|
2019-09-02 23:37:42 +02:00
|
|
|
|
2020-05-16 23:31:07 +02:00
|
|
|
((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->clearColor[0] = ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->clearColor[1] = packVec4IntoABGR8(pColor->float32);
|
|
|
|
((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->flags |= VC4_SUBMIT_CL_USE_CLEAR_COLOR;
|
2020-03-11 21:42:46 +01:00
|
|
|
|
2020-05-16 23:31:07 +02:00
|
|
|
((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->width = i->width;
|
|
|
|
((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->height = i->height;
|
|
|
|
|
|
|
|
assert(((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->memGuard == 0xDDDDDDDD);
|
2019-09-01 20:14:47 +02:00
|
|
|
}
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdClearColorImage));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdClearDepthStencilImage
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearDepthStencilImage)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkImage image,
|
|
|
|
VkImageLayout imageLayout,
|
|
|
|
const VkClearDepthStencilValue* pDepthStencil,
|
|
|
|
uint32_t rangeCount,
|
|
|
|
const VkImageSubresourceRange* pRanges)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdClearDepthStencilImage));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
assert(image);
|
|
|
|
assert(pDepthStencil);
|
|
|
|
|
|
|
|
//TODO
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdClearDepthStencilImage));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdClearAttachments
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearAttachments)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
uint32_t attachmentCount,
|
|
|
|
const VkClearAttachment* pAttachments,
|
|
|
|
uint32_t rectCount,
|
|
|
|
const VkClearRect* pRects)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdClearAttachments));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
assert(pAttachments);
|
|
|
|
assert(pRects);
|
|
|
|
|
2020-05-08 14:06:45 +02:00
|
|
|
_commandBuffer* cmdBuf = commandBuffer;
|
|
|
|
_device* device = cmdBuf->dev;
|
|
|
|
|
|
|
|
if(!cmdBuf->currRenderPass)
|
|
|
|
{
|
|
|
|
//no active render pass
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdClearAttachments));
|
2020-05-08 14:06:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-10 20:03:36 +02:00
|
|
|
_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));
|
|
|
|
|
2020-05-08 14:06:45 +02:00
|
|
|
for(uint32_t c = 0; c < attachmentCount; ++c)
|
|
|
|
{
|
|
|
|
uint32_t clearColor = 0, clearDepth = 0, clearStencil = 0;
|
|
|
|
|
|
|
|
if(pAttachments[c].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT)
|
|
|
|
{
|
|
|
|
clearColor = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pAttachments[c].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT)
|
|
|
|
{
|
|
|
|
clearDepth = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pAttachments[c].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)
|
|
|
|
{
|
|
|
|
clearStencil = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkPipeline blitPipeline;
|
|
|
|
VkPipelineLayout blitPipelineLayout;
|
|
|
|
|
|
|
|
VkPipelineDepthStencilStateCreateInfo dsci = {};
|
|
|
|
dsci.depthCompareOp = VK_COMPARE_OP_ALWAYS;
|
|
|
|
dsci.depthTestEnable = 1;
|
|
|
|
dsci.depthWriteEnable = clearDepth;
|
|
|
|
dsci.minDepthBounds = 0.0f;
|
|
|
|
dsci.maxDepthBounds = 1.0f;
|
|
|
|
dsci.stencilTestEnable = clearStencil;
|
|
|
|
dsci.front.compareMask = 0xff;
|
|
|
|
dsci.front.writeMask = 0xff;
|
|
|
|
dsci.front.reference = pAttachments[c].clearValue.depthStencil.stencil;
|
|
|
|
dsci.front.depthFailOp = VK_STENCIL_OP_REPLACE;
|
|
|
|
dsci.front.failOp = VK_STENCIL_OP_REPLACE;
|
|
|
|
dsci.front.passOp = VK_STENCIL_OP_REPLACE;
|
|
|
|
dsci.back = dsci.front;
|
|
|
|
|
2020-05-10 20:03:36 +02:00
|
|
|
createClearPipeline(device, &dsci, clearColor ? device->emulClearShaderModule : device->emulClearNoColorShaderModule, device->emulClearDsl, &blitPipelineLayout, cmdBuf->currRenderPass, &blitPipeline);
|
2020-05-08 14:06:45 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCmdBindPipeline)(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, blitPipeline);
|
2020-05-08 14:06:45 +02:00
|
|
|
|
|
|
|
VkDeviceSize offsets = 0;
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCmdBindVertexBuffers)(commandBuffer, 0, 1, &device->emulFsqVertexBuffer, &offsets );
|
2020-05-08 14:06:45 +02:00
|
|
|
|
|
|
|
uint32_t clearColorValue = 0, stencilSetup = 0, depthClearValue = 0;
|
|
|
|
|
|
|
|
clearColorValue = packVec4IntoABGR8(&pAttachments[c].clearValue.color.float32[0]);
|
2020-05-10 20:03:36 +02:00
|
|
|
depthClearValue = (uint32_t)(pAttachments[c].clearValue.depthStencil.depth * 0xffffffu) & 0xffffffu;
|
2020-05-08 14:06:45 +02:00
|
|
|
uint32_t numValues = 1;
|
|
|
|
encodeStencilValue(&stencilSetup, &numValues, dsci.front, dsci.back, clearStencil);
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t fragConstants[3];
|
|
|
|
fragConstants[0] = clearColorValue;
|
|
|
|
fragConstants[1] = stencilSetup;
|
|
|
|
fragConstants[2] = depthClearValue;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCmdPushConstants)(commandBuffer, blitPipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragConstants), &fragConstants);
|
2020-05-08 14:06:45 +02:00
|
|
|
|
|
|
|
for(uint32_t d = 0; d < rectCount; ++d)
|
|
|
|
{
|
|
|
|
VkViewport vp = {};
|
|
|
|
vp.x = pRects[d].rect.offset.x;
|
|
|
|
vp.y = pRects[d].rect.offset.y;
|
|
|
|
vp.width = pRects[d].rect.extent.width;
|
|
|
|
vp.height = pRects[d].rect.extent.height;
|
|
|
|
vp.minDepth = 0.0f;
|
|
|
|
vp.maxDepth = 1.0f;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCmdSetViewport)(commandBuffer, 0, 1, &vp);
|
2020-05-08 14:06:45 +02:00
|
|
|
|
|
|
|
float Wcoeff = 1.0f; //1.0f / Wc = 2.0 - Wcoeff
|
|
|
|
float viewportScaleX = (float)(vp.width) * 0.5f * 16.0f;
|
|
|
|
float viewportScaleY = 1.0f * (float)(vp.height) * 0.5f * 16.0f;
|
|
|
|
float Zs = 1.0f;
|
|
|
|
|
|
|
|
uint32_t vertConstants[4];
|
|
|
|
vertConstants[0] = *(uint32_t*)&Wcoeff;
|
|
|
|
vertConstants[1] = *(uint32_t*)&viewportScaleX;
|
|
|
|
vertConstants[2] = *(uint32_t*)&viewportScaleY;
|
|
|
|
vertConstants[3] = *(uint32_t*)&Zs;
|
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCmdPushConstants)(commandBuffer, blitPipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(vertConstants), &vertConstants);
|
2020-05-08 14:06:45 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkCmdDraw)(commandBuffer, 6, 1, 0, 0);
|
2020-05-08 14:06:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//free up resources
|
2020-05-18 23:38:57 +02:00
|
|
|
RPIFUNC(vkDestroyPipelineLayout)(device, blitPipelineLayout, 0);
|
|
|
|
RPIFUNC(vkDestroyPipeline)(device, blitPipeline, 0);
|
2020-05-08 14:06:45 +02:00
|
|
|
}
|
2020-05-10 20:03:36 +02:00
|
|
|
|
|
|
|
//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));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdClearAttachments));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdFillBuffer
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdFillBuffer)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkBuffer dstBuffer,
|
|
|
|
VkDeviceSize dstOffset,
|
|
|
|
VkDeviceSize size,
|
|
|
|
uint32_t data)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdFillBuffer));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
//TODO
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdFillBuffer));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdUpdateBuffer
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdUpdateBuffer)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkBuffer dstBuffer,
|
|
|
|
VkDeviceSize dstOffset,
|
|
|
|
VkDeviceSize dataSize,
|
|
|
|
const void* pData)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdUpdateBuffer));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
//TODO
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdUpdateBuffer));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdBindIndexBuffer
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdBindIndexBuffer)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkBuffer buffer,
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkIndexType indexType)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdBindIndexBuffer));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2019-09-23 20:40:36 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
if(indexType == VK_INDEX_TYPE_UINT32)
|
|
|
|
{
|
|
|
|
UNSUPPORTED(VK_INDEX_TYPE_UINT32);
|
|
|
|
}
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
|
|
|
|
cb->indexBuffer = buffer;
|
|
|
|
cb->indexBufferOffset = offset;
|
|
|
|
|
|
|
|
cb->indexBufferDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdBindIndexBuffer));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetLineWidth
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdSetLineWidth)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
float lineWidth)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetLineWidth));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
cb->lineWidth = lineWidth;
|
|
|
|
|
|
|
|
cb->lineWidthDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetLineWidth));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetDepthBias
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdSetDepthBias)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
float depthBiasConstantFactor,
|
|
|
|
float depthBiasClamp,
|
|
|
|
float depthBiasSlopeFactor)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetDepthBias));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
cb->depthBiasConstantFactor = depthBiasConstantFactor;
|
|
|
|
cb->depthBiasClamp = depthBiasClamp;
|
|
|
|
cb->depthBiasSlopeFactor = depthBiasSlopeFactor;
|
|
|
|
|
|
|
|
cb->depthBiasDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetDepthBias));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetBlendConstants
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdSetBlendConstants)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
const float blendConstants[4])
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetBlendConstants));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
memcpy(cb->blendConstants, blendConstants, 4 * sizeof(float));
|
|
|
|
|
|
|
|
cb->blendConstantsDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetBlendConstants));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetDepthBounds
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdSetDepthBounds)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
float minDepthBounds,
|
|
|
|
float maxDepthBounds)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetDepthBounds));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
cb->minDepthBounds = minDepthBounds;
|
|
|
|
cb->maxDepthBounds = maxDepthBounds;
|
|
|
|
|
|
|
|
cb->depthBoundsDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetDepthBounds));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetStencilCompareMask
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdSetStencilCompareMask)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkStencilFaceFlags faceMask,
|
|
|
|
uint32_t compareMask)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetStencilCompareMask));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
|
|
|
|
if(faceMask & VK_STENCIL_FACE_FRONT_BIT)
|
|
|
|
{
|
|
|
|
cb->stencilCompareMask[0] = compareMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(faceMask & VK_STENCIL_FACE_BACK_BIT)
|
|
|
|
{
|
|
|
|
cb->stencilCompareMask[1] = compareMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb->stencilCompareMaskDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetStencilCompareMask));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetStencilWriteMask
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdSetStencilWriteMask)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkStencilFaceFlags faceMask,
|
|
|
|
uint32_t writeMask)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetStencilWriteMask));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
|
|
|
|
if(faceMask & VK_STENCIL_FACE_FRONT_BIT)
|
|
|
|
{
|
|
|
|
cb->stencilWriteMask[0] = writeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(faceMask & VK_STENCIL_FACE_BACK_BIT)
|
|
|
|
{
|
|
|
|
cb->stencilWriteMask[1] = writeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb->stencilWriteMaskDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetStencilWriteMask));
|
2018-10-21 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdSetStencilReference
|
|
|
|
*/
|
2020-05-18 23:38:57 +02:00
|
|
|
VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdSetStencilReference)(
|
2018-10-21 14:33:02 +02:00
|
|
|
VkCommandBuffer commandBuffer,
|
|
|
|
VkStencilFaceFlags faceMask,
|
|
|
|
uint32_t reference)
|
|
|
|
{
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILESTART(RPIFUNC(vkCmdSetStencilReference));
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2018-10-21 14:33:02 +02:00
|
|
|
assert(commandBuffer);
|
|
|
|
|
|
|
|
_commandBuffer* cb = commandBuffer;
|
|
|
|
|
|
|
|
if(faceMask & VK_STENCIL_FACE_FRONT_BIT)
|
|
|
|
{
|
|
|
|
cb->stencilReference[0] = reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(faceMask & VK_STENCIL_FACE_BACK_BIT)
|
|
|
|
{
|
|
|
|
cb->stencilReference[1] = reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb->stencilReferenceDirty = 1;
|
2020-05-18 20:39:33 +02:00
|
|
|
|
2020-05-18 23:38:57 +02:00
|
|
|
PROFILEEND(RPIFUNC(vkCmdSetStencilReference));
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|