Skip to content

Commit

Permalink
Native: GPU triangle rendering works in both Vulkan and D3D12.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkoleci committed Dec 16, 2024
1 parent dd28a69 commit 6305690
Show file tree
Hide file tree
Showing 8 changed files with 871 additions and 235 deletions.
35 changes: 15 additions & 20 deletions src/native/engine/include/alimer_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ typedef struct GPUBufferImpl* GPUBuffer;
typedef struct GPUTextureImpl* GPUTexture;
typedef struct GPUSamplerImpl* GPUSampler;
typedef struct GPUQuerySetImpl* GPUQuerySet;
typedef struct GPUShaderModuleImpl* GPUShaderModule;
typedef struct GPUBindGroupLayoutImpl* GPUBindGroupLayout;
typedef struct GPUBindGroupImpl* GPUBindGroup;
typedef struct GPUPipelineLayoutImpl* GPUPipelineLayout;
Expand Down Expand Up @@ -218,9 +217,8 @@ typedef enum GPUShaderStage {
} GPUShaderStage;

typedef enum GPUVertexStepMode {
GPUVertexStepMode_Undefined = 0,
GPUVertexStepMode_Vertex = 1,
GPUVertexStepMode_Instance = 2,
GPUVertexStepMode_Vertex = 0,
GPUVertexStepMode_Instance = 1,

_GPUVertexStepMode_Force32 = 0x7FFFFFFF
} GPUVertexStepMode;
Expand Down Expand Up @@ -447,20 +445,17 @@ typedef struct GPUPipelineLayoutDesc {
const char* label DEFAULT_INITIALIZER(nullptr);
} GPUPipelineLayoutDesc;

typedef struct GPUShaderModuleDesc {
typedef struct GPUShaderDesc {
GPUShaderStage stage;
size_t bytecodeSize;
const void* bytecode;
} GPUShaderModuleDesc;

typedef struct GPUComputeState {
GPUShaderModule module;
const char* entryPoint DEFAULT_INITIALIZER("main");
} GPUComputeState;
} GPUShaderDesc;

typedef struct GPUComputePipelineDesc {
const char* label DEFAULT_INITIALIZER(nullptr);
GPUPipelineLayout layout;
GPUComputeState compute;
GPUShaderDesc shader;
} GPUComputePipelineDesc;

