mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
wg_engine: refactor pipeline creation
Pipeline creation workflow redesigned. Make code more compact No any public interfaces changed
This commit is contained in:
parent
4a38a4d360
commit
18db3ab1fd
2 changed files with 147 additions and 151 deletions
|
@ -47,20 +47,12 @@ WGPURenderPipeline WgPipelines::createRenderPipeline(
|
||||||
const WGPUShaderModule shaderModule, const char* vsEntryPoint, const char* fsEntryPoint,
|
const WGPUShaderModule shaderModule, const char* vsEntryPoint, const char* fsEntryPoint,
|
||||||
const WGPUPipelineLayout pipelineLayout,
|
const WGPUPipelineLayout pipelineLayout,
|
||||||
const WGPUVertexBufferLayout *vertexBufferLayouts, const uint32_t vertexBufferLayoutsCount,
|
const WGPUVertexBufferLayout *vertexBufferLayouts, const uint32_t vertexBufferLayoutsCount,
|
||||||
const WGPUColorWriteMaskFlags writeMask, const WGPUTextureFormat colorTargetFormat,
|
const WGPUColorWriteMaskFlags writeMask, const WGPUTextureFormat colorTargetFormat, const WGPUBlendState blendState,
|
||||||
const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt,
|
const WGPUDepthStencilState depthStencilState, const WGPUMultisampleState multisampleState)
|
||||||
const WGPUCompareFunction stencilFunctionBack, const WGPUStencilOperation stencilOperationBack,
|
|
||||||
const WGPUCompareFunction depthCompare, WGPUBool depthWriteEnabled, const WGPUMultisampleState multisampleState, const WGPUBlendState blendState)
|
|
||||||
{
|
{
|
||||||
const WGPUColorTargetState colorTargetState { .format = colorTargetFormat, .blend = &blendState, .writeMask = writeMask };
|
const WGPUColorTargetState colorTargetState { .format = colorTargetFormat, .blend = &blendState, .writeMask = writeMask };
|
||||||
const WGPUColorTargetState colorTargetStates[] { colorTargetState };
|
const WGPUColorTargetState colorTargetStates[] { colorTargetState };
|
||||||
const WGPUPrimitiveState primitiveState { .topology = WGPUPrimitiveTopology_TriangleList };
|
const WGPUPrimitiveState primitiveState { .topology = WGPUPrimitiveTopology_TriangleList };
|
||||||
const WGPUDepthStencilState depthStencilState {
|
|
||||||
.format = WGPUTextureFormat_Depth24PlusStencil8, .depthWriteEnabled = depthWriteEnabled, .depthCompare = depthCompare,
|
|
||||||
.stencilFront = { .compare = stencilFunctionFrnt, .failOp = stencilOperationFrnt, .depthFailOp = WGPUStencilOperation_Zero, .passOp = stencilOperationFrnt },
|
|
||||||
.stencilBack = { .compare = stencilFunctionBack, .failOp = stencilOperationBack, .depthFailOp = WGPUStencilOperation_Zero, .passOp = stencilOperationBack },
|
|
||||||
.stencilReadMask = 0xFFFFFFFF, .stencilWriteMask = 0xFFFFFFFF
|
|
||||||
};
|
|
||||||
const WGPUVertexState vertexState { .module = shaderModule, .entryPoint = vsEntryPoint, .bufferCount = vertexBufferLayoutsCount, .buffers = vertexBufferLayouts };
|
const WGPUVertexState vertexState { .module = shaderModule, .entryPoint = vsEntryPoint, .bufferCount = vertexBufferLayoutsCount, .buffers = vertexBufferLayouts };
|
||||||
const WGPUFragmentState fragmentState { .module = shaderModule, .entryPoint = fsEntryPoint, .targetCount = 1, .targets = colorTargetStates };
|
const WGPUFragmentState fragmentState { .module = shaderModule, .entryPoint = fsEntryPoint, .targetCount = 1, .targets = colorTargetStates };
|
||||||
const WGPURenderPipelineDescriptor renderPipelineDesc {
|
const WGPURenderPipelineDescriptor renderPipelineDesc {
|
||||||
|
@ -129,6 +121,29 @@ void WgPipelines::releaseShaderModule(WGPUShaderModule& shaderModule)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WGPUDepthStencilState WgPipelines::makeDepthStencilState(
|
||||||
|
const WGPUCompareFunction depthCompare, WGPUBool depthWriteEnabled,
|
||||||
|
const WGPUCompareFunction stencilFunction, const WGPUStencilOperation stencilOperation)
|
||||||
|
{
|
||||||
|
return makeDepthStencilState(depthCompare, depthWriteEnabled, stencilFunction, stencilOperation, stencilFunction, stencilOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WGPUDepthStencilState WgPipelines::makeDepthStencilState(
|
||||||
|
const WGPUCompareFunction depthCompare, WGPUBool depthWriteEnabled,
|
||||||
|
const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt,
|
||||||
|
const WGPUCompareFunction stencilFunctionBack, const WGPUStencilOperation stencilOperationBack)
|
||||||
|
{
|
||||||
|
const WGPUDepthStencilState depthStencilState {
|
||||||
|
.format = WGPUTextureFormat_Depth24PlusStencil8, .depthWriteEnabled = depthWriteEnabled, .depthCompare = depthCompare,
|
||||||
|
.stencilFront = { .compare = stencilFunctionFrnt, .failOp = stencilOperationFrnt, .depthFailOp = WGPUStencilOperation_Zero, .passOp = stencilOperationFrnt },
|
||||||
|
.stencilBack = { .compare = stencilFunctionBack, .failOp = stencilOperationBack, .depthFailOp = WGPUStencilOperation_Zero, .passOp = stencilOperationBack },
|
||||||
|
.stencilReadMask = 0xFFFFFFFF, .stencilWriteMask = 0xFFFFFFFF
|
||||||
|
};
|
||||||
|
return depthStencilState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgPipelines::initialize(WgContext& context)
|
void WgPipelines::initialize(WgContext& context)
|
||||||
{
|
{
|
||||||
// common pipeline settings
|
// common pipeline settings
|
||||||
|
@ -145,19 +160,15 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
const WGPUTextureFormat offscreenTargetFormat = WGPUTextureFormat_RGBA8Unorm;
|
const WGPUTextureFormat offscreenTargetFormat = WGPUTextureFormat_RGBA8Unorm;
|
||||||
|
|
||||||
// blend states
|
// blend states
|
||||||
const WGPUBlendState blendStateSrc {
|
WGPUBlendComponent blendComponentSrc { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_Zero };
|
||||||
.color = { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_Zero },
|
WGPUBlendComponent blendComponentNrm { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_OneMinusSrcAlpha };
|
||||||
.alpha = { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_Zero }
|
const WGPUBlendState blendStateSrc { .color = blendComponentSrc, .alpha = blendComponentSrc };
|
||||||
};
|
const WGPUBlendState blendStateNrm { .color = blendComponentNrm, .alpha = blendComponentNrm };
|
||||||
const WGPUBlendState blendStateNrm {
|
|
||||||
.color = { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_OneMinusSrcAlpha },
|
|
||||||
.alpha = { .operation = WGPUBlendOperation_Add, .srcFactor = WGPUBlendFactor_One, .dstFactor = WGPUBlendFactor_OneMinusSrcAlpha }
|
|
||||||
};
|
|
||||||
|
|
||||||
const WgBindGroupLayouts& layouts = context.layouts;
|
const WgBindGroupLayouts& layouts = context.layouts;
|
||||||
// bind group layouts helpers
|
// bind group layouts helpers
|
||||||
const WGPUBindGroupLayout bindGroupLayoutsStencil[] = { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un };
|
const WGPUBindGroupLayout bindGroupLayoutsStencil[] { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un };
|
||||||
const WGPUBindGroupLayout bindGroupLayoutsDepth[] = { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un, layouts.layoutBuffer1Un };
|
const WGPUBindGroupLayout bindGroupLayoutsDepth[] { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un, layouts.layoutBuffer1Un };
|
||||||
// bind group layouts normal blend
|
// bind group layouts normal blend
|
||||||
const WGPUBindGroupLayout bindGroupLayoutsSolid[] { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un, layouts.layoutBuffer1Un };
|
const WGPUBindGroupLayout bindGroupLayoutsSolid[] { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un, layouts.layoutBuffer1Un };
|
||||||
const WGPUBindGroupLayout bindGroupLayoutsGradient[] { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un, layouts.layoutTexSampledBuff2Un };
|
const WGPUBindGroupLayout bindGroupLayoutsGradient[] { layouts.layoutBuffer1Un, layouts.layoutBuffer2Un, layouts.layoutTexSampledBuff2Un };
|
||||||
|
@ -173,6 +184,20 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
// bind group layouts blit
|
// bind group layouts blit
|
||||||
const WGPUBindGroupLayout bindGroupLayoutsBlit[] { layouts.layoutTexSampled };
|
const WGPUBindGroupLayout bindGroupLayoutsBlit[] { layouts.layoutTexSampled };
|
||||||
|
|
||||||
|
// depth stencil state markup
|
||||||
|
const WGPUDepthStencilState depthStencilStateWinding = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_IncrementWrap, WGPUCompareFunction_Always, WGPUStencilOperation_DecrementWrap);
|
||||||
|
const WGPUDepthStencilState depthStencilStateEvenOdd = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_Invert);
|
||||||
|
const WGPUDepthStencilState depthStencilStateDirect = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_Replace);
|
||||||
|
// depth stencil state clip path
|
||||||
|
const WGPUDepthStencilState depthStencilStateCopyStencilToDepth = makeDepthStencilState(WGPUCompareFunction_Always, true, WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero);
|
||||||
|
const WGPUDepthStencilState depthStencilStateCopyStencilToDepthInt = makeDepthStencilState(WGPUCompareFunction_Greater, true, WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero);
|
||||||
|
const WGPUDepthStencilState depthStencilStateCopyDepthToStencil = makeDepthStencilState(WGPUCompareFunction_Equal, false, WGPUCompareFunction_Always, WGPUStencilOperation_Replace);
|
||||||
|
const WGPUDepthStencilState depthStencilStateMergeDepthStencil = makeDepthStencilState(WGPUCompareFunction_Equal, true, WGPUCompareFunction_Always, WGPUStencilOperation_Keep);
|
||||||
|
const WGPUDepthStencilState depthStencilStateClearDepth = makeDepthStencilState(WGPUCompareFunction_Always, true, WGPUCompareFunction_Always, WGPUStencilOperation_Keep);
|
||||||
|
// depth stencil state blend, compose and blit
|
||||||
|
const WGPUDepthStencilState depthStencilStateShape = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero);
|
||||||
|
const WGPUDepthStencilState depthStencilStateScene = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_Zero);
|
||||||
|
|
||||||
// shaders
|
// shaders
|
||||||
char shaderSourceBuff[16384]{};
|
char shaderSourceBuff[16384]{};
|
||||||
shader_stencil = createShaderModule(context.device, "The shader stencil", cShaderSrc_Stencil);
|
shader_stencil = createShaderModule(context.device, "The shader stencil", cShaderSrc_Stencil);
|
||||||
|
@ -215,122 +240,96 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
// render pipeline winding
|
// render pipeline winding
|
||||||
winding = createRenderPipeline(
|
winding = createRenderPipeline(
|
||||||
context.device, "The render pipeline winding",
|
context.device, "The render pipeline winding",
|
||||||
shader_stencil, "vs_main", "fs_main", layout_stencil,
|
shader_stencil, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_stencil, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_IncrementWrap,
|
depthStencilStateWinding, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_DecrementWrap,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
// render pipeline even-odd
|
// render pipeline even-odd
|
||||||
evenodd = createRenderPipeline(
|
evenodd = createRenderPipeline(
|
||||||
context.device, "The render pipeline even-odd",
|
context.device, "The render pipeline even-odd",
|
||||||
shader_stencil, "vs_main", "fs_main", layout_stencil,
|
shader_stencil, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_stencil, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Invert,
|
depthStencilStateEvenOdd, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Invert,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
// render pipeline direct
|
// render pipeline direct
|
||||||
direct = createRenderPipeline(
|
direct = createRenderPipeline(
|
||||||
context.device, "The render pipeline direct",
|
context.device, "The render pipeline direct",
|
||||||
shader_stencil, "vs_main", "fs_main", layout_stencil,
|
shader_stencil, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_stencil, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Replace,
|
depthStencilStateDirect, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Replace,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
|
|
||||||
// render pipeline copy stencil to depth (front)
|
// render pipeline copy stencil to depth (front)
|
||||||
copy_stencil_to_depth = createRenderPipeline(
|
copy_stencil_to_depth = createRenderPipeline(
|
||||||
context.device, "The render pipeline copy stencil to depth front",
|
context.device, "The render pipeline copy stencil to depth front",
|
||||||
shader_depth, "vs_main", "fs_main", layout_depth,
|
shader_depth, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_depth, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateCopyStencilToDepth , multisampleState);
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, true, multisampleState, blendStateSrc);
|
|
||||||
// render pipeline copy stencil to depth (intermidiate)
|
// render pipeline copy stencil to depth (intermidiate)
|
||||||
copy_stencil_to_depth_interm = createRenderPipeline(
|
copy_stencil_to_depth_interm = createRenderPipeline(
|
||||||
context.device, "The render pipeline copy stencil to depth intermidiate",
|
context.device, "The render pipeline copy stencil to depth intermidiate",
|
||||||
shader_depth, "vs_main", "fs_main", layout_depth,
|
shader_depth, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_depth, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateCopyStencilToDepthInt, multisampleState);
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Greater, true, multisampleState, blendStateSrc);
|
|
||||||
// render pipeline depth to stencil
|
// render pipeline depth to stencil
|
||||||
copy_depth_to_stencil = createRenderPipeline(
|
copy_depth_to_stencil = createRenderPipeline(
|
||||||
context.device, "The render pipeline depth to stencil",
|
context.device, "The render pipeline depth to stencil",
|
||||||
shader_depth, "vs_main", "fs_main", layout_depth,
|
shader_depth, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_depth, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Replace,
|
depthStencilStateCopyDepthToStencil, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Replace,
|
|
||||||
WGPUCompareFunction_Equal, false, multisampleState, blendStateSrc);
|
|
||||||
// render pipeline merge depth with stencil
|
// render pipeline merge depth with stencil
|
||||||
merge_depth_stencil = createRenderPipeline(
|
merge_depth_stencil = createRenderPipeline(
|
||||||
context.device, "The render pipeline merge depth with stencil",
|
context.device, "The render pipeline merge depth with stencil",
|
||||||
shader_depth, "vs_main", "fs_main", layout_depth,
|
shader_depth, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_depth, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Keep,
|
depthStencilStateMergeDepthStencil, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Keep,
|
|
||||||
WGPUCompareFunction_Equal, true, multisampleState, blendStateSrc);
|
|
||||||
// render pipeline clear depth
|
// render pipeline clear depth
|
||||||
clear_depth = createRenderPipeline(
|
clear_depth = createRenderPipeline(
|
||||||
context.device, "The render pipeline clear depth",
|
context.device, "The render pipeline clear depth",
|
||||||
shader_depth, "vs_main", "fs_main", layout_depth,
|
shader_depth, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_depth, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_None, offscreenTargetFormat,
|
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Keep,
|
depthStencilStateClearDepth, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Keep,
|
|
||||||
WGPUCompareFunction_Always, true, multisampleState, blendStateSrc);
|
|
||||||
|
|
||||||
// render pipeline solid
|
// render pipeline solid
|
||||||
solid = createRenderPipeline(
|
solid = createRenderPipeline(
|
||||||
context.device, "The render pipeline solid",
|
context.device, "The render pipeline solid",
|
||||||
shader_solid, "vs_main", "fs_main", layout_solid,
|
shader_solid, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_solid, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateNrm);
|
|
||||||
// render pipeline radial
|
// render pipeline radial
|
||||||
radial = createRenderPipeline(
|
radial = createRenderPipeline(
|
||||||
context.device, "The render pipeline radial",
|
context.device, "The render pipeline radial",
|
||||||
shader_radial, "vs_main", "fs_main", layout_gradient,
|
shader_radial, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_gradient, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateNrm);
|
|
||||||
// render pipeline linear
|
// render pipeline linear
|
||||||
linear = createRenderPipeline(
|
linear = createRenderPipeline(
|
||||||
context.device, "The render pipeline linear",
|
context.device, "The render pipeline linear",
|
||||||
shader_linear, "vs_main", "fs_main", layout_gradient,
|
shader_linear, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsShape, 1,
|
layout_gradient, vertexBufferLayoutsShape, 1,
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateNrm);
|
|
||||||
// render pipeline image
|
// render pipeline image
|
||||||
image = createRenderPipeline(
|
image = createRenderPipeline(
|
||||||
context.device, "The render pipeline image",
|
context.device, "The render pipeline image",
|
||||||
shader_image, "vs_main", "fs_main", layout_image,
|
shader_image, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsImage, 2,
|
layout_image, vertexBufferLayoutsImage, 2,
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateNrm);
|
|
||||||
// render pipeline scene
|
// render pipeline scene
|
||||||
scene = createRenderPipeline(
|
scene = createRenderPipeline(
|
||||||
context.device, "The render pipeline scene",
|
context.device, "The render pipeline scene",
|
||||||
shader_scene, "vs_main", "fs_main", layout_scene,
|
shader_scene, "vs_main", "fs_main",
|
||||||
vertexBufferLayoutsImage, 2,
|
layout_scene, vertexBufferLayoutsImage, 2,
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateNrm,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
depthStencilStateScene, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateNrm);
|
|
||||||
|
|
||||||
// blend shader names
|
// blend shader names
|
||||||
const char* shaderBlendNames[] {
|
const char* shaderBlendNames[] {
|
||||||
|
@ -357,45 +356,40 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
// render pipeline shape blend
|
// render pipeline shape blend
|
||||||
for (uint32_t i = 0; i < 18; i++) {
|
for (uint32_t i = 0; i < 18; i++) {
|
||||||
// blend solid
|
// blend solid
|
||||||
solid_blend[i] = createRenderPipeline(context.device, "The render pipeline solid blend",
|
solid_blend[i] = createRenderPipeline(
|
||||||
shader_solid_blend, "vs_main", shaderBlendNames[i], layout_solid_blend,
|
context.device, "The render pipeline solid blend",
|
||||||
vertexBufferLayoutsShape, 1,
|
shader_solid_blend, "vs_main", shaderBlendNames[i],
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
layout_solid_blend, vertexBufferLayoutsShape, 1,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
// blend radial
|
// blend radial
|
||||||
radial_blend[i] = createRenderPipeline(context.device, "The render pipeline radial blend",
|
radial_blend[i] = createRenderPipeline(
|
||||||
shader_radial_blend, "vs_main", shaderBlendNames[i], layout_gradient_blend,
|
context.device, "The render pipeline radial blend",
|
||||||
vertexBufferLayoutsShape, 1,
|
shader_radial_blend, "vs_main", shaderBlendNames[i],
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
layout_gradient_blend, vertexBufferLayoutsShape, 1,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
// blend linear
|
// blend linear
|
||||||
linear_blend[i] = createRenderPipeline(context.device, "The render pipeline linear blend",
|
linear_blend[i] = createRenderPipeline(
|
||||||
shader_linear_blend, "vs_main", shaderBlendNames[i], layout_gradient_blend,
|
context.device, "The render pipeline linear blend",
|
||||||
vertexBufferLayoutsShape, 1,
|
shader_linear_blend, "vs_main", shaderBlendNames[i],
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
layout_gradient_blend, vertexBufferLayoutsShape, 1,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
// blend image
|
// blend image
|
||||||
image_blend[i] = createRenderPipeline(context.device, "The render pipeline image blend",
|
image_blend[i] = createRenderPipeline(
|
||||||
shader_image_blend, "vs_main", shaderBlendNames[i], layout_image_blend,
|
context.device, "The render pipeline image blend",
|
||||||
vertexBufferLayoutsImage, 2,
|
shader_image_blend, "vs_main", shaderBlendNames[i],
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
layout_image_blend, vertexBufferLayoutsImage, 2,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_NotEqual, WGPUStencilOperation_Zero,
|
depthStencilStateShape, multisampleState);
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
// blend scene
|
// blend scene
|
||||||
scene_blend[i] = createRenderPipeline(context.device, "The render pipeline scene blend",
|
scene_blend[i] = createRenderPipeline(
|
||||||
shader_scene_blend, "vs_main", shaderBlendNames[i], layout_scene_blend,
|
context.device, "The render pipeline scene blend",
|
||||||
vertexBufferLayoutsImage, 2,
|
shader_scene_blend, "vs_main", shaderBlendNames[i],
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
layout_scene_blend, vertexBufferLayoutsImage, 2,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
WGPUColorWriteMask_All, offscreenTargetFormat, blendStateSrc,
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
depthStencilStateScene, multisampleState);
|
||||||
WGPUCompareFunction_Always, false, multisampleState, blendStateSrc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// compose shader names
|
// compose shader names
|
||||||
|
@ -432,23 +426,19 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
for (uint32_t i = 0; i < 11; i++) {
|
for (uint32_t i = 0; i < 11; i++) {
|
||||||
scene_compose[i] = createRenderPipeline(
|
scene_compose[i] = createRenderPipeline(
|
||||||
context.device, "The render pipeline scene composition",
|
context.device, "The render pipeline scene composition",
|
||||||
shader_scene_compose, "vs_main", shaderComposeNames[i], layout_scene_compose,
|
shader_scene_compose, "vs_main", shaderComposeNames[i],
|
||||||
vertexBufferLayoutsImage, 2,
|
layout_scene_compose, vertexBufferLayoutsImage, 2,
|
||||||
WGPUColorWriteMask_All, offscreenTargetFormat,
|
WGPUColorWriteMask_All, offscreenTargetFormat, composeBlends[i],
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
depthStencilStateScene, multisampleState);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleState, composeBlends[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// render pipeline blit
|
// render pipeline blit
|
||||||
blit = createRenderPipeline(context.device, "The render pipeline blit",
|
blit = createRenderPipeline(
|
||||||
shader_blit, "vs_main", "fs_main", layout_blit,
|
context.device, "The render pipeline blit",
|
||||||
vertexBufferLayoutsImage, 2,
|
shader_blit, "vs_main", "fs_main",
|
||||||
// must be preferred screen pixel format
|
layout_blit, vertexBufferLayoutsImage, 2,
|
||||||
WGPUColorWriteMask_All, context.preferredFormat,
|
WGPUColorWriteMask_All, context.preferredFormat, blendStateSrc, // must be preferred screen pixel format
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
depthStencilStateScene, multisampleStateX1);
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
|
||||||
WGPUCompareFunction_Always, false, multisampleStateX1, blendStateSrc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WgPipelines::releaseGraphicHandles(WgContext& context)
|
void WgPipelines::releaseGraphicHandles(WgContext& context)
|
||||||
|
|
|
@ -101,10 +101,8 @@ private:
|
||||||
const WGPUShaderModule shaderModule, const char* vsEntryPoint, const char* fsEntryPoint,
|
const WGPUShaderModule shaderModule, const char* vsEntryPoint, const char* fsEntryPoint,
|
||||||
const WGPUPipelineLayout pipelineLayout,
|
const WGPUPipelineLayout pipelineLayout,
|
||||||
const WGPUVertexBufferLayout *vertexBufferLayouts, const uint32_t vertexBufferLayoutsCount,
|
const WGPUVertexBufferLayout *vertexBufferLayouts, const uint32_t vertexBufferLayoutsCount,
|
||||||
const WGPUColorWriteMaskFlags writeMask, const WGPUTextureFormat colorTargetFormat,
|
const WGPUColorWriteMaskFlags writeMask, const WGPUTextureFormat colorTargetFormat, const WGPUBlendState blendState,
|
||||||
const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt,
|
const WGPUDepthStencilState depthStencilState, const WGPUMultisampleState multisampleState);
|
||||||
const WGPUCompareFunction stencilFunctionBack, const WGPUStencilOperation stencilOperationBack,
|
|
||||||
const WGPUCompareFunction depthCompare, WGPUBool depthWriteEnabled, const WGPUMultisampleState multisampleState, const WGPUBlendState blendState);
|
|
||||||
WGPUComputePipeline createComputePipeline(
|
WGPUComputePipeline createComputePipeline(
|
||||||
WGPUDevice device, const char* pipelineLabel,
|
WGPUDevice device, const char* pipelineLabel,
|
||||||
const WGPUShaderModule shaderModule, const char* entryPoint,
|
const WGPUShaderModule shaderModule, const char* entryPoint,
|
||||||
|
@ -113,6 +111,14 @@ private:
|
||||||
void releaseRenderPipeline(WGPURenderPipeline& renderPipeline);
|
void releaseRenderPipeline(WGPURenderPipeline& renderPipeline);
|
||||||
void releasePipelineLayout(WGPUPipelineLayout& pipelineLayout);
|
void releasePipelineLayout(WGPUPipelineLayout& pipelineLayout);
|
||||||
void releaseShaderModule(WGPUShaderModule& shaderModule);
|
void releaseShaderModule(WGPUShaderModule& shaderModule);
|
||||||
|
|
||||||
|
WGPUDepthStencilState makeDepthStencilState(
|
||||||
|
const WGPUCompareFunction depthCompare, WGPUBool depthWriteEnabled,
|
||||||
|
const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt);
|
||||||
|
WGPUDepthStencilState makeDepthStencilState(
|
||||||
|
const WGPUCompareFunction depthCompare, WGPUBool depthWriteEnabled,
|
||||||
|
const WGPUCompareFunction stencilFunctionFrnt, const WGPUStencilOperation stencilOperationFrnt,
|
||||||
|
const WGPUCompareFunction stencilFunctionBack, const WGPUStencilOperation stencilOperationBack);
|
||||||
public:
|
public:
|
||||||
void initialize(WgContext& context);
|
void initialize(WgContext& context);
|
||||||
void release(WgContext& context);
|
void release(WgContext& context);
|
||||||
|
|
Loading…
Add table
Reference in a new issue