summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/common/resource.cc
blob: ffcbb57489c5bd80033254ca10a8ee15822fe751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file contains the implementation of the helper functions for resources.

#include "gpu/command_buffer/common/resource.h"

namespace gpu {

namespace texture {

// Gets the number of bytes per block for a given format.
unsigned int GetBytesPerBlock(Format format) {
  switch (format) {
    case kXRGB8:
    case kARGB8:
    case kR32F:
      return 4;
    case kABGR16F:
      return 8;
    case kABGR32F:
      return 16;
    case kDXT1:
      return 8;
    case kUnknown:
    default:
      // TODO(petersont): Add DXT3/5 support.
      LOG(FATAL) << "Invalid format";
      return 1;
  }
}

// Gets the width of a block for a given format.
unsigned int GetBlockSizeX(Format format) {
  switch (format) {
    case kXRGB8:
    case kARGB8:
    case kABGR16F:
    case kR32F:
    case kABGR32F:
      return 1;
    case kDXT1:
      return 4;
    case kUnknown:
    default:
      // TODO(petersont): Add DXT3/5 support.
      LOG(FATAL) << "Invalid format";
      return 1;
  }
}

// Gets the height of a block for a given format.
unsigned int GetBlockSizeY(Format format) {
  // NOTE: currently only supported formats use square blocks.
  return GetBlockSizeX(format);
}

}  // namespace texture

namespace effect_param {

// Gets the size of the data of a given parameter type.
unsigned int GetDataSize(DataType type) {
  switch (type) {
    case kUnknown:
      return 0;
    case kFloat1:
      return sizeof(float);  // NOLINT
    case kFloat2:
      return sizeof(float) * 2;  // NOLINT
    case kFloat3:
      return sizeof(float) * 3;  // NOLINT
    case kFloat4:
      return sizeof(float) * 4;  // NOLINT
    case kMatrix4:
      return sizeof(float) * 16;  // NOLINT
    case kInt:
      return sizeof(int);  // NOLINT
    case kBool:
      return sizeof(bool);  // NOLINT
    case kSampler:
      return sizeof(ResourceId);  // NOLINT
    case kTexture:
      return sizeof(ResourceId);  // NOLINT
    case kNumTypes:
    case kMake32Bit:
    default:
      LOG(FATAL) << "Invalid type.";
      return 0;
  }
}

}  // namespace effect_param

}  // namespace gpu