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
|
// cpu-resource-views.h
#pragma once
#include "cpu-base.h"
#include "cpu-buffer.h"
#include "cpu-texture.h"
namespace gfx
{
using namespace Slang;
namespace cpu
{
class ResourceViewImpl : public ResourceViewBase
{
public:
enum class Kind
{
Buffer,
Texture,
};
Kind getViewKind() const { return m_kind; }
Desc const& getDesc() const { return m_desc; }
protected:
ResourceViewImpl(Kind kind, Desc const& desc);
private:
Kind m_kind;
};
class BufferResourceViewImpl : public ResourceViewImpl
{
public:
BufferResourceViewImpl(Desc const& desc, BufferResourceImpl* buffer)
: ResourceViewImpl(Kind::Buffer, desc), m_buffer(buffer)
{
}
BufferResourceImpl* getBuffer() const;
private:
RefPtr<BufferResourceImpl> m_buffer;
};
class TextureResourceViewImpl : public ResourceViewImpl, public slang_prelude::IRWTexture
{
public:
TextureResourceViewImpl(Desc const& desc, TextureResourceImpl* texture)
: ResourceViewImpl(Kind::Texture, desc), m_texture(texture)
{
}
TextureResourceImpl* getTexture() const;
//
// ITexture interface
//
slang_prelude::TextureDimensions GetDimensions(int mipLevel = -1) SLANG_OVERRIDE;
void Load(const int32_t* texelCoords, void* outData, size_t dataSize) SLANG_OVERRIDE;
void Sample(
slang_prelude::SamplerState samplerState,
const float* coords,
void* outData,
size_t dataSize) SLANG_OVERRIDE;
void SampleLevel(
slang_prelude::SamplerState samplerState,
const float* coords,
float level,
void* outData,
size_t dataSize) SLANG_OVERRIDE;
//
// IRWTexture interface
//
void* refAt(const uint32_t* texelCoords) SLANG_OVERRIDE;
private:
RefPtr<TextureResourceImpl> m_texture;
void* _getTexelPtr(int32_t const* texelCoords);
};
} // namespace cpu
} // namespace gfx
|