mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
metal: clean up some code around render pipeline states.
This commit is contained in:
@@ -864,9 +864,6 @@ void Graphics::setRenderTargets(const RenderTargets &rts)
|
||||
throw love::Exception("Invalid slice index: %d.", slice + 1);
|
||||
}
|
||||
|
||||
int w = firsttex->getWidth(firsttarget.mipmap);
|
||||
int h = firsttex->getHeight(firsttarget.mipmap);
|
||||
|
||||
flushBatchedDraws();
|
||||
|
||||
if (rts.depthStencil.texture == nullptr && rts.temporaryRTFlags != 0)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "graphics/Graphics.h"
|
||||
#include "Metal.h"
|
||||
#include "Shader.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
@@ -209,8 +210,8 @@ private:
|
||||
|
||||
id<MTLDepthStencilState> getCachedDepthStencilState(const DepthState &depth, const StencilState &stencil);
|
||||
void applyRenderState(id<MTLRenderCommandEncoder> renderEncoder, const VertexAttributes &attributes);
|
||||
void applyShaderUniforms(id<MTLComputeCommandEncoder> encoder, Shader *shader);
|
||||
void applyShaderUniforms(id<MTLRenderCommandEncoder> renderEncoder, Shader *shader, Texture *maintex);
|
||||
void applyShaderUniforms(id<MTLComputeCommandEncoder> encoder, love::graphics::Shader *shader);
|
||||
void applyShaderUniforms(id<MTLRenderCommandEncoder> renderEncoder, love::graphics::Shader *shader, Texture *maintex);
|
||||
|
||||
id<MTLCommandQueue> commandQueue;
|
||||
|
||||
@@ -225,8 +226,7 @@ private:
|
||||
|
||||
uint32 dirtyRenderState;
|
||||
CullMode lastCullMode;
|
||||
VertexAttributes lastVertexAttributes;
|
||||
PixelFormat activeDepthStencilFormat;
|
||||
Shader::RenderPipelineKey lastRenderPipelineKey;
|
||||
bool windowHasStencil;
|
||||
int shaderSwitches;
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ Graphics::Graphics()
|
||||
, passDesc(nil)
|
||||
, dirtyRenderState(STATEBIT_ALL)
|
||||
, lastCullMode(CULL_MAX_ENUM)
|
||||
, activeDepthStencilFormat(PIXELFORMAT_UNKNOWN)
|
||||
, lastRenderPipelineKey()
|
||||
, windowHasStencil(false)
|
||||
, shaderSwitches(0)
|
||||
, requestedBackbufferMSAA(0)
|
||||
@@ -626,6 +626,11 @@ id<MTLRenderCommandEncoder> Graphics::useRenderEncoder()
|
||||
setAttachment(rt, passDesc.stencilAttachment, attachmentStoreActions.stencil, false);
|
||||
attachmentStoreActions.depth = MTLStoreActionDontCare;
|
||||
attachmentStoreActions.stencil = MTLStoreActionDontCare;
|
||||
|
||||
auto &key = lastRenderPipelineKey;
|
||||
key.colorRenderTargetFormats = isGammaCorrect() ? PIXELFORMAT_BGRA8_UNORM_sRGB : PIXELFORMAT_BGRA8_UNORM;
|
||||
key.depthStencilFormat = backbufferDepthStencil->getPixelFormat();
|
||||
key.msaa = backbufferMSAA ? (uint8) backbufferMSAA->getMSAA() : 1;
|
||||
}
|
||||
|
||||
renderEncoder = [useCommandBuffer() renderCommandEncoderWithDescriptor:passDesc];
|
||||
@@ -891,43 +896,20 @@ void Graphics::applyRenderState(id<MTLRenderCommandEncoder> encoder, const Verte
|
||||
[encoder setCullMode:mode];
|
||||
}
|
||||
|
||||
if ((dirtyState & pipelineStateBits) != 0 || !(attributes == lastVertexAttributes))
|
||||
if ((dirtyState & pipelineStateBits) != 0 || !(attributes == lastRenderPipelineKey.vertexAttributes))
|
||||
{
|
||||
lastVertexAttributes = attributes;
|
||||
auto &key = lastRenderPipelineKey;
|
||||
|
||||
key.vertexAttributes = attributes;
|
||||
|
||||
Shader *shader = (Shader *) Shader::current;
|
||||
id<MTLRenderPipelineState> pipeline = nil;
|
||||
|
||||
if (shader)
|
||||
{
|
||||
Shader::RenderPipelineKey key;
|
||||
|
||||
key.vertexAttributes = attributes;
|
||||
key.blend = state.blend;
|
||||
key.colorChannelMask = state.colorMask;
|
||||
|
||||
const auto &firsttarget = state.renderTargets.getFirstTarget();
|
||||
|
||||
if (firsttarget.texture.get() == nullptr)
|
||||
{
|
||||
key.colorRenderTargetFormats = isGammaCorrect() ? PIXELFORMAT_BGRA8_UNORM_sRGB : PIXELFORMAT_BGRA8_UNORM;
|
||||
key.depthStencilFormat = backbufferDepthStencil->getPixelFormat();
|
||||
key.msaa = backbufferMSAA ? (uint8) backbufferMSAA->getMSAA() : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto &rts = state.renderTargets.colors;
|
||||
|
||||
for (size_t i = 0; i < rts.size(); i++)
|
||||
key.colorRenderTargetFormats |= (rts[i].texture->getPixelFormat()) << (8 * i);
|
||||
|
||||
// Don't query the current RTs because they don't include
|
||||
// automatic depth/stencil.
|
||||
key.depthStencilFormat = activeDepthStencilFormat;
|
||||
|
||||
key.msaa = (uint8) firsttarget.texture->getMSAA();
|
||||
}
|
||||
|
||||
pipeline = shader->getCachedRenderPipeline(key);
|
||||
}
|
||||
|
||||
@@ -1361,9 +1343,19 @@ void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int /*pixelw*/
|
||||
setAttachment(rt, passDesc.stencilAttachment, attachmentStoreActions.stencil);
|
||||
}
|
||||
|
||||
activeDepthStencilFormat = dsformat;
|
||||
if (!isbackbuffer)
|
||||
{
|
||||
lastRenderPipelineKey.colorRenderTargetFormats = 0;
|
||||
for (size_t i = 0; i < rts.colors.size(); i++)
|
||||
lastRenderPipelineKey.colorRenderTargetFormats |= (rts.colors[i].texture->getPixelFormat()) << (8 * i);
|
||||
|
||||
lastRenderPipelineKey.msaa = (uint8) rts.getFirstTarget().texture->getMSAA();
|
||||
}
|
||||
|
||||
lastRenderPipelineKey.depthStencilFormat = dsformat;
|
||||
lastRenderPipelineKey.vertexAttributes = VertexAttributes();
|
||||
|
||||
dirtyRenderState = STATEBIT_ALL;
|
||||
lastVertexAttributes = VertexAttributes();
|
||||
}}
|
||||
|
||||
void Graphics::endPass()
|
||||
|
||||
Reference in New Issue
Block a user