|
@@ -121,8 +121,6 @@ namespace love {
|
|
|
|
|
|
endRecordingGraphicsCommands();
|
|
endRecordingGraphicsCommands();
|
|
|
|
|
|
- prepareDraw(currentFrame);
|
|
|
|
-
|
|
|
|
if (imagesInFlight[imageIndex] != VK_NULL_HANDLE) {
|
|
if (imagesInFlight[imageIndex] != VK_NULL_HANDLE) {
|
|
vkWaitForFences(device, 1, &imagesInFlight.at(imageIndex), VK_TRUE, UINT64_MAX);
|
|
vkWaitForFences(device, 1, &imagesInFlight.at(imageIndex), VK_TRUE, UINT64_MAX);
|
|
}
|
|
}
|
|
@@ -209,7 +207,6 @@ namespace love {
|
|
createFramebuffers();
|
|
createFramebuffers();
|
|
createCommandPool();
|
|
createCommandPool();
|
|
createCommandBuffers();
|
|
createCommandBuffers();
|
|
- createUniformBuffers();
|
|
|
|
createDefaultTexture();
|
|
createDefaultTexture();
|
|
createQuadIndexBuffer();
|
|
createQuadIndexBuffer();
|
|
createDescriptorPool();
|
|
createDescriptorPool();
|
|
@@ -333,12 +330,42 @@ namespace love {
|
|
|
|
|
|
ensureGraphicsPipelineConfiguration(configuration);
|
|
ensureGraphicsPipelineConfiguration(configuration);
|
|
|
|
|
|
- vkCmdBindDescriptorSets(commandBuffers.at(imageIndex), VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, getDescriptorSet(currentFrame), 0, nullptr);
|
|
|
|
|
|
+ auto descriptorSets = getDescriptorSet(currentFrame);
|
|
|
|
+ auto descriptorSet = *descriptorSets;
|
|
|
|
+ vkCmdBindDescriptorSets(commandBuffers.at(imageIndex), VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, descriptorSets, 0, nullptr);
|
|
vkCmdBindVertexBuffers(commandBuffers.at(imageIndex), 0, buffers.size(), buffers.data(), offsets.data());
|
|
vkCmdBindVertexBuffers(commandBuffers.at(imageIndex), 0, buffers.size(), buffers.data(), offsets.data());
|
|
vkCmdBindIndexBuffer(commandBuffers.at(imageIndex), (VkBuffer)cmd.indexBuffer->getHandle(), 0, getVulkanIndexBufferType(cmd.indexType));
|
|
vkCmdBindIndexBuffer(commandBuffers.at(imageIndex), (VkBuffer)cmd.indexBuffer->getHandle(), 0, getVulkanIndexBufferType(cmd.indexType));
|
|
vkCmdDrawIndexed(commandBuffers.at(imageIndex), static_cast<uint32_t>(cmd.indexCount), 1, 0, 0, 0);
|
|
vkCmdDrawIndexed(commandBuffers.at(imageIndex), static_cast<uint32_t>(cmd.indexCount), 1, 0, 0, 0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ PixelFormat Graphics::getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const {
|
|
|
|
+ std::cout << "getSizedFormat ";
|
|
|
|
+
|
|
|
|
+ switch (format) {
|
|
|
|
+ PIXELFORMAT_NORMAL:
|
|
|
|
+ if (isGammaCorrect()) {
|
|
|
|
+ return PIXELFORMAT_RGBA8_UNORM_sRGB;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return PIXELFORMAT_RGBA8_UNORM;
|
|
|
|
+ }
|
|
|
|
+ case PIXELFORMAT_HDR:
|
|
|
|
+ return PIXELFORMAT_RGBA16_FLOAT;
|
|
|
|
+ default:
|
|
|
|
+ return format;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRGB) {
|
|
|
|
+ std::cout << "isPixelFormatSupported ";
|
|
|
|
+ switch (format) {
|
|
|
|
+ case PIXELFORMAT_LA8_UNORM:
|
|
|
|
+ return false;
|
|
|
|
+ default:
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
void Graphics::drawQuads(int start, int count, const VertexAttributes& attributes, const BufferBindings& buffers, graphics::Texture* texture) {
|
|
void Graphics::drawQuads(int start, int count, const VertexAttributes& attributes, const BufferBindings& buffers, graphics::Texture* texture) {
|
|
std::cout << "drawQuads ";
|
|
std::cout << "drawQuads ";
|
|
|
|
|
|
@@ -416,12 +443,29 @@ namespace love {
|
|
}
|
|
}
|
|
|
|
|
|
VkDescriptorSet* Graphics::getDescriptorSet(int currentFrame) {
|
|
VkDescriptorSet* Graphics::getDescriptorSet(int currentFrame) {
|
|
- auto it = textureToDescriptorSetsMap.find(currentTexture);
|
|
|
|
- if (it == textureToDescriptorSetsMap.end()) {
|
|
|
|
- textureToDescriptorSetsMap[currentTexture] = createDescriptorSets(currentTexture);
|
|
|
|
|
|
+ DecriptorSetConfiguration config;
|
|
|
|
+ config.texture = currentTexture;
|
|
|
|
+ config.buffer = getUniformBuffer();
|
|
|
|
+ for (auto i = 0; i < descriptorSetsMap.size(); i++) {
|
|
|
|
+ if (descriptorSetsMap[i].first == config) {
|
|
|
|
+ return &descriptorSetsMap[i].second[currentFrame];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ auto descriptorSets = createDescriptorSets(config);
|
|
|
|
+ descriptorSetsMap.push_back(std::make_pair(config, descriptorSets));
|
|
|
|
+ return &descriptorSetsMap.back().second[currentFrame];
|
|
|
|
+ }
|
|
|
|
|
|
- return &textureToDescriptorSetsMap.at(currentTexture)[currentFrame];
|
|
|
|
|
|
+ graphics::StreamBuffer* Graphics::getUniformBuffer() {
|
|
|
|
+ auto data = getCurrentBuiltinUniformData();
|
|
|
|
+ for (auto it : uniformBufferMap) {
|
|
|
|
+ if (it.first == data) {
|
|
|
|
+ return it.second;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ auto buffer = createUniformBufferFromData(data);
|
|
|
|
+ uniformBufferMap.push_back(std::make_pair(data, buffer));
|
|
|
|
+ return buffer;
|
|
}
|
|
}
|
|
|
|
|
|
VkCommandBuffer Graphics::beginSingleTimeCommands() {
|
|
VkCommandBuffer Graphics::beginSingleTimeCommands() {
|
|
@@ -456,9 +500,7 @@ namespace love {
|
|
vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer);
|
|
vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer);
|
|
}
|
|
}
|
|
|
|
|
|
- void Graphics::prepareDraw(uint32_t currentImage) {
|
|
|
|
- auto& buffer = uniformBuffers.at(currentImage);
|
|
|
|
-
|
|
|
|
|
|
+ graphics::Shader::BuiltinUniformData Graphics::getCurrentBuiltinUniformData() {
|
|
love::graphics::Shader::BuiltinUniformData data;
|
|
love::graphics::Shader::BuiltinUniformData data;
|
|
|
|
|
|
data.transformMatrix = getTransform();
|
|
data.transformMatrix = getTransform();
|
|
@@ -493,9 +535,16 @@ namespace love {
|
|
data.constantColor = getColor();
|
|
data.constantColor = getColor();
|
|
gammaCorrectColor(data.constantColor);
|
|
gammaCorrectColor(data.constantColor);
|
|
|
|
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ graphics::StreamBuffer* Graphics::createUniformBufferFromData(graphics::Shader::BuiltinUniformData data) {
|
|
|
|
+ auto buffer = newStreamBuffer(BUFFERUSAGE_UNIFORM, sizeof(data));
|
|
auto mappedInfo = buffer->map(0);
|
|
auto mappedInfo = buffer->map(0);
|
|
memcpy(mappedInfo.data, &data, sizeof(data));
|
|
memcpy(mappedInfo.data, &data, sizeof(data));
|
|
buffer->unmap(0);
|
|
buffer->unmap(0);
|
|
|
|
+
|
|
|
|
+ return buffer;
|
|
}
|
|
}
|
|
|
|
|
|
void Graphics::createVulkanInstance() {
|
|
void Graphics::createVulkanInstance() {
|
|
@@ -997,14 +1046,6 @@ namespace love {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- void Graphics::createUniformBuffers() {
|
|
|
|
- VkDeviceSize bufferSize = sizeof(graphics::Shader::BuiltinUniformData);
|
|
|
|
-
|
|
|
|
- for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
|
|
- uniformBuffers.push_back(std::make_unique<StreamBuffer>(vmaAllocator, BUFFERUSAGE_UNIFORM, bufferSize));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void Graphics::createDescriptorPool() {
|
|
void Graphics::createDescriptorPool() {
|
|
std::array<VkDescriptorPoolSize, 2> poolSizes{};
|
|
std::array<VkDescriptorPoolSize, 2> poolSizes{};
|
|
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
|
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
|
@@ -1026,7 +1067,7 @@ namespace love {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- std::vector<VkDescriptorSet> Graphics::createDescriptorSets(graphics::Texture* texture) {
|
|
|
|
|
|
+ std::vector<VkDescriptorSet> Graphics::createDescriptorSets(DecriptorSetConfiguration config) {
|
|
std::vector<VkDescriptorSetLayout> layouts(MAX_FRAMES_IN_FLIGHT, descriptorSetLayout);
|
|
std::vector<VkDescriptorSetLayout> layouts(MAX_FRAMES_IN_FLIGHT, descriptorSetLayout);
|
|
VkDescriptorSetAllocateInfo allocInfo{};
|
|
VkDescriptorSetAllocateInfo allocInfo{};
|
|
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
@@ -1055,13 +1096,13 @@ namespace love {
|
|
|
|
|
|
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
VkDescriptorBufferInfo bufferInfo{};
|
|
VkDescriptorBufferInfo bufferInfo{};
|
|
- bufferInfo.buffer = (VkBuffer)uniformBuffers.at(i)->getHandle();
|
|
|
|
|
|
+ bufferInfo.buffer = (VkBuffer)config.buffer->getHandle();
|
|
bufferInfo.offset = 0;
|
|
bufferInfo.offset = 0;
|
|
bufferInfo.range = sizeof(graphics::Shader::BuiltinUniformData);
|
|
bufferInfo.range = sizeof(graphics::Shader::BuiltinUniformData);
|
|
|
|
|
|
VkDescriptorImageInfo imageInfo{};
|
|
VkDescriptorImageInfo imageInfo{};
|
|
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
- Texture* vkTexture = (Texture*)texture;
|
|
|
|
|
|
+ Texture* vkTexture = (Texture*)config.texture;
|
|
imageInfo.imageView = vkTexture->getImageView();
|
|
imageInfo.imageView = vkTexture->getImageView();
|
|
imageInfo.sampler = vkTexture->getSampler();
|
|
imageInfo.sampler = vkTexture->getSampler();
|
|
|
|
|
|
@@ -1448,8 +1489,8 @@ namespace love {
|
|
vkDestroyImageView(device, swapChainImageViews[i], nullptr);
|
|
vkDestroyImageView(device, swapChainImageViews[i], nullptr);
|
|
}
|
|
}
|
|
vkDestroySwapchainKHR(device, swapChain, nullptr);
|
|
vkDestroySwapchainKHR(device, swapChain, nullptr);
|
|
- uniformBuffers.clear();
|
|
|
|
- textureToDescriptorSetsMap.clear();
|
|
|
|
|
|
+ uniformBufferMap.clear();
|
|
|
|
+ descriptorSetsMap.clear();
|
|
}
|
|
}
|
|
|
|
|
|
void Graphics::recreateSwapChain() {
|
|
void Graphics::recreateSwapChain() {
|
|
@@ -1461,7 +1502,6 @@ namespace love {
|
|
createImageViews();
|
|
createImageViews();
|
|
createRenderPass();
|
|
createRenderPass();
|
|
createFramebuffers();
|
|
createFramebuffers();
|
|
- createUniformBuffers();
|
|
|
|
createDescriptorPool();
|
|
createDescriptorPool();
|
|
createCommandBuffers();
|
|
createCommandBuffers();
|
|
startRecordingGraphicsCommands();
|
|
startRecordingGraphicsCommands();
|