redo MTLRenderPassDescriptor creation
This commit is contained in:
@@ -13,7 +13,7 @@ void metelBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!wasDepthStencil) {
|
if(!wasDepthStencil) {
|
||||||
MTLRenderPassColorAttachmentDescriptor* color = passInfo.framebuffer->framebuffer->framebuffer.colorAttachments[i];
|
MTLRenderPassColorAttachmentDescriptor* color = passInfo.framebuffer->framebuffer->subpasses[i].colorAttachments[i];
|
||||||
color.clearColor = MTLClearColorMake(
|
color.clearColor = MTLClearColorMake(
|
||||||
passInfo.clearValues[i].red,
|
passInfo.clearValues[i].red,
|
||||||
passInfo.clearValues[i].green,
|
passInfo.clearValues[i].green,
|
||||||
@@ -22,7 +22,7 @@ void metelBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer->commandBuffer->encoder = [buffer->commandBuffer->commandBuffer renderCommandEncoderWithDescriptor:passInfo.framebuffer->framebuffer->framebuffer];
|
buffer->commandBuffer->encoder = [buffer->commandBuffer->commandBuffer renderCommandEncoderWithDescriptor:passInfo.framebuffer->framebuffer->subpasses[0]];
|
||||||
MTLViewport vp = {(double)passInfo.offset.x, (double)passInfo.offset.y, (double)passInfo.size.x, (double)passInfo.size.y, 0.0f, 1.0f};
|
MTLViewport vp = {(double)passInfo.offset.x, (double)passInfo.offset.y, (double)passInfo.size.x, (double)passInfo.size.y, 0.0f, 1.0f};
|
||||||
id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder;
|
id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder;
|
||||||
[encoder setViewport:vp];
|
[encoder setViewport:vp];
|
||||||
|
@@ -2,11 +2,15 @@
|
|||||||
#include "framebuffer/gryphn_framebuffer.h"
|
#include "framebuffer/gryphn_framebuffer.h"
|
||||||
#include "utils/gryphn_bool.h"
|
#include "utils/gryphn_bool.h"
|
||||||
#include "utils/gryphn_image_format.h"
|
#include "utils/gryphn_image_format.h"
|
||||||
|
#include "utils/lists/gryphn_array_list.h"
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
#import <Metal/MTLRenderPass.h>
|
#import <Metal/MTLRenderPass.h>
|
||||||
|
|
||||||
|
typedef MTLRenderPassDescriptor* mtlSubpass;
|
||||||
|
|
||||||
typedef struct gnPlatformFramebuffer_t {
|
typedef struct gnPlatformFramebuffer_t {
|
||||||
MTLRenderPassDescriptor* framebuffer;
|
uint32_t subpassCount;
|
||||||
|
mtlSubpass* subpasses;
|
||||||
} gnPlatformFramebuffer;
|
} gnPlatformFramebuffer;
|
||||||
|
|
||||||
gnBool isDepthFormat(gnImageFormat format);
|
gnBool isDepthFormat(gnImageFormat format);
|
||||||
|
@@ -37,38 +37,36 @@ gnReturnCode createMetalFramebuffer(gnFramebuffer framebuffer, gnOutputDevice de
|
|||||||
return GN_DIVERGENT_RENDERPASS;
|
return GN_DIVERGENT_RENDERPASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
framebuffer->framebuffer->framebuffer = [[MTLRenderPassDescriptor alloc] init];
|
framebuffer->framebuffer->subpassCount = info.renderPassDescriptor->info.subpassCount;
|
||||||
[framebuffer->framebuffer->framebuffer setRenderTargetWidth:info.size.x];
|
framebuffer->framebuffer->subpasses = malloc(sizeof(mtlSubpass) * framebuffer->framebuffer->subpassCount);
|
||||||
[framebuffer->framebuffer->framebuffer setRenderTargetHeight:info.size.y];
|
|
||||||
|
|
||||||
int colorAttachment = 0;
|
for (int i = 0; i < info.renderPassDescriptor->info.subpassCount; i++) {
|
||||||
for (int i = 0; i < info.renderPassDescriptor->info.attachmentCount; i++) {
|
framebuffer->framebuffer->subpasses[i] = [[MTLRenderPassDescriptor alloc] init];
|
||||||
gnBool wasDepthStencil = gnFalse;
|
[framebuffer->framebuffer->subpasses[i] setRenderTargetWidth:info.size.x];
|
||||||
if (isDepthFormat(info.renderPassDescriptor->info.attachmentInfos[i].format)) {
|
[framebuffer->framebuffer->subpasses[i] setRenderTargetHeight:info.size.y];
|
||||||
MTLRenderPassDepthAttachmentDescriptor* depthAttachment = framebuffer->framebuffer->framebuffer.depthAttachment;
|
|
||||||
depthAttachment.texture = info.attachments[i]->texture->texture;
|
|
||||||
depthAttachment.loadAction = mtlGryphnLoadOperation(info.renderPassDescriptor->info.attachmentInfos[i].loadOperation);
|
|
||||||
depthAttachment.storeAction = mtlGryphnStoreOperation(info.renderPassDescriptor->info.attachmentInfos[i].storeOperation);
|
|
||||||
depthAttachment.clearDepth = 1.0f;
|
|
||||||
wasDepthStencil = gnTrue;
|
|
||||||
}
|
|
||||||
if (isStencilFormat(info.renderPassDescriptor->info.attachmentInfos[i].format)) {
|
|
||||||
MTLRenderPassStencilAttachmentDescriptor* stencilAttachment = framebuffer->framebuffer->framebuffer.stencilAttachment;
|
|
||||||
stencilAttachment.texture = info.attachments[i]->texture->texture;
|
|
||||||
wasDepthStencil = gnTrue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!wasDepthStencil) {
|
for (int c = 0; c < info.renderPassDescriptor->info.subpassInfos[i].colorAttachmentCount; c++) {
|
||||||
MTLRenderPassColorAttachmentDescriptor* color = framebuffer->framebuffer->framebuffer.colorAttachments[colorAttachment];
|
uint32_t attachmentIndex = info.renderPassDescriptor->info.subpassInfos[i].colorAttachments[i].index;
|
||||||
color.texture = info.attachments[i]->texture->texture;
|
MTLRenderPassColorAttachmentDescriptor* color = framebuffer->framebuffer->subpasses[i].colorAttachments[c];
|
||||||
|
color.texture = info.attachments[attachmentIndex]->texture->texture;
|
||||||
|
|
||||||
color.loadAction = mtlGryphnLoadOperation(info.renderPassDescriptor->info.attachmentInfos[i].loadOperation);
|
color.loadAction = mtlGryphnLoadOperation(info.renderPassDescriptor->info.attachmentInfos[attachmentIndex].loadOperation);
|
||||||
color.storeAction = mtlGryphnStoreOperation(info.renderPassDescriptor->info.attachmentInfos[i].storeOperation);
|
color.storeAction = mtlGryphnStoreOperation(info.renderPassDescriptor->info.attachmentInfos[attachmentIndex].storeOperation);
|
||||||
|
|
||||||
if (color.loadAction == MTLLoadActionClear)
|
if (color.loadAction == MTLLoadActionClear)
|
||||||
color.clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0);
|
color.clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
colorAttachment++;
|
if (info.renderPassDescriptor->info.subpassInfos[i].depthAttachment != NULL) {
|
||||||
|
MTLRenderPassDepthAttachmentDescriptor* depthAttachment = framebuffer->framebuffer->subpasses[i].depthAttachment;
|
||||||
|
uint32_t attachmentIndex = info.renderPassDescriptor->info.subpassInfos[i].depthAttachment->index;
|
||||||
|
depthAttachment.texture = info.attachments[attachmentIndex]->texture->texture;
|
||||||
|
depthAttachment.loadAction = mtlGryphnLoadOperation(info.renderPassDescriptor->info.attachmentInfos[attachmentIndex].loadOperation);
|
||||||
|
depthAttachment.storeAction = mtlGryphnStoreOperation(info.renderPassDescriptor->info.attachmentInfos[attachmentIndex].storeOperation);
|
||||||
|
depthAttachment.clearDepth = 1.0f;
|
||||||
|
|
||||||
|
MTLRenderPassStencilAttachmentDescriptor* stencilAttachment = framebuffer->framebuffer->subpasses[attachmentIndex].stencilAttachment;
|
||||||
|
stencilAttachment.texture = info.attachments[i]->texture->texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +74,7 @@ gnReturnCode createMetalFramebuffer(gnFramebuffer framebuffer, gnOutputDevice de
|
|||||||
}
|
}
|
||||||
|
|
||||||
void destroyMetalFramebuffer(gnFramebuffer framebuffer) {
|
void destroyMetalFramebuffer(gnFramebuffer framebuffer) {
|
||||||
[framebuffer->framebuffer->framebuffer release];
|
for (int i = 0; i < framebuffer->framebuffer->subpassCount; i++) [framebuffer->framebuffer->subpasses[i] release];
|
||||||
|
free(framebuffer->framebuffer->subpasses);
|
||||||
free(framebuffer->framebuffer);
|
free(framebuffer->framebuffer);
|
||||||
}
|
}
|
||||||
|
@@ -27,8 +27,8 @@ VkSamplerAddressMode vkGryphnTextureWrap(gnTextureWrap wrap) {
|
|||||||
VkImageUsageFlags gnImageUsageToVulkan(gnTextureUsageFlags flags) {
|
VkImageUsageFlags gnImageUsageToVulkan(gnTextureUsageFlags flags) {
|
||||||
VkImageUsageFlags vkFlags = 0;
|
VkImageUsageFlags vkFlags = 0;
|
||||||
|
|
||||||
if ((flags & GN_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT) == GN_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT) vkFlags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
|
||||||
if ((flags & GN_TEXTURE_USAGE_COLOR_ATTACHMENT) == GN_TEXTURE_USAGE_COLOR_ATTACHMENT) vkFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
if ((flags & GN_TEXTURE_USAGE_COLOR_ATTACHMENT) == GN_TEXTURE_USAGE_COLOR_ATTACHMENT) vkFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
|
if ((flags & GN_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT) == GN_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT) vkFlags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||||
if ((flags & GN_TEXTURE_USAGE_SAMPLED) == GN_TEXTURE_USAGE_SAMPLED) vkFlags |= VK_IMAGE_USAGE_SAMPLED_BIT;
|
if ((flags & GN_TEXTURE_USAGE_SAMPLED) == GN_TEXTURE_USAGE_SAMPLED) vkFlags |= VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
if ((flags & GN_TEXTURE_USAGE_WRITE_TARGET) == GN_TEXTURE_USAGE_WRITE_TARGET) vkFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
if ((flags & GN_TEXTURE_USAGE_WRITE_TARGET) == GN_TEXTURE_USAGE_WRITE_TARGET) vkFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||||
if ((flags & GN_TEXTURE_RESOLVE_ATTACHMENT) == GN_TEXTURE_RESOLVE_ATTACHMENT) vkFlags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
|
if ((flags & GN_TEXTURE_RESOLVE_ATTACHMENT) == GN_TEXTURE_RESOLVE_ATTACHMENT) vkFlags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
|
||||||
|
@@ -18,11 +18,11 @@ typedef enum gnTextureWrap {
|
|||||||
} gnTextureWrap;
|
} gnTextureWrap;
|
||||||
|
|
||||||
typedef enum gnTextureUsageFlags {
|
typedef enum gnTextureUsageFlags {
|
||||||
GN_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT = 1 << 0,
|
GN_TEXTURE_USAGE_COLOR_ATTACHMENT = 1 << 0,
|
||||||
GN_TEXTURE_USAGE_COLOR_ATTACHMENT = 1 << 1,
|
GN_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT = 1 << 1,
|
||||||
GN_TEXTURE_USAGE_SAMPLED = 1 << 2,
|
GN_TEXTURE_RESOLVE_ATTACHMENT = 1 << 2,
|
||||||
GN_TEXTURE_USAGE_WRITE_TARGET = 1 << 3,
|
GN_TEXTURE_USAGE_SAMPLED = 1 << 3,
|
||||||
GN_TEXTURE_RESOLVE_ATTACHMENT = 1 << 4
|
GN_TEXTURE_USAGE_WRITE_TARGET = 1 << 4,
|
||||||
} gnTextureUsageFlags;
|
} gnTextureUsageFlags;
|
||||||
|
|
||||||
typedef struct gnTextureInfo {
|
typedef struct gnTextureInfo {
|
||||||
|
Reference in New Issue
Block a user