mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-30 00:17:40 +00:00
Add SDL_SetGPUBlendConstants, SDL_SetGPUStencilReference (#10704)
This commit is contained in:
parent
04a732881a
commit
2d4eb29c37
10 changed files with 383 additions and 189 deletions
|
@ -1207,8 +1207,8 @@ typedef struct SDL_GPUDepthStencilState
|
||||||
SDL_GPUStencilOpState frontStencilState;
|
SDL_GPUStencilOpState frontStencilState;
|
||||||
Uint8 compareMask;
|
Uint8 compareMask;
|
||||||
Uint8 writeMask;
|
Uint8 writeMask;
|
||||||
Uint8 reference;
|
|
||||||
Uint8 padding2;
|
Uint8 padding2;
|
||||||
|
Uint8 padding3;
|
||||||
} SDL_GPUDepthStencilState;
|
} SDL_GPUDepthStencilState;
|
||||||
|
|
||||||
typedef struct SDL_GPUColorAttachmentDescription
|
typedef struct SDL_GPUColorAttachmentDescription
|
||||||
|
@ -1238,7 +1238,6 @@ typedef struct SDL_GPUGraphicsPipelineCreateInfo
|
||||||
SDL_GPUMultisampleState multisampleState;
|
SDL_GPUMultisampleState multisampleState;
|
||||||
SDL_GPUDepthStencilState depthStencilState;
|
SDL_GPUDepthStencilState depthStencilState;
|
||||||
SDL_GPUGraphicsPipelineAttachmentInfo attachmentInfo;
|
SDL_GPUGraphicsPipelineAttachmentInfo attachmentInfo;
|
||||||
float blendConstants[4];
|
|
||||||
|
|
||||||
SDL_PropertiesID props;
|
SDL_PropertiesID props;
|
||||||
} SDL_GPUGraphicsPipelineCreateInfo;
|
} SDL_GPUGraphicsPipelineCreateInfo;
|
||||||
|
@ -2140,6 +2139,33 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetGPUScissor(
|
||||||
SDL_GPURenderPass *renderPass,
|
SDL_GPURenderPass *renderPass,
|
||||||
const SDL_Rect *scissor);
|
const SDL_Rect *scissor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current blend constants on a command buffer.
|
||||||
|
*
|
||||||
|
* \param renderPass a render pass handle.
|
||||||
|
* \param blendConstants the blend constant color.
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.0.0.
|
||||||
|
*
|
||||||
|
* \sa SDL_GPU_BLENDFACTOR_CONSTANT_COLOR
|
||||||
|
* \sa SDL_GPU_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR
|
||||||
|
*/
|
||||||
|
extern SDL_DECLSPEC void SDLCALL SDL_SetGPUBlendConstants(
|
||||||
|
SDL_GPURenderPass *renderPass,
|
||||||
|
SDL_FColor blendConstants);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current stencil reference value on a command buffer.
|
||||||
|
*
|
||||||
|
* \param renderPass a render pass handle.
|
||||||
|
* \param reference the stencil reference value to set.
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.0.0.
|
||||||
|
*/
|
||||||
|
extern SDL_DECLSPEC void SDLCALL SDL_SetGPUStencilReference(
|
||||||
|
SDL_GPURenderPass *renderPass,
|
||||||
|
Uint8 reference);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds vertex buffers on a command buffer for use with subsequent draw
|
* Binds vertex buffers on a command buffer for use with subsequent draw
|
||||||
* calls.
|
* calls.
|
||||||
|
|
|
@ -778,8 +778,10 @@ SDL3_0.0.0 {
|
||||||
SDL_SetEventEnabled;
|
SDL_SetEventEnabled;
|
||||||
SDL_SetEventFilter;
|
SDL_SetEventFilter;
|
||||||
SDL_SetFloatProperty;
|
SDL_SetFloatProperty;
|
||||||
|
SDL_SetGPUBlendConstants;
|
||||||
SDL_SetGPUBufferName;
|
SDL_SetGPUBufferName;
|
||||||
SDL_SetGPUScissor;
|
SDL_SetGPUScissor;
|
||||||
|
SDL_SetGPUStencilReference;
|
||||||
SDL_SetGPUSwapchainParameters;
|
SDL_SetGPUSwapchainParameters;
|
||||||
SDL_SetGPUTextureName;
|
SDL_SetGPUTextureName;
|
||||||
SDL_SetGPUViewport;
|
SDL_SetGPUViewport;
|
||||||
|
|
|
@ -803,8 +803,10 @@
|
||||||
#define SDL_SetEventEnabled SDL_SetEventEnabled_REAL
|
#define SDL_SetEventEnabled SDL_SetEventEnabled_REAL
|
||||||
#define SDL_SetEventFilter SDL_SetEventFilter_REAL
|
#define SDL_SetEventFilter SDL_SetEventFilter_REAL
|
||||||
#define SDL_SetFloatProperty SDL_SetFloatProperty_REAL
|
#define SDL_SetFloatProperty SDL_SetFloatProperty_REAL
|
||||||
|
#define SDL_SetGPUBlendConstants SDL_SetGPUBlendConstants_REAL
|
||||||
#define SDL_SetGPUBufferName SDL_SetGPUBufferName_REAL
|
#define SDL_SetGPUBufferName SDL_SetGPUBufferName_REAL
|
||||||
#define SDL_SetGPUScissor SDL_SetGPUScissor_REAL
|
#define SDL_SetGPUScissor SDL_SetGPUScissor_REAL
|
||||||
|
#define SDL_SetGPUStencilReference SDL_SetGPUStencilReference_REAL
|
||||||
#define SDL_SetGPUSwapchainParameters SDL_SetGPUSwapchainParameters_REAL
|
#define SDL_SetGPUSwapchainParameters SDL_SetGPUSwapchainParameters_REAL
|
||||||
#define SDL_SetGPUTextureName SDL_SetGPUTextureName_REAL
|
#define SDL_SetGPUTextureName SDL_SetGPUTextureName_REAL
|
||||||
#define SDL_SetGPUViewport SDL_SetGPUViewport_REAL
|
#define SDL_SetGPUViewport SDL_SetGPUViewport_REAL
|
||||||
|
|
|
@ -813,8 +813,10 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_SetCursor,(SDL_Cursor *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(void,SDL_SetEventEnabled,(Uint32 a, SDL_bool b),(a,b),)
|
SDL_DYNAPI_PROC(void,SDL_SetEventEnabled,(Uint32 a, SDL_bool b),(a,b),)
|
||||||
SDL_DYNAPI_PROC(void,SDL_SetEventFilter,(SDL_EventFilter a, void *b),(a,b),)
|
SDL_DYNAPI_PROC(void,SDL_SetEventFilter,(SDL_EventFilter a, void *b),(a,b),)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_SetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_SetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return)
|
||||||
|
SDL_DYNAPI_PROC(void,SDL_SetGPUBlendConstants,(SDL_GPURenderPass *a, SDL_FColor b),(a,b),)
|
||||||
SDL_DYNAPI_PROC(void,SDL_SetGPUBufferName,(SDL_GPUDevice *a, SDL_GPUBuffer *b, const char *c),(a,b,c),)
|
SDL_DYNAPI_PROC(void,SDL_SetGPUBufferName,(SDL_GPUDevice *a, SDL_GPUBuffer *b, const char *c),(a,b,c),)
|
||||||
SDL_DYNAPI_PROC(void,SDL_SetGPUScissor,(SDL_GPURenderPass *a, const SDL_Rect *b),(a,b),)
|
SDL_DYNAPI_PROC(void,SDL_SetGPUScissor,(SDL_GPURenderPass *a, const SDL_Rect *b),(a,b),)
|
||||||
|
SDL_DYNAPI_PROC(void,SDL_SetGPUStencilReference,(SDL_GPURenderPass *a, Uint8 b),(a,b),)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_SetGPUSwapchainParameters,(SDL_GPUDevice *a, SDL_Window *b, SDL_GPUSwapchainComposition c, SDL_GPUPresentMode d),(a,b,c,d),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_SetGPUSwapchainParameters,(SDL_GPUDevice *a, SDL_Window *b, SDL_GPUSwapchainComposition c, SDL_GPUPresentMode d),(a,b,c,d),return)
|
||||||
SDL_DYNAPI_PROC(void,SDL_SetGPUTextureName,(SDL_GPUDevice *a, SDL_GPUTexture *b, const char *c),(a,b,c),)
|
SDL_DYNAPI_PROC(void,SDL_SetGPUTextureName,(SDL_GPUDevice *a, SDL_GPUTexture *b, const char *c),(a,b,c),)
|
||||||
SDL_DYNAPI_PROC(void,SDL_SetGPUViewport,(SDL_GPURenderPass *a, const SDL_GPUViewport *b),(a,b),)
|
SDL_DYNAPI_PROC(void,SDL_SetGPUViewport,(SDL_GPURenderPass *a, const SDL_GPUViewport *b),(a,b),)
|
||||||
|
|
|
@ -194,11 +194,6 @@ SDL_GPUGraphicsPipeline *SDL_GPU_FetchBlitPipeline(
|
||||||
|
|
||||||
blitPipelineCreateInfo.primitiveType = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
|
blitPipelineCreateInfo.primitiveType = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
|
||||||
|
|
||||||
blitPipelineCreateInfo.blendConstants[0] = 1.0f;
|
|
||||||
blitPipelineCreateInfo.blendConstants[1] = 1.0f;
|
|
||||||
blitPipelineCreateInfo.blendConstants[2] = 1.0f;
|
|
||||||
blitPipelineCreateInfo.blendConstants[3] = 1.0f;
|
|
||||||
|
|
||||||
pipeline = SDL_CreateGPUGraphicsPipeline(
|
pipeline = SDL_CreateGPUGraphicsPipeline(
|
||||||
device,
|
device,
|
||||||
&blitPipelineCreateInfo);
|
&blitPipelineCreateInfo);
|
||||||
|
@ -1281,6 +1276,42 @@ void SDL_SetGPUScissor(
|
||||||
scissor);
|
scissor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDL_SetGPUBlendConstants(
|
||||||
|
SDL_GPURenderPass *renderPass,
|
||||||
|
SDL_FColor blendConstants)
|
||||||
|
{
|
||||||
|
if (renderPass == NULL) {
|
||||||
|
SDL_InvalidParamError("renderPass");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RENDERPASS_DEVICE->debugMode) {
|
||||||
|
CHECK_RENDERPASS
|
||||||
|
}
|
||||||
|
|
||||||
|
RENDERPASS_DEVICE->SetBlendConstants(
|
||||||
|
RENDERPASS_COMMAND_BUFFER,
|
||||||
|
blendConstants);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDL_SetGPUStencilReference(
|
||||||
|
SDL_GPURenderPass *renderPass,
|
||||||
|
Uint8 reference)
|
||||||
|
{
|
||||||
|
if (renderPass == NULL) {
|
||||||
|
SDL_InvalidParamError("renderPass");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RENDERPASS_DEVICE->debugMode) {
|
||||||
|
CHECK_RENDERPASS
|
||||||
|
}
|
||||||
|
|
||||||
|
RENDERPASS_DEVICE->SetStencilReference(
|
||||||
|
RENDERPASS_COMMAND_BUFFER,
|
||||||
|
reference);
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_BindGPUVertexBuffers(
|
void SDL_BindGPUVertexBuffers(
|
||||||
SDL_GPURenderPass *renderPass,
|
SDL_GPURenderPass *renderPass,
|
||||||
Uint32 firstBinding,
|
Uint32 firstBinding,
|
||||||
|
|
|
@ -398,6 +398,14 @@ struct SDL_GPUDevice
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
const SDL_Rect *scissor);
|
const SDL_Rect *scissor);
|
||||||
|
|
||||||
|
void (*SetBlendConstants)(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
SDL_FColor blendConstants);
|
||||||
|
|
||||||
|
void (*SetStencilReference)(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
Uint8 reference);
|
||||||
|
|
||||||
void (*BindVertexBuffers)(
|
void (*BindVertexBuffers)(
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
Uint32 firstBinding,
|
Uint32 firstBinding,
|
||||||
|
@ -716,6 +724,8 @@ struct SDL_GPUDevice
|
||||||
ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
|
ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
|
||||||
ASSIGN_DRIVER_FUNC(SetViewport, name) \
|
ASSIGN_DRIVER_FUNC(SetViewport, name) \
|
||||||
ASSIGN_DRIVER_FUNC(SetScissor, name) \
|
ASSIGN_DRIVER_FUNC(SetScissor, name) \
|
||||||
|
ASSIGN_DRIVER_FUNC(SetBlendConstants, name) \
|
||||||
|
ASSIGN_DRIVER_FUNC(SetStencilReference, name) \
|
||||||
ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
|
ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
|
||||||
ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
|
ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
|
||||||
ASSIGN_DRIVER_FUNC(BindVertexSamplers, name) \
|
ASSIGN_DRIVER_FUNC(BindVertexSamplers, name) \
|
||||||
|
|
|
@ -476,7 +476,6 @@ typedef struct D3D11Shader
|
||||||
|
|
||||||
typedef struct D3D11GraphicsPipeline
|
typedef struct D3D11GraphicsPipeline
|
||||||
{
|
{
|
||||||
float blendConstants[4];
|
|
||||||
Sint32 numColorAttachments;
|
Sint32 numColorAttachments;
|
||||||
DXGI_FORMAT colorAttachmentFormats[MAX_COLOR_TARGET_BINDINGS];
|
DXGI_FORMAT colorAttachmentFormats[MAX_COLOR_TARGET_BINDINGS];
|
||||||
ID3D11BlendState *colorAttachmentBlendState;
|
ID3D11BlendState *colorAttachmentBlendState;
|
||||||
|
@ -486,7 +485,6 @@ typedef struct D3D11GraphicsPipeline
|
||||||
Uint8 hasDepthStencilAttachment;
|
Uint8 hasDepthStencilAttachment;
|
||||||
DXGI_FORMAT depthStencilAttachmentFormat;
|
DXGI_FORMAT depthStencilAttachmentFormat;
|
||||||
ID3D11DepthStencilState *depthStencilState;
|
ID3D11DepthStencilState *depthStencilState;
|
||||||
Uint8 stencilRef;
|
|
||||||
|
|
||||||
SDL_GPUPrimitiveType primitiveType;
|
SDL_GPUPrimitiveType primitiveType;
|
||||||
ID3D11RasterizerState *rasterizerState;
|
ID3D11RasterizerState *rasterizerState;
|
||||||
|
@ -615,6 +613,8 @@ typedef struct D3D11CommandBuffer
|
||||||
|
|
||||||
// Render Pass
|
// Render Pass
|
||||||
D3D11GraphicsPipeline *graphicsPipeline;
|
D3D11GraphicsPipeline *graphicsPipeline;
|
||||||
|
Uint8 stencilRef;
|
||||||
|
SDL_FColor blendConstants;
|
||||||
|
|
||||||
// Render Pass MSAA resolve
|
// Render Pass MSAA resolve
|
||||||
D3D11Texture *colorTargetResolveTexture[MAX_COLOR_TARGET_BINDINGS];
|
D3D11Texture *colorTargetResolveTexture[MAX_COLOR_TARGET_BINDINGS];
|
||||||
|
@ -1541,11 +1541,6 @@ static SDL_GPUGraphicsPipeline *D3D11_CreateGraphicsPipeline(
|
||||||
pipeline->colorAttachmentFormats[i] = SDLToD3D11_TextureFormat[pipelineCreateInfo->attachmentInfo.colorAttachmentDescriptions[i].format];
|
pipeline->colorAttachmentFormats[i] = SDLToD3D11_TextureFormat[pipelineCreateInfo->attachmentInfo.colorAttachmentDescriptions[i].format];
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline->blendConstants[0] = pipelineCreateInfo->blendConstants[0];
|
|
||||||
pipeline->blendConstants[1] = pipelineCreateInfo->blendConstants[1];
|
|
||||||
pipeline->blendConstants[2] = pipelineCreateInfo->blendConstants[2];
|
|
||||||
pipeline->blendConstants[3] = pipelineCreateInfo->blendConstants[3];
|
|
||||||
|
|
||||||
// Multisample
|
// Multisample
|
||||||
|
|
||||||
pipeline->multisampleState = pipelineCreateInfo->multisampleState;
|
pipeline->multisampleState = pipelineCreateInfo->multisampleState;
|
||||||
|
@ -1558,7 +1553,6 @@ static SDL_GPUGraphicsPipeline *D3D11_CreateGraphicsPipeline(
|
||||||
|
|
||||||
pipeline->hasDepthStencilAttachment = pipelineCreateInfo->attachmentInfo.hasDepthStencilAttachment;
|
pipeline->hasDepthStencilAttachment = pipelineCreateInfo->attachmentInfo.hasDepthStencilAttachment;
|
||||||
pipeline->depthStencilAttachmentFormat = SDLToD3D11_TextureFormat[pipelineCreateInfo->attachmentInfo.depthStencilFormat];
|
pipeline->depthStencilAttachmentFormat = SDLToD3D11_TextureFormat[pipelineCreateInfo->attachmentInfo.depthStencilFormat];
|
||||||
pipeline->stencilRef = pipelineCreateInfo->depthStencilState.reference;
|
|
||||||
|
|
||||||
// Rasterizer
|
// Rasterizer
|
||||||
|
|
||||||
|
@ -3204,6 +3198,8 @@ static SDL_GPUCommandBuffer *D3D11_AcquireCommandBuffer(
|
||||||
|
|
||||||
commandBuffer = D3D11_INTERNAL_GetInactiveCommandBufferFromPool(renderer);
|
commandBuffer = D3D11_INTERNAL_GetInactiveCommandBufferFromPool(renderer);
|
||||||
commandBuffer->graphicsPipeline = NULL;
|
commandBuffer->graphicsPipeline = NULL;
|
||||||
|
commandBuffer->stencilRef = 0;
|
||||||
|
commandBuffer->blendConstants = (SDL_FColor){ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
commandBuffer->computePipeline = NULL;
|
commandBuffer->computePipeline = NULL;
|
||||||
for (i = 0; i < MAX_COLOR_TARGET_BINDINGS; i += 1) {
|
for (i = 0; i < MAX_COLOR_TARGET_BINDINGS; i += 1) {
|
||||||
commandBuffer->colorTargetResolveTexture[i] = NULL;
|
commandBuffer->colorTargetResolveTexture[i] = NULL;
|
||||||
|
@ -3384,6 +3380,78 @@ static void D3D11_INTERNAL_PushUniformData(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void D3D11_SetViewport(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
const SDL_GPUViewport *viewport)
|
||||||
|
{
|
||||||
|
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
||||||
|
D3D11_VIEWPORT vp = {
|
||||||
|
viewport->x,
|
||||||
|
viewport->y,
|
||||||
|
viewport->w,
|
||||||
|
viewport->h,
|
||||||
|
viewport->minDepth,
|
||||||
|
viewport->maxDepth
|
||||||
|
};
|
||||||
|
|
||||||
|
ID3D11DeviceContext_RSSetViewports(
|
||||||
|
d3d11CommandBuffer->context,
|
||||||
|
1,
|
||||||
|
&vp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void D3D11_SetScissor(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
const SDL_Rect *scissor)
|
||||||
|
{
|
||||||
|
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
||||||
|
D3D11_RECT rect = {
|
||||||
|
scissor->x,
|
||||||
|
scissor->y,
|
||||||
|
scissor->x + scissor->w,
|
||||||
|
scissor->y + scissor->h
|
||||||
|
};
|
||||||
|
|
||||||
|
ID3D11DeviceContext_RSSetScissorRects(
|
||||||
|
d3d11CommandBuffer->context,
|
||||||
|
1,
|
||||||
|
&rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void D3D11_SetBlendConstants(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
SDL_FColor blendConstants)
|
||||||
|
{
|
||||||
|
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
||||||
|
FLOAT blendFactor[4] = { blendConstants.r, blendConstants.g, blendConstants.b, blendConstants.a };
|
||||||
|
|
||||||
|
d3d11CommandBuffer->blendConstants = blendConstants;
|
||||||
|
|
||||||
|
if (d3d11CommandBuffer->graphicsPipeline != NULL) {
|
||||||
|
ID3D11DeviceContext_OMSetBlendState(
|
||||||
|
d3d11CommandBuffer->context,
|
||||||
|
d3d11CommandBuffer->graphicsPipeline->colorAttachmentBlendState,
|
||||||
|
blendFactor,
|
||||||
|
d3d11CommandBuffer->graphicsPipeline->multisampleState.sampleMask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void D3D11_SetStencilReference(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
Uint8 reference)
|
||||||
|
{
|
||||||
|
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
||||||
|
|
||||||
|
d3d11CommandBuffer->stencilRef = reference;
|
||||||
|
|
||||||
|
if (d3d11CommandBuffer->graphicsPipeline != NULL) {
|
||||||
|
ID3D11DeviceContext_OMSetDepthStencilState(
|
||||||
|
d3d11CommandBuffer->context,
|
||||||
|
d3d11CommandBuffer->graphicsPipeline->depthStencilState,
|
||||||
|
reference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void D3D11_BeginRenderPass(
|
static void D3D11_BeginRenderPass(
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
const SDL_GPUColorAttachmentInfo *colorAttachmentInfos,
|
const SDL_GPUColorAttachmentInfo *colorAttachmentInfos,
|
||||||
|
@ -3396,8 +3464,8 @@ static void D3D11_BeginRenderPass(
|
||||||
ID3D11DepthStencilView *dsv = NULL;
|
ID3D11DepthStencilView *dsv = NULL;
|
||||||
Uint32 vpWidth = SDL_MAX_UINT32;
|
Uint32 vpWidth = SDL_MAX_UINT32;
|
||||||
Uint32 vpHeight = SDL_MAX_UINT32;
|
Uint32 vpHeight = SDL_MAX_UINT32;
|
||||||
D3D11_VIEWPORT viewport;
|
SDL_GPUViewport viewport;
|
||||||
D3D11_RECT scissorRect;
|
SDL_Rect scissorRect;
|
||||||
|
|
||||||
d3d11CommandBuffer->needVertexSamplerBind = true;
|
d3d11CommandBuffer->needVertexSamplerBind = true;
|
||||||
d3d11CommandBuffer->needVertexResourceBind = true;
|
d3d11CommandBuffer->needVertexResourceBind = true;
|
||||||
|
@ -3524,28 +3592,34 @@ static void D3D11_BeginRenderPass(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default viewport and scissor state
|
// Set sensible default states
|
||||||
viewport.TopLeftX = 0;
|
viewport.x = 0;
|
||||||
viewport.TopLeftY = 0;
|
viewport.y = 0;
|
||||||
viewport.Width = (FLOAT)vpWidth;
|
viewport.w = (float)vpWidth;
|
||||||
viewport.Height = (FLOAT)vpHeight;
|
viewport.h = (float)vpHeight;
|
||||||
viewport.MinDepth = 0;
|
viewport.minDepth = 0;
|
||||||
viewport.MaxDepth = 1;
|
viewport.maxDepth = 1;
|
||||||
|
|
||||||
ID3D11DeviceContext_RSSetViewports(
|
D3D11_SetViewport(
|
||||||
d3d11CommandBuffer->context,
|
commandBuffer,
|
||||||
1,
|
|
||||||
&viewport);
|
&viewport);
|
||||||
|
|
||||||
scissorRect.left = 0;
|
scissorRect.x = 0;
|
||||||
scissorRect.right = (LONG)viewport.Width;
|
scissorRect.y = 0;
|
||||||
scissorRect.top = 0;
|
scissorRect.w = (int)vpWidth;
|
||||||
scissorRect.bottom = (LONG)viewport.Height;
|
scissorRect.h = (int)vpHeight;
|
||||||
|
|
||||||
ID3D11DeviceContext_RSSetScissorRects(
|
D3D11_SetScissor(
|
||||||
d3d11CommandBuffer->context,
|
commandBuffer,
|
||||||
1,
|
|
||||||
&scissorRect);
|
&scissorRect);
|
||||||
|
|
||||||
|
D3D11_SetStencilReference(
|
||||||
|
commandBuffer,
|
||||||
|
0);
|
||||||
|
|
||||||
|
D3D11_SetBlendConstants(
|
||||||
|
commandBuffer,
|
||||||
|
(SDL_FColor){ 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
}
|
}
|
||||||
|
|
||||||
static void D3D11_BindGraphicsPipeline(
|
static void D3D11_BindGraphicsPipeline(
|
||||||
|
@ -3554,19 +3628,25 @@ static void D3D11_BindGraphicsPipeline(
|
||||||
{
|
{
|
||||||
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
||||||
D3D11GraphicsPipeline *pipeline = (D3D11GraphicsPipeline *)graphicsPipeline;
|
D3D11GraphicsPipeline *pipeline = (D3D11GraphicsPipeline *)graphicsPipeline;
|
||||||
|
FLOAT blendFactor[4] = {
|
||||||
|
d3d11CommandBuffer->blendConstants.r,
|
||||||
|
d3d11CommandBuffer->blendConstants.g,
|
||||||
|
d3d11CommandBuffer->blendConstants.b,
|
||||||
|
d3d11CommandBuffer->blendConstants.a
|
||||||
|
};
|
||||||
|
|
||||||
d3d11CommandBuffer->graphicsPipeline = pipeline;
|
d3d11CommandBuffer->graphicsPipeline = pipeline;
|
||||||
|
|
||||||
ID3D11DeviceContext_OMSetBlendState(
|
ID3D11DeviceContext_OMSetBlendState(
|
||||||
d3d11CommandBuffer->context,
|
d3d11CommandBuffer->context,
|
||||||
pipeline->colorAttachmentBlendState,
|
pipeline->colorAttachmentBlendState,
|
||||||
pipeline->blendConstants,
|
blendFactor,
|
||||||
pipeline->multisampleState.sampleMask);
|
pipeline->multisampleState.sampleMask);
|
||||||
|
|
||||||
ID3D11DeviceContext_OMSetDepthStencilState(
|
ID3D11DeviceContext_OMSetDepthStencilState(
|
||||||
d3d11CommandBuffer->context,
|
d3d11CommandBuffer->context,
|
||||||
pipeline->depthStencilState,
|
pipeline->depthStencilState,
|
||||||
pipeline->stencilRef);
|
d3d11CommandBuffer->stencilRef);
|
||||||
|
|
||||||
ID3D11DeviceContext_IASetPrimitiveTopology(
|
ID3D11DeviceContext_IASetPrimitiveTopology(
|
||||||
d3d11CommandBuffer->context,
|
d3d11CommandBuffer->context,
|
||||||
|
@ -3612,44 +3692,6 @@ static void D3D11_BindGraphicsPipeline(
|
||||||
d3d11CommandBuffer->needFragmentUniformBufferBind = true;
|
d3d11CommandBuffer->needFragmentUniformBufferBind = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void D3D11_SetViewport(
|
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
|
||||||
const SDL_GPUViewport *viewport)
|
|
||||||
{
|
|
||||||
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
|
||||||
D3D11_VIEWPORT vp = {
|
|
||||||
viewport->x,
|
|
||||||
viewport->y,
|
|
||||||
viewport->w,
|
|
||||||
viewport->h,
|
|
||||||
viewport->minDepth,
|
|
||||||
viewport->maxDepth
|
|
||||||
};
|
|
||||||
|
|
||||||
ID3D11DeviceContext_RSSetViewports(
|
|
||||||
d3d11CommandBuffer->context,
|
|
||||||
1,
|
|
||||||
&vp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void D3D11_SetScissor(
|
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
|
||||||
const SDL_Rect *scissor)
|
|
||||||
{
|
|
||||||
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
|
|
||||||
D3D11_RECT rect = {
|
|
||||||
scissor->x,
|
|
||||||
scissor->y,
|
|
||||||
scissor->x + scissor->w,
|
|
||||||
scissor->y + scissor->h
|
|
||||||
};
|
|
||||||
|
|
||||||
ID3D11DeviceContext_RSSetScissorRects(
|
|
||||||
d3d11CommandBuffer->context,
|
|
||||||
1,
|
|
||||||
&rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void D3D11_BindVertexBuffers(
|
static void D3D11_BindVertexBuffers(
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
Uint32 firstBinding,
|
Uint32 firstBinding,
|
||||||
|
@ -5786,11 +5828,6 @@ static void D3D11_INTERNAL_InitBlitPipelines(
|
||||||
|
|
||||||
blitPipelineCreateInfo.primitiveType = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
|
blitPipelineCreateInfo.primitiveType = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
|
||||||
|
|
||||||
blitPipelineCreateInfo.blendConstants[0] = 1.0f;
|
|
||||||
blitPipelineCreateInfo.blendConstants[1] = 1.0f;
|
|
||||||
blitPipelineCreateInfo.blendConstants[2] = 1.0f;
|
|
||||||
blitPipelineCreateInfo.blendConstants[3] = 1.0f;
|
|
||||||
|
|
||||||
blitPipeline = D3D11_CreateGraphicsPipeline(
|
blitPipeline = D3D11_CreateGraphicsPipeline(
|
||||||
(SDL_GPURenderer *)renderer,
|
(SDL_GPURenderer *)renderer,
|
||||||
&blitPipelineCreateInfo);
|
&blitPipelineCreateInfo);
|
||||||
|
|
|
@ -775,9 +775,6 @@ struct D3D12GraphicsPipeline
|
||||||
|
|
||||||
Uint32 vertexStrides[MAX_BUFFER_BINDINGS];
|
Uint32 vertexStrides[MAX_BUFFER_BINDINGS];
|
||||||
|
|
||||||
float blendConstants[4];
|
|
||||||
Uint8 stencilRef;
|
|
||||||
|
|
||||||
Uint32 vertexSamplerCount;
|
Uint32 vertexSamplerCount;
|
||||||
Uint32 vertexUniformBufferCount;
|
Uint32 vertexUniformBufferCount;
|
||||||
Uint32 vertexStorageBufferCount;
|
Uint32 vertexStorageBufferCount;
|
||||||
|
@ -2603,11 +2600,6 @@ static SDL_GPUGraphicsPipeline *D3D12_CreateGraphicsPipeline(
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline->primitiveType = pipelineCreateInfo->primitiveType;
|
pipeline->primitiveType = pipelineCreateInfo->primitiveType;
|
||||||
pipeline->blendConstants[0] = pipelineCreateInfo->blendConstants[0];
|
|
||||||
pipeline->blendConstants[1] = pipelineCreateInfo->blendConstants[1];
|
|
||||||
pipeline->blendConstants[2] = pipelineCreateInfo->blendConstants[2];
|
|
||||||
pipeline->blendConstants[3] = pipelineCreateInfo->blendConstants[3];
|
|
||||||
pipeline->stencilRef = pipelineCreateInfo->depthStencilState.reference;
|
|
||||||
|
|
||||||
pipeline->vertexSamplerCount = vertShader->samplerCount;
|
pipeline->vertexSamplerCount = vertShader->samplerCount;
|
||||||
pipeline->vertexStorageTextureCount = vertShader->storageTextureCount;
|
pipeline->vertexStorageTextureCount = vertShader->storageTextureCount;
|
||||||
|
@ -3611,6 +3603,23 @@ static void D3D12_SetScissor(
|
||||||
ID3D12GraphicsCommandList_RSSetScissorRects(d3d12CommandBuffer->graphicsCommandList, 1, &scissorRect);
|
ID3D12GraphicsCommandList_RSSetScissorRects(d3d12CommandBuffer->graphicsCommandList, 1, &scissorRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void D3D12_SetBlendConstants(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
SDL_FColor blendConstants)
|
||||||
|
{
|
||||||
|
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
|
||||||
|
FLOAT blendFactor[4] = { blendConstants.r, blendConstants.g, blendConstants.b, blendConstants.a };
|
||||||
|
ID3D12GraphicsCommandList_OMSetBlendFactor(d3d12CommandBuffer->graphicsCommandList, blendFactor);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void D3D12_SetStencilReference(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
Uint8 reference
|
||||||
|
) {
|
||||||
|
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
|
||||||
|
ID3D12GraphicsCommandList_OMSetStencilRef(d3d12CommandBuffer->graphicsCommandList, reference);
|
||||||
|
}
|
||||||
|
|
||||||
static D3D12TextureSubresource *D3D12_INTERNAL_FetchTextureSubresource(
|
static D3D12TextureSubresource *D3D12_INTERNAL_FetchTextureSubresource(
|
||||||
D3D12TextureContainer *container,
|
D3D12TextureContainer *container,
|
||||||
Uint32 layer,
|
Uint32 layer,
|
||||||
|
@ -3783,7 +3792,6 @@ static void D3D12_BeginRenderPass(
|
||||||
const SDL_GPUDepthStencilAttachmentInfo *depthStencilAttachmentInfo)
|
const SDL_GPUDepthStencilAttachmentInfo *depthStencilAttachmentInfo)
|
||||||
{
|
{
|
||||||
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
|
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
|
||||||
/* D3D12Renderer *renderer = d3d12CommandBuffer->renderer; */
|
|
||||||
|
|
||||||
Uint32 framebufferWidth = SDL_MAX_UINT32;
|
Uint32 framebufferWidth = SDL_MAX_UINT32;
|
||||||
Uint32 framebufferHeight = SDL_MAX_UINT32;
|
Uint32 framebufferHeight = SDL_MAX_UINT32;
|
||||||
|
@ -3915,7 +3923,7 @@ static void D3D12_BeginRenderPass(
|
||||||
false,
|
false,
|
||||||
(depthStencilAttachmentInfo == NULL) ? NULL : &dsv);
|
(depthStencilAttachmentInfo == NULL) ? NULL : &dsv);
|
||||||
|
|
||||||
// Set sensible default viewport state
|
// Set sensible default states
|
||||||
SDL_GPUViewport defaultViewport;
|
SDL_GPUViewport defaultViewport;
|
||||||
defaultViewport.x = 0;
|
defaultViewport.x = 0;
|
||||||
defaultViewport.y = 0;
|
defaultViewport.y = 0;
|
||||||
|
@ -3937,6 +3945,14 @@ static void D3D12_BeginRenderPass(
|
||||||
D3D12_SetScissor(
|
D3D12_SetScissor(
|
||||||
commandBuffer,
|
commandBuffer,
|
||||||
&defaultScissor);
|
&defaultScissor);
|
||||||
|
|
||||||
|
D3D12_SetStencilReference(
|
||||||
|
commandBuffer,
|
||||||
|
0);
|
||||||
|
|
||||||
|
D3D12_SetBlendConstants(
|
||||||
|
commandBuffer,
|
||||||
|
(SDL_FColor){ 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
}
|
}
|
||||||
|
|
||||||
static void D3D12_INTERNAL_TrackUniformBuffer(
|
static void D3D12_INTERNAL_TrackUniformBuffer(
|
||||||
|
@ -4120,21 +4136,9 @@ static void D3D12_BindGraphicsPipeline(
|
||||||
|
|
||||||
// Set the pipeline state
|
// Set the pipeline state
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(d3d12CommandBuffer->graphicsCommandList, pipeline->pipelineState);
|
ID3D12GraphicsCommandList_SetPipelineState(d3d12CommandBuffer->graphicsCommandList, pipeline->pipelineState);
|
||||||
|
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(d3d12CommandBuffer->graphicsCommandList, pipeline->rootSignature->handle);
|
ID3D12GraphicsCommandList_SetGraphicsRootSignature(d3d12CommandBuffer->graphicsCommandList, pipeline->rootSignature->handle);
|
||||||
|
|
||||||
ID3D12GraphicsCommandList_IASetPrimitiveTopology(d3d12CommandBuffer->graphicsCommandList, SDLToD3D12_PrimitiveType[pipeline->primitiveType]);
|
ID3D12GraphicsCommandList_IASetPrimitiveTopology(d3d12CommandBuffer->graphicsCommandList, SDLToD3D12_PrimitiveType[pipeline->primitiveType]);
|
||||||
|
|
||||||
float blendFactor[4] = {
|
|
||||||
pipeline->blendConstants[0],
|
|
||||||
pipeline->blendConstants[1],
|
|
||||||
pipeline->blendConstants[2],
|
|
||||||
pipeline->blendConstants[3]
|
|
||||||
};
|
|
||||||
ID3D12GraphicsCommandList_OMSetBlendFactor(d3d12CommandBuffer->graphicsCommandList, blendFactor);
|
|
||||||
|
|
||||||
ID3D12GraphicsCommandList_OMSetStencilRef(d3d12CommandBuffer->graphicsCommandList, pipeline->stencilRef);
|
|
||||||
|
|
||||||
// Mark that bindings are needed
|
// Mark that bindings are needed
|
||||||
d3d12CommandBuffer->needVertexSamplerBind = true;
|
d3d12CommandBuffer->needVertexSamplerBind = true;
|
||||||
d3d12CommandBuffer->needVertexStorageTextureBind = true;
|
d3d12CommandBuffer->needVertexStorageTextureBind = true;
|
||||||
|
|
|
@ -402,14 +402,12 @@ typedef struct MetalGraphicsPipeline
|
||||||
{
|
{
|
||||||
id<MTLRenderPipelineState> handle;
|
id<MTLRenderPipelineState> handle;
|
||||||
|
|
||||||
float blendConstants[4];
|
|
||||||
Uint32 sampleMask;
|
Uint32 sampleMask;
|
||||||
|
|
||||||
SDL_GPURasterizerState rasterizerState;
|
SDL_GPURasterizerState rasterizerState;
|
||||||
SDL_GPUPrimitiveType primitiveType;
|
SDL_GPUPrimitiveType primitiveType;
|
||||||
|
|
||||||
id<MTLDepthStencilState> depthStencilState;
|
id<MTLDepthStencilState> depthStencilState;
|
||||||
Uint8 stencilReference;
|
|
||||||
|
|
||||||
Uint32 vertexSamplerCount;
|
Uint32 vertexSamplerCount;
|
||||||
Uint32 vertexUniformBufferCount;
|
Uint32 vertexUniformBufferCount;
|
||||||
|
@ -1103,13 +1101,8 @@ static SDL_GPUGraphicsPipeline *METAL_CreateGraphicsPipeline(
|
||||||
|
|
||||||
result = SDL_malloc(sizeof(MetalGraphicsPipeline));
|
result = SDL_malloc(sizeof(MetalGraphicsPipeline));
|
||||||
result->handle = pipelineState;
|
result->handle = pipelineState;
|
||||||
result->blendConstants[0] = pipelineCreateInfo->blendConstants[0];
|
|
||||||
result->blendConstants[1] = pipelineCreateInfo->blendConstants[1];
|
|
||||||
result->blendConstants[2] = pipelineCreateInfo->blendConstants[2];
|
|
||||||
result->blendConstants[3] = pipelineCreateInfo->blendConstants[3];
|
|
||||||
result->sampleMask = pipelineCreateInfo->multisampleState.sampleMask;
|
result->sampleMask = pipelineCreateInfo->multisampleState.sampleMask;
|
||||||
result->depthStencilState = depthStencilState;
|
result->depthStencilState = depthStencilState;
|
||||||
result->stencilReference = pipelineCreateInfo->depthStencilState.reference;
|
|
||||||
result->rasterizerState = pipelineCreateInfo->rasterizerState;
|
result->rasterizerState = pipelineCreateInfo->rasterizerState;
|
||||||
result->primitiveType = pipelineCreateInfo->primitiveType;
|
result->primitiveType = pipelineCreateInfo->primitiveType;
|
||||||
result->vertexSamplerCount = vertexShader->samplerCount;
|
result->vertexSamplerCount = vertexShader->samplerCount;
|
||||||
|
@ -2087,6 +2080,65 @@ static void METAL_INTERNAL_ReturnUniformBufferToPool(
|
||||||
uniformBuffer->drawOffset = 0;
|
uniformBuffer->drawOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void METAL_SetViewport(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
const SDL_GPUViewport *viewport)
|
||||||
|
{
|
||||||
|
@autoreleasepool {
|
||||||
|
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
|
||||||
|
MTLViewport metalViewport;
|
||||||
|
|
||||||
|
metalViewport.originX = viewport->x;
|
||||||
|
metalViewport.originY = viewport->y;
|
||||||
|
metalViewport.width = viewport->w;
|
||||||
|
metalViewport.height = viewport->h;
|
||||||
|
metalViewport.znear = viewport->minDepth;
|
||||||
|
metalViewport.zfar = viewport->maxDepth;
|
||||||
|
|
||||||
|
[metalCommandBuffer->renderEncoder setViewport:metalViewport];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void METAL_SetScissor(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
const SDL_Rect *scissor)
|
||||||
|
{
|
||||||
|
@autoreleasepool {
|
||||||
|
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
|
||||||
|
MTLScissorRect metalScissor;
|
||||||
|
|
||||||
|
metalScissor.x = scissor->x;
|
||||||
|
metalScissor.y = scissor->y;
|
||||||
|
metalScissor.width = scissor->w;
|
||||||
|
metalScissor.height = scissor->h;
|
||||||
|
|
||||||
|
[metalCommandBuffer->renderEncoder setScissorRect:metalScissor];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void METAL_SetBlendConstants(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
SDL_FColor blendConstants)
|
||||||
|
{
|
||||||
|
@autoreleasepool {
|
||||||
|
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
|
||||||
|
[metalCommandBuffer->renderEncoder setBlendColorRed:blendConstants.r
|
||||||
|
green:blendConstants.g
|
||||||
|
blue:blendConstants.b
|
||||||
|
alpha:blendConstants.a];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void METAL_SetStencilReference(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
Uint8 reference
|
||||||
|
) {
|
||||||
|
@autoreleasepool {
|
||||||
|
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
|
||||||
|
[metalCommandBuffer->renderEncoder setStencilReferenceValue:reference];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void METAL_BeginRenderPass(
|
static void METAL_BeginRenderPass(
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
const SDL_GPUColorAttachmentInfo *colorAttachmentInfos,
|
const SDL_GPUColorAttachmentInfo *colorAttachmentInfos,
|
||||||
|
@ -2099,8 +2151,8 @@ static void METAL_BeginRenderPass(
|
||||||
MTLRenderPassDescriptor *passDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
MTLRenderPassDescriptor *passDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
||||||
Uint32 vpWidth = UINT_MAX;
|
Uint32 vpWidth = UINT_MAX;
|
||||||
Uint32 vpHeight = UINT_MAX;
|
Uint32 vpHeight = UINT_MAX;
|
||||||
MTLViewport viewport;
|
SDL_GPUViewport viewport;
|
||||||
MTLScissorRect scissorRect;
|
SDL_Rect scissorRect;
|
||||||
|
|
||||||
for (Uint32 i = 0; i < colorAttachmentCount; i += 1) {
|
for (Uint32 i = 0; i < colorAttachmentCount; i += 1) {
|
||||||
MetalTextureContainer *container = (MetalTextureContainer *)colorAttachmentInfos[i].texture;
|
MetalTextureContainer *container = (MetalTextureContainer *)colorAttachmentInfos[i].texture;
|
||||||
|
@ -2201,20 +2253,28 @@ static void METAL_BeginRenderPass(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default viewport and scissor state
|
// Set sensible default states
|
||||||
viewport.originX = 0;
|
viewport.x = 0;
|
||||||
viewport.originY = 0;
|
viewport.y = 0;
|
||||||
viewport.width = vpWidth;
|
viewport.w = vpWidth;
|
||||||
viewport.height = vpHeight;
|
viewport.h = vpHeight;
|
||||||
viewport.znear = 0;
|
viewport.minDepth = 0;
|
||||||
viewport.zfar = 1;
|
viewport.maxDepth = 1;
|
||||||
[metalCommandBuffer->renderEncoder setViewport:viewport];
|
METAL_SetViewport(commandBuffer, &viewport);
|
||||||
|
|
||||||
scissorRect.x = 0;
|
scissorRect.x = 0;
|
||||||
scissorRect.y = 0;
|
scissorRect.y = 0;
|
||||||
scissorRect.width = vpWidth;
|
scissorRect.w = vpWidth;
|
||||||
scissorRect.height = vpHeight;
|
scissorRect.h = vpHeight;
|
||||||
[metalCommandBuffer->renderEncoder setScissorRect:scissorRect];
|
METAL_SetScissor(commandBuffer, &scissorRect);
|
||||||
|
|
||||||
|
METAL_SetBlendConstants(
|
||||||
|
commandBuffer,
|
||||||
|
(SDL_FColor){ 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
|
|
||||||
|
METAL_SetStencilReference(
|
||||||
|
commandBuffer,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2240,19 +2300,10 @@ static void METAL_BindGraphicsPipeline(
|
||||||
slopeScale:((rast->depthBiasEnable) ? rast->depthBiasSlopeFactor : 0)
|
slopeScale:((rast->depthBiasEnable) ? rast->depthBiasSlopeFactor : 0)
|
||||||
clamp:((rast->depthBiasEnable) ? rast->depthBiasClamp : 0)];
|
clamp:((rast->depthBiasEnable) ? rast->depthBiasClamp : 0)];
|
||||||
|
|
||||||
// Apply blend constants
|
|
||||||
[metalCommandBuffer->renderEncoder
|
|
||||||
setBlendColorRed:metalGraphicsPipeline->blendConstants[0]
|
|
||||||
green:metalGraphicsPipeline->blendConstants[1]
|
|
||||||
blue:metalGraphicsPipeline->blendConstants[2]
|
|
||||||
alpha:metalGraphicsPipeline->blendConstants[3]];
|
|
||||||
|
|
||||||
// Apply depth-stencil state
|
// Apply depth-stencil state
|
||||||
if (metalGraphicsPipeline->depthStencilState != NULL) {
|
if (metalGraphicsPipeline->depthStencilState != NULL) {
|
||||||
[metalCommandBuffer->renderEncoder
|
[metalCommandBuffer->renderEncoder
|
||||||
setDepthStencilState:metalGraphicsPipeline->depthStencilState];
|
setDepthStencilState:metalGraphicsPipeline->depthStencilState];
|
||||||
[metalCommandBuffer->renderEncoder
|
|
||||||
setStencilReferenceValue:metalGraphicsPipeline->stencilReference];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Uint32 i = 0; i < metalGraphicsPipeline->vertexUniformBufferCount; i += 1) {
|
for (Uint32 i = 0; i < metalGraphicsPipeline->vertexUniformBufferCount; i += 1) {
|
||||||
|
@ -2274,42 +2325,6 @@ static void METAL_BindGraphicsPipeline(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void METAL_SetViewport(
|
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
|
||||||
const SDL_GPUViewport *viewport)
|
|
||||||
{
|
|
||||||
@autoreleasepool {
|
|
||||||
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
|
|
||||||
MTLViewport metalViewport;
|
|
||||||
|
|
||||||
metalViewport.originX = viewport->x;
|
|
||||||
metalViewport.originY = viewport->y;
|
|
||||||
metalViewport.width = viewport->w;
|
|
||||||
metalViewport.height = viewport->h;
|
|
||||||
metalViewport.znear = viewport->minDepth;
|
|
||||||
metalViewport.zfar = viewport->maxDepth;
|
|
||||||
|
|
||||||
[metalCommandBuffer->renderEncoder setViewport:metalViewport];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void METAL_SetScissor(
|
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
|
||||||
const SDL_Rect *scissor)
|
|
||||||
{
|
|
||||||
@autoreleasepool {
|
|
||||||
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
|
|
||||||
MTLScissorRect metalScissor;
|
|
||||||
|
|
||||||
metalScissor.x = scissor->x;
|
|
||||||
metalScissor.y = scissor->y;
|
|
||||||
metalScissor.width = scissor->w;
|
|
||||||
metalScissor.height = scissor->h;
|
|
||||||
|
|
||||||
[metalCommandBuffer->renderEncoder setScissorRect:metalScissor];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void METAL_BindVertexBuffers(
|
static void METAL_BindVertexBuffers(
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
Uint32 firstBinding,
|
Uint32 firstBinding,
|
||||||
|
|
|
@ -996,10 +996,12 @@ typedef struct VulkanCommandBuffer
|
||||||
|
|
||||||
VulkanTextureSubresource *depthStencilAttachmentSubresource; // may be NULL
|
VulkanTextureSubresource *depthStencilAttachmentSubresource; // may be NULL
|
||||||
|
|
||||||
// Viewport/scissor state
|
// Dynamic state
|
||||||
|
|
||||||
VkViewport currentViewport;
|
VkViewport currentViewport;
|
||||||
VkRect2D currentScissor;
|
VkRect2D currentScissor;
|
||||||
|
float blendConstants[4];
|
||||||
|
Uint8 stencilRef;
|
||||||
|
|
||||||
// Resource bind state
|
// Resource bind state
|
||||||
|
|
||||||
|
@ -6425,7 +6427,9 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
|
||||||
|
|
||||||
static const VkDynamicState dynamicStates[] = {
|
static const VkDynamicState dynamicStates[] = {
|
||||||
VK_DYNAMIC_STATE_VIEWPORT,
|
VK_DYNAMIC_STATE_VIEWPORT,
|
||||||
VK_DYNAMIC_STATE_SCISSOR
|
VK_DYNAMIC_STATE_SCISSOR,
|
||||||
|
VK_DYNAMIC_STATE_BLEND_CONSTANTS,
|
||||||
|
VK_DYNAMIC_STATE_STENCIL_REFERENCE
|
||||||
};
|
};
|
||||||
VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo;
|
VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo;
|
||||||
|
|
||||||
|
@ -6590,8 +6594,7 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
|
||||||
pipelineCreateInfo->depthStencilState.compareMask;
|
pipelineCreateInfo->depthStencilState.compareMask;
|
||||||
frontStencilState.writeMask =
|
frontStencilState.writeMask =
|
||||||
pipelineCreateInfo->depthStencilState.writeMask;
|
pipelineCreateInfo->depthStencilState.writeMask;
|
||||||
frontStencilState.reference =
|
frontStencilState.reference = 0;
|
||||||
pipelineCreateInfo->depthStencilState.reference;
|
|
||||||
|
|
||||||
backStencilState.failOp = SDLToVK_StencilOp[pipelineCreateInfo->depthStencilState.backStencilState.failOp];
|
backStencilState.failOp = SDLToVK_StencilOp[pipelineCreateInfo->depthStencilState.backStencilState.failOp];
|
||||||
backStencilState.passOp = SDLToVK_StencilOp[pipelineCreateInfo->depthStencilState.backStencilState.passOp];
|
backStencilState.passOp = SDLToVK_StencilOp[pipelineCreateInfo->depthStencilState.backStencilState.passOp];
|
||||||
|
@ -6601,8 +6604,7 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
|
||||||
pipelineCreateInfo->depthStencilState.compareMask;
|
pipelineCreateInfo->depthStencilState.compareMask;
|
||||||
backStencilState.writeMask =
|
backStencilState.writeMask =
|
||||||
pipelineCreateInfo->depthStencilState.writeMask;
|
pipelineCreateInfo->depthStencilState.writeMask;
|
||||||
backStencilState.reference =
|
backStencilState.reference = 0;
|
||||||
pipelineCreateInfo->depthStencilState.reference;
|
|
||||||
|
|
||||||
depthStencilStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
depthStencilStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||||
depthStencilStateCreateInfo.pNext = NULL;
|
depthStencilStateCreateInfo.pNext = NULL;
|
||||||
|
@ -6644,14 +6646,10 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
|
||||||
pipelineCreateInfo->attachmentInfo.colorAttachmentCount;
|
pipelineCreateInfo->attachmentInfo.colorAttachmentCount;
|
||||||
colorBlendStateCreateInfo.pAttachments =
|
colorBlendStateCreateInfo.pAttachments =
|
||||||
colorBlendAttachmentStates;
|
colorBlendAttachmentStates;
|
||||||
colorBlendStateCreateInfo.blendConstants[0] =
|
colorBlendStateCreateInfo.blendConstants[0] = 1.0f;
|
||||||
pipelineCreateInfo->blendConstants[0];
|
colorBlendStateCreateInfo.blendConstants[1] = 1.0f;
|
||||||
colorBlendStateCreateInfo.blendConstants[1] =
|
colorBlendStateCreateInfo.blendConstants[2] = 1.0f;
|
||||||
pipelineCreateInfo->blendConstants[1];
|
colorBlendStateCreateInfo.blendConstants[3] = 1.0f;
|
||||||
colorBlendStateCreateInfo.blendConstants[2] =
|
|
||||||
pipelineCreateInfo->blendConstants[2];
|
|
||||||
colorBlendStateCreateInfo.blendConstants[3] =
|
|
||||||
pipelineCreateInfo->blendConstants[3];
|
|
||||||
|
|
||||||
// We don't support LogicOp, so this is easy.
|
// We don't support LogicOp, so this is easy.
|
||||||
colorBlendStateCreateInfo.logicOpEnable = VK_FALSE;
|
colorBlendStateCreateInfo.logicOpEnable = VK_FALSE;
|
||||||
|
@ -7530,6 +7528,56 @@ static void VULKAN_SetScissor(
|
||||||
&vulkanCommandBuffer->currentScissor);
|
&vulkanCommandBuffer->currentScissor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void VULKAN_INTERNAL_SetCurrentBlendConstants(
|
||||||
|
VulkanCommandBuffer *vulkanCommandBuffer,
|
||||||
|
SDL_FColor blendConstants)
|
||||||
|
{
|
||||||
|
vulkanCommandBuffer->blendConstants[0] = blendConstants.r;
|
||||||
|
vulkanCommandBuffer->blendConstants[1] = blendConstants.g;
|
||||||
|
vulkanCommandBuffer->blendConstants[2] = blendConstants.b;
|
||||||
|
vulkanCommandBuffer->blendConstants[3] = blendConstants.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void VULKAN_SetBlendConstants(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
SDL_FColor blendConstants)
|
||||||
|
{
|
||||||
|
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer;
|
||||||
|
VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer;
|
||||||
|
|
||||||
|
VULKAN_INTERNAL_SetCurrentBlendConstants(
|
||||||
|
vulkanCommandBuffer,
|
||||||
|
blendConstants);
|
||||||
|
|
||||||
|
renderer->vkCmdSetBlendConstants(
|
||||||
|
vulkanCommandBuffer->commandBuffer,
|
||||||
|
vulkanCommandBuffer->blendConstants);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void VULKAN_INTERNAL_SetCurrentStencilReference(
|
||||||
|
VulkanCommandBuffer *vulkanCommandBuffer,
|
||||||
|
Uint8 reference)
|
||||||
|
{
|
||||||
|
vulkanCommandBuffer->stencilRef = reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void VULKAN_SetStencilReference(
|
||||||
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
|
Uint8 reference)
|
||||||
|
{
|
||||||
|
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer;
|
||||||
|
VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer;
|
||||||
|
|
||||||
|
VULKAN_INTERNAL_SetCurrentStencilReference(
|
||||||
|
vulkanCommandBuffer,
|
||||||
|
reference);
|
||||||
|
|
||||||
|
renderer->vkCmdSetStencilReference(
|
||||||
|
vulkanCommandBuffer->commandBuffer,
|
||||||
|
VK_STENCIL_FACE_FRONT_AND_BACK,
|
||||||
|
reference);
|
||||||
|
}
|
||||||
|
|
||||||
static void VULKAN_BindVertexSamplers(
|
static void VULKAN_BindVertexSamplers(
|
||||||
SDL_GPUCommandBuffer *commandBuffer,
|
SDL_GPUCommandBuffer *commandBuffer,
|
||||||
Uint32 firstSlot,
|
Uint32 firstSlot,
|
||||||
|
@ -7986,7 +8034,7 @@ static void VULKAN_BeginRenderPass(
|
||||||
|
|
||||||
SDL_stack_free(clearValues);
|
SDL_stack_free(clearValues);
|
||||||
|
|
||||||
// Set sensible default viewport state
|
// Set sensible default states
|
||||||
|
|
||||||
defaultViewport.x = 0;
|
defaultViewport.x = 0;
|
||||||
defaultViewport.y = 0;
|
defaultViewport.y = 0;
|
||||||
|
@ -8007,6 +8055,14 @@ static void VULKAN_BeginRenderPass(
|
||||||
VULKAN_INTERNAL_SetCurrentScissor(
|
VULKAN_INTERNAL_SetCurrentScissor(
|
||||||
vulkanCommandBuffer,
|
vulkanCommandBuffer,
|
||||||
&defaultScissor);
|
&defaultScissor);
|
||||||
|
|
||||||
|
VULKAN_INTERNAL_SetCurrentBlendConstants(
|
||||||
|
vulkanCommandBuffer,
|
||||||
|
(SDL_FColor){ 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
|
|
||||||
|
VULKAN_INTERNAL_SetCurrentStencilReference(
|
||||||
|
vulkanCommandBuffer,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VULKAN_BindGraphicsPipeline(
|
static void VULKAN_BindGraphicsPipeline(
|
||||||
|
@ -8038,6 +8094,15 @@ static void VULKAN_BindGraphicsPipeline(
|
||||||
1,
|
1,
|
||||||
&vulkanCommandBuffer->currentScissor);
|
&vulkanCommandBuffer->currentScissor);
|
||||||
|
|
||||||
|
renderer->vkCmdSetBlendConstants(
|
||||||
|
vulkanCommandBuffer->commandBuffer,
|
||||||
|
vulkanCommandBuffer->blendConstants);
|
||||||
|
|
||||||
|
renderer->vkCmdSetStencilReference(
|
||||||
|
vulkanCommandBuffer->commandBuffer,
|
||||||
|
VK_STENCIL_FACE_FRONT_AND_BACK,
|
||||||
|
vulkanCommandBuffer->stencilRef);
|
||||||
|
|
||||||
// Acquire uniform buffers if necessary
|
// Acquire uniform buffers if necessary
|
||||||
for (Uint32 i = 0; i < pipeline->resourceLayout.vertexUniformBufferCount; i += 1) {
|
for (Uint32 i = 0; i < pipeline->resourceLayout.vertexUniformBufferCount; i += 1) {
|
||||||
if (vulkanCommandBuffer->vertexUniformBuffers[i] == NULL) {
|
if (vulkanCommandBuffer->vertexUniformBuffers[i] == NULL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue