Skip to content

Commit

Permalink
fix binding
Browse files Browse the repository at this point in the history
  • Loading branch information
hana-alice committed Jun 25, 2023
1 parent c044f37 commit 58c03e7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
38 changes: 36 additions & 2 deletions cocos/gfx/webgpu/webgpu-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => {
oldDeviceCopyBuffersToTexture.call(this, buffers, texture, regions);
};


const SEPARATE_SAMPLER_BINDING_OFFSET = 16;
function seperateCombinedSamplerTexture (shaderSource: string) {
// gather
let samplerReg = /.*?(\(set = \d+, binding = )(\d+)\) uniform[^;]+sampler(\w*) (\w+);/g;
Expand Down Expand Up @@ -226,7 +226,7 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => {
let sampReg = /.*?(\(set = \d+, binding = )(\d+)\) uniform[^;]+sampler(\w*) (\w+);/g;
let it = sampReg.exec(code);
while (it) {
code = code.replace(sampReg, `layout$1 $2 + 16) uniform texture$3 $4;\nlayout$1 $2) uniform sampler $4_sampler;\n`);
code = code.replace(sampReg, `layout$1 $2) uniform texture$3 $4;\nlayout$1 $2 + ${SEPARATE_SAMPLER_BINDING_OFFSET}) uniform sampler $4_sampler;\n`);
it = sampReg.exec(code);
}

Expand Down Expand Up @@ -339,6 +339,40 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => {
code = replaceBultin(name, type, code);
});

///////////////////////////////////////////////////////////
// isNan, isInf has been removed in dawn:tint

let functionDefs = '';
const precisionKeyWord = 'highp';
const isNanIndex = code.indexOf('isnan');
if (isNanIndex !== -1) {
// getPrecision(isNanIndex);
functionDefs += `\n
bool isNan(${precisionKeyWord} float val) {
return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;
}
\n`;
code = code.replace(/isnan\(/gi, 'isNan(');
}

const isInfIndex = code.indexOf('isinf');
if (isInfIndex !== -1) {
// getPrecision(isInfIndex);
functionDefs += `\n
bool isInf(${precisionKeyWord} float x) {
return x == x * 2.0 && x != 0.0;
}
\n`;
code = code.replace(/isinf\(/gi, 'isInf(');
}

///////////////////////////////////////////////////////////

let firstPrecisionIdx = code.indexOf('precision');
firstPrecisionIdx = code.indexOf(';', firstPrecisionIdx);
firstPrecisionIdx += 1;
code = `${code.slice(0, firstPrecisionIdx)}\n${functionDefs}\n${code.slice(firstPrecisionIdx)}`;

return code;
}

Expand Down
2 changes: 1 addition & 1 deletion native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void CCWGPUCommandBuffer::bindStates() {
}
}

if (1) {
if (0) {
ccstd::vector<DescriptorSet *> dsSets;
for (size_t i = 0; i < setLayouts.size(); i++) {
dsSets.push_back(descriptorSets[i].descriptorSet);
Expand Down
6 changes: 0 additions & 6 deletions native/cocos/renderer/gfx-wgpu/WGPUUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ void clearRect(CommandBuffer* cmdBuff, Texture* texture, const Rect& renderArea,
auto dimension = toWGPUTextureDimension(ccTexture->getTextureType());
auto wgpuTextureView = ccTexture->gpuTextureObject()->selfView;

printf("111111\n");
if (!clearPassData.vertShader) {
const char* clearQuadVert = R"(
struct VertexOutput {
Expand Down Expand Up @@ -291,7 +290,6 @@ void genMipMap(Texture* texture, uint8_t fromLevel, uint8_t levelCount, uint32_t
auto dimension = toWGPUTextureDimension(ccTexture->getTextureType());
auto* wgpuTexture = ccTexture->gpuTextureObject()->wgpuTexture;

printf("333333\n");
if (!mipmapData.vertShader) {
// WGPUBufferDescriptor bufferDesc;
// bufferDesc.usage = WGPUBufferUsage_Vertex;
Expand Down Expand Up @@ -430,7 +428,6 @@ fn frag_main(@location(0) fragUV : vec2<f32>) -> @location(0) vec4<f32> {
fragState.targetCount = 1;
fragState.targets = &colorState;

printf("4444444\n");
WGPUMultisampleState multisample{};
multisample.count = 1;
multisample.alphaToCoverageEnabled = false;
Expand All @@ -447,9 +444,7 @@ fn frag_main(@location(0) fragUV : vec2<f32>) -> @location(0) vec4<f32> {
mipmapData.pipeline = wgpuDeviceCreateRenderPipeline(wgpuDevice, &pipelineDesc);
}

printf("555555\n");
WGPUTextureViewDescriptor desc{};
printf("desc ptr %p %d %x\n", desc.nextInChain, desc.nextInChain, desc.nextInChain);
desc.format = format;
desc.dimension = WGPUTextureViewDimension_2D;
desc.baseMipLevel = fromLevel;
Expand All @@ -458,7 +453,6 @@ fn frag_main(@location(0) fragUV : vec2<f32>) -> @location(0) vec4<f32> {
desc.arrayLayerCount = 1;
desc.aspect = WGPUTextureAspect_All;

printf("66666\n");
CC_ASSERT_GT(i, 0);
auto cmdBuffCommandEncoder = static_cast<CCWGPUCommandBuffer*>(cmdBuff)->gpuCommandBufferObject()->wgpuCommandEncoder;
auto commandEncoder = cmdBuffCommandEncoder;
Expand Down

0 comments on commit 58c03e7

Please sign in to comment.