typedef struct GPUVertexAttribute {
Expand All @@ -477,15 +472,17 @@ typedef struct GPUVertexBufferLayout {
} GPUVertexBufferLayout;

typedef struct GPUVertexState {
GPUShaderModule module;
const char* entryPoint DEFAULT_INITIALIZER("main");
uint32_t bufferCount DEFAULT_INITIALIZER(0);
const GPUVertexBufferLayout* buffers DEFAULT_INITIALIZER(nullptr);
} GPUVertexState;

typedef struct GPURenderPipelineDesc {
const char* label DEFAULT_INITIALIZER(nullptr);
GPUPipelineLayout layout;

uint32_t shaderCount;
const GPUShaderDesc* shaders;

GPUVertexState vertex;
uint32_t rasterSampleCount DEFAULT_INITIALIZER(1);
GPUBool alphaToCoverageEnabled DEFAULT_INITIALIZER(false);
Expand Down Expand Up @@ -577,6 +574,8 @@ typedef struct GPUSurfaceCapabilities {
GPUTextureUsage supportedUsage;
uint32_t formatCount;
const PixelFormat* formats;
uint32_t presentModeCount;
const GPUPresentMode* presentModes;
} GPUSurfaceCapabilities;

typedef struct GPUSurfaceConfig {
Expand Down Expand Up @@ -623,6 +622,7 @@ ALIMER_API GPUDevice agpuCreateDevice(GPUAdapter adapter, const GPUDeviceDesc* d
ALIMER_API void agpuDeviceSetLabel(GPUDevice device, const char* label);
ALIMER_API uint32_t agpuDeviceAddRef(GPUDevice device);
ALIMER_API uint32_t agpuDeviceRelease(GPUDevice device);
ALIMER_API GPUBackendType agpuDeviceGetBackend(GPUDevice device);
ALIMER_API bool agpuDeviceHasFeature(GPUDevice device, GPUFeature feature);
ALIMER_API GPUQueue agpuDeviceGetQueue(GPUDevice device, GPUQueueType type);
ALIMER_API bool agpuDeviceWaitIdle(GPUDevice device);
Expand Down Expand Up @@ -691,12 +691,6 @@ ALIMER_API uint32_t agpuTextureGetLevelHeight(GPUTexture texture, uint32_t mipLe
ALIMER_API uint32_t agpuTextureAddRef(GPUTexture texture);
ALIMER_API uint32_t agpuTextureRelease(GPUTexture texture);

/* ShaderModule */
ALIMER_API GPUShaderModule agpuCreateShaderModule(GPUDevice device, const GPUShaderModuleDesc* desc);
ALIMER_API void agpuShaderModuleSetLabel(GPUShaderModule shaderModule, const char* label);
ALIMER_API uint32_t agpuShaderModuleAddRef(GPUShaderModule shaderModule);
ALIMER_API uint32_t agpuShaderModuleRelease(GPUShaderModule shaderModule);

/* Sampler */
ALIMER_API GPUSampler agpuCreateSampler(GPUDevice device, const GPUSamplerDesc* desc);
ALIMER_API void agpuSamplerSetLabel(GPUSampler sampler, const char* label);
Expand All @@ -722,7 +716,8 @@ ALIMER_API uint32_t agpuRenderPipelineAddRef(GPURenderPipeline renderPipeline);
ALIMER_API uint32_t agpuRenderPipelineRelease(GPURenderPipeline renderPipeline);

/* Other */
ALIMER_API uint32_t agpuVertexFormatGetByteSize(GPUVertexFormat format);
ALIMER_API uint32_t agpuGetVertexFormatByteSize(GPUVertexFormat format);
ALIMER_API uint32_t agpuGetVertexFormatComponentCount(GPUVertexFormat format);
ALIMER_API GPUAdapterVendor agpuGPUAdapterVendorFromID(uint32_t vendorId);
ALIMER_API uint32_t agpuGPUAdapterVendorToID(GPUAdapterVendor vendor);

Expand Down
46 changes: 21 additions & 25 deletions src/native/engine/src/alimer_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ uint32_t agpuDeviceRelease(GPUDevice device)
return device->Release();
}

GPUBackendType agpuDeviceGetBackend(GPUDevice device)
{
return device->GetBackend();
}

bool agpuDeviceHasFeature(GPUDevice device, GPUFeature feature)
{
return device->HasFeature(feature);
Expand Down Expand Up @@ -569,27 +574,6 @@ uint32_t agpuTextureRelease(GPUTexture texture)
return texture->Release();
}

/* ShaderModule */
GPUShaderModule agpuCreateShaderModule(GPUDevice device, const GPUShaderModuleDesc* desc)
{
return device->CreateShaderModule(desc);
}

void agpuShaderModuleSetLabel(GPUShaderModule shaderModule, const char* label)
{
shaderModule->SetLabel(label);
}

uint32_t agpuShaderModuleAddRef(GPUShaderModule shaderModule)
{
return shaderModule->AddRef();
}

uint32_t agpuShaderModuleRelease(GPUShaderModule shaderModule)
{
return shaderModule->Release();
}

/* Sampler */
static GPUSamplerDesc _GPUSamplerDesc_Defaults(const GPUSamplerDesc* desc) {
GPUSamplerDesc def = {};
Expand Down Expand Up @@ -791,14 +775,26 @@ enum class KnownGPUAdapterVendor
BROADCOM = 0x014e4
};

uint32_t agpuVertexFormatGetByteSize(GPUVertexFormat format)
static const VertexFormatInfo& GetVertexFormatInfo(GPUVertexFormat format)
{
if (format >= _GPUVertexFormat_Count)
return 0;
if (format >= _PixelFormat_Count)
return kVertexFormatTable[0]; // Undefined

const VertexFormatInfo& info = kVertexFormatTable[format];
ALIMER_ASSERT(info.format == format);
return info.byteSize;
return info;
}

uint32_t agpuGetVertexFormatByteSize(GPUVertexFormat format)
{
const VertexFormatInfo& formatInfo = GetVertexFormatInfo(format);
return formatInfo.byteSize;
}

uint32_t agpuGetVertexFormatComponentCount(GPUVertexFormat format)
{
const VertexFormatInfo& formatInfo = GetVertexFormatInfo(format);
return formatInfo.componentCount;
}

GPUAdapterVendor agpuGPUAdapterVendorFromID(uint32_t vendorId)
Expand Down
7 changes: 1 addition & 6 deletions src/native/engine/src/alimer_gpu_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ struct GPUQuerySetImpl : public GPUResource

};

struct GPUShaderModuleImpl : public GPUResource
{

};

struct GPUBindGroupLayoutImpl : public GPUResource
{

Expand Down Expand Up @@ -160,6 +155,7 @@ struct GPUQueueImpl : public GPUResource

struct GPUDeviceImpl : public GPUResource
{
virtual GPUBackendType GetBackend() const = 0;
virtual bool HasFeature(GPUFeature feature) const = 0;
virtual GPUQueue GetQueue(GPUQueueType type) = 0;
virtual bool WaitIdle() = 0;
Expand All @@ -171,7 +167,6 @@ struct GPUDeviceImpl : public GPUResource
virtual GPUSampler CreateSampler(const GPUSamplerDesc& desc) = 0;
virtual GPUBindGroupLayout CreateBindGroupLayout(const GPUBindGroupLayoutDesc& desc) = 0;
virtual GPUPipelineLayout CreatePipelineLayout(const GPUPipelineLayoutDesc& desc) = 0;
virtual GPUShaderModule CreateShaderModule(const GPUShaderModuleDesc* desc) = 0;
virtual GPUComputePipeline CreateComputePipeline(const GPUComputePipelineDesc& desc) = 0;
virtual GPURenderPipeline CreateRenderPipeline(const GPURenderPipelineDesc& desc) = 0;
};
Expand Down
Loading

0 comments on commit 6305690

Please sign in to comment.