mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-14 15:42:49 +02:00
Add the SDL_GPU API
Project Lead: Evan Hemsley <evan@moonside.games> Co-designer, Metal Port, Console Ports: Co-authored-by: Caleb Cornett <caleb.cornett@outlook.com> Production, QA, Debug: Co-authored-by: Ethan Lee <flibitijibibo@gmail.com> SDL_Render Driver, Bugfixes: Co-authored-by: Andrei Alexeyev <akari@taisei-project.org> Additional D3D12 Programming, Bugfixes: Co-authored-by: Bart van der Werf <bluelive@gmail.com> Bugfixes and Feedback: Co-authored-by: Zakary Strange <zakarystrange@gmail.com> Co-authored-by: meyraud705 <meyraud705@gmail.com> Co-authored-by: Joshua T. Fisher <playmer@gmail.com> Co-authored-by: Topi Ritala <ritalat@fastmail.com> Co-authored-by: David Gow <david@ingeniumdigital.com> Original API Proposal: Co-authored-by: Ryan C. Gordon <icculus@icculus.org>
This commit is contained in:
2400
src/gpu/SDL_gpu.c
Normal file
2400
src/gpu/SDL_gpu.c
Normal file
File diff suppressed because it is too large
Load Diff
779
src/gpu/SDL_sysgpu.h
Normal file
779
src/gpu/SDL_sysgpu.h
Normal file
@@ -0,0 +1,779 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
#ifndef SDL_GPU_DRIVER_H
|
||||
#define SDL_GPU_DRIVER_H
|
||||
|
||||
// Common Structs
|
||||
|
||||
typedef struct Pass
|
||||
{
|
||||
SDL_GpuCommandBuffer *commandBuffer;
|
||||
SDL_bool inProgress;
|
||||
} Pass;
|
||||
|
||||
typedef struct CommandBufferCommonHeader
|
||||
{
|
||||
SDL_GpuDevice *device;
|
||||
Pass renderPass;
|
||||
SDL_bool graphicsPipelineBound;
|
||||
Pass computePass;
|
||||
SDL_bool computePipelineBound;
|
||||
Pass copyPass;
|
||||
SDL_bool submitted;
|
||||
} CommandBufferCommonHeader;
|
||||
|
||||
typedef struct TextureCommonHeader
|
||||
{
|
||||
SDL_GpuTextureCreateInfo info;
|
||||
} TextureCommonHeader;
|
||||
|
||||
typedef struct BlitFragmentUniforms
|
||||
{
|
||||
// texcoord space
|
||||
float left;
|
||||
float top;
|
||||
float width;
|
||||
float height;
|
||||
|
||||
Uint32 mipLevel;
|
||||
float layerOrDepth;
|
||||
} BlitFragmentUniforms;
|
||||
|
||||
typedef struct BlitPipelineCacheEntry
|
||||
{
|
||||
SDL_GpuTextureType type;
|
||||
SDL_GpuTextureFormat format;
|
||||
SDL_GpuGraphicsPipeline *pipeline;
|
||||
} BlitPipelineCacheEntry;
|
||||
|
||||
// Internal Helper Utilities
|
||||
|
||||
#define SDL_GPU_TEXTUREFORMAT_MAX (SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT + 1)
|
||||
#define SDL_GPU_SWAPCHAINCOMPOSITION_MAX (SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048 + 1)
|
||||
#define SDL_GPU_PRESENTMODE_MAX (SDL_GPU_PRESENTMODE_MAILBOX + 1)
|
||||
|
||||
static inline Sint32 Texture_GetBlockSize(
|
||||
SDL_GpuTextureFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case SDL_GPU_TEXTUREFORMAT_BC1_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_BC2_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_BC3_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_BC7_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_BC3_UNORM_SRGB:
|
||||
case SDL_GPU_TEXTUREFORMAT_BC7_UNORM_SRGB:
|
||||
return 4;
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_B5G6R5_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_B5G5R5A1_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_R10G10B10A2_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_A8_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8_SNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_SNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16_FLOAT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16_FLOAT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R32_FLOAT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R32G32_FLOAT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB:
|
||||
case SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB:
|
||||
return 1;
|
||||
default:
|
||||
SDL_assert_release(!"Unrecognized TextureFormat!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline SDL_bool IsDepthFormat(
|
||||
SDL_GpuTextureFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case SDL_GPU_TEXTUREFORMAT_D16_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_D24_UNORM:
|
||||
case SDL_GPU_TEXTUREFORMAT_D32_FLOAT:
|
||||
case SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT:
|
||||
return SDL_TRUE;
|
||||
|
||||
default:
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static inline SDL_bool IsStencilFormat(
|
||||
SDL_GpuTextureFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT:
|
||||
return SDL_TRUE;
|
||||
|
||||
default:
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static inline SDL_bool IsIntegerFormat(
|
||||
SDL_GpuTextureFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case SDL_GPU_TEXTUREFORMAT_R8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16_UINT:
|
||||
case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UINT:
|
||||
return SDL_TRUE;
|
||||
|
||||
default:
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static inline Uint32 IndexSize(SDL_GpuIndexElementSize size)
|
||||
{
|
||||
return (size == SDL_GPU_INDEXELEMENTSIZE_16BIT) ? 2 : 4;
|
||||
}
|
||||
|
||||
static inline Uint32 BytesPerRow(
|
||||
Sint32 width,
|
||||
SDL_GpuTextureFormat format)
|
||||
{
|
||||
Uint32 blocksPerRow = width;
|
||||
|
||||
if (format == SDL_GPU_TEXTUREFORMAT_BC1_UNORM ||
|
||||
format == SDL_GPU_TEXTUREFORMAT_BC2_UNORM ||
|
||||
format == SDL_GPU_TEXTUREFORMAT_BC3_UNORM ||
|
||||
format == SDL_GPU_TEXTUREFORMAT_BC7_UNORM) {
|
||||
blocksPerRow = (width + 3) / 4;
|
||||
}
|
||||
|
||||
return blocksPerRow * SDL_GpuTextureFormatTexelBlockSize(format);
|
||||
}
|
||||
|
||||
static inline Sint32 BytesPerImage(
|
||||
Uint32 width,
|
||||
Uint32 height,
|
||||
SDL_GpuTextureFormat format)
|
||||
{
|
||||
Uint32 blocksPerRow = width;
|
||||
Uint32 blocksPerColumn = height;
|
||||
|
||||
if (format == SDL_GPU_TEXTUREFORMAT_BC1_UNORM ||
|
||||
format == SDL_GPU_TEXTUREFORMAT_BC2_UNORM ||
|
||||
format == SDL_GPU_TEXTUREFORMAT_BC3_UNORM ||
|
||||
format == SDL_GPU_TEXTUREFORMAT_BC7_UNORM) {
|
||||
blocksPerRow = (width + 3) / 4;
|
||||
blocksPerColumn = (height + 3) / 4;
|
||||
}
|
||||
|
||||
return blocksPerRow * blocksPerColumn * SDL_GpuTextureFormatTexelBlockSize(format);
|
||||
}
|
||||
|
||||
// GraphicsDevice Limits
|
||||
|
||||
#define MAX_TEXTURE_SAMPLERS_PER_STAGE 16
|
||||
#define MAX_STORAGE_TEXTURES_PER_STAGE 8
|
||||
#define MAX_STORAGE_BUFFERS_PER_STAGE 8
|
||||
#define MAX_UNIFORM_BUFFERS_PER_STAGE 4
|
||||
#define MAX_COMPUTE_WRITE_TEXTURES 8
|
||||
#define MAX_COMPUTE_WRITE_BUFFERS 8
|
||||
#define UNIFORM_BUFFER_SIZE 32768
|
||||
#define MAX_BUFFER_BINDINGS 16
|
||||
#define MAX_COLOR_TARGET_BINDINGS 4
|
||||
#define MAX_PRESENT_COUNT 16
|
||||
#define MAX_FRAMES_IN_FLIGHT 3
|
||||
|
||||
// Internal Macros
|
||||
|
||||
#define EXPAND_ARRAY_IF_NEEDED(arr, elementType, newCount, capacity, newCapacity) \
|
||||
if (newCount >= capacity) { \
|
||||
capacity = newCapacity; \
|
||||
arr = (elementType *)SDL_realloc( \
|
||||
arr, \
|
||||
sizeof(elementType) * capacity); \
|
||||
}
|
||||
|
||||
// Internal Declarations
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
SDL_GpuGraphicsPipeline *SDL_Gpu_FetchBlitPipeline(
|
||||
SDL_GpuDevice *device,
|
||||
SDL_GpuTextureType sourceTextureType,
|
||||
SDL_GpuTextureFormat destinationFormat,
|
||||
SDL_GpuShader *blitVertexShader,
|
||||
SDL_GpuShader *blitFrom2DShader,
|
||||
SDL_GpuShader *blitFrom2DArrayShader,
|
||||
SDL_GpuShader *blitFrom3DShader,
|
||||
SDL_GpuShader *blitFromCubeShader,
|
||||
BlitPipelineCacheEntry **blitPipelines,
|
||||
Uint32 *blitPipelineCount,
|
||||
Uint32 *blitPipelineCapacity);
|
||||
|
||||
void SDL_Gpu_BlitCommon(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBlitRegion *source,
|
||||
SDL_GpuBlitRegion *destination,
|
||||
SDL_FlipMode flipMode,
|
||||
SDL_GpuFilter filterMode,
|
||||
SDL_bool cycle,
|
||||
SDL_GpuSampler *blitLinearSampler,
|
||||
SDL_GpuSampler *blitNearestSampler,
|
||||
SDL_GpuShader *blitVertexShader,
|
||||
SDL_GpuShader *blitFrom2DShader,
|
||||
SDL_GpuShader *blitFrom2DArrayShader,
|
||||
SDL_GpuShader *blitFrom3DShader,
|
||||
SDL_GpuShader *blitFromCubeShader,
|
||||
BlitPipelineCacheEntry **blitPipelines,
|
||||
Uint32 *blitPipelineCount,
|
||||
Uint32 *blitPipelineCapacity);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
// SDL_GpuDevice Definition
|
||||
|
||||
typedef struct SDL_GpuRenderer SDL_GpuRenderer;
|
||||
|
||||
struct SDL_GpuDevice
|
||||
{
|
||||
// Quit
|
||||
|
||||
void (*DestroyDevice)(SDL_GpuDevice *device);
|
||||
|
||||
// State Creation
|
||||
|
||||
SDL_GpuComputePipeline *(*CreateComputePipeline)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuComputePipelineCreateInfo *pipelineCreateInfo);
|
||||
|
||||
SDL_GpuGraphicsPipeline *(*CreateGraphicsPipeline)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuGraphicsPipelineCreateInfo *pipelineCreateInfo);
|
||||
|
||||
SDL_GpuSampler *(*CreateSampler)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuSamplerCreateInfo *samplerCreateInfo);
|
||||
|
||||
SDL_GpuShader *(*CreateShader)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuShaderCreateInfo *shaderCreateInfo);
|
||||
|
||||
SDL_GpuTexture *(*CreateTexture)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuTextureCreateInfo *textureCreateInfo);
|
||||
|
||||
SDL_GpuBuffer *(*CreateBuffer)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuBufferUsageFlags usageFlags,
|
||||
Uint32 sizeInBytes);
|
||||
|
||||
SDL_GpuTransferBuffer *(*CreateTransferBuffer)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuTransferBufferUsage usage,
|
||||
Uint32 sizeInBytes);
|
||||
|
||||
// Debug Naming
|
||||
|
||||
void (*SetBufferName)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuBuffer *buffer,
|
||||
const char *text);
|
||||
|
||||
void (*SetTextureName)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuTexture *texture,
|
||||
const char *text);
|
||||
|
||||
void (*InsertDebugLabel)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
const char *text);
|
||||
|
||||
void (*PushDebugGroup)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
const char *name);
|
||||
|
||||
void (*PopDebugGroup)(
|
||||
SDL_GpuCommandBuffer *commandBuffer);
|
||||
|
||||
// Disposal
|
||||
|
||||
void (*ReleaseTexture)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuTexture *texture);
|
||||
|
||||
void (*ReleaseSampler)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuSampler *sampler);
|
||||
|
||||
void (*ReleaseBuffer)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuBuffer *buffer);
|
||||
|
||||
void (*ReleaseTransferBuffer)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuTransferBuffer *transferBuffer);
|
||||
|
||||
void (*ReleaseShader)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuShader *shader);
|
||||
|
||||
void (*ReleaseComputePipeline)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuComputePipeline *computePipeline);
|
||||
|
||||
void (*ReleaseGraphicsPipeline)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuGraphicsPipeline *graphicsPipeline);
|
||||
|
||||
// Render Pass
|
||||
|
||||
void (*BeginRenderPass)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuColorAttachmentInfo *colorAttachmentInfos,
|
||||
Uint32 colorAttachmentCount,
|
||||
SDL_GpuDepthStencilAttachmentInfo *depthStencilAttachmentInfo);
|
||||
|
||||
void (*BindGraphicsPipeline)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuGraphicsPipeline *graphicsPipeline);
|
||||
|
||||
void (*SetViewport)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuViewport *viewport);
|
||||
|
||||
void (*SetScissor)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_Rect *scissor);
|
||||
|
||||
void (*BindVertexBuffers)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstBinding,
|
||||
SDL_GpuBufferBinding *pBindings,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*BindIndexBuffer)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBufferBinding *pBinding,
|
||||
SDL_GpuIndexElementSize indexElementSize);
|
||||
|
||||
void (*BindVertexSamplers)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuTextureSamplerBinding *textureSamplerBindings,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*BindVertexStorageTextures)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuTexture **storageTextures,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*BindVertexStorageBuffers)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuBuffer **storageBuffers,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*BindFragmentSamplers)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuTextureSamplerBinding *textureSamplerBindings,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*BindFragmentStorageTextures)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuTexture **storageTextures,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*BindFragmentStorageBuffers)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuBuffer **storageBuffers,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*PushVertexUniformData)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 slotIndex,
|
||||
const void *data,
|
||||
Uint32 dataLengthInBytes);
|
||||
|
||||
void (*PushFragmentUniformData)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 slotIndex,
|
||||
const void *data,
|
||||
Uint32 dataLengthInBytes);
|
||||
|
||||
void (*DrawIndexedPrimitives)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 indexCount,
|
||||
Uint32 instanceCount,
|
||||
Uint32 firstIndex,
|
||||
Sint32 vertexOffset,
|
||||
Uint32 firstInstance);
|
||||
|
||||
void (*DrawPrimitives)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 vertexCount,
|
||||
Uint32 instanceCount,
|
||||
Uint32 firstVertex,
|
||||
Uint32 firstInstance);
|
||||
|
||||
void (*DrawPrimitivesIndirect)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBuffer *buffer,
|
||||
Uint32 offsetInBytes,
|
||||
Uint32 drawCount,
|
||||
Uint32 stride);
|
||||
|
||||
void (*DrawIndexedPrimitivesIndirect)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBuffer *buffer,
|
||||
Uint32 offsetInBytes,
|
||||
Uint32 drawCount,
|
||||
Uint32 stride);
|
||||
|
||||
void (*EndRenderPass)(
|
||||
SDL_GpuCommandBuffer *commandBuffer);
|
||||
|
||||
// Compute Pass
|
||||
|
||||
void (*BeginComputePass)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuStorageTextureWriteOnlyBinding *storageTextureBindings,
|
||||
Uint32 storageTextureBindingCount,
|
||||
SDL_GpuStorageBufferWriteOnlyBinding *storageBufferBindings,
|
||||
Uint32 storageBufferBindingCount);
|
||||
|
||||
void (*BindComputePipeline)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuComputePipeline *computePipeline);
|
||||
|
||||
void (*BindComputeStorageTextures)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuTexture **storageTextures,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*BindComputeStorageBuffers)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 firstSlot,
|
||||
SDL_GpuBuffer **storageBuffers,
|
||||
Uint32 bindingCount);
|
||||
|
||||
void (*PushComputeUniformData)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 slotIndex,
|
||||
const void *data,
|
||||
Uint32 dataLengthInBytes);
|
||||
|
||||
void (*DispatchCompute)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
Uint32 groupCountX,
|
||||
Uint32 groupCountY,
|
||||
Uint32 groupCountZ);
|
||||
|
||||
void (*DispatchComputeIndirect)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBuffer *buffer,
|
||||
Uint32 offsetInBytes);
|
||||
|
||||
void (*EndComputePass)(
|
||||
SDL_GpuCommandBuffer *commandBuffer);
|
||||
|
||||
// TransferBuffer Data
|
||||
|
||||
void *(*MapTransferBuffer)(
|
||||
SDL_GpuRenderer *device,
|
||||
SDL_GpuTransferBuffer *transferBuffer,
|
||||
SDL_bool cycle);
|
||||
|
||||
void (*UnmapTransferBuffer)(
|
||||
SDL_GpuRenderer *device,
|
||||
SDL_GpuTransferBuffer *transferBuffer);
|
||||
|
||||
// Copy Pass
|
||||
|
||||
void (*BeginCopyPass)(
|
||||
SDL_GpuCommandBuffer *commandBuffer);
|
||||
|
||||
void (*UploadToTexture)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuTextureTransferInfo *source,
|
||||
SDL_GpuTextureRegion *destination,
|
||||
SDL_bool cycle);
|
||||
|
||||
void (*UploadToBuffer)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuTransferBufferLocation *source,
|
||||
SDL_GpuBufferRegion *destination,
|
||||
SDL_bool cycle);
|
||||
|
||||
void (*CopyTextureToTexture)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuTextureLocation *source,
|
||||
SDL_GpuTextureLocation *destination,
|
||||
Uint32 w,
|
||||
Uint32 h,
|
||||
Uint32 d,
|
||||
SDL_bool cycle);
|
||||
|
||||
void (*CopyBufferToBuffer)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBufferLocation *source,
|
||||
SDL_GpuBufferLocation *destination,
|
||||
Uint32 size,
|
||||
SDL_bool cycle);
|
||||
|
||||
void (*GenerateMipmaps)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuTexture *texture);
|
||||
|
||||
void (*DownloadFromTexture)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuTextureRegion *source,
|
||||
SDL_GpuTextureTransferInfo *destination);
|
||||
|
||||
void (*DownloadFromBuffer)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBufferRegion *source,
|
||||
SDL_GpuTransferBufferLocation *destination);
|
||||
|
||||
void (*EndCopyPass)(
|
||||
SDL_GpuCommandBuffer *commandBuffer);
|
||||
|
||||
void (*Blit)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_GpuBlitRegion *source,
|
||||
SDL_GpuBlitRegion *destination,
|
||||
SDL_FlipMode flipMode,
|
||||
SDL_GpuFilter filterMode,
|
||||
SDL_bool cycle);
|
||||
|
||||
// Submission/Presentation
|
||||
|
||||
SDL_bool (*SupportsSwapchainComposition)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_Window *window,
|
||||
SDL_GpuSwapchainComposition swapchainComposition);
|
||||
|
||||
SDL_bool (*SupportsPresentMode)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_Window *window,
|
||||
SDL_GpuPresentMode presentMode);
|
||||
|
||||
SDL_bool (*ClaimWindow)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_Window *window);
|
||||
|
||||
void (*UnclaimWindow)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_Window *window);
|
||||
|
||||
SDL_bool (*SetSwapchainParameters)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_Window *window,
|
||||
SDL_GpuSwapchainComposition swapchainComposition,
|
||||
SDL_GpuPresentMode presentMode);
|
||||
|
||||
SDL_GpuTextureFormat (*GetSwapchainTextureFormat)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_Window *window);
|
||||
|
||||
SDL_GpuCommandBuffer *(*AcquireCommandBuffer)(
|
||||
SDL_GpuRenderer *driverData);
|
||||
|
||||
SDL_GpuTexture *(*AcquireSwapchainTexture)(
|
||||
SDL_GpuCommandBuffer *commandBuffer,
|
||||
SDL_Window *window,
|
||||
Uint32 *pWidth,
|
||||
Uint32 *pHeight);
|
||||
|
||||
void (*Submit)(
|
||||
SDL_GpuCommandBuffer *commandBuffer);
|
||||
|
||||
SDL_GpuFence *(*SubmitAndAcquireFence)(
|
||||
SDL_GpuCommandBuffer *commandBuffer);
|
||||
|
||||
void (*Wait)(
|
||||
SDL_GpuRenderer *driverData);
|
||||
|
||||
void (*WaitForFences)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_bool waitAll,
|
||||
SDL_GpuFence **pFences,
|
||||
Uint32 fenceCount);
|
||||
|
||||
SDL_bool (*QueryFence)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuFence *fence);
|
||||
|
||||
void (*ReleaseFence)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuFence *fence);
|
||||
|
||||
// Feature Queries
|
||||
|
||||
SDL_bool (*SupportsTextureFormat)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuTextureFormat format,
|
||||
SDL_GpuTextureType type,
|
||||
SDL_GpuTextureUsageFlags usage);
|
||||
|
||||
SDL_bool (*SupportsSampleCount)(
|
||||
SDL_GpuRenderer *driverData,
|
||||
SDL_GpuTextureFormat format,
|
||||
SDL_GpuSampleCount desiredSampleCount);
|
||||
|
||||
// Opaque pointer for the Driver
|
||||
SDL_GpuRenderer *driverData;
|
||||
|
||||
// Store this for SDL_GetGpuDriver()
|
||||
SDL_GpuDriver backend;
|
||||
|
||||
// Store this for SDL_gpu.c's debug layer
|
||||
SDL_bool debugMode;
|
||||
SDL_GpuShaderFormat shaderFormats;
|
||||
};
|
||||
|
||||
#define ASSIGN_DRIVER_FUNC(func, name) \
|
||||
result->func = name##_##func;
|
||||
#define ASSIGN_DRIVER(name) \
|
||||
ASSIGN_DRIVER_FUNC(DestroyDevice, name) \
|
||||
ASSIGN_DRIVER_FUNC(CreateComputePipeline, name) \
|
||||
ASSIGN_DRIVER_FUNC(CreateGraphicsPipeline, name) \
|
||||
ASSIGN_DRIVER_FUNC(CreateSampler, name) \
|
||||
ASSIGN_DRIVER_FUNC(CreateShader, name) \
|
||||
ASSIGN_DRIVER_FUNC(CreateTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(CreateBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(CreateTransferBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(SetBufferName, name) \
|
||||
ASSIGN_DRIVER_FUNC(SetTextureName, name) \
|
||||
ASSIGN_DRIVER_FUNC(InsertDebugLabel, name) \
|
||||
ASSIGN_DRIVER_FUNC(PushDebugGroup, name) \
|
||||
ASSIGN_DRIVER_FUNC(PopDebugGroup, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseSampler, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseTransferBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseShader, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseComputePipeline, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseGraphicsPipeline, name) \
|
||||
ASSIGN_DRIVER_FUNC(BeginRenderPass, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
|
||||
ASSIGN_DRIVER_FUNC(SetViewport, name) \
|
||||
ASSIGN_DRIVER_FUNC(SetScissor, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindVertexSamplers, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindVertexStorageTextures, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindVertexStorageBuffers, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindFragmentSamplers, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindFragmentStorageTextures, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindFragmentStorageBuffers, name) \
|
||||
ASSIGN_DRIVER_FUNC(PushVertexUniformData, name) \
|
||||
ASSIGN_DRIVER_FUNC(PushFragmentUniformData, name) \
|
||||
ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \
|
||||
ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \
|
||||
ASSIGN_DRIVER_FUNC(DrawPrimitivesIndirect, name) \
|
||||
ASSIGN_DRIVER_FUNC(DrawIndexedPrimitivesIndirect, name) \
|
||||
ASSIGN_DRIVER_FUNC(EndRenderPass, name) \
|
||||
ASSIGN_DRIVER_FUNC(BeginComputePass, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindComputePipeline, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindComputeStorageTextures, name) \
|
||||
ASSIGN_DRIVER_FUNC(BindComputeStorageBuffers, name) \
|
||||
ASSIGN_DRIVER_FUNC(PushComputeUniformData, name) \
|
||||
ASSIGN_DRIVER_FUNC(DispatchCompute, name) \
|
||||
ASSIGN_DRIVER_FUNC(DispatchComputeIndirect, name) \
|
||||
ASSIGN_DRIVER_FUNC(EndComputePass, name) \
|
||||
ASSIGN_DRIVER_FUNC(MapTransferBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(UnmapTransferBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(BeginCopyPass, name) \
|
||||
ASSIGN_DRIVER_FUNC(UploadToTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(UploadToBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(DownloadFromTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(DownloadFromBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(CopyBufferToBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(GenerateMipmaps, name) \
|
||||
ASSIGN_DRIVER_FUNC(EndCopyPass, name) \
|
||||
ASSIGN_DRIVER_FUNC(Blit, name) \
|
||||
ASSIGN_DRIVER_FUNC(SupportsSwapchainComposition, name) \
|
||||
ASSIGN_DRIVER_FUNC(SupportsPresentMode, name) \
|
||||
ASSIGN_DRIVER_FUNC(ClaimWindow, name) \
|
||||
ASSIGN_DRIVER_FUNC(UnclaimWindow, name) \
|
||||
ASSIGN_DRIVER_FUNC(SetSwapchainParameters, name) \
|
||||
ASSIGN_DRIVER_FUNC(GetSwapchainTextureFormat, name) \
|
||||
ASSIGN_DRIVER_FUNC(AcquireCommandBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(AcquireSwapchainTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(Submit, name) \
|
||||
ASSIGN_DRIVER_FUNC(SubmitAndAcquireFence, name) \
|
||||
ASSIGN_DRIVER_FUNC(Wait, name) \
|
||||
ASSIGN_DRIVER_FUNC(WaitForFences, name) \
|
||||
ASSIGN_DRIVER_FUNC(QueryFence, name) \
|
||||
ASSIGN_DRIVER_FUNC(ReleaseFence, name) \
|
||||
ASSIGN_DRIVER_FUNC(SupportsTextureFormat, name) \
|
||||
ASSIGN_DRIVER_FUNC(SupportsSampleCount, name)
|
||||
|
||||
typedef struct SDL_GpuBootstrap
|
||||
{
|
||||
const char *Name;
|
||||
const SDL_GpuDriver backendflag;
|
||||
const SDL_GpuShaderFormat shaderFormats;
|
||||
SDL_bool (*PrepareDriver)(SDL_VideoDevice *_this);
|
||||
SDL_GpuDevice *(*CreateDevice)(SDL_bool debugMode, SDL_bool preferLowPower, SDL_PropertiesID props);
|
||||
} SDL_GpuBootstrap;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern SDL_GpuBootstrap VulkanDriver;
|
||||
extern SDL_GpuBootstrap D3D11Driver;
|
||||
extern SDL_GpuBootstrap D3D12Driver;
|
||||
extern SDL_GpuBootstrap MetalDriver;
|
||||
extern SDL_GpuBootstrap PS5Driver;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDL_GPU_DRIVER_H
|
||||
1328
src/gpu/d3d11/D3D11_Blit.h
Normal file
1328
src/gpu/d3d11/D3D11_Blit.h
Normal file
File diff suppressed because it is too large
Load Diff
6135
src/gpu/d3d11/SDL_gpu_d3d11.c
Normal file
6135
src/gpu/d3d11/SDL_gpu_d3d11.c
Normal file
File diff suppressed because it is too large
Load Diff
7
src/gpu/d3d11/compile_shaders.bat
Normal file
7
src/gpu/d3d11/compile_shaders.bat
Normal file
@@ -0,0 +1,7 @@
|
||||
fxc /T vs_5_0 /E FullscreenVert /Fh D3D11_FullscreenVert.h ..\d3dcommon\D3D_Blit.hlsl
|
||||
fxc /T ps_5_0 /E BlitFrom2D /Fh D3D11_BlitFrom2D.h ..\d3dcommon\D3D_Blit.hlsl
|
||||
fxc /T ps_5_0 /E BlitFrom2DArray /Fh D3D11_BlitFrom2DArray.h ..\d3dcommon\D3D_Blit.hlsl
|
||||
fxc /T ps_5_0 /E BlitFrom3D /Fh D3D11_BlitFrom3D.h ..\d3dcommon\D3D_Blit.hlsl
|
||||
fxc /T ps_5_0 /E BlitFromCube /Fh D3D11_BlitFromCube.h ..\d3dcommon\D3D_Blit.hlsl
|
||||
copy /b D3D11_FullscreenVert.h+D3D11_BlitFrom2D.h+D3D11_BlitFrom2DArray.h+D3D11_BlitFrom3D.h+D3D11_BlitFromCube.h D3D11_Blit.h
|
||||
del D3D11_FullscreenVert.h D3D11_BlitFrom2D.h D3D11_BlitFrom2DArray.h D3D11_BlitFrom3D.h D3D11_BlitFromCube.h
|
||||
2665
src/gpu/d3d12/D3D12_Blit.h
Normal file
2665
src/gpu/d3d12/D3D12_Blit.h
Normal file
File diff suppressed because it is too large
Load Diff
8255
src/gpu/d3d12/SDL_gpu_d3d12.c
Normal file
8255
src/gpu/d3d12/SDL_gpu_d3d12.c
Normal file
File diff suppressed because it is too large
Load Diff
17
src/gpu/d3d12/compile_shaders.bat
Normal file
17
src/gpu/d3d12/compile_shaders.bat
Normal file
@@ -0,0 +1,17 @@
|
||||
rem This script runs for the Windows build, but also via the _xbox variant with these vars set.
|
||||
rem Make sure to default to building for Windows if they're not set.
|
||||
if %DXC%.==. set DXC=dxc
|
||||
if %SUFFIX%.==. set SUFFIX=.h
|
||||
|
||||
echo Building with %DXC%
|
||||
echo Suffix %SUFFIX%
|
||||
|
||||
cd "%~dp0"
|
||||
|
||||
%DXC% -E FullscreenVert -T vs_6_0 -Fh D3D12_FullscreenVert.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
|
||||
%DXC% -E BlitFrom2D -T ps_6_0 -Fh D3D12_BlitFrom2D.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
|
||||
%DXC% -E BlitFrom2DArray -T ps_6_0 -Fh D3D12_BlitFrom2DArray.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
|
||||
%DXC% -E BlitFrom3D -T ps_6_0 -Fh D3D12_BlitFrom3D.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
|
||||
%DXC% -E BlitFromCube -T ps_6_0 -Fh D3D12_BlitFromCube.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
|
||||
copy /b D3D12_FullscreenVert.h+D3D12_BlitFrom2D.h+D3D12_BlitFrom2DArray.h+D3D12_BlitFrom3D.h+D3D12_BlitFromCube.h D3D12_Blit%SUFFIX%
|
||||
del D3D12_FullscreenVert.h D3D12_BlitFrom2D.h D3D12_BlitFrom2DArray.h D3D12_BlitFrom3D.h D3D12_BlitFromCube.h
|
||||
13
src/gpu/d3d12/compile_shaders_xbox.bat
Normal file
13
src/gpu/d3d12/compile_shaders_xbox.bat
Normal file
@@ -0,0 +1,13 @@
|
||||
if %2.==one. goto setxboxone
|
||||
rem Xbox Series compile
|
||||
set DXC="%GameDKLatest%\GXDK\bin\Scarlett\DXC.exe"
|
||||
set SUFFIX=_Series.h
|
||||
goto startbuild
|
||||
|
||||
:setxboxone
|
||||
set DXC="%GameDKLatest%\GXDK\bin\XboxOne\DXC.exe"
|
||||
set SUFFIX=_One.h
|
||||
|
||||
:startbuild
|
||||
|
||||
call "%~dp0\compile_shaders.bat"
|
||||
91
src/gpu/d3dcommon/D3D_Blit.hlsl
Normal file
91
src/gpu/d3dcommon/D3D_Blit.hlsl
Normal file
@@ -0,0 +1,91 @@
|
||||
#if D3D12
|
||||
#define BlitRS \
|
||||
"DescriptorTable ( Sampler(s0, space=2), visibility = SHADER_VISIBILITY_PIXEL ),"\
|
||||
"DescriptorTable ( SRV(t0, space=2), visibility = SHADER_VISIBILITY_PIXEL ),"\
|
||||
"CBV(b0, space=3, visibility = SHADER_VISIBILITY_PIXEL),"\
|
||||
|
||||
#define REG(reg, space) register(reg, space)
|
||||
#else
|
||||
#define REG(reg, space) register(reg)
|
||||
#endif
|
||||
|
||||
struct VertexToPixel
|
||||
{
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 pos : SV_POSITION;
|
||||
};
|
||||
|
||||
cbuffer SourceRegionBuffer : REG(b0, space3)
|
||||
{
|
||||
float2 UVLeftTop;
|
||||
float2 UVDimensions;
|
||||
uint MipLevel;
|
||||
float LayerOrDepth;
|
||||
};
|
||||
|
||||
Texture2D SourceTexture2D : REG(t0, space2);
|
||||
Texture2DArray SourceTexture2DArray : REG(t0, space2);
|
||||
Texture3D SourceTexture3D : REG(t0, space2);
|
||||
TextureCube SourceTextureCube : REG(t0, space2);
|
||||
sampler SourceSampler : REG(s0, space2);
|
||||
|
||||
#if D3D12
|
||||
[RootSignature(BlitRS)]
|
||||
#endif
|
||||
VertexToPixel FullscreenVert(uint vI : SV_VERTEXID)
|
||||
{
|
||||
float2 inTex = float2((vI << 1) & 2, vI & 2);
|
||||
VertexToPixel Out = (VertexToPixel)0;
|
||||
Out.tex = inTex;
|
||||
Out.pos = float4(inTex * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
|
||||
return Out;
|
||||
}
|
||||
|
||||
#if D3D12
|
||||
[RootSignature(BlitRS)]
|
||||
#endif
|
||||
float4 BlitFrom2D(VertexToPixel input) : SV_Target0
|
||||
{
|
||||
float2 newCoord = UVLeftTop + UVDimensions * input.tex;
|
||||
return SourceTexture2D.SampleLevel(SourceSampler, newCoord, MipLevel);
|
||||
}
|
||||
|
||||
#if D3D12
|
||||
[RootSignature(BlitRS)]
|
||||
#endif
|
||||
float4 BlitFrom2DArray(VertexToPixel input) : SV_Target0
|
||||
{
|
||||
float3 newCoord = float3(UVLeftTop + UVDimensions * input.tex, (uint)LayerOrDepth);
|
||||
return SourceTexture2DArray.SampleLevel(SourceSampler, newCoord, MipLevel);
|
||||
}
|
||||
|
||||
#if D3D12
|
||||
[RootSignature(BlitRS)]
|
||||
#endif
|
||||
float4 BlitFrom3D(VertexToPixel input) : SV_Target0
|
||||
{
|
||||
float3 newCoord = float3(UVLeftTop + UVDimensions * input.tex, LayerOrDepth);
|
||||
return SourceTexture3D.SampleLevel(SourceSampler, newCoord, MipLevel);
|
||||
}
|
||||
|
||||
#if D3D12
|
||||
[RootSignature(BlitRS)]
|
||||
#endif
|
||||
float4 BlitFromCube(VertexToPixel input) : SV_Target0
|
||||
{
|
||||
// Thanks, Wikipedia! https://en.wikipedia.org/wiki/Cube_mapping
|
||||
float3 newCoord;
|
||||
float2 scaledUV = UVLeftTop + UVDimensions * input.tex;
|
||||
float u = 2.0 * scaledUV.x - 1.0;
|
||||
float v = 2.0 * scaledUV.y - 1.0;
|
||||
switch ((uint)LayerOrDepth) {
|
||||
case 0: newCoord = float3(1.0, -v, -u); break; // POSITIVE X
|
||||
case 1: newCoord = float3(-1.0, -v, u); break; // NEGATIVE X
|
||||
case 2: newCoord = float3(u, -1.0, -v); break; // POSITIVE Y
|
||||
case 3: newCoord = float3(u, 1.0, v); break; // NEGATIVE Y
|
||||
case 4: newCoord = float3(u, -v, 1.0); break; // POSITIVE Z
|
||||
case 5: newCoord = float3(-u, -v, -1.0); break; // NEGATIVE Z
|
||||
default: newCoord = float3(0, 0, 0); break; // silences warning
|
||||
}
|
||||
return SourceTextureCube.SampleLevel(SourceSampler, newCoord, MipLevel);
|
||||
}
|
||||
7969
src/gpu/metal/Metal_Blit.h
Normal file
7969
src/gpu/metal/Metal_Blit.h
Normal file
File diff suppressed because it is too large
Load Diff
85
src/gpu/metal/Metal_Blit.metal
Normal file
85
src/gpu/metal/Metal_Blit.metal
Normal file
@@ -0,0 +1,85 @@
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct VertexToFragment {
|
||||
float2 tex;
|
||||
float4 pos [[position]];
|
||||
};
|
||||
|
||||
struct SourceRegion {
|
||||
float2 UVLeftTop;
|
||||
float2 UVDimensions;
|
||||
uint MipLevel;
|
||||
float LayerOrDepth;
|
||||
};
|
||||
|
||||
#if COMPILE_FullscreenVert
|
||||
vertex VertexToFragment FullscreenVert(uint vI [[vertex_id]]) {
|
||||
float2 inTex = float2((vI << 1) & 2, vI & 2);
|
||||
VertexToFragment out;
|
||||
out.tex = inTex;
|
||||
out.pos = float4(inTex * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if COMPILE_BlitFrom2D
|
||||
fragment float4 BlitFrom2D(
|
||||
VertexToFragment input [[stage_in]],
|
||||
constant SourceRegion &sourceRegion [[buffer(0)]],
|
||||
texture2d<float> sourceTexture [[texture(0)]],
|
||||
sampler sourceSampler [[sampler(0)]])
|
||||
{
|
||||
float2 newCoord = sourceRegion.UVLeftTop + sourceRegion.UVDimensions * input.tex;
|
||||
return sourceTexture.sample(sourceSampler, newCoord, level(sourceRegion.MipLevel));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if COMPILE_BlitFrom2DArray
|
||||
fragment float4 BlitFrom2DArray(
|
||||
VertexToFragment input [[stage_in]],
|
||||
constant SourceRegion &sourceRegion [[buffer(0)]],
|
||||
texture2d_array<float> sourceTexture [[texture(0)]],
|
||||
sampler sourceSampler [[sampler(0)]])
|
||||
{
|
||||
float2 newCoord = sourceRegion.UVLeftTop + sourceRegion.UVDimensions * input.tex;
|
||||
return sourceTexture.sample(sourceSampler, newCoord, (uint)sourceRegion.LayerOrDepth, level(sourceRegion.MipLevel));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if COMPILE_BlitFrom3D
|
||||
fragment float4 BlitFrom3D(
|
||||
VertexToFragment input [[stage_in]],
|
||||
constant SourceRegion &sourceRegion [[buffer(0)]],
|
||||
texture3d<float> sourceTexture [[texture(0)]],
|
||||
sampler sourceSampler [[sampler(0)]])
|
||||
{
|
||||
float2 newCoord = sourceRegion.UVLeftTop + sourceRegion.UVDimensions * input.tex;
|
||||
return sourceTexture.sample(sourceSampler, float3(newCoord, sourceRegion.LayerOrDepth), level(sourceRegion.MipLevel));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if COMPILE_BlitFromCube
|
||||
fragment float4 BlitFromCube(
|
||||
VertexToFragment input [[stage_in]],
|
||||
constant SourceRegion &sourceRegion [[buffer(0)]],
|
||||
texturecube<float> sourceTexture [[texture(0)]],
|
||||
sampler sourceSampler [[sampler(0)]])
|
||||
{
|
||||
// Thanks, Wikipedia! https://en.wikipedia.org/wiki/Cube_mapping
|
||||
float2 scaledUV = sourceRegion.UVLeftTop + sourceRegion.UVDimensions * input.tex;
|
||||
float u = 2.0 * scaledUV.x - 1.0;
|
||||
float v = 2.0 * scaledUV.y - 1.0;
|
||||
float3 newCoord;
|
||||
switch ((uint)sourceRegion.LayerOrDepth) {
|
||||
case 0: newCoord = float3(1.0, -v, -u); break; // POSITIVE X
|
||||
case 1: newCoord = float3(-1.0, -v, u); break; // NEGATIVE X
|
||||
case 2: newCoord = float3(u, -1.0, -v); break; // POSITIVE Y
|
||||
case 3: newCoord = float3(u, 1.0, v); break; // NEGATIVE Y
|
||||
case 4: newCoord = float3(u, -v, 1.0); break; // POSITIVE Z
|
||||
case 5: newCoord = float3(-u, -v, -1.0); break; // NEGATIVE Z
|
||||
default: newCoord = float3(0, 0, 0); break; // silences warning
|
||||
}
|
||||
return sourceTexture.sample(sourceSampler, newCoord, level(sourceRegion.MipLevel));
|
||||
}
|
||||
#endif
|
||||
3984
src/gpu/metal/SDL_gpu_metal.m
Normal file
3984
src/gpu/metal/SDL_gpu_metal.m
Normal file
File diff suppressed because it is too large
Load Diff
68
src/gpu/metal/compile_shaders.sh
Executable file
68
src/gpu/metal/compile_shaders.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
set -e
|
||||
cd `dirname "$0"`
|
||||
|
||||
shadernames=(FullscreenVert BlitFrom2D BlitFrom2DArray BlitFrom3D BlitFromCube)
|
||||
|
||||
generate_shaders()
|
||||
{
|
||||
fileplatform=$1
|
||||
compileplatform=$2
|
||||
sdkplatform=$3
|
||||
minversion=$4
|
||||
|
||||
for shadername in "${shadernames[@]}"; do
|
||||
xcrun -sdk $sdkplatform metal -c -std=$compileplatform-metal1.1 -m$sdkplatform-version-min=$minversion -Wall -O3 -D COMPILE_$shadername -o ./$shadername.air ./Metal_Blit.metal || exit $?
|
||||
xcrun -sdk $sdkplatform metallib -o $shadername.metallib $shadername.air || exit $?
|
||||
xxd -i $shadername.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./${shadername}_$fileplatform.h
|
||||
rm -f $shadername.air $shadername.metallib
|
||||
done
|
||||
}
|
||||
|
||||
generate_shaders macos macos macosx 10.11
|
||||
generate_shaders ios ios iphoneos 8.0
|
||||
generate_shaders iphonesimulator ios iphonesimulator 8.0
|
||||
generate_shaders tvos ios appletvos 9.0
|
||||
generate_shaders tvsimulator ios appletvsimulator 9.0
|
||||
|
||||
# Bundle together one mega-header
|
||||
catShaders()
|
||||
{
|
||||
target=$1
|
||||
for shadername in "${shadernames[@]}"; do
|
||||
cat ${shadername}_$target.h >> Metal_Blit.h
|
||||
done
|
||||
}
|
||||
|
||||
rm -f Metal_Blit.h
|
||||
echo "#if defined(SDL_PLATFORM_IOS)" >> Metal_Blit.h
|
||||
echo "#if TARGET_OS_SIMULATOR" >> Metal_Blit.h
|
||||
catShaders iphonesimulator
|
||||
echo "#else" >> Metal_Blit.h
|
||||
catShaders ios
|
||||
echo "#endif" >> Metal_Blit.h
|
||||
echo "#elif defined(SDL_PLATFORM_TVOS)" >> Metal_Blit.h
|
||||
echo "#if TARGET_OS_SIMULATOR" >> Metal_Blit.h
|
||||
catShaders tvsimulator
|
||||
echo "#else" >> Metal_Blit.h
|
||||
catShaders tvos
|
||||
echo "#endif" >> Metal_Blit.h
|
||||
echo "#else" >> Metal_Blit.h
|
||||
catShaders macos
|
||||
echo "#endif" >> Metal_Blit.h
|
||||
|
||||
# Clean up
|
||||
cleanupShaders()
|
||||
{
|
||||
target=$1
|
||||
for shadername in "${shadernames[@]}"; do
|
||||
rm -f ${shadername}_$target.h
|
||||
done
|
||||
}
|
||||
cleanupShaders iphonesimulator
|
||||
cleanupShaders ios
|
||||
cleanupShaders tvsimulator
|
||||
cleanupShaders tvos
|
||||
cleanupShaders macos
|
||||
11797
src/gpu/vulkan/SDL_gpu_vulkan.c
Normal file
11797
src/gpu/vulkan/SDL_gpu_vulkan.c
Normal file
File diff suppressed because it is too large
Load Diff
176
src/gpu/vulkan/SDL_gpu_vulkan_vkfuncs.h
Normal file
176
src/gpu/vulkan/SDL_gpu_vulkan_vkfuncs.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Global functions from the Vulkan Loader
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_GLOBAL_FUNCTION
|
||||
#define VULKAN_GLOBAL_FUNCTION(name)
|
||||
#endif
|
||||
VULKAN_GLOBAL_FUNCTION(vkCreateInstance)
|
||||
VULKAN_GLOBAL_FUNCTION(vkEnumerateInstanceExtensionProperties)
|
||||
VULKAN_GLOBAL_FUNCTION(vkEnumerateInstanceLayerProperties)
|
||||
|
||||
/*
|
||||
* vkInstance, created by global vkCreateInstance function
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_INSTANCE_FUNCTION
|
||||
#define VULKAN_INSTANCE_FUNCTION(name)
|
||||
#endif
|
||||
|
||||
// Vulkan 1.0
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetDeviceProcAddr)
|
||||
VULKAN_INSTANCE_FUNCTION(vkCreateDevice)
|
||||
VULKAN_INSTANCE_FUNCTION(vkDestroyInstance)
|
||||
VULKAN_INSTANCE_FUNCTION(vkEnumerateDeviceExtensionProperties)
|
||||
VULKAN_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceFormatProperties)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceImageFormatProperties)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties)
|
||||
|
||||
// VK_KHR_get_physical_device_properties2, needed for KHR_driver_properties
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties2KHR)
|
||||
|
||||
// VK_KHR_surface
|
||||
VULKAN_INSTANCE_FUNCTION(vkDestroySurfaceKHR)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR)
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR)
|
||||
|
||||
// VK_EXT_debug_utils
|
||||
VULKAN_INSTANCE_FUNCTION(vkCmdBeginDebugUtilsLabelEXT)
|
||||
VULKAN_INSTANCE_FUNCTION(vkSetDebugUtilsObjectNameEXT)
|
||||
VULKAN_INSTANCE_FUNCTION(vkCmdEndDebugUtilsLabelEXT)
|
||||
VULKAN_INSTANCE_FUNCTION(vkCmdInsertDebugUtilsLabelEXT)
|
||||
|
||||
/*
|
||||
* vkDevice, created by a vkInstance
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_DEVICE_FUNCTION
|
||||
#define VULKAN_DEVICE_FUNCTION(name)
|
||||
#endif
|
||||
|
||||
// Vulkan 1.0
|
||||
VULKAN_DEVICE_FUNCTION(vkAllocateCommandBuffers)
|
||||
VULKAN_DEVICE_FUNCTION(vkAllocateDescriptorSets)
|
||||
VULKAN_DEVICE_FUNCTION(vkAllocateMemory)
|
||||
VULKAN_DEVICE_FUNCTION(vkBeginCommandBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkBindBufferMemory)
|
||||
VULKAN_DEVICE_FUNCTION(vkBindImageMemory)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdBeginRenderPass)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdBindDescriptorSets)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdBindIndexBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdBindPipeline)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdBindVertexBuffers)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdBlitImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdClearAttachments)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdClearColorImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdClearDepthStencilImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdCopyBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdCopyImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdCopyBufferToImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdCopyImageToBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdDispatch)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdDispatchIndirect)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdDraw)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdDrawIndexed)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdDrawIndexedIndirect)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdDrawIndirect)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdEndRenderPass)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdPipelineBarrier)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdResolveImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdSetBlendConstants)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdSetDepthBias)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdSetScissor)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdSetStencilReference)
|
||||
VULKAN_DEVICE_FUNCTION(vkCmdSetViewport)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateCommandPool)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateDescriptorPool)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateDescriptorSetLayout)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateFence)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateFramebuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateComputePipelines)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateGraphicsPipelines)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateImageView)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreatePipelineCache)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreatePipelineLayout)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateRenderPass)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateSampler)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateSemaphore)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateShaderModule)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyCommandPool)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyDescriptorPool)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyDescriptorSetLayout)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyDevice)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyFence)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyFramebuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyImage)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyImageView)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyPipeline)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyPipelineCache)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyPipelineLayout)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyRenderPass)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroySampler)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroySemaphore)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroyShaderModule)
|
||||
VULKAN_DEVICE_FUNCTION(vkDeviceWaitIdle)
|
||||
VULKAN_DEVICE_FUNCTION(vkEndCommandBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkFreeCommandBuffers)
|
||||
VULKAN_DEVICE_FUNCTION(vkFreeMemory)
|
||||
VULKAN_DEVICE_FUNCTION(vkGetDeviceQueue)
|
||||
VULKAN_DEVICE_FUNCTION(vkGetPipelineCacheData)
|
||||
VULKAN_DEVICE_FUNCTION(vkGetFenceStatus)
|
||||
VULKAN_DEVICE_FUNCTION(vkGetBufferMemoryRequirements)
|
||||
VULKAN_DEVICE_FUNCTION(vkGetImageMemoryRequirements)
|
||||
VULKAN_DEVICE_FUNCTION(vkMapMemory)
|
||||
VULKAN_DEVICE_FUNCTION(vkQueueSubmit)
|
||||
VULKAN_DEVICE_FUNCTION(vkQueueWaitIdle)
|
||||
VULKAN_DEVICE_FUNCTION(vkResetCommandBuffer)
|
||||
VULKAN_DEVICE_FUNCTION(vkResetCommandPool)
|
||||
VULKAN_DEVICE_FUNCTION(vkResetDescriptorPool)
|
||||
VULKAN_DEVICE_FUNCTION(vkResetFences)
|
||||
VULKAN_DEVICE_FUNCTION(vkUnmapMemory)
|
||||
VULKAN_DEVICE_FUNCTION(vkUpdateDescriptorSets)
|
||||
VULKAN_DEVICE_FUNCTION(vkWaitForFences)
|
||||
|
||||
// VK_KHR_swapchain
|
||||
VULKAN_DEVICE_FUNCTION(vkAcquireNextImageKHR)
|
||||
VULKAN_DEVICE_FUNCTION(vkCreateSwapchainKHR)
|
||||
VULKAN_DEVICE_FUNCTION(vkDestroySwapchainKHR)
|
||||
VULKAN_DEVICE_FUNCTION(vkQueuePresentKHR)
|
||||
VULKAN_DEVICE_FUNCTION(vkGetSwapchainImagesKHR)
|
||||
|
||||
/*
|
||||
* Redefine these every time you include this header!
|
||||
*/
|
||||
#undef VULKAN_GLOBAL_FUNCTION
|
||||
#undef VULKAN_INSTANCE_FUNCTION
|
||||
#undef VULKAN_DEVICE_FUNCTION
|
||||
Reference in New Issue
Block a user