1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2024-12-01 13:24:20 +01:00

cubemapping seems fully functional

This commit is contained in:
Unknown 2020-04-14 21:29:04 +01:00
parent cb60bade91
commit 715be8accd
2 changed files with 102 additions and 26 deletions

View File

@ -959,7 +959,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkCmdCopyBufferToImage(
fragConstants[0] = *(uint32_t*)&w;
fragConstants[1] = *(uint32_t*)&bppfloat;
fragConstants[2] = size;
fragConstants[3] = 0;
fragConstants[3] = pRegions[c].bufferOffset;
rpi_vkCmdPushConstants(commandBuffer, blitPipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragConstants), &fragConstants);

View File

@ -736,16 +736,18 @@ void recordCommandBuffers()
float viewportScaleX = (float)(swapChainExtent.width) * 0.5f * 16.0f;
float viewportScaleY = -1.0f * (float)(swapChainExtent.height) * 0.5f * 16.0f;
float Zs = 0.5f;
float Zo = 0.5f;
uint32_t pushConstants[4];
uint32_t pushConstants[5];
pushConstants[0] = *(uint32_t*)&Wcoeff;
pushConstants[1] = *(uint32_t*)&viewportScaleX;
pushConstants[2] = *(uint32_t*)&viewportScaleY;
pushConstants[3] = *(uint32_t*)&Zs;
pushConstants[4] = *(uint32_t*)&Zo;
vkCmdPushConstants(presentCommandBuffers[i], samplePipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(pushConstants), &pushConstants);
vkCmdDraw(presentCommandBuffers[i], 3, 1, 0, 0);
vkCmdDraw(presentCommandBuffers[i], 12*3, 1, 0, 0);
vkCmdEndRenderPass(presentCommandBuffers[i]);
}
@ -900,8 +902,8 @@ void CreateShaders()
///packed
///horizontal
///stride=1
///vectors to read = 2 (how many components)
"sig_load_imm ; vr_setup = load32.always(0x00201a00) ; nop = load32.always() ;\n"
///vectors to read = 3 (how many components)
"sig_load_imm ; vr_setup = load32.always(0x00301a00) ; nop = load32.always() ;\n"
///uni = viewportXScale
///r0 = vpm * uni
"sig_none ; nop = nop(r0, r0, vpm_read, uni) ; r0 = fmul.always(a, b) ;\n"
@ -911,9 +913,9 @@ void CreateShaders()
///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"
"sig_none ; r0 = or.always(a, a, vpm_read, rb0) ; r3 = fmul.always(r2, b) ;\n"
///ra0.16b = int(r3)
"sig_none ; rx0.16b = ftoi.always(r3, r3) ; nop = nop(r0, r0) ;\n"
"sig_none ; rx0.16b = ftoi.always(r3, r3, uni, nop) ; r0 = fmul.always(r0, a) ;\n"
///set up VPM write for subsequent writes
///0x00001a00: 0000 0000 0000 0000 0001 1010 0000 0000
///addr: 0
@ -928,7 +930,7 @@ void CreateShaders()
/// Zs
///uni = 0.5
///vpm = uni
"sig_none ; vpm = or.always(a, a, uni, nop) ; nop = nop(r0, r0);\n"
"sig_none ; vpm = fadd.always(r0, 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"
@ -942,7 +944,7 @@ void CreateShaders()
///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"
"sig_load_imm ; vr_setup = load32.always(0x00301a00) ; 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"
@ -958,24 +960,24 @@ void CreateShaders()
///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"
///r2 = vpm
"sig_none ; r2 = or.always(a, a, vpm_read, nop) ; 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"
"sig_none ; rx0.16b = ftoi.always(r1, r1) ; vpm = v8min.always(r2, r2) ;\n"
///write Wc
///vpm = 1.0
"sig_small_imm ; vpm = or.always(b, b, nop, 0x3f800000) ; nop = nop(r0, r0) ;\n"
///r2 = r2 * uni (0.5)
"sig_small_imm ; vpm = or.always(b, b, uni, 0x3f800000) ; r2 = fmul.always(r2, a) ;\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"
///vpm = r2
"sig_none ; vpm = fadd.always(r2, 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"
@ -998,11 +1000,22 @@ void CreateShaders()
"sig_load_imm ; r2 = load32.always(0x3a72b9d6) ; nop = load32() ;" //1/1080
"sig_none ; r0 = itof.always(a, a, x_pix, y_pix) ; r1 = fmul.always(r2, r0); ;" //r1 contains tex coord y
"sig_load_imm ; r2 = load32.always(0x3a088888) ; nop = load32() ;" //1/1920
"sig_none ; nop = nop(r0, r0) ; r0 = fmul.always(r2, r0) ;" //tex coord x [0...1]
"sig_small_imm ; r1 = fsub.always(b, r1, nop, 0x3f800000) ; nop = nop(r0, r0) ;" //tex coord y [0...1]
"sig_small_imm ; nop = nop(r0, r0, nop, 0x40000000) ; r0 = fmul.always(r0, b) ;" //r0 * 2
"sig_small_imm ; r0 = fsub.always(r0, b, nop, 0x3f800000) ; nop = nop(r0, r0) ;" //r0 - 1
"sig_small_imm ; nop = nop(r0, r0, nop, 0x40000000) ; r1 = fmul.always(r1, b) ;" //r1 * 2
"sig_small_imm ; r1 = fsub.always(r1, b, nop, 0x3f800000) ; nop = nop(r0, r0) ;" //r1 - 1
"sig_small_imm ; r2 = or.always(b, b, nop, 0xbf800000) ; nop = nop(r0, r0) ;"
///write texture addresses (x, y)
///writing tmu0_s signals that all coordinates are written
"sig_small_imm ; tmu0_r = or.always(b, b, nop, 0x3f800000) ; nop = nop(r0, r0) ;"
"sig_none ; tmu0_t = or.always(r1, r1) ; r0 = fmul.always(r2, r0) ;" //r0 contains tex coord x
"sig_none ; tmu0_s = or.always(r0, r0) ; nop = nop(r0, r0) ;"
"sig_none ; tmu0_r = or.always(r2, r2) ; nop = nop(r0, r0) ;" //tex coord z
"sig_none ; tmu0_t = or.always(r1, r1) ; nop = nop(r0, r0) ;" //tex coord y
"sig_none ; tmu0_s = or.always(r0, r0) ; nop = nop(r0, r0) ;" //tex coord x
///suspend thread (after 2 nops) to wait for TMU request to finish
"sig_thread_switch ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"
"sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"
@ -1064,6 +1077,15 @@ void CreateShaders()
12, //resource offset
VK_SHADER_STAGE_VERTEX_BIT
},
{
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT,
VK_DESCRIPTOR_TYPE_MAX_ENUM, //descriptor type
0, //descriptor set #
0, //descriptor binding #
0, //descriptor array element #
16, //resource offset
VK_SHADER_STAGE_VERTEX_BIT
},
//fragment shader uniforms
{
VK_RPI_ASSEMBLY_MAPPING_TYPE_DESCRIPTOR,
@ -1103,7 +1125,7 @@ void CreatePipeline()
VkVertexInputBindingDescription vertexInputBindingDescription =
{
0,
sizeof(float) * 2,
sizeof(float) * 3,
VK_VERTEX_INPUT_RATE_VERTEX
};
@ -1111,7 +1133,7 @@ void CreatePipeline()
{
0,
0,
VK_FORMAT_R32G32_SFLOAT,
VK_FORMAT_R32G32B32_SFLOAT,
0
};
@ -1165,7 +1187,7 @@ void CreatePipeline()
{ //create sample pipeline
VkPushConstantRange pushConstantRanges[2];
pushConstantRanges[0].offset = 0;
pushConstantRanges[0].size = 4 * 4; //4 * 32bits
pushConstantRanges[0].size = 5 * 4; //4 * 32bits
pushConstantRanges[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
pushConstantRanges[1].offset = 0;
@ -1495,7 +1517,7 @@ void CreateVertexBuffer()
VkMemoryRequirements mr;
{ //create triangle vertex buffer
unsigned vboSize = sizeof(float) * 1 * 3 * 2; //1 * 3 x vec2
unsigned vboSize = sizeof(float) * 12 * 3 * 3; //12 * 3 x vec3
VkBufferCreateInfo ci = {};
ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@ -1515,11 +1537,65 @@ void CreateVertexBuffer()
float vertices[] =
{
-1, -1,
1, -1,
0, 1
-1, -1, -1,
1, -1, -1,
-1, 1, -1,
-1, 1, -1,
1, 1, -1,
1, -1, -1,
1, -1, -1,
1, 1, -1,
1, -1, 1,
1, -1, 1,
1, 1, -1,
1, 1, 1,
1, 1, 1,
1, 1, -1,
-1, 1, -1,
-1, 1, -1,
1, 1, 1,
-1, 1, 1,
-1, 1, 1,
-1, -1, -1,
-1, 1, -1,
-1, -1, -1,
-1, 1, 1,
-1, -1, 1,
-1, 1, 1,
1, 1, 1,
1, -1, 1,
1, -1, 1,
-1, -1, 1,
-1, 1, 1,
-1, -1, -1,
1, -1, -1,
1, -1, 1,
1, -1, 1,
-1, -1, 1,
-1, -1, -1,
};
//transform our cube
// for(uint32_t c = 0; c < 12 * 3 * 3; c+=3)
// {
// vertices[c+0] *= 0.25f;
// vertices[c+1] *= 0.25f;
// vertices[c+2] *= 0.25f;
// vertices[c+2] -= 0.5f;
// }
void* data;
res = vkMapMemory(device, triangleVertexBufferMemory, 0, mr.size, 0, &data);
memcpy(data, vertices, vboSize);