diff --git a/cocos/gfx/webgpu/webgpu-define.ts b/cocos/gfx/webgpu/webgpu-define.ts index c00a2b2df8e..ca15a9b9fb9 100644 --- a/cocos/gfx/webgpu/webgpu-define.ts +++ b/cocos/gfx/webgpu/webgpu-define.ts @@ -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; @@ -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); } @@ -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; } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp b/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp index 8daeab75e5e..ba39ba46d3c 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp @@ -373,7 +373,7 @@ void CCWGPUCommandBuffer::bindStates() { } } - if (1) { + if (0) { ccstd::vector dsSets; for (size_t i = 0; i < setLayouts.size(); i++) { dsSets.push_back(descriptorSets[i].descriptorSet); diff --git a/native/cocos/renderer/gfx-wgpu/WGPUUtils.cpp b/native/cocos/renderer/gfx-wgpu/WGPUUtils.cpp index 5c5ea03d046..1ac4c9ead80 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUUtils.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUUtils.cpp @@ -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 { @@ -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; @@ -430,7 +428,6 @@ fn frag_main(@location(0) fragUV : vec2) -> @location(0) vec4 { fragState.targetCount = 1; fragState.targets = &colorState; - printf("4444444\n"); WGPUMultisampleState multisample{}; multisample.count = 1; multisample.alphaToCoverageEnabled = false; @@ -447,9 +444,7 @@ fn frag_main(@location(0) fragUV : vec2) -> @location(0) vec4 { 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; @@ -458,7 +453,6 @@ fn frag_main(@location(0) fragUV : vec2) -> @location(0) vec4 { desc.arrayLayerCount = 1; desc.aspect = WGPUTextureAspect_All; - printf("66666\n"); CC_ASSERT_GT(i, 0); auto cmdBuffCommandEncoder = static_cast(cmdBuff)->gpuCommandBufferObject()->wgpuCommandEncoder; auto commandEncoder = cmdBuffCommandEncoder;