Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor api/operation/rendering/* #4205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/webgpu/api/operation/rendering/3d_texture_slices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Test rendering to 3d texture slices.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { kTextureFormatInfo } from '../../../format_info.js';
import { GPUTest } from '../../../gpu_test.js';
import { getColorRenderByteCost } from '../../../format_info.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
import { kBytesPerRowAlignment } from '../../../util/texture/layout.js';

const kSize = 4;
const kFormat = 'rgba8unorm' as const;

class F extends GPUTest {
class F extends AllFeaturesMaxLimitsGPUTest {
createShaderModule(attachmentCount: number = 1): GPUShaderModule {
let locations = '';
let outputs = '';
Expand Down Expand Up @@ -170,7 +170,7 @@ g.test('multiple_color_attachments,same_mip_level')
.fn(t => {
const { sameTexture, samePass, mipLevel } = t.params;

const formatByteCost = kTextureFormatInfo[kFormat].colorRender.byteCost;
const formatByteCost = getColorRenderByteCost(kFormat);
const maxAttachmentCountPerSample = Math.trunc(
t.device.limits.maxColorAttachmentBytesPerSample / formatByteCost
);
Expand Down Expand Up @@ -288,7 +288,7 @@ g.test('multiple_color_attachments,same_slice_with_diff_mip_levels')

const kBaseSize = 1;

const formatByteCost = kTextureFormatInfo[kFormat].colorRender.byteCost;
const formatByteCost = getColorRenderByteCost(kFormat);
const maxAttachmentCountPerSample = Math.trunc(
t.device.limits.maxColorAttachmentBytesPerSample / formatByteCost
);
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/api/operation/rendering/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Basic command buffer rendering tests.

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { now } from '../../../../common/util/util.js';
import { GPUTest } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';
import { checkElementsEqual } from '../../../util/check_contents.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('clear').fn(t => {
const dst = t.createBufferTracked({
Expand Down
26 changes: 13 additions & 13 deletions src/webgpu/api/operation/rendering/color_target_state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import {
kBlendOperations,
} from '../../../capability_info.js';
import { GPUConst } from '../../../constants.js';
import { kRegularTextureFormats, kTextureFormatInfo } from '../../../format_info.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import {
EncodableTextureFormat,
kPossibleColorRenderableTextureFormats,
} from '../../../format_info.js';
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { clamp } from '../../../util/math.js';
import { TexelView } from '../../../util/texture/texel_view.js';

class BlendingTest extends GPUTest {
class BlendingTest extends AllFeaturesMaxLimitsGPUTest {
createRenderPipelineForTest(colorTargetState: GPUColorTargetState): GPURenderPipeline {
return this.device.createRenderPipeline({
layout: 'auto',
Expand Down Expand Up @@ -378,25 +381,19 @@ struct FragOutput {
);
});

const kBlendableFormats = kRegularTextureFormats.filter(f => {
const info = kTextureFormatInfo[f];
return info.colorRender && info.color.type === 'float';
});

g.test('blending,formats')
.desc(
`Test blending results works for all formats that support it, and that blending is not applied
for formats that do not. Blending should be done in linear space for srgb formats.`
)
.params(u =>
u //
.combine('format', kBlendableFormats)
.combine('format', kPossibleColorRenderableTextureFormats)
)
.beforeAllSubcases(t => {
t.skipIfTextureFormatNotSupportedDeprecated(t.params.format);
})
.fn(t => {
const { format } = t.params;
t.skipIfTextureFormatNotSupported(format);
t.skipIfTextureFormatNotBlendable(format);

const pipeline = t.device.createRenderPipeline({
layout: 'auto',
Expand Down Expand Up @@ -457,7 +454,10 @@ g.test('blending,formats')
t.device.queue.submit([commandEncoder.finish()]);

const expColor = { R: 0.6, G: 0.6, B: 0.6, A: 0.6 };
const expTexelView = TexelView.fromTexelsAsColors(format, _coords => expColor);
const expTexelView = TexelView.fromTexelsAsColors(
format as EncodableTextureFormat,
_coords => expColor
);
t.expectTexelViewComparisonIsOkInTexture({ texture: renderTarget }, expTexelView, [1, 1, 1]);
});

Expand Down
107 changes: 50 additions & 57 deletions src/webgpu/api/operation/rendering/depth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Test related to depth buffer, depth op, compare func, etc.

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { TypedArrayBufferView } from '../../../../common/util/util.js';
import { kDepthStencilFormats, kTextureFormatInfo } from '../../../format_info.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { isStencilTextureFormat, kDepthTextureFormats } from '../../../format_info.js';
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { TexelView } from '../../../util/texture/texel_view.js';

const backgroundColor = [0x00, 0x00, 0x00, 0xff];
Expand All @@ -21,7 +21,7 @@ type TestStates = {
depth: number;
};

class DepthTest extends TextureTestMixin(GPUTest) {
class DepthTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
runDepthStateTest(testStates: TestStates[], expectedColor: Float32Array) {
const renderTargetFormat = 'rgba8unorm';

Expand Down Expand Up @@ -187,7 +187,7 @@ g.test('depth_write_disabled')
.fn(t => {
const { depthWriteEnabled, lastDepth, _expectedColor } = t.params;

const depthSpencilFormat: GPUTextureFormat = 'depth24plus-stencil8';
const depthStencilFormat: GPUTextureFormat = 'depth24plus-stencil8';

const stencilState = {
compare: 'always',
Expand All @@ -197,7 +197,7 @@ g.test('depth_write_disabled')
} as const;

const baseState = {
format: depthSpencilFormat,
format: depthStencilFormat,
depthWriteEnabled: true,
depthCompare: 'always',
stencilFront: stencilState,
Expand All @@ -207,7 +207,7 @@ g.test('depth_write_disabled')
} as const;

const depthWriteState = {
format: depthSpencilFormat,
format: depthStencilFormat,
depthWriteEnabled,
depthCompare: 'always',
stencilFront: stencilState,
Expand All @@ -217,7 +217,7 @@ g.test('depth_write_disabled')
} as const;

const checkState = {
format: depthSpencilFormat,
format: depthStencilFormat,
depthWriteEnabled: false,
depthCompare: 'equal',
stencilFront: stencilState,
Expand Down Expand Up @@ -256,18 +256,18 @@ g.test('depth_test_fail')
.fn(t => {
const { secondDepth, lastDepth, _expectedColor } = t.params;

const depthSpencilFormat: GPUTextureFormat = 'depth24plus-stencil8';
const depthStencilFormat: GPUTextureFormat = 'depth24plus-stencil8';

const baseState = {
format: depthSpencilFormat,
format: depthStencilFormat,
depthWriteEnabled: true,
depthCompare: 'always',
stencilReadMask: 0xff,
stencilWriteMask: 0xff,
} as const;

const depthTestState = {
format: depthSpencilFormat,
format: depthStencilFormat,
depthWriteEnabled: true,
depthCompare: 'less',
stencilReadMask: 0xff,
Expand All @@ -292,55 +292,48 @@ g.test('depth_compare_func')
`Tests each depth compare function works properly. Clears the depth attachment to various values, and renders a point at depth 0.5 with various depthCompare modes.`
)
.params(u =>
u
.combine(
'format',
kDepthStencilFormats.filter(format => kTextureFormatInfo[format].depth)
)
.combineWithParams([
{ depthCompare: 'never', depthClearValue: 1.0, _expected: backgroundColor },
{ depthCompare: 'never', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
{ depthCompare: 'never', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'less', depthClearValue: 1.0, _expected: triangleColor },
{ depthCompare: 'less', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
{ depthCompare: 'less', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'less-equal', depthClearValue: 1.0, _expected: triangleColor },
{
depthCompare: 'less-equal',
depthClearValue: kMiddleDepthValue,
_expected: triangleColor,
},
{ depthCompare: 'less-equal', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'equal', depthClearValue: 1.0, _expected: backgroundColor },
{ depthCompare: 'equal', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
{ depthCompare: 'equal', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'not-equal', depthClearValue: 1.0, _expected: triangleColor },
{
depthCompare: 'not-equal',
depthClearValue: kMiddleDepthValue,
_expected: backgroundColor,
},
{ depthCompare: 'not-equal', depthClearValue: 0.0, _expected: triangleColor },
{ depthCompare: 'greater-equal', depthClearValue: 1.0, _expected: backgroundColor },
{
depthCompare: 'greater-equal',
depthClearValue: kMiddleDepthValue,
_expected: triangleColor,
},
{ depthCompare: 'greater-equal', depthClearValue: 0.0, _expected: triangleColor },
{ depthCompare: 'greater', depthClearValue: 1.0, _expected: backgroundColor },
{ depthCompare: 'greater', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
{ depthCompare: 'greater', depthClearValue: 0.0, _expected: triangleColor },
{ depthCompare: 'always', depthClearValue: 1.0, _expected: triangleColor },
{ depthCompare: 'always', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
{ depthCompare: 'always', depthClearValue: 0.0, _expected: triangleColor },
] as const)
u.combine('format', kDepthTextureFormats).combineWithParams([
{ depthCompare: 'never', depthClearValue: 1.0, _expected: backgroundColor },
{ depthCompare: 'never', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
{ depthCompare: 'never', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'less', depthClearValue: 1.0, _expected: triangleColor },
{ depthCompare: 'less', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
{ depthCompare: 'less', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'less-equal', depthClearValue: 1.0, _expected: triangleColor },
{
depthCompare: 'less-equal',
depthClearValue: kMiddleDepthValue,
_expected: triangleColor,
},
{ depthCompare: 'less-equal', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'equal', depthClearValue: 1.0, _expected: backgroundColor },
{ depthCompare: 'equal', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
{ depthCompare: 'equal', depthClearValue: 0.0, _expected: backgroundColor },
{ depthCompare: 'not-equal', depthClearValue: 1.0, _expected: triangleColor },
{
depthCompare: 'not-equal',
depthClearValue: kMiddleDepthValue,
_expected: backgroundColor,
},
{ depthCompare: 'not-equal', depthClearValue: 0.0, _expected: triangleColor },
{ depthCompare: 'greater-equal', depthClearValue: 1.0, _expected: backgroundColor },
{
depthCompare: 'greater-equal',
depthClearValue: kMiddleDepthValue,
_expected: triangleColor,
},
{ depthCompare: 'greater-equal', depthClearValue: 0.0, _expected: triangleColor },
{ depthCompare: 'greater', depthClearValue: 1.0, _expected: backgroundColor },
{ depthCompare: 'greater', depthClearValue: kMiddleDepthValue, _expected: backgroundColor },
{ depthCompare: 'greater', depthClearValue: 0.0, _expected: triangleColor },
{ depthCompare: 'always', depthClearValue: 1.0, _expected: triangleColor },
{ depthCompare: 'always', depthClearValue: kMiddleDepthValue, _expected: triangleColor },
{ depthCompare: 'always', depthClearValue: 0.0, _expected: triangleColor },
] as const)
)
.beforeAllSubcases(t => {
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
})
.fn(t => {
const { depthCompare, depthClearValue, _expected, format } = t.params;
t.skipIfTextureFormatNotSupported(format);

const colorAttachmentFormat = 'rgba8unorm';
const colorAttachment = t.createTextureTracked({
Expand Down Expand Up @@ -397,7 +390,7 @@ g.test('depth_compare_func')
depthLoadOp: 'clear',
depthStoreOp: 'store',
};
if (kTextureFormatInfo[format].stencil) {
if (isStencilTextureFormat(format)) {
depthStencilAttachment.stencilClearValue = 0;
depthStencilAttachment.stencilLoadOp = 'clear';
depthStencilAttachment.stencilStoreOp = 'store';
Expand Down
16 changes: 8 additions & 8 deletions src/webgpu/api/operation/rendering/depth_bias.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Tests render results with different depth bias values like 'positive', 'negative
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { unreachable } from '../../../../common/util/util.js';
import {
kTextureFormatInfo,
DepthStencilFormat,
EncodableTextureFormat,
isDepthTextureFormat,
isStencilTextureFormat,
} from '../../../format_info.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { TexelView } from '../../../util/texture/texel_view.js';

enum QuadAngle {
Expand All @@ -29,7 +30,7 @@ enum QuadAngle {
// depthBias = 0.25 / (2 ** (-2 - 23)) = 8388608.
const kPointTwoFiveBiasForPointTwoFiveZOnFloat = 8388608;

class DepthBiasTest extends TextureTestMixin(GPUTest) {
class DepthBiasTest extends TextureTestMixin(AllFeaturesMaxLimitsGPUTest) {
runDepthBiasTestInternal(
depthFormat: DepthStencilFormat,
{
Expand All @@ -47,7 +48,6 @@ class DepthBiasTest extends TextureTestMixin(GPUTest) {
}
): { renderTarget: GPUTexture; depthTexture: GPUTexture } {
const renderTargetFormat = 'rgba8unorm';
const depthFormatInfo = kTextureFormatInfo[depthFormat];

let vertexShaderCode: string;
switch (quadAngle) {
Expand Down Expand Up @@ -103,10 +103,10 @@ class DepthBiasTest extends TextureTestMixin(GPUTest) {

const depthStencilAttachment: GPURenderPassDepthStencilAttachment = {
view: depthTexture.createView(),
depthLoadOp: depthFormatInfo.depth ? 'clear' : undefined,
depthStoreOp: depthFormatInfo.depth ? 'store' : undefined,
stencilLoadOp: depthFormatInfo.stencil ? 'clear' : undefined,
stencilStoreOp: depthFormatInfo.stencil ? 'store' : undefined,
depthLoadOp: isDepthTextureFormat(depthFormat) ? 'clear' : undefined,
depthStoreOp: isDepthTextureFormat(depthFormat) ? 'store' : undefined,
stencilLoadOp: isStencilTextureFormat(depthFormat) ? 'clear' : undefined,
stencilStoreOp: isStencilTextureFormat(depthFormat) ? 'store' : undefined,
depthClearValue: initialDepth,
};

Expand Down
Loading