Use the correct namespace for structures

Otherwise the debugger may use the wrong structure definition at runtime.
This commit is contained in:
Sam Lantinga
2024-09-11 11:21:09 -07:00
parent 77c569496d
commit 667a3e40e9
3 changed files with 106 additions and 106 deletions

View File

@@ -53,19 +53,19 @@
// Sampler types // Sampler types
typedef enum typedef enum
{ {
SDL_D3D11_SAMPLER_NEAREST_CLAMP, D3D11_SAMPLER_NEAREST_CLAMP,
SDL_D3D11_SAMPLER_NEAREST_WRAP, D3D11_SAMPLER_NEAREST_WRAP,
SDL_D3D11_SAMPLER_LINEAR_CLAMP, D3D11_SAMPLER_LINEAR_CLAMP,
SDL_D3D11_SAMPLER_LINEAR_WRAP, D3D11_SAMPLER_LINEAR_WRAP,
SDL_NUM_D3D11_SAMPLERS D3D11_SAMPLER_COUNT
} SDL_D3D11_sampler_type; } D3D11_Sampler;
// Vertex shader, common values // Vertex shader, common values
typedef struct typedef struct
{ {
Float4X4 model; Float4X4 model;
Float4X4 projectionAndView; Float4X4 projectionAndView;
} VertexShaderConstants; } D3D11_VertexShaderConstants;
// These should mirror the definitions in D3D11_PixelShader_Common.hlsli // These should mirror the definitions in D3D11_PixelShader_Common.hlsli
//static const float TONEMAP_NONE = 0; //static const float TONEMAP_NONE = 0;
@@ -96,13 +96,13 @@ typedef struct
float sdr_white_point; float sdr_white_point;
float YCbCr_matrix[16]; float YCbCr_matrix[16];
} PixelShaderConstants; } D3D11_PixelShaderConstants;
typedef struct typedef struct
{ {
ID3D11Buffer *constants; ID3D11Buffer *constants;
PixelShaderConstants shader_constants; D3D11_PixelShaderConstants shader_constants;
} PixelShaderState; } D3D11_PixelShaderState;
// Per-vertex data // Per-vertex data
typedef struct typedef struct
@@ -110,7 +110,7 @@ typedef struct
Float2 pos; Float2 pos;
Float2 tex; Float2 tex;
SDL_FColor color; SDL_FColor color;
} VertexPositionColor; } D3D11_VertexPositionColor;
// Per-texture data // Per-texture data
typedef struct typedef struct
@@ -173,7 +173,7 @@ typedef struct
ID3D11PixelShader *pixelShaders[NUM_SHADERS]; ID3D11PixelShader *pixelShaders[NUM_SHADERS];
int blendModesCount; int blendModesCount;
D3D11_BlendMode *blendModes; D3D11_BlendMode *blendModes;
ID3D11SamplerState *samplers[SDL_NUM_D3D11_SAMPLERS]; ID3D11SamplerState *samplers[D3D11_SAMPLER_COUNT];
D3D_FEATURE_LEVEL featureLevel; D3D_FEATURE_LEVEL featureLevel;
bool pixelSizeChanged; bool pixelSizeChanged;
@@ -182,7 +182,7 @@ typedef struct
ID3D11RasterizerState *clippedRasterizer; ID3D11RasterizerState *clippedRasterizer;
// Vertex buffer constants // Vertex buffer constants
VertexShaderConstants vertexShaderConstantsData; D3D11_VertexShaderConstants vertexShaderConstantsData;
ID3D11Buffer *vertexShaderConstants; ID3D11Buffer *vertexShaderConstants;
// Cached renderer properties // Cached renderer properties
@@ -191,7 +191,7 @@ typedef struct
ID3D11RasterizerState *currentRasterizerState; ID3D11RasterizerState *currentRasterizerState;
ID3D11BlendState *currentBlendState; ID3D11BlendState *currentBlendState;
D3D11_Shader currentShader; D3D11_Shader currentShader;
PixelShaderState currentShaderState[NUM_SHADERS]; D3D11_PixelShaderState currentShaderState[NUM_SHADERS];
ID3D11ShaderResourceView *currentShaderResource; ID3D11ShaderResourceView *currentShaderResource;
ID3D11SamplerState *currentSampler; ID3D11SamplerState *currentSampler;
bool cliprectDirty; bool cliprectDirty;
@@ -698,7 +698,7 @@ static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer)
// Setup space to hold vertex shader constants: // Setup space to hold vertex shader constants:
SDL_zero(constantBufferDesc); SDL_zero(constantBufferDesc);
constantBufferDesc.ByteWidth = sizeof(VertexShaderConstants); constantBufferDesc.ByteWidth = sizeof(D3D11_VertexShaderConstants);
constantBufferDesc.Usage = D3D11_USAGE_DEFAULT; constantBufferDesc.Usage = D3D11_USAGE_DEFAULT;
constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
result = ID3D11Device_CreateBuffer(data->d3dDevice, result = ID3D11Device_CreateBuffer(data->d3dDevice,
@@ -721,7 +721,7 @@ static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer)
{ D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_CLAMP }, { D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_CLAMP },
{ D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_WRAP }, { D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_WRAP },
}; };
SDL_COMPILE_TIME_ASSERT(samplerParams_SIZE, SDL_arraysize(samplerParams) == SDL_NUM_D3D11_SAMPLERS); SDL_COMPILE_TIME_ASSERT(samplerParams_SIZE, SDL_arraysize(samplerParams) == D3D11_SAMPLER_COUNT);
SDL_zero(samplerDesc); SDL_zero(samplerDesc);
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
samplerDesc.MipLODBias = 0.0f; samplerDesc.MipLODBias = 0.0f;
@@ -1834,7 +1834,7 @@ static bool D3D11_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
static bool D3D11_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) static bool D3D11_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{ {
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); D3D11_VertexPositionColor *verts = (D3D11_VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(D3D11_VertexPositionColor), 0, &cmd->data.draw.first);
int i; int i;
SDL_FColor color = cmd->data.draw.color; SDL_FColor color = cmd->data.draw.color;
bool convert_color = SDL_RenderingLinearSpace(renderer); bool convert_color = SDL_RenderingLinearSpace(renderer);
@@ -1868,7 +1868,7 @@ static bool D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
{ {
int i; int i;
int count = indices ? num_indices : num_vertices; int count = indices ? num_indices : num_vertices;
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); D3D11_VertexPositionColor *verts = (D3D11_VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(D3D11_VertexPositionColor), 0, &cmd->data.draw.first);
bool convert_color = SDL_RenderingLinearSpace(renderer); bool convert_color = SDL_RenderingLinearSpace(renderer);
D3D11_TextureData *textureData = texture ? (D3D11_TextureData *)texture->internal : NULL; D3D11_TextureData *textureData = texture ? (D3D11_TextureData *)texture->internal : NULL;
float u_scale = textureData ? (float)texture->w / textureData->w : 0.0f; float u_scale = textureData ? (float)texture->w / textureData->w : 0.0f;
@@ -1923,7 +1923,7 @@ static bool D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal;
HRESULT result = S_OK; HRESULT result = S_OK;
const int vbidx = rendererData->currentVertexBuffer; const int vbidx = rendererData->currentVertexBuffer;
const UINT stride = sizeof(VertexPositionColor); const UINT stride = sizeof(D3D11_VertexPositionColor);
const UINT offset = 0; const UINT offset = 0;
if (dataSizeInBytes == 0) { if (dataSizeInBytes == 0) {
@@ -2087,7 +2087,7 @@ static ID3D11RenderTargetView *D3D11_GetCurrentRenderTargetView(SDL_Renderer *re
} }
} }
static void D3D11_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, PixelShaderConstants *constants) static void D3D11_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, D3D11_PixelShaderConstants *constants)
{ {
float output_headroom; float output_headroom;
@@ -2150,7 +2150,7 @@ static void D3D11_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderC
} }
static bool D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, static bool D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd,
D3D11_Shader shader, const PixelShaderConstants *shader_constants, D3D11_Shader shader, const D3D11_PixelShaderConstants *shader_constants,
const int numShaderResources, ID3D11ShaderResourceView **shaderResources, const int numShaderResources, ID3D11ShaderResourceView **shaderResources,
ID3D11SamplerState *sampler, const Float4X4 *matrix) ID3D11SamplerState *sampler, const Float4X4 *matrix)
@@ -2163,8 +2163,8 @@ static bool D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *
const SDL_BlendMode blendMode = cmd->data.draw.blend; const SDL_BlendMode blendMode = cmd->data.draw.blend;
ID3D11BlendState *blendState = NULL; ID3D11BlendState *blendState = NULL;
bool updateSubresource = false; bool updateSubresource = false;
PixelShaderState *shader_state = &rendererData->currentShaderState[shader]; D3D11_PixelShaderState *shader_state = &rendererData->currentShaderState[shader];
PixelShaderConstants solid_constants; D3D11_PixelShaderConstants solid_constants;
if (numShaderResources > 0) { if (numShaderResources > 0) {
shaderResource = shaderResources[0]; shaderResource = shaderResources[0];
@@ -2308,7 +2308,7 @@ static bool D3D11_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal;
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->internal; D3D11_TextureData *textureData = (D3D11_TextureData *)texture->internal;
ID3D11SamplerState *textureSampler; ID3D11SamplerState *textureSampler;
PixelShaderConstants constants; D3D11_PixelShaderConstants constants;
if (!textureData) { if (!textureData) {
return SDL_SetError("Texture is not currently available"); return SDL_SetError("Texture is not currently available");
@@ -2320,10 +2320,10 @@ static bool D3D11_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
case D3D11_FILTER_MIN_MAG_MIP_POINT: case D3D11_FILTER_MIN_MAG_MIP_POINT:
switch (cmd->data.draw.texture_address_mode) { switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP: case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = rendererData->samplers[SDL_D3D11_SAMPLER_NEAREST_CLAMP]; textureSampler = rendererData->samplers[D3D11_SAMPLER_NEAREST_CLAMP];
break; break;
case SDL_TEXTURE_ADDRESS_WRAP: case SDL_TEXTURE_ADDRESS_WRAP:
textureSampler = rendererData->samplers[SDL_D3D11_SAMPLER_NEAREST_WRAP]; textureSampler = rendererData->samplers[D3D11_SAMPLER_NEAREST_WRAP];
break; break;
default: default:
return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode); return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode);
@@ -2332,10 +2332,10 @@ static bool D3D11_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
case D3D11_FILTER_MIN_MAG_MIP_LINEAR: case D3D11_FILTER_MIN_MAG_MIP_LINEAR:
switch (cmd->data.draw.texture_address_mode) { switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP: case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = rendererData->samplers[SDL_D3D11_SAMPLER_LINEAR_CLAMP]; textureSampler = rendererData->samplers[D3D11_SAMPLER_LINEAR_CLAMP];
break; break;
case SDL_TEXTURE_ADDRESS_WRAP: case SDL_TEXTURE_ADDRESS_WRAP:
textureSampler = rendererData->samplers[SDL_D3D11_SAMPLER_LINEAR_WRAP]; textureSampler = rendererData->samplers[D3D11_SAMPLER_LINEAR_WRAP];
break; break;
default: default:
return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode); return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode);
@@ -2458,7 +2458,7 @@ static bool D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd
{ {
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(D3D11_VertexPositionColor);
D3D11_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, 0, NULL, NULL, NULL); D3D11_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, 0, NULL, NULL, NULL);
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, start, count); D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, start, count);
break; break;
@@ -2468,8 +2468,8 @@ static bool D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd
{ {
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(D3D11_VertexPositionColor);
const VertexPositionColor *verts = (VertexPositionColor *)(((Uint8 *)vertices) + first); const D3D11_VertexPositionColor *verts = (D3D11_VertexPositionColor *)(((Uint8 *)vertices) + first);
D3D11_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, 0, NULL, NULL, NULL); D3D11_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, 0, NULL, NULL, NULL);
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, start, count); D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, start, count);
if (verts[0].pos.x != verts[count - 1].pos.x || verts[0].pos.y != verts[count - 1].pos.y) { if (verts[0].pos.x != verts[count - 1].pos.x || verts[0].pos.y != verts[count - 1].pos.y) {
@@ -2492,7 +2492,7 @@ static bool D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd
SDL_Texture *texture = cmd->data.draw.texture; SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(D3D11_VertexPositionColor);
if (texture) { if (texture) {
D3D11_SetCopyState(renderer, cmd, NULL); D3D11_SetCopyState(renderer, cmd, NULL);

View File

@@ -59,19 +59,19 @@ extern "C" {
// Sampler types // Sampler types
typedef enum typedef enum
{ {
SDL_D3D12_SAMPLER_NEAREST_CLAMP, D3D12_SAMPLER_NEAREST_CLAMP,
SDL_D3D12_SAMPLER_NEAREST_WRAP, D3D12_SAMPLER_NEAREST_WRAP,
SDL_D3D12_SAMPLER_LINEAR_CLAMP, D3D12_SAMPLER_LINEAR_CLAMP,
SDL_D3D12_SAMPLER_LINEAR_WRAP, D3D12_SAMPLER_LINEAR_WRAP,
SDL_D3D12_NUM_SAMPLERS D3D12_SAMPLER_COUNT
} SDL_D3D12_sampler_type; } D3D12_Sampler;
// Vertex shader, common values // Vertex shader, common values
typedef struct typedef struct
{ {
Float4X4 model; Float4X4 model;
Float4X4 projectionAndView; Float4X4 projectionAndView;
} VertexShaderConstants; } D3D12_VertexShaderConstants;
// These should mirror the definitions in D3D12_PixelShader_Common.hlsli // These should mirror the definitions in D3D12_PixelShader_Common.hlsli
//static const float TONEMAP_NONE = 0; //static const float TONEMAP_NONE = 0;
@@ -102,7 +102,7 @@ typedef struct
float sdr_white_point; float sdr_white_point;
float YCbCr_matrix[16]; float YCbCr_matrix[16];
} PixelShaderConstants; } D3D12_PixelShaderConstants;
// Per-vertex data // Per-vertex data
typedef struct typedef struct
@@ -110,7 +110,7 @@ typedef struct
Float2 pos; Float2 pos;
Float2 tex; Float2 tex;
SDL_FColor color; SDL_FColor color;
} VertexPositionColor; } D3D12_VertexPositionColor;
// Per-texture data // Per-texture data
typedef struct typedef struct
@@ -154,7 +154,7 @@ typedef struct
typedef struct typedef struct
{ {
D3D12_Shader shader; D3D12_Shader shader;
PixelShaderConstants shader_constants; D3D12_PixelShaderConstants shader_constants;
SDL_BlendMode blendMode; SDL_BlendMode blendMode;
D3D12_PRIMITIVE_TOPOLOGY_TYPE topology; D3D12_PRIMITIVE_TOPOLOGY_TYPE topology;
DXGI_FORMAT rtvFormat; DXGI_FORMAT rtvFormat;
@@ -226,7 +226,7 @@ typedef struct
D3D12_PipelineState *currentPipelineState; D3D12_PipelineState *currentPipelineState;
D3D12_VertexBuffer vertexBuffers[SDL_D3D12_NUM_VERTEX_BUFFERS]; D3D12_VertexBuffer vertexBuffers[SDL_D3D12_NUM_VERTEX_BUFFERS];
D3D12_CPU_DESCRIPTOR_HANDLE samplers[SDL_D3D12_NUM_SAMPLERS]; D3D12_CPU_DESCRIPTOR_HANDLE samplers[D3D12_SAMPLER_COUNT];
// Data for staging/allocating textures // Data for staging/allocating textures
ID3D12Resource *uploadBuffers[SDL_D3D12_NUM_UPLOAD_BUFFERS]; ID3D12Resource *uploadBuffers[SDL_D3D12_NUM_UPLOAD_BUFFERS];
@@ -237,7 +237,7 @@ typedef struct
D3D12_SRVPoolNode srvPoolNodes[SDL_D3D12_MAX_NUM_TEXTURES]; D3D12_SRVPoolNode srvPoolNodes[SDL_D3D12_MAX_NUM_TEXTURES];
// Vertex buffer constants // Vertex buffer constants
VertexShaderConstants vertexShaderConstantsData; D3D12_VertexShaderConstants vertexShaderConstantsData;
// Cached renderer properties // Cached renderer properties
DXGI_MODE_ROTATION rotation; DXGI_MODE_ROTATION rotation;
@@ -752,7 +752,7 @@ static HRESULT D3D12_CreateVertexBuffer(D3D12_RenderData *data, size_t vbidx, si
} }
data->vertexBuffers[vbidx].view.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(data->vertexBuffers[vbidx].resource); data->vertexBuffers[vbidx].view.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(data->vertexBuffers[vbidx].resource);
data->vertexBuffers[vbidx].view.StrideInBytes = sizeof(VertexPositionColor); data->vertexBuffers[vbidx].view.StrideInBytes = sizeof(D3D12_VertexPositionColor);
data->vertexBuffers[vbidx].size = size; data->vertexBuffers[vbidx].size = size;
return result; return result;
@@ -1106,7 +1106,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
{ D3D12_FILTER_MIN_MAG_MIP_LINEAR, D3D12_TEXTURE_ADDRESS_MODE_CLAMP }, { D3D12_FILTER_MIN_MAG_MIP_LINEAR, D3D12_TEXTURE_ADDRESS_MODE_CLAMP },
{ D3D12_FILTER_MIN_MAG_MIP_LINEAR, D3D12_TEXTURE_ADDRESS_MODE_WRAP }, { D3D12_FILTER_MIN_MAG_MIP_LINEAR, D3D12_TEXTURE_ADDRESS_MODE_WRAP },
}; };
SDL_COMPILE_TIME_ASSERT(samplerParams_SIZE, SDL_arraysize(samplerParams) == SDL_D3D12_NUM_SAMPLERS); SDL_COMPILE_TIME_ASSERT(samplerParams_SIZE, SDL_arraysize(samplerParams) == D3D12_SAMPLER_COUNT);
SDL_zero(samplerDesc); SDL_zero(samplerDesc);
samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP; samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
samplerDesc.MipLODBias = 0.0f; samplerDesc.MipLODBias = 0.0f;
@@ -2294,7 +2294,7 @@ static bool D3D12_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
static bool D3D12_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) static bool D3D12_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{ {
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); D3D12_VertexPositionColor *verts = (D3D12_VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(D3D12_VertexPositionColor), 0, &cmd->data.draw.first);
int i; int i;
SDL_FColor color = cmd->data.draw.color; SDL_FColor color = cmd->data.draw.color;
bool convert_color = SDL_RenderingLinearSpace(renderer); bool convert_color = SDL_RenderingLinearSpace(renderer);
@@ -2328,7 +2328,7 @@ static bool D3D12_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
{ {
int i; int i;
int count = indices ? num_indices : num_vertices; int count = indices ? num_indices : num_vertices;
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); D3D12_VertexPositionColor *verts = (D3D12_VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(D3D12_VertexPositionColor), 0, &cmd->data.draw.first);
bool convert_color = SDL_RenderingLinearSpace(renderer); bool convert_color = SDL_RenderingLinearSpace(renderer);
D3D12_TextureData *textureData = texture ? (D3D12_TextureData *)texture->internal : NULL; D3D12_TextureData *textureData = texture ? (D3D12_TextureData *)texture->internal : NULL;
float u_scale = textureData ? (float)texture->w / textureData->w : 0.0f; float u_scale = textureData ? (float)texture->w / textureData->w : 0.0f;
@@ -2517,7 +2517,7 @@ static bool D3D12_UpdateViewport(SDL_Renderer *renderer)
return true; return true;
} }
static void D3D12_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, PixelShaderConstants *constants) static void D3D12_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, D3D12_PixelShaderConstants *constants)
{ {
float output_headroom; float output_headroom;
@@ -2579,7 +2579,7 @@ static void D3D12_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderC
} }
} }
static bool D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, D3D12_Shader shader, const PixelShaderConstants *shader_constants, static bool D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, D3D12_Shader shader, const D3D12_PixelShaderConstants *shader_constants,
D3D12_PRIMITIVE_TOPOLOGY_TYPE topology, D3D12_PRIMITIVE_TOPOLOGY_TYPE topology,
const int numShaderResources, D3D12_CPU_DESCRIPTOR_HANDLE *shaderResources, const int numShaderResources, D3D12_CPU_DESCRIPTOR_HANDLE *shaderResources,
D3D12_CPU_DESCRIPTOR_HANDLE *sampler, const Float4X4 *matrix) D3D12_CPU_DESCRIPTOR_HANDLE *sampler, const Float4X4 *matrix)
@@ -2594,7 +2594,7 @@ static bool D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *
D3D12_CPU_DESCRIPTOR_HANDLE firstShaderResource; D3D12_CPU_DESCRIPTOR_HANDLE firstShaderResource;
DXGI_FORMAT rtvFormat = rendererData->renderTargetFormat; DXGI_FORMAT rtvFormat = rendererData->renderTargetFormat;
D3D12_PipelineState *currentPipelineState = rendererData->currentPipelineState;; D3D12_PipelineState *currentPipelineState = rendererData->currentPipelineState;;
PixelShaderConstants solid_constants; D3D12_PixelShaderConstants solid_constants;
if (rendererData->textureRenderTarget) { if (rendererData->textureRenderTarget) {
rtvFormat = rendererData->textureRenderTarget->mainTextureFormat; rtvFormat = rendererData->textureRenderTarget->mainTextureFormat;
@@ -2735,7 +2735,7 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal;
D3D12_TextureData *textureData = (D3D12_TextureData *)texture->internal; D3D12_TextureData *textureData = (D3D12_TextureData *)texture->internal;
D3D12_CPU_DESCRIPTOR_HANDLE *textureSampler; D3D12_CPU_DESCRIPTOR_HANDLE *textureSampler;
PixelShaderConstants constants; D3D12_PixelShaderConstants constants;
D3D12_SetupShaderConstants(renderer, cmd, texture, &constants); D3D12_SetupShaderConstants(renderer, cmd, texture, &constants);
@@ -2743,10 +2743,10 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
case D3D12_FILTER_MIN_MAG_MIP_POINT: case D3D12_FILTER_MIN_MAG_MIP_POINT:
switch (cmd->data.draw.texture_address_mode) { switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP: case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = &rendererData->samplers[SDL_D3D12_SAMPLER_NEAREST_CLAMP]; textureSampler = &rendererData->samplers[D3D12_SAMPLER_NEAREST_CLAMP];
break; break;
case SDL_TEXTURE_ADDRESS_WRAP: case SDL_TEXTURE_ADDRESS_WRAP:
textureSampler = &rendererData->samplers[SDL_D3D12_SAMPLER_NEAREST_WRAP]; textureSampler = &rendererData->samplers[D3D12_SAMPLER_NEAREST_WRAP];
break; break;
default: default:
return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode); return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode);
@@ -2755,10 +2755,10 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
case D3D12_FILTER_MIN_MAG_MIP_LINEAR: case D3D12_FILTER_MIN_MAG_MIP_LINEAR:
switch (cmd->data.draw.texture_address_mode) { switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP: case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = &rendererData->samplers[SDL_D3D12_SAMPLER_LINEAR_CLAMP]; textureSampler = &rendererData->samplers[D3D12_SAMPLER_LINEAR_CLAMP];
break; break;
case SDL_TEXTURE_ADDRESS_WRAP: case SDL_TEXTURE_ADDRESS_WRAP:
textureSampler = &rendererData->samplers[SDL_D3D12_SAMPLER_LINEAR_WRAP]; textureSampler = &rendererData->samplers[D3D12_SAMPLER_LINEAR_WRAP];
break; break;
default: default:
return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode); return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode);
@@ -2899,7 +2899,7 @@ static bool D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd
{ {
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(D3D12_VertexPositionColor);
D3D12_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT, 0, NULL, NULL, NULL); D3D12_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT, 0, NULL, NULL, NULL);
D3D12_DrawPrimitives(renderer, D3D_PRIMITIVE_TOPOLOGY_POINTLIST, start, count); D3D12_DrawPrimitives(renderer, D3D_PRIMITIVE_TOPOLOGY_POINTLIST, start, count);
break; break;
@@ -2909,8 +2909,8 @@ static bool D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd
{ {
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(D3D12_VertexPositionColor);
const VertexPositionColor *verts = (VertexPositionColor *)(((Uint8 *)vertices) + first); const D3D12_VertexPositionColor *verts = (D3D12_VertexPositionColor *)(((Uint8 *)vertices) + first);
D3D12_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE, 0, NULL, NULL, NULL); D3D12_SetDrawState(renderer, cmd, SHADER_SOLID, NULL, D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE, 0, NULL, NULL, NULL);
D3D12_DrawPrimitives(renderer, D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, start, count); D3D12_DrawPrimitives(renderer, D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, start, count);
if (verts[0].pos.x != verts[count - 1].pos.x || verts[0].pos.y != verts[count - 1].pos.y) { if (verts[0].pos.x != verts[count - 1].pos.x || verts[0].pos.y != verts[count - 1].pos.y) {
@@ -2933,7 +2933,7 @@ static bool D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd
SDL_Texture *texture = cmd->data.draw.texture; SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(D3D12_VertexPositionColor);
if (texture) { if (texture) {
D3D12_SetCopyState(renderer, cmd, NULL); D3D12_SetCopyState(renderer, cmd, NULL);

View File

@@ -152,27 +152,27 @@ VULKAN_FUNCTIONS()
// Renderpass types // Renderpass types
typedef enum { typedef enum {
SDL_VULKAN_RENDERPASS_LOAD = 0, VULKAN_RENDERPASS_LOAD = 0,
SDL_VULKAN_RENDERPASS_CLEAR = 1, VULKAN_RENDERPASS_CLEAR = 1,
SDL_VULKAN_NUM_RENDERPASSES VULKAN_RENDERPASS_COUNT
} SDL_vulkan_renderpass_type; } VULKAN_RenderPass;
// Sampler types // Sampler types
typedef enum typedef enum
{ {
SDL_VULKAN_SAMPLER_NEAREST_CLAMP, VULKAN_SAMPLER_NEAREST_CLAMP,
SDL_VULKAN_SAMPLER_NEAREST_WRAP, VULKAN_SAMPLER_NEAREST_WRAP,
SDL_VULKAN_SAMPLER_LINEAR_CLAMP, VULKAN_SAMPLER_LINEAR_CLAMP,
SDL_VULKAN_SAMPLER_LINEAR_WRAP, VULKAN_SAMPLER_LINEAR_WRAP,
SDL_VULKAN_NUM_SAMPLERS VULKAN_SAMPLER_COUNT
} SDL_vulkan_sampler_type; } VULKAN_Sampler;
// Vertex shader, common values // Vertex shader, common values
typedef struct typedef struct
{ {
Float4X4 model; Float4X4 model;
Float4X4 projectionAndView; Float4X4 projectionAndView;
} VertexShaderConstants; } VULKAN_VertexShaderConstants;
// These should mirror the definitions in VULKAN_PixelShader_Common.hlsli // These should mirror the definitions in VULKAN_PixelShader_Common.hlsli
//static const float TONEMAP_NONE = 0; //static const float TONEMAP_NONE = 0;
@@ -205,7 +205,7 @@ typedef struct
float tonemap_factor1; float tonemap_factor1;
float tonemap_factor2; float tonemap_factor2;
float sdr_white_point; float sdr_white_point;
} PixelShaderConstants; } VULKAN_PixelShaderConstants;
// Per-vertex data // Per-vertex data
typedef struct typedef struct
@@ -213,7 +213,7 @@ typedef struct
float pos[2]; float pos[2];
float tex[2]; float tex[2];
SDL_FColor color; SDL_FColor color;
} VertexPositionColor; } VULKAN_VertexPositionColor;
// Vulkan Buffer // Vulkan Buffer
typedef struct typedef struct
@@ -240,7 +240,7 @@ typedef struct
typedef struct typedef struct
{ {
VULKAN_Image mainImage; VULKAN_Image mainImage;
VkRenderPass mainRenderpasses[SDL_VULKAN_NUM_RENDERPASSES]; VkRenderPass mainRenderpasses[VULKAN_RENDERPASS_COUNT];
VkFramebuffer mainFramebuffer; VkFramebuffer mainFramebuffer;
VULKAN_Buffer stagingBuffer; VULKAN_Buffer stagingBuffer;
VkFilter scaleMode; VkFilter scaleMode;
@@ -264,7 +264,7 @@ typedef struct
typedef struct typedef struct
{ {
VULKAN_Shader shader; VULKAN_Shader shader;
PixelShaderConstants shader_constants; VULKAN_PixelShaderConstants shader_constants;
SDL_BlendMode blendMode; SDL_BlendMode blendMode;
VkPrimitiveTopology topology; VkPrimitiveTopology topology;
VkFormat format; VkFormat format;
@@ -308,7 +308,7 @@ typedef struct
int vsync; int vsync;
VkFramebuffer *framebuffers; VkFramebuffer *framebuffers;
VkRenderPass renderPasses[SDL_VULKAN_NUM_RENDERPASSES]; VkRenderPass renderPasses[VULKAN_RENDERPASS_COUNT];
VkRenderPass currentRenderPass; VkRenderPass currentRenderPass;
VkShaderModule vertexShaderModules[NUM_SHADERS]; VkShaderModule vertexShaderModules[NUM_SHADERS];
@@ -318,7 +318,7 @@ typedef struct
// Vertex buffer data // Vertex buffer data
VULKAN_Buffer vertexBuffers[SDL_VULKAN_NUM_VERTEX_BUFFERS]; VULKAN_Buffer vertexBuffers[SDL_VULKAN_NUM_VERTEX_BUFFERS];
VertexShaderConstants vertexShaderConstantsData; VULKAN_VertexShaderConstants vertexShaderConstantsData;
// Data for staging/allocating textures // Data for staging/allocating textures
VULKAN_Buffer **uploadBuffers; VULKAN_Buffer **uploadBuffers;
@@ -330,7 +330,7 @@ typedef struct
uint32_t currentConstantBufferIndex; uint32_t currentConstantBufferIndex;
int32_t currentConstantBufferOffset; int32_t currentConstantBufferOffset;
VkSampler samplers[SDL_VULKAN_NUM_SAMPLERS]; VkSampler samplers[VULKAN_SAMPLER_COUNT];
VkDescriptorPool **descriptorPools; VkDescriptorPool **descriptorPools;
uint32_t *numDescriptorPools; uint32_t *numDescriptorPools;
uint32_t currentDescriptorPoolIndex; uint32_t currentDescriptorPoolIndex;
@@ -542,7 +542,7 @@ static void VULKAN_DestroyAll(SDL_Renderer *renderer)
VULKAN_DestroyBuffer(rendererData, &rendererData->vertexBuffers[i]); VULKAN_DestroyBuffer(rendererData, &rendererData->vertexBuffers[i]);
} }
SDL_memset(rendererData->vertexBuffers, 0, sizeof(rendererData->vertexBuffers)); SDL_memset(rendererData->vertexBuffers, 0, sizeof(rendererData->vertexBuffers));
for (uint32_t i = 0; i < SDL_VULKAN_NUM_RENDERPASSES; i++) { for (uint32_t i = 0; i < VULKAN_RENDERPASS_COUNT; i++) {
if (rendererData->renderPasses[i] != VK_NULL_HANDLE) { if (rendererData->renderPasses[i] != VK_NULL_HANDLE) {
vkDestroyRenderPass(rendererData->device, rendererData->renderPasses[i], NULL); vkDestroyRenderPass(rendererData->device, rendererData->renderPasses[i], NULL);
rendererData->renderPasses[i] = VK_NULL_HANDLE; rendererData->renderPasses[i] = VK_NULL_HANDLE;
@@ -902,15 +902,15 @@ static void VULKAN_BeginRenderPass(VULKAN_RenderData *rendererData, VkAttachment
switch (loadOp) { switch (loadOp) {
case VK_ATTACHMENT_LOAD_OP_CLEAR: case VK_ATTACHMENT_LOAD_OP_CLEAR:
rendererData->currentRenderPass = rendererData->textureRenderTarget ? rendererData->currentRenderPass = rendererData->textureRenderTarget ?
rendererData->textureRenderTarget->mainRenderpasses[SDL_VULKAN_RENDERPASS_CLEAR] : rendererData->textureRenderTarget->mainRenderpasses[VULKAN_RENDERPASS_CLEAR] :
rendererData->renderPasses[SDL_VULKAN_RENDERPASS_CLEAR]; rendererData->renderPasses[VULKAN_RENDERPASS_CLEAR];
break; break;
case VK_ATTACHMENT_LOAD_OP_LOAD: case VK_ATTACHMENT_LOAD_OP_LOAD:
default: default:
rendererData->currentRenderPass = rendererData->textureRenderTarget ? rendererData->currentRenderPass = rendererData->textureRenderTarget ?
rendererData->textureRenderTarget->mainRenderpasses[SDL_VULKAN_RENDERPASS_LOAD] : rendererData->textureRenderTarget->mainRenderpasses[VULKAN_RENDERPASS_LOAD] :
rendererData->renderPasses[SDL_VULKAN_RENDERPASS_LOAD]; rendererData->renderPasses[VULKAN_RENDERPASS_LOAD];
break; break;
} }
@@ -1926,7 +1926,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert
{ VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE }, { VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE },
{ VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT }, { VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT },
}; };
SDL_COMPILE_TIME_ASSERT(samplerParams_SIZE, SDL_arraysize(samplerParams) == SDL_VULKAN_NUM_SAMPLERS); SDL_COMPILE_TIME_ASSERT(samplerParams_SIZE, SDL_arraysize(samplerParams) == VULKAN_SAMPLER_COUNT);
VkSamplerCreateInfo samplerCreateInfo = { 0 }; VkSamplerCreateInfo samplerCreateInfo = { 0 };
samplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; samplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; samplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
@@ -1962,7 +1962,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert
} }
static VkResult VULKAN_CreateFramebuffersAndRenderPasses(SDL_Renderer *renderer, int w, int h, static VkResult VULKAN_CreateFramebuffersAndRenderPasses(SDL_Renderer *renderer, int w, int h,
VkFormat format, int imageViewCount, VkImageView *imageViews, VkFramebuffer *framebuffers, VkRenderPass renderPasses[SDL_VULKAN_NUM_RENDERPASSES]) VkFormat format, int imageViewCount, VkImageView *imageViews, VkFramebuffer *framebuffers, VkRenderPass renderPasses[VULKAN_RENDERPASS_COUNT])
{ {
VULKAN_RenderData *rendererData = (VULKAN_RenderData *) renderer->internal; VULKAN_RenderData *rendererData = (VULKAN_RenderData *) renderer->internal;
VkResult result; VkResult result;
@@ -2013,14 +2013,14 @@ static VkResult VULKAN_CreateFramebuffersAndRenderPasses(SDL_Renderer *renderer,
renderPassCreateInfo.dependencyCount = 1; renderPassCreateInfo.dependencyCount = 1;
renderPassCreateInfo.pDependencies = &subPassDependency; renderPassCreateInfo.pDependencies = &subPassDependency;
result = vkCreateRenderPass(rendererData->device, &renderPassCreateInfo, NULL, &renderPasses[SDL_VULKAN_RENDERPASS_LOAD]); result = vkCreateRenderPass(rendererData->device, &renderPassCreateInfo, NULL, &renderPasses[VULKAN_RENDERPASS_LOAD]);
if (result != VK_SUCCESS) { if (result != VK_SUCCESS) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkCreateRenderPass(): %s\n", SDL_Vulkan_GetResultString(result)); SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkCreateRenderPass(): %s\n", SDL_Vulkan_GetResultString(result));
return result; return result;
} }
attachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
result = vkCreateRenderPass(rendererData->device, &renderPassCreateInfo, NULL, &renderPasses[SDL_VULKAN_RENDERPASS_CLEAR]); result = vkCreateRenderPass(rendererData->device, &renderPassCreateInfo, NULL, &renderPasses[VULKAN_RENDERPASS_CLEAR]);
if (result != VK_SUCCESS) { if (result != VK_SUCCESS) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkCreateRenderPass(): %s\n", SDL_Vulkan_GetResultString(result)); SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkCreateRenderPass(): %s\n", SDL_Vulkan_GetResultString(result));
return result; return result;
@@ -2029,7 +2029,7 @@ static VkResult VULKAN_CreateFramebuffersAndRenderPasses(SDL_Renderer *renderer,
VkFramebufferCreateInfo framebufferCreateInfo = { 0 }; VkFramebufferCreateInfo framebufferCreateInfo = { 0 };
framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
framebufferCreateInfo.pNext = NULL; framebufferCreateInfo.pNext = NULL;
framebufferCreateInfo.renderPass = rendererData->renderPasses[SDL_VULKAN_RENDERPASS_LOAD]; framebufferCreateInfo.renderPass = rendererData->renderPasses[VULKAN_RENDERPASS_LOAD];
framebufferCreateInfo.attachmentCount = 1; framebufferCreateInfo.attachmentCount = 1;
framebufferCreateInfo.width = w; framebufferCreateInfo.width = w;
framebufferCreateInfo.height = h; framebufferCreateInfo.height = h;
@@ -3072,7 +3072,7 @@ static bool VULKAN_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
static bool VULKAN_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) static bool VULKAN_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{ {
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); VULKAN_VertexPositionColor *verts = (VULKAN_VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VULKAN_VertexPositionColor), 0, &cmd->data.draw.first);
int i; int i;
bool convert_color = SDL_RenderingLinearSpace(renderer); bool convert_color = SDL_RenderingLinearSpace(renderer);
@@ -3102,7 +3102,7 @@ static bool VULKAN_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
{ {
int i; int i;
int count = indices ? num_indices : num_vertices; int count = indices ? num_indices : num_vertices;
VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); VULKAN_VertexPositionColor *verts = (VULKAN_VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VULKAN_VertexPositionColor), 0, &cmd->data.draw.first);
bool convert_color = SDL_RenderingLinearSpace(renderer); bool convert_color = SDL_RenderingLinearSpace(renderer);
VULKAN_TextureData *textureData = texture ? (VULKAN_TextureData *)texture->internal : NULL; VULKAN_TextureData *textureData = texture ? (VULKAN_TextureData *)texture->internal : NULL;
float u_scale = textureData ? (float)texture->w / textureData->width : 0.0f; float u_scale = textureData ? (float)texture->w / textureData->width : 0.0f;
@@ -3255,7 +3255,7 @@ static bool VULKAN_UpdateClipRect(SDL_Renderer *renderer)
return true; return true;
} }
static void VULKAN_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, PixelShaderConstants *constants) static void VULKAN_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, VULKAN_PixelShaderConstants *constants)
{ {
float output_headroom; float output_headroom;
@@ -3366,7 +3366,7 @@ static VkResult VULKAN_CreateDescriptorSetAndPipelineLayout(VULKAN_RenderData *r
// Pipeline layout // Pipeline layout
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = { 0 }; VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = { 0 };
VkPushConstantRange pushConstantRange; VkPushConstantRange pushConstantRange;
pushConstantRange.size = sizeof( VertexShaderConstants ); pushConstantRange.size = sizeof( VULKAN_VertexShaderConstants );
pushConstantRange.offset = 0; pushConstantRange.offset = 0;
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
pipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
@@ -3441,7 +3441,7 @@ static VkDescriptorSet VULKAN_AllocateDescriptorSet(SDL_Renderer *renderer, VULK
VkDescriptorBufferInfo bufferDescriptor = { 0 }; VkDescriptorBufferInfo bufferDescriptor = { 0 };
bufferDescriptor.buffer = constantBuffer; bufferDescriptor.buffer = constantBuffer;
bufferDescriptor.offset = constantBufferOffset; bufferDescriptor.offset = constantBufferOffset;
bufferDescriptor.range = sizeof(PixelShaderConstants); bufferDescriptor.range = sizeof(VULKAN_PixelShaderConstants);
VkWriteDescriptorSet descriptorWrites[2]; VkWriteDescriptorSet descriptorWrites[2];
SDL_memset(descriptorWrites, 0, sizeof(descriptorWrites)); SDL_memset(descriptorWrites, 0, sizeof(descriptorWrites));
@@ -3479,7 +3479,7 @@ static VkDescriptorSet VULKAN_AllocateDescriptorSet(SDL_Renderer *renderer, VULK
} }
static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, VULKAN_Shader shader, VkPipelineLayout pipelineLayout, VkDescriptorSetLayout descriptorSetLayout, static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, VULKAN_Shader shader, VkPipelineLayout pipelineLayout, VkDescriptorSetLayout descriptorSetLayout,
const PixelShaderConstants *shader_constants, VkPrimitiveTopology topology, VkImageView imageView, VkSampler sampler, const Float4X4 *matrix, VULKAN_DrawStateCache *stateCache) const VULKAN_PixelShaderConstants *shader_constants, VkPrimitiveTopology topology, VkImageView imageView, VkSampler sampler, const Float4X4 *matrix, VULKAN_DrawStateCache *stateCache)
{ {
VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal;
@@ -3487,7 +3487,7 @@ static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand
VkFormat format = rendererData->surfaceFormat.format; VkFormat format = rendererData->surfaceFormat.format;
const Float4X4 *newmatrix = matrix ? matrix : &rendererData->identity; const Float4X4 *newmatrix = matrix ? matrix : &rendererData->identity;
bool updateConstants = false; bool updateConstants = false;
PixelShaderConstants solid_constants; VULKAN_PixelShaderConstants solid_constants;
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
VkBuffer constantBuffer; VkBuffer constantBuffer;
VkDeviceSize constantBufferOffset; VkDeviceSize constantBufferOffset;
@@ -3570,7 +3570,7 @@ static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand
// Align the next address to the minUniformBufferOffsetAlignment // Align the next address to the minUniformBufferOffsetAlignment
VkDeviceSize alignment = rendererData->physicalDeviceProperties.limits.minUniformBufferOffsetAlignment; VkDeviceSize alignment = rendererData->physicalDeviceProperties.limits.minUniformBufferOffsetAlignment;
SDL_assert(rendererData->currentConstantBufferOffset >= 0 ); SDL_assert(rendererData->currentConstantBufferOffset >= 0 );
rendererData->currentConstantBufferOffset += (int32_t)(sizeof(PixelShaderConstants) + alignment - 1) & ~(alignment - 1); rendererData->currentConstantBufferOffset += (int32_t)(sizeof(VULKAN_PixelShaderConstants) + alignment - 1) & ~(alignment - 1);
constantBufferOffset = rendererData->currentConstantBufferOffset; constantBufferOffset = rendererData->currentConstantBufferOffset;
} }
@@ -3610,7 +3610,7 @@ static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand
// Upload constants to persistently mapped buffer // Upload constants to persistently mapped buffer
uint8_t *dst = (uint8_t *)rendererData->constantBuffers[rendererData->currentCommandBufferIndex][rendererData->currentConstantBufferIndex].mappedBufferPtr; uint8_t *dst = (uint8_t *)rendererData->constantBuffers[rendererData->currentCommandBufferIndex][rendererData->currentConstantBufferIndex].mappedBufferPtr;
dst += constantBufferOffset; dst += constantBufferOffset;
SDL_memcpy(dst, &rendererData->currentPipelineState->shader_constants, sizeof(PixelShaderConstants)); SDL_memcpy(dst, &rendererData->currentPipelineState->shader_constants, sizeof(VULKAN_PixelShaderConstants));
} }
// Allocate/update descriptor set with the bindings // Allocate/update descriptor set with the bindings
@@ -3633,7 +3633,7 @@ static bool VULKAN_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand
VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal;
VULKAN_TextureData *textureData = (VULKAN_TextureData *)texture->internal; VULKAN_TextureData *textureData = (VULKAN_TextureData *)texture->internal;
VkSampler textureSampler = VK_NULL_HANDLE; VkSampler textureSampler = VK_NULL_HANDLE;
PixelShaderConstants constants; VULKAN_PixelShaderConstants constants;
VkDescriptorSetLayout descriptorSetLayout = (textureData->descriptorSetLayoutYcbcr != VK_NULL_HANDLE) ? textureData->descriptorSetLayoutYcbcr : rendererData->descriptorSetLayout; VkDescriptorSetLayout descriptorSetLayout = (textureData->descriptorSetLayoutYcbcr != VK_NULL_HANDLE) ? textureData->descriptorSetLayoutYcbcr : rendererData->descriptorSetLayout;
VkPipelineLayout pipelineLayout = (textureData->pipelineLayoutYcbcr != VK_NULL_HANDLE) ? textureData->pipelineLayoutYcbcr : rendererData->pipelineLayout; VkPipelineLayout pipelineLayout = (textureData->pipelineLayoutYcbcr != VK_NULL_HANDLE) ? textureData->pipelineLayoutYcbcr : rendererData->pipelineLayout;
@@ -3643,10 +3643,10 @@ static bool VULKAN_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand
case VK_FILTER_NEAREST: case VK_FILTER_NEAREST:
switch (cmd->data.draw.texture_address_mode) { switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP: case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = rendererData->samplers[SDL_VULKAN_SAMPLER_NEAREST_CLAMP]; textureSampler = rendererData->samplers[VULKAN_SAMPLER_NEAREST_CLAMP];
break; break;
case SDL_TEXTURE_ADDRESS_WRAP: case SDL_TEXTURE_ADDRESS_WRAP:
textureSampler = rendererData->samplers[SDL_VULKAN_SAMPLER_NEAREST_WRAP]; textureSampler = rendererData->samplers[VULKAN_SAMPLER_NEAREST_WRAP];
break; break;
default: default:
return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode); return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode);
@@ -3655,10 +3655,10 @@ static bool VULKAN_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand
case VK_FILTER_LINEAR: case VK_FILTER_LINEAR:
switch (cmd->data.draw.texture_address_mode) { switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP: case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = rendererData->samplers[SDL_VULKAN_SAMPLER_LINEAR_CLAMP]; textureSampler = rendererData->samplers[VULKAN_SAMPLER_LINEAR_CLAMP];
break; break;
case SDL_TEXTURE_ADDRESS_WRAP: case SDL_TEXTURE_ADDRESS_WRAP:
textureSampler = rendererData->samplers[SDL_VULKAN_SAMPLER_LINEAR_WRAP]; textureSampler = rendererData->samplers[VULKAN_SAMPLER_LINEAR_WRAP];
break; break;
default: default:
return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode); return SDL_SetError("Unknown texture address mode: %d\n", cmd->data.draw.texture_address_mode);
@@ -3779,7 +3779,7 @@ static bool VULKAN_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cm
{ {
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(VULKAN_VertexPositionColor);
VULKAN_SetDrawState(renderer, cmd, SHADER_SOLID, rendererData->pipelineLayout, rendererData->descriptorSetLayout, NULL, VK_PRIMITIVE_TOPOLOGY_POINT_LIST, VK_NULL_HANDLE, VK_NULL_HANDLE, NULL, &stateCache); VULKAN_SetDrawState(renderer, cmd, SHADER_SOLID, rendererData->pipelineLayout, rendererData->descriptorSetLayout, NULL, VK_PRIMITIVE_TOPOLOGY_POINT_LIST, VK_NULL_HANDLE, VK_NULL_HANDLE, NULL, &stateCache);
VULKAN_DrawPrimitives(renderer, VK_PRIMITIVE_TOPOLOGY_POINT_LIST, start, count); VULKAN_DrawPrimitives(renderer, VK_PRIMITIVE_TOPOLOGY_POINT_LIST, start, count);
break; break;
@@ -3789,8 +3789,8 @@ static bool VULKAN_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cm
{ {
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(VULKAN_VertexPositionColor);
const VertexPositionColor *verts = (VertexPositionColor *)(((Uint8 *)vertices) + first); const VULKAN_VertexPositionColor *verts = (VULKAN_VertexPositionColor *)(((Uint8 *)vertices) + first);
VULKAN_SetDrawState(renderer, cmd, SHADER_SOLID, rendererData->pipelineLayout, rendererData->descriptorSetLayout, NULL, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, VK_NULL_HANDLE, VK_NULL_HANDLE, NULL, &stateCache); VULKAN_SetDrawState(renderer, cmd, SHADER_SOLID, rendererData->pipelineLayout, rendererData->descriptorSetLayout, NULL, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, VK_NULL_HANDLE, VK_NULL_HANDLE, NULL, &stateCache);
VULKAN_DrawPrimitives(renderer, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, start, count); VULKAN_DrawPrimitives(renderer, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, start, count);
if (verts[0].pos[0] != verts[count - 1].pos[0] || verts[0].pos[1] != verts[count - 1].pos[1]) { if (verts[0].pos[0] != verts[count - 1].pos[0] || verts[0].pos[1] != verts[count - 1].pos[1]) {
@@ -3814,7 +3814,7 @@ static bool VULKAN_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cm
SDL_Texture *texture = cmd->data.draw.texture; SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first; const size_t first = cmd->data.draw.first;
const size_t start = first / sizeof(VertexPositionColor); const size_t start = first / sizeof(VULKAN_VertexPositionColor);
if (texture) { if (texture) {
VULKAN_SetCopyState(renderer, cmd, NULL, &stateCache); VULKAN_SetCopyState(renderer, cmd, NULL, &stateCache);