WIP: Vulkan: Workbench #107886
|
@ -423,8 +423,8 @@ void VKFrameBuffer::render_pass_create()
|
||||||
attachment_description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachment_description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachment_description.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
|
attachment_description.initialLayout = texture.current_layout_get();
|
||||||
attachment_description.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
|
attachment_description.finalLayout = texture.current_layout_get();
|
||||||
|
|
||||||
/* Create the attachment reference. */
|
/* Create the attachment reference. */
|
||||||
const bool is_depth_attachment = ELEM(
|
const bool is_depth_attachment = ELEM(
|
||||||
|
|
|
@ -177,7 +177,8 @@ void VKPipeline::finalize(VKContext &context,
|
||||||
pipeline_create_info.pMultisampleState = &multisample_state;
|
pipeline_create_info.pMultisampleState = &multisample_state;
|
||||||
|
|
||||||
/* States from the state manager. */
|
/* States from the state manager. */
|
||||||
const VKPipelineStateManager &state_manager = state_manager_get();
|
VKPipelineStateManager &state_manager = state_manager_get();
|
||||||
|
state_manager.finalize_color_blend_state(framebuffer);
|
||||||
pipeline_create_info.pColorBlendState = &state_manager.pipeline_color_blend_state;
|
pipeline_create_info.pColorBlendState = &state_manager.pipeline_color_blend_state;
|
||||||
pipeline_create_info.pRasterizationState = &state_manager.rasterization_state;
|
pipeline_create_info.pRasterizationState = &state_manager.rasterization_state;
|
||||||
pipeline_create_info.pDepthStencilState = &state_manager.depth_stencil_state;
|
pipeline_create_info.pDepthStencilState = &state_manager.depth_stencil_state;
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vk_pipeline_state.hh"
|
#include "vk_pipeline_state.hh"
|
||||||
|
#include "vk_framebuffer.hh"
|
||||||
|
#include "vk_texture.hh"
|
||||||
|
|
||||||
namespace blender::gpu {
|
namespace blender::gpu {
|
||||||
VKPipelineStateManager::VKPipelineStateManager()
|
VKPipelineStateManager::VKPipelineStateManager()
|
||||||
|
@ -22,12 +24,12 @@ VKPipelineStateManager::VKPipelineStateManager()
|
||||||
|
|
||||||
/* TODO should be extracted from current framebuffer and should not be done here and now. */
|
/* TODO should be extracted from current framebuffer and should not be done here and now. */
|
||||||
/* When the attachments differ the state should be forced. */
|
/* When the attachments differ the state should be forced. */
|
||||||
VkPipelineColorBlendAttachmentState color_blend_attachment = {};
|
color_blend_attachment_template = {};
|
||||||
color_blend_attachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
|
color_blend_attachment_template.colorWriteMask = VK_COLOR_COMPONENT_R_BIT |
|
||||||
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
VK_COLOR_COMPONENT_G_BIT |
|
||||||
color_blend_attachments.append(color_blend_attachment);
|
VK_COLOR_COMPONENT_B_BIT |
|
||||||
pipeline_color_blend_state.attachmentCount = color_blend_attachments.size();
|
VK_COLOR_COMPONENT_A_BIT;
|
||||||
pipeline_color_blend_state.pAttachments = color_blend_attachments.data();
|
color_blend_attachment_int_template = color_blend_attachment_template;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKPipelineStateManager::set_state(const GPUState &state, const GPUStateMutable &mutable_state)
|
void VKPipelineStateManager::set_state(const GPUState &state, const GPUStateMutable &mutable_state)
|
||||||
|
@ -74,10 +76,34 @@ void VKPipelineStateManager::force_state(const GPUState &state,
|
||||||
set_state(state, mutable_state);
|
set_state(state, mutable_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VKPipelineStateManager::finalize_color_blend_state(const VKFrameBuffer &framebuffer)
|
||||||
|
{
|
||||||
|
color_blend_attachments.clear();
|
||||||
|
|
||||||
|
for (int color_slot = 0; color_slot < GPU_FB_MAX_COLOR_ATTACHMENT; color_slot++) {
|
||||||
|
VKTexture *texture = unwrap(unwrap(framebuffer.color_tex(color_slot)));
|
||||||
|
if (texture) {
|
||||||
|
eGPUTextureFormatFlag format_flag = texture->format_flag_get();
|
||||||
|
if (format_flag & GPU_FORMAT_INTEGER) {
|
||||||
|
color_blend_attachments.append(color_blend_attachment_int_template);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
color_blend_attachments.append(color_blend_attachment_template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
color_blend_attachments.append(color_blend_attachment_template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline_color_blend_state.attachmentCount = color_blend_attachments.size();
|
||||||
|
pipeline_color_blend_state.pAttachments = color_blend_attachments.data();
|
||||||
|
}
|
||||||
|
|
||||||
void VKPipelineStateManager::set_blend(const eGPUBlend blend)
|
void VKPipelineStateManager::set_blend(const eGPUBlend blend)
|
||||||
{
|
{
|
||||||
VkPipelineColorBlendStateCreateInfo &cb = pipeline_color_blend_state;
|
VkPipelineColorBlendStateCreateInfo &cb = pipeline_color_blend_state;
|
||||||
VkPipelineColorBlendAttachmentState &att_state = color_blend_attachments.last();
|
VkPipelineColorBlendAttachmentState &att_state = color_blend_attachment_template;
|
||||||
|
|
||||||
att_state.blendEnable = VK_TRUE;
|
att_state.blendEnable = VK_TRUE;
|
||||||
att_state.alphaBlendOp = VK_BLEND_OP_ADD;
|
att_state.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||||
|
@ -186,20 +212,19 @@ void VKPipelineStateManager::set_write_mask(const eGPUWriteMask write_mask)
|
||||||
{
|
{
|
||||||
depth_stencil_state.depthWriteEnable = (write_mask & GPU_WRITE_DEPTH) ? VK_TRUE : VK_FALSE;
|
depth_stencil_state.depthWriteEnable = (write_mask & GPU_WRITE_DEPTH) ? VK_TRUE : VK_FALSE;
|
||||||
|
|
||||||
VkPipelineColorBlendAttachmentState &att_state = color_blend_attachments.last();
|
color_blend_attachment_template.colorWriteMask = 0;
|
||||||
att_state.colorWriteMask = 0;
|
|
||||||
|
|
||||||
if ((write_mask & GPU_WRITE_RED) != 0) {
|
if ((write_mask & GPU_WRITE_RED) != 0) {
|
||||||
att_state.colorWriteMask |= VK_COLOR_COMPONENT_R_BIT;
|
color_blend_attachment_template.colorWriteMask |= VK_COLOR_COMPONENT_R_BIT;
|
||||||
}
|
}
|
||||||
if ((write_mask & GPU_WRITE_GREEN) != 0) {
|
if ((write_mask & GPU_WRITE_GREEN) != 0) {
|
||||||
att_state.colorWriteMask |= VK_COLOR_COMPONENT_G_BIT;
|
color_blend_attachment_template.colorWriteMask |= VK_COLOR_COMPONENT_G_BIT;
|
||||||
}
|
}
|
||||||
if ((write_mask & GPU_WRITE_BLUE) != 0) {
|
if ((write_mask & GPU_WRITE_BLUE) != 0) {
|
||||||
att_state.colorWriteMask |= VK_COLOR_COMPONENT_B_BIT;
|
color_blend_attachment_template.colorWriteMask |= VK_COLOR_COMPONENT_B_BIT;
|
||||||
}
|
}
|
||||||
if ((write_mask & GPU_WRITE_ALPHA) != 0) {
|
if ((write_mask & GPU_WRITE_ALPHA) != 0) {
|
||||||
att_state.colorWriteMask |= VK_COLOR_COMPONENT_A_BIT;
|
color_blend_attachment_template.colorWriteMask |= VK_COLOR_COMPONENT_A_BIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,21 @@
|
||||||
#include "BLI_vector.hh"
|
#include "BLI_vector.hh"
|
||||||
|
|
||||||
namespace blender::gpu {
|
namespace blender::gpu {
|
||||||
|
class VKFrameBuffer;
|
||||||
|
|
||||||
class VKPipelineStateManager {
|
class VKPipelineStateManager {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GPUState current_;
|
GPUState current_;
|
||||||
GPUStateMutable current_mutable_;
|
GPUStateMutable current_mutable_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VkPipelineColorBlendStateCreateInfo pipeline_color_blend_state;
|
VkPipelineColorBlendStateCreateInfo pipeline_color_blend_state;
|
||||||
|
/* Template of the color blending for color attachments.
|
||||||
|
* Blending is not supported on Integer based textures.
|
||||||
|
*/
|
||||||
|
VkPipelineColorBlendAttachmentState color_blend_attachment_template;
|
||||||
|
VkPipelineColorBlendAttachmentState color_blend_attachment_int_template;
|
||||||
Vector<VkPipelineColorBlendAttachmentState> color_blend_attachments;
|
Vector<VkPipelineColorBlendAttachmentState> color_blend_attachments;
|
||||||
VkPipelineRasterizationStateCreateInfo rasterization_state;
|
VkPipelineRasterizationStateCreateInfo rasterization_state;
|
||||||
VkPipelineDepthStencilStateCreateInfo depth_stencil_state;
|
VkPipelineDepthStencilStateCreateInfo depth_stencil_state;
|
||||||
|
@ -29,6 +36,8 @@ class VKPipelineStateManager {
|
||||||
void set_state(const GPUState &state, const GPUStateMutable &mutable_state);
|
void set_state(const GPUState &state, const GPUStateMutable &mutable_state);
|
||||||
void force_state(const GPUState &state, const GPUStateMutable &mutable_state);
|
void force_state(const GPUState &state, const GPUStateMutable &mutable_state);
|
||||||
|
|
||||||
|
void finalize_color_blend_state(const VKFrameBuffer &framebuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set_blend(eGPUBlend blend);
|
void set_blend(eGPUBlend blend);
|
||||||
void set_write_mask(eGPUWriteMask write_mask);
|
void set_write_mask(eGPUWriteMask write_mask);
|
||||||
|
|
Loading…
Reference in New Issue