gallium/tgsi: Split sampler views from shader resources.

This commit splits the current concept of resource into "sampler
views" and "shader resources":

"Sampler views" are textures or buffers that are bound to a given
shader stage and can be read from in conjunction with a sampler
object.  They are analogous to OpenGL texture objects or Direct3D
SRVs.

"Shader resources" are textures or buffers that can be read and
written from a shader.  There's no support for floating point
coordinates, address wrap modes or filtering, and, unlike sampler
views, shader resources are global for the whole graphics pipeline.
They are analogous to OpenGL image objects (as in
ARB_shader_image_load_store) or Direct3D UAVs.

Most hardware is likely to implement shader resources and sampler
views as separate objects, so, having the distinction at the API level
simplifies things slightly for the driver.

This patch introduces the SVIEW register file with a declaration token
and syntax analogous to the already existing RES register file.  After
this change, the SAMPLE_* opcodes no longer accept a resource as
input, but rather a SVIEW object.  To preserve the functionality of
reading from a sampler view with integer coordinates, the
SAMPLE_I(_MS) opcodes are introduced which are similar to LOAD(_MS)
but take a SVIEW register instead of a RES register as argument.
This commit is contained in:
Francisco Jerez 2012-05-01 02:38:51 +02:00
parent d9d82dcd00
commit a5f44cc8c2
17 changed files with 308 additions and 188 deletions

View File

@ -227,42 +227,66 @@ tgsi_build_declaration_semantic(
return ds;
}
static struct tgsi_declaration_resource
tgsi_default_declaration_resource(void)
{
struct tgsi_declaration_resource declaration_resource;
struct tgsi_declaration_resource dr;
declaration_resource.Resource = TGSI_TEXTURE_UNKNOWN;
declaration_resource.ReturnTypeX = PIPE_TYPE_UNORM;
declaration_resource.ReturnTypeY = PIPE_TYPE_UNORM;
declaration_resource.ReturnTypeZ = PIPE_TYPE_UNORM;
declaration_resource.ReturnTypeW = PIPE_TYPE_UNORM;
dr.Resource = TGSI_BUFFER;
return declaration_resource;
return dr;
}
static struct tgsi_declaration_resource
tgsi_build_declaration_resource(unsigned texture,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w,
struct tgsi_declaration *declaration,
struct tgsi_header *header)
{
struct tgsi_declaration_resource declaration_resource;
struct tgsi_declaration_resource dr;
declaration_resource = tgsi_default_declaration_resource();
declaration_resource.Resource = texture;
declaration_resource.ReturnTypeX = return_type_x;
declaration_resource.ReturnTypeY = return_type_y;
declaration_resource.ReturnTypeZ = return_type_z;
declaration_resource.ReturnTypeW = return_type_w;
dr = tgsi_default_declaration_resource();
dr.Resource = texture;
declaration_grow(declaration, header);
return declaration_resource;
return dr;
}
static struct tgsi_declaration_sampler_view
tgsi_default_declaration_sampler_view(void)
{
struct tgsi_declaration_sampler_view dsv;
dsv.Resource = TGSI_BUFFER;
dsv.ReturnTypeX = PIPE_TYPE_UNORM;
dsv.ReturnTypeY = PIPE_TYPE_UNORM;
dsv.ReturnTypeZ = PIPE_TYPE_UNORM;
dsv.ReturnTypeW = PIPE_TYPE_UNORM;
return dsv;
}
static struct tgsi_declaration_sampler_view
tgsi_build_declaration_sampler_view(unsigned texture,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w,
struct tgsi_declaration *declaration,
struct tgsi_header *header)
{
struct tgsi_declaration_sampler_view dsv;
dsv = tgsi_default_declaration_sampler_view();
dsv.Resource = texture;
dsv.ReturnTypeX = return_type_x;
dsv.ReturnTypeY = return_type_y;
dsv.ReturnTypeZ = return_type_z;
dsv.ReturnTypeW = return_type_w;
declaration_grow(declaration, header);
return dsv;
}
@ -276,6 +300,7 @@ tgsi_default_full_declaration( void )
full_declaration.Semantic = tgsi_default_declaration_semantic();
full_declaration.ImmediateData.u = NULL;
full_declaration.Resource = tgsi_default_declaration_resource();
full_declaration.SamplerView = tgsi_default_declaration_sampler_view();
return full_declaration;
}
@ -375,14 +400,29 @@ tgsi_build_full_declaration(
size++;
*dr = tgsi_build_declaration_resource(full_decl->Resource.Resource,
full_decl->Resource.ReturnTypeX,
full_decl->Resource.ReturnTypeY,
full_decl->Resource.ReturnTypeZ,
full_decl->Resource.ReturnTypeW,
declaration,
header);
}
if (full_decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
struct tgsi_declaration_sampler_view *dsv;
if (maxsize <= size) {
return 0;
}
dsv = (struct tgsi_declaration_sampler_view *)&tokens[size];
size++;
*dsv = tgsi_build_declaration_sampler_view(
full_decl->SamplerView.Resource,
full_decl->SamplerView.ReturnTypeX,
full_decl->SamplerView.ReturnTypeY,
full_decl->SamplerView.ReturnTypeZ,
full_decl->SamplerView.ReturnTypeW,
declaration,
header);
}
return size;
}

View File

@ -285,21 +285,25 @@ iter_declaration(
if (decl->Declaration.File == TGSI_FILE_RESOURCE) {
TXT(", ");
ENM(decl->Resource.Resource, tgsi_texture_names);
TXT(", ");
if ((decl->Resource.ReturnTypeX == decl->Resource.ReturnTypeY) &&
(decl->Resource.ReturnTypeX == decl->Resource.ReturnTypeZ) &&
(decl->Resource.ReturnTypeX == decl->Resource.ReturnTypeW)) {
ENM(decl->Resource.ReturnTypeX, tgsi_type_names);
} else {
ENM(decl->Resource.ReturnTypeX, tgsi_type_names);
TXT(", ");
ENM(decl->Resource.ReturnTypeY, tgsi_type_names);
TXT(", ");
ENM(decl->Resource.ReturnTypeZ, tgsi_type_names);
TXT(", ");
ENM(decl->Resource.ReturnTypeW, tgsi_type_names);
}
}
if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
TXT(", ");
ENM(decl->SamplerView.Resource, tgsi_texture_names);
TXT(", ");
if ((decl->SamplerView.ReturnTypeX == decl->SamplerView.ReturnTypeY) &&
(decl->SamplerView.ReturnTypeX == decl->SamplerView.ReturnTypeZ) &&
(decl->SamplerView.ReturnTypeX == decl->SamplerView.ReturnTypeW)) {
ENM(decl->SamplerView.ReturnTypeX, tgsi_type_names);
} else {
ENM(decl->SamplerView.ReturnTypeX, tgsi_type_names);
TXT(", ");
ENM(decl->SamplerView.ReturnTypeY, tgsi_type_names);
TXT(", ");
ENM(decl->SamplerView.ReturnTypeZ, tgsi_type_names);
TXT(", ");
ENM(decl->SamplerView.ReturnTypeW, tgsi_type_names);
}
}
if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT &&

View File

@ -2121,7 +2121,7 @@ exec_sample(struct tgsi_exec_machine *mach,
control = tgsi_sampler_lod_bias;
}
switch (mach->Resources[resource_unit].Resource) {
switch (mach->SamplerViews[resource_unit].Resource) {
case TGSI_TEXTURE_1D:
case TGSI_TEXTURE_SHADOW1D:
FETCH(&r[0], 0, TGSI_CHAN_X);
@ -2215,7 +2215,7 @@ exec_sample_d(struct tgsi_exec_machine *mach,
* XXX: This is fake SAMPLE_D -- the derivatives are not taken into account, yet.
*/
switch (mach->Resources[resource_unit].Resource) {
switch (mach->SamplerViews[resource_unit].Resource) {
case TGSI_TEXTURE_1D:
case TGSI_TEXTURE_SHADOW1D:
@ -2338,8 +2338,8 @@ static void
exec_declaration(struct tgsi_exec_machine *mach,
const struct tgsi_full_declaration *decl)
{
if (decl->Declaration.File == TGSI_FILE_RESOURCE) {
mach->Resources[decl->Range.First] = decl->Resource;
if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
mach->SamplerViews[decl->Range.First] = decl->SamplerView;
return;
}
@ -4154,11 +4154,11 @@ exec_instruction(
exec_endswitch(mach);
break;
case TGSI_OPCODE_LOAD:
case TGSI_OPCODE_SAMPLE_I:
assert(0);
break;
case TGSI_OPCODE_LOAD_MS:
case TGSI_OPCODE_SAMPLE_I_MS:
assert(0);
break;
@ -4190,7 +4190,7 @@ exec_instruction(
assert(0);
break;
case TGSI_OPCODE_RESINFO:
case TGSI_OPCODE_SVIEWINFO:
assert(0);
break;

View File

@ -331,7 +331,8 @@ struct tgsi_exec_machine
struct tgsi_full_declaration *Declarations;
uint NumDeclarations;
struct tgsi_declaration_resource Resources[PIPE_MAX_SHADER_RESOURCES];
struct tgsi_declaration_sampler_view
SamplerViews[PIPE_MAX_SHADER_SAMPLER_VIEWS];
boolean UsedGeometryShader;
};

View File

@ -183,22 +183,23 @@ static const struct tgsi_opcode_info opcode_info[TGSI_OPCODE_LAST] =
{ 0, 0, 0, 0, 0, 0, NONE, "DEFAULT", TGSI_OPCODE_DEFAULT },
{ 0, 0, 0, 0, 0, 0, NONE, "ENDSWITCH", TGSI_OPCODE_ENDSWITCH },
{ 1, 2, 0, 0, 0, 0, OTHR, "LOAD", TGSI_OPCODE_LOAD },
{ 1, 2, 0, 0, 0, 0, OTHR, "LOAD_MS", TGSI_OPCODE_LOAD_MS },
{ 1, 3, 0, 0, 0, 0, OTHR, "SAMPLE", TGSI_OPCODE_SAMPLE },
{ 1, 2, 0, 0, 0, 0, OTHR, "SAMPLE_I", TGSI_OPCODE_SAMPLE_I },
{ 1, 2, 0, 0, 0, 0, OTHR, "SAMPLE_I_MS", TGSI_OPCODE_SAMPLE_I_MS },
{ 1, 4, 0, 0, 0, 0, OTHR, "SAMPLE_B", TGSI_OPCODE_SAMPLE_B },
{ 1, 4, 0, 0, 0, 0, OTHR, "SAMPLE_C", TGSI_OPCODE_SAMPLE_C },
{ 1, 4, 0, 0, 0, 0, OTHR, "SAMPLE_C_LZ", TGSI_OPCODE_SAMPLE_C_LZ },
{ 1, 5, 0, 0, 0, 0, OTHR, "SAMPLE_D", TGSI_OPCODE_SAMPLE_D },
{ 1, 3, 0, 0, 0, 0, OTHR, "SAMPLE_L", TGSI_OPCODE_SAMPLE_L },
{ 1, 3, 0, 0, 0, 0, OTHR, "GATHER4", TGSI_OPCODE_GATHER4 },
{ 1, 2, 0, 0, 0, 0, OTHR, "RESINFO", TGSI_OPCODE_RESINFO },
{ 1, 2, 0, 0, 0, 0, OTHR, "SVIEWINFO", TGSI_OPCODE_SVIEWINFO },
{ 1, 2, 0, 0, 0, 0, OTHR, "SAMPLE_POS", TGSI_OPCODE_SAMPLE_POS },
{ 1, 2, 0, 0, 0, 0, OTHR, "SAMPLE_INFO", TGSI_OPCODE_SAMPLE_INFO },
{ 1, 1, 0, 0, 0, 0, COMP, "UARL", TGSI_OPCODE_UARL },
{ 1, 3, 0, 0, 0, 0, COMP, "UCMP", TGSI_OPCODE_UCMP },
{ 1, 1, 0, 0, 0, 0, COMP, "IABS", TGSI_OPCODE_IABS },
{ 1, 1, 0, 0, 0, 0, COMP, "ISSG", TGSI_OPCODE_ISSG },
{ 1, 2, 0, 0, 0, 0, OTHR, "LOAD", TGSI_OPCODE_LOAD },
};
const struct tgsi_opcode_info *

View File

@ -168,16 +168,16 @@ OP01(CASE)
OP00(DEFAULT)
OP00(ENDSWITCH)
OP12(LOAD)
OP12(LOAD_MS)
OP13(SAMPLE)
OP12(SAMPLE_I)
OP12(SAMPLE_I_MS)
OP14(SAMPLE_B)
OP14(SAMPLE_C)
OP14(SAMPLE_C_LZ)
OP15(SAMPLE_D)
OP13(SAMPLE_L)
OP13(GATHER4)
OP12(RESINFO)
OP12(SVIEWINFO)
OP13(SAMPLE_POS)
OP12(SAMPLE_INFO)

View File

@ -132,6 +132,10 @@ tgsi_parse_token(
next_token(ctx, &decl->Resource);
}
if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
next_token(ctx, &decl->SamplerView);
}
break;
}

View File

@ -70,6 +70,7 @@ struct tgsi_full_declaration
struct tgsi_declaration_semantic Semantic;
struct tgsi_immediate_array_data ImmediateData;
struct tgsi_declaration_resource Resource;
struct tgsi_declaration_sampler_view SamplerView;
};
struct tgsi_full_immediate

View File

@ -53,7 +53,8 @@ const char *tgsi_file_names[TGSI_FILE_COUNT] =
"SV",
"IMMX",
"TEMPX",
"RES"
"RES",
"SVIEW"
};
const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT] =

View File

@ -1066,6 +1066,22 @@ static boolean parse_declaration( struct translate_ctx *ctx )
report_error(ctx, "Expected texture target");
return FALSE;
}
ctx->cur = cur;
} else if (file == TGSI_FILE_SAMPLER_VIEW) {
for (i = 0; i < TGSI_TEXTURE_COUNT; i++) {
if (str_match_no_case(&cur, tgsi_texture_names[i])) {
if (!is_digit_alpha_underscore(cur)) {
decl.SamplerView.Resource = i;
break;
}
}
}
if (i == TGSI_TEXTURE_COUNT) {
report_error(ctx, "Expected texture target");
return FALSE;
}
eat_opt_white( &cur );
if (*cur != ',') {
report_error( ctx, "Expected `,'" );
@ -1079,16 +1095,16 @@ static boolean parse_declaration( struct translate_ctx *ctx )
if (!is_digit_alpha_underscore(cur)) {
switch (j) {
case 0:
decl.Resource.ReturnTypeX = i;
decl.SamplerView.ReturnTypeX = i;
break;
case 1:
decl.Resource.ReturnTypeY = i;
decl.SamplerView.ReturnTypeY = i;
break;
case 2:
decl.Resource.ReturnTypeZ = i;
decl.SamplerView.ReturnTypeZ = i;
break;
case 3:
decl.Resource.ReturnTypeW = i;
decl.SamplerView.ReturnTypeW = i;
break;
default:
assert(0);
@ -1116,10 +1132,10 @@ static boolean parse_declaration( struct translate_ctx *ctx )
}
}
if (j < 4) {
decl.Resource.ReturnTypeY =
decl.Resource.ReturnTypeZ =
decl.Resource.ReturnTypeW =
decl.Resource.ReturnTypeX;
decl.SamplerView.ReturnTypeY =
decl.SamplerView.ReturnTypeZ =
decl.SamplerView.ReturnTypeW =
decl.SamplerView.ReturnTypeX;
}
ctx->cur = cur;
} else {

View File

@ -47,7 +47,7 @@ union tgsi_any_token {
struct tgsi_declaration_range decl_range;
struct tgsi_declaration_dimension decl_dim;
struct tgsi_declaration_semantic decl_semantic;
struct tgsi_declaration_resource decl_resource;
struct tgsi_declaration_sampler_view decl_sampler_view;
struct tgsi_immediate imm;
union tgsi_immediate_data imm_data;
struct tgsi_instruction insn;
@ -147,8 +147,8 @@ struct ureg_program
unsigned return_type_y;
unsigned return_type_z;
unsigned return_type_w;
} resource[PIPE_MAX_SHADER_RESOURCES];
unsigned nr_resources;
} sampler_view[PIPE_MAX_SHADER_SAMPLER_VIEWS];
unsigned nr_sampler_views;
unsigned temps_active[UREG_MAX_TEMP / 32];
unsigned nr_temps;
@ -615,34 +615,34 @@ struct ureg_src ureg_DECL_sampler( struct ureg_program *ureg,
}
/*
* Allocate a new shader resource.
* Allocate a new shader sampler view.
*/
struct ureg_src
ureg_DECL_resource(struct ureg_program *ureg,
unsigned index,
unsigned target,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w)
ureg_DECL_sampler_view(struct ureg_program *ureg,
unsigned index,
unsigned target,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w)
{
struct ureg_src reg = ureg_src_register(TGSI_FILE_RESOURCE, index);
struct ureg_src reg = ureg_src_register(TGSI_FILE_SAMPLER_VIEW, index);
uint i;
for (i = 0; i < ureg->nr_resources; i++) {
if (ureg->resource[i].index == index) {
for (i = 0; i < ureg->nr_sampler_views; i++) {
if (ureg->sampler_view[i].index == index) {
return reg;
}
}
if (i < PIPE_MAX_SHADER_RESOURCES) {
ureg->resource[i].index = index;
ureg->resource[i].target = target;
ureg->resource[i].return_type_x = return_type_x;
ureg->resource[i].return_type_y = return_type_y;
ureg->resource[i].return_type_z = return_type_z;
ureg->resource[i].return_type_w = return_type_w;
ureg->nr_resources++;
if (i < PIPE_MAX_SHADER_SAMPLER_VIEWS) {
ureg->sampler_view[i].index = index;
ureg->sampler_view[i].target = target;
ureg->sampler_view[i].return_type_x = return_type_x;
ureg->sampler_view[i].return_type_y = return_type_y;
ureg->sampler_view[i].return_type_z = return_type_z;
ureg->sampler_view[i].return_type_w = return_type_w;
ureg->nr_sampler_views++;
return reg;
}
@ -891,7 +891,7 @@ ureg_emit_dst( struct ureg_program *ureg,
assert(dst.File != TGSI_FILE_CONSTANT);
assert(dst.File != TGSI_FILE_INPUT);
assert(dst.File != TGSI_FILE_SAMPLER);
assert(dst.File != TGSI_FILE_RESOURCE);
assert(dst.File != TGSI_FILE_SAMPLER_VIEW);
assert(dst.File != TGSI_FILE_IMMEDIATE);
assert(dst.File < TGSI_FILE_COUNT);
@ -1297,20 +1297,20 @@ emit_decl_range2D(struct ureg_program *ureg,
}
static void
emit_decl_resource(struct ureg_program *ureg,
unsigned index,
unsigned target,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w )
emit_decl_sampler_view(struct ureg_program *ureg,
unsigned index,
unsigned target,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w )
{
union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
out[0].value = 0;
out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
out[0].decl.NrTokens = 3;
out[0].decl.File = TGSI_FILE_RESOURCE;
out[0].decl.File = TGSI_FILE_SAMPLER_VIEW;
out[0].decl.UsageMask = 0xf;
out[0].decl.Interpolate = TGSI_INTERPOLATE_CONSTANT;
@ -1319,11 +1319,11 @@ emit_decl_resource(struct ureg_program *ureg,
out[1].decl_range.Last = index;
out[2].value = 0;
out[2].decl_resource.Resource = target;
out[2].decl_resource.ReturnTypeX = return_type_x;
out[2].decl_resource.ReturnTypeY = return_type_y;
out[2].decl_resource.ReturnTypeZ = return_type_z;
out[2].decl_resource.ReturnTypeW = return_type_w;
out[2].decl_sampler_view.Resource = target;
out[2].decl_sampler_view.ReturnTypeX = return_type_x;
out[2].decl_sampler_view.ReturnTypeY = return_type_y;
out[2].decl_sampler_view.ReturnTypeZ = return_type_z;
out[2].decl_sampler_view.ReturnTypeW = return_type_w;
}
static void
@ -1473,14 +1473,14 @@ static void emit_decls( struct ureg_program *ureg )
ureg->sampler[i].Index, 1 );
}
for (i = 0; i < ureg->nr_resources; i++) {
emit_decl_resource(ureg,
ureg->resource[i].index,
ureg->resource[i].target,
ureg->resource[i].return_type_x,
ureg->resource[i].return_type_y,
ureg->resource[i].return_type_z,
ureg->resource[i].return_type_w);
for (i = 0; i < ureg->nr_sampler_views; i++) {
emit_decl_sampler_view(ureg,
ureg->sampler_view[i].index,
ureg->sampler_view[i].target,
ureg->sampler_view[i].return_type_x,
ureg->sampler_view[i].return_type_y,
ureg->sampler_view[i].return_type_z,
ureg->sampler_view[i].return_type_w);
}
if (ureg->const_decls.nr_constant_ranges) {

View File

@ -292,13 +292,13 @@ ureg_DECL_sampler( struct ureg_program *,
unsigned index );
struct ureg_src
ureg_DECL_resource(struct ureg_program *,
unsigned index,
unsigned target,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w );
ureg_DECL_sampler_view(struct ureg_program *,
unsigned index,
unsigned target,
unsigned return_type_x,
unsigned return_type_y,
unsigned return_type_z,
unsigned return_type_w );
static INLINE struct ureg_src

View File

@ -1312,28 +1312,36 @@ This opcode is the inverse of :opcode:`DFRACEXP`.
dst.zw = \sqrt{src.zw}
.. _resourceopcodes:
.. _samplingopcodes:
Resource Access Opcodes
^^^^^^^^^^^^^^^^^^^^^^^^
Resource Sampling Opcodes
^^^^^^^^^^^^^^^^^^^^^^^^^
Those opcodes follow very closely semantics of the respective Direct3D
instructions. If in doubt double check Direct3D documentation.
.. opcode:: LOAD - Simplified alternative to the "SAMPLE" instruction.
Using the provided integer address, LOAD fetches data
from the specified buffer/texture without any filtering.
.. opcode:: SAMPLE - Using provided address, sample data from the
specified texture using the filtering mode identified
by the gven sampler. The source data may come from
any resource type other than buffers.
SAMPLE dst, address, sampler_view, sampler
e.g.
SAMPLE TEMP[0], TEMP[1], SVIEW[0], SAMP[0]
.. opcode:: SAMPLE_I - Simplified alternative to the SAMPLE instruction.
Using the provided integer address, SAMPLE_I fetches data
from the specified sampler view without any filtering.
The source data may come from any resource type other
than CUBE.
LOAD dst, address, resource
SAMPLE_I dst, address, sampler_view
e.g.
LOAD TEMP[0], TEMP[1], RES[0]
SAMPLE_I TEMP[0], TEMP[1], SVIEW[0]
The 'address' is specified as unsigned integers. If the
'address' is out of range [0...(# texels - 1)] the
result of the fetch is always 0 in all components.
As such the instruction doesn't honor address wrap
modes, in cases where that behavior is desirable
'sample' instruction should be used.
'SAMPLE' instruction should be used.
address.w always provides an unsigned integer mipmap
level. If the value is out of the range then the
instruction always returns 0 in all components.
@ -1348,7 +1356,7 @@ instructions. If in doubt double check Direct3D documentation.
For 2D texture arrays address.z provides the array
index, otherwise it exhibits the same behavior as in
the case for 1D texture arrays.
The exeact semantics of the source address are presented
The exact semantics of the source address are presented
in the table below:
resource type X Y Z W
------------- ------------------------
@ -1364,25 +1372,16 @@ instructions. If in doubt double check Direct3D documentation.
Where 'mpl' is a mipmap level and 'idx' is the
array index.
.. opcode:: LOAD_MS - Just like LOAD but allows fetch data from
.. opcode:: SAMPLE_I_MS - Just like SAMPLE_I but allows fetch data from
multi-sampled surfaces.
.. opcode:: SAMPLE - Using provided address, sample data from the
specified texture using the filtering mode identified
by the gven sampler. The source data may come from
any resource type other than buffers.
SAMPLE dst, address, resource, sampler
e.g.
SAMPLE TEMP[0], TEMP[1], RES[0], SAMP[0]
.. opcode:: SAMPLE_B - Just like the SAMPLE instruction with the
exception that an additiona bias is applied to the
level of detail computed as part of the instruction
execution.
SAMPLE_B dst, address, resource, sampler, lod_bias
SAMPLE_B dst, address, sampler_view, sampler, lod_bias
e.g.
SAMPLE_B TEMP[0], TEMP[1], RES[0], SAMP[0], TEMP[2].x
SAMPLE_B TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x
.. opcode:: SAMPLE_C - Similar to the SAMPLE instruction but it
performs a comparison filter. The operands to SAMPLE_C
@ -1394,33 +1393,32 @@ instructions. If in doubt double check Direct3D documentation.
reference value against the red component value for the
surce resource at each texel that the currently configured
texture filter covers based on the provided coordinates.
SAMPLE_C dst, address, resource.r, sampler, ref_value
SAMPLE_C dst, address, sampler_view.r, sampler, ref_value
e.g.
SAMPLE_C TEMP[0], TEMP[1], RES[0].r, SAMP[0], TEMP[2].x
SAMPLE_C TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x
.. opcode:: SAMPLE_C_LZ - Same as SAMPLE_C, but LOD is 0 and derivatives
are ignored. The LZ stands for level-zero.
SAMPLE_C_LZ dst, address, resource.r, sampler, ref_value
SAMPLE_C_LZ dst, address, sampler_view.r, sampler, ref_value
e.g.
SAMPLE_C_LZ TEMP[0], TEMP[1], RES[0].r, SAMP[0], TEMP[2].x
SAMPLE_C_LZ TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x
.. opcode:: SAMPLE_D - SAMPLE_D is identical to the SAMPLE opcode except
that the derivatives for the source address in the x
direction and the y direction are provided by extra
parameters.
SAMPLE_D dst, address, resource, sampler, der_x, der_y
SAMPLE_D dst, address, sampler_view, sampler, der_x, der_y
e.g.
SAMPLE_D TEMP[0], TEMP[1], RES[0], SAMP[0], TEMP[2], TEMP[3]
SAMPLE_D TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2], TEMP[3]
.. opcode:: SAMPLE_L - SAMPLE_L is identical to the SAMPLE opcode except
that the LOD is provided directly as a scalar value,
representing no anisotropy. Source addresses A channel
is used as the LOD.
SAMPLE_L dst, address, resource, sampler
SAMPLE_L dst, address, sampler_view, sampler
e.g.
SAMPLE_L TEMP[0], TEMP[1], RES[0], SAMP[0]
SAMPLE_L TEMP[0], TEMP[1], SVIEW[0], SAMP[0]
.. opcode:: GATHER4 - Gathers the four texels to be used in a bi-linear
filtering operation and packs them into a single register.
@ -1435,18 +1433,18 @@ instructions. If in doubt double check Direct3D documentation.
the magnitude of the deltas are half a texel.
.. opcode:: RESINFO - query the dimensions of a given input buffer.
.. opcode:: SVIEWINFO - query the dimensions of a given sampler view.
dst receives width, height, depth or array size and
number of mipmap levels. The dst can have a writemask
which will specify what info is the caller interested
in.
RESINFO dst, src_mip_level, resource
SVIEWINFO dst, src_mip_level, sampler_view
e.g.
RESINFO TEMP[0], TEMP[1].x, RES[0]
SVIEWINFO TEMP[0], TEMP[1].x, SVIEW[0]
src_mip_level is an unsigned integer scalar. If it's
out of range then returns 0 for width, height and
depth/array size but the total number of mipmap is
still returned correctly for the given resource.
still returned correctly for the given sampler view.
The returned width, height and depth values are for
the mipmap level selected by the src_mip_level and
are in the number of texels.
@ -1463,6 +1461,36 @@ instructions. If in doubt double check Direct3D documentation.
not a render target, the result is 0.
.. _resourceopcodes:
Resource Access Opcodes
^^^^^^^^^^^^^^^^^^^^^^^
.. opcode:: LOAD - Fetch data from a shader resource
Syntax: ``LOAD dst, resource, address``
Example: ``LOAD TEMP[0], RES[0], TEMP[1]``
Using the provided integer address, LOAD fetches data
from the specified buffer or texture without any
filtering.
The 'address' is specified as a vector of unsigned
integers. If the 'address' is out of range the result
is unspecified.
Only the first mipmap level of a resource can be read
from using this instruction.
For 1D or 2D texture arrays, the array index is
provided as an unsigned integer in address.y or
address.z, respectively. address.yz are ignored for
buffers and 1D textures. address.z is ignored for 1D
texture arrays and 2D textures. address.w is always
ignored.
Explanation of symbols used
------------------------------
@ -1690,12 +1718,28 @@ is a writable stencil reference value. Only the Y component is writable.
This allows the fragment shader to change the fragments stencilref value.
Declaration Resource
Declaration Sampler View
^^^^^^^^^^^^^^^^^^^^^^^^
Follows Declaration token if file is TGSI_FILE_SAMPLER_VIEW.
DCL SVIEW[#], resource, type(s)
Declares a shader input sampler view and assigns it to a SVIEW[#]
register.
resource can be one of BUFFER, 1D, 2D, 3D, 1DArray and 2DArray.
type must be 1 or 4 entries (if specifying on a per-component
level) out of UNORM, SNORM, SINT, UINT and FLOAT.
Declaration Resource
^^^^^^^^^^^^^^^^^^^^
Follows Declaration token if file is TGSI_FILE_RESOURCE.
DCL RES[#], resource, type(s)
DCL RES[#], resource
Declares a shader input resource and assigns it to a RES[#]
register.
@ -1703,9 +1747,6 @@ Declaration Resource
resource can be one of BUFFER, 1D, 2D, 3D, CUBE, 1DArray and
2DArray.
type must be 1 or 4 entries (if specifying on a per-component
level) out of UNORM, SNORM, SINT, UINT and FLOAT.
Properties
^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -548,7 +548,7 @@ static nv50_ir::operation translateOpcode(uint opcode)
NV50_IR_OPCODE_CASE(SAMPLE_D, TXD);
NV50_IR_OPCODE_CASE(SAMPLE_L, TXL);
NV50_IR_OPCODE_CASE(GATHER4, TXG);
NV50_IR_OPCODE_CASE(RESINFO, TXQ);
NV50_IR_OPCODE_CASE(SVIEWINFO, TXQ);
NV50_IR_OPCODE_CASE(END, EXIT);
@ -597,8 +597,8 @@ public:
int clipVertexOutput;
uint8_t *resourceTargets; // TGSI_TEXTURE_*
unsigned resourceCount;
uint8_t *samplerViewTargets; // TGSI_TEXTURE_*
unsigned samplerViewCount;
private:
int inferSysValDirection(unsigned sn) const;
@ -617,7 +617,7 @@ Source::Source(struct nv50_ir_prog_info *prog) : info(prog)
if (prog->dbgFlags & NV50_IR_DEBUG_BASIC)
tgsi_dump(tokens, 0);
resourceTargets = NULL;
samplerViewTargets = NULL;
mainTempsInLMem = FALSE;
}
@ -632,8 +632,8 @@ Source::~Source()
if (info->immd.type)
FREE(info->immd.type);
if (resourceTargets)
delete[] resourceTargets;
if (samplerViewTargets)
delete[] samplerViewTargets;
}
bool Source::scanSource()
@ -650,8 +650,8 @@ bool Source::scanSource()
clipVertexOutput = -1;
resourceCount = scan.file_max[TGSI_FILE_RESOURCE] + 1;
resourceTargets = new uint8_t[resourceCount];
samplerViewCount = scan.file_max[TGSI_FILE_SAMPLER_VIEW] + 1;
samplerViewTargets = new uint8_t[samplerViewCount];
info->immd.bufSize = 0;
tempArrayCount = 0;
@ -874,9 +874,9 @@ bool Source::scanDeclaration(const struct tgsi_full_declaration *decl)
info->sv[i].input = inferSysValDirection(sn);
}
break;
case TGSI_FILE_RESOURCE:
case TGSI_FILE_SAMPLER_VIEW:
for (i = first; i <= last; ++i)
resourceTargets[i] = decl->Resource.Resource;
samplerViewTargets[i] = decl->SamplerView.Resource;
break;
case TGSI_FILE_IMMEDIATE_ARRAY:
{
@ -1000,13 +1000,15 @@ bool Source::scanInstruction(const struct tgsi_full_instruction *inst)
nv50_ir::TexInstruction::Target
Instruction::getTexture(const tgsi::Source *code, int s) const
{
if (insn->Instruction.Texture) {
return translateTexture(insn->Texture.Texture);
} else {
switch (getSrc(s).getFile()) {
case TGSI_FILE_SAMPLER_VIEW: {
// XXX: indirect access
unsigned int r = getSrc(s).getIndex(0);
assert(r < code->resourceCount);
return translateTexture(code->resourceTargets[r]);
assert(r < code->samplerViewCount);
return translateTexture(code->samplerViewTargets[r]);
}
default:
return translateTexture(insn->Texture.Texture);
}
}
@ -2042,7 +2044,7 @@ Converter::handleInstruction(const struct tgsi_full_instruction *insn)
handleTXF(dst0, 1);
break;
case TGSI_OPCODE_TXQ:
case TGSI_OPCODE_RESINFO:
case TGSI_OPCODE_SVIEWINFO:
handleTXQ(dst0, TXQ_DIMS);
break;
case TGSI_OPCODE_F2I:

View File

@ -5220,16 +5220,16 @@ static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction[] = {
{TGSI_OPCODE_CASE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_DEFAULT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_ENDSWITCH, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_LOAD, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_LOAD_MS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_I, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_I_MS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_B, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_C, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_C_LZ, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_D, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_L, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_GATHER4, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_RESINFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SVIEWINFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_POS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_INFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_UARL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT, tgsi_r600_arl},
@ -5394,16 +5394,16 @@ static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction[] = {
{TGSI_OPCODE_CASE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_DEFAULT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_ENDSWITCH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_LOAD, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_LOAD_MS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_I, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_I_MS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_B, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_C, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_C_LZ, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_D, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_L, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_GATHER4, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_RESINFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SVIEWINFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_POS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_INFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_UARL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT, tgsi_eg_arl},
@ -5568,16 +5568,16 @@ static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction[] = {
{TGSI_OPCODE_CASE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_DEFAULT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_ENDSWITCH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
{TGSI_OPCODE_LOAD, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_LOAD_MS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_I, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_I_MS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_B, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_C, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_C_LZ, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_D, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_L, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_GATHER4, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_RESINFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SVIEWINFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_POS, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_SAMPLE_INFO, 0, 0, tgsi_unsupported},
{TGSI_OPCODE_UARL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT, tgsi_eg_arl},

View File

@ -76,6 +76,7 @@ enum tgsi_file_type {
TGSI_FILE_IMMEDIATE_ARRAY =10,
TGSI_FILE_TEMPORARY_ARRAY =11,
TGSI_FILE_RESOURCE =12,
TGSI_FILE_SAMPLER_VIEW =13,
TGSI_FILE_COUNT /**< how many TGSI_FILE_ types */
};
@ -159,6 +160,11 @@ struct tgsi_declaration_semantic
};
struct tgsi_declaration_resource {
unsigned Resource : 8; /**< one of TGSI_TEXTURE_ */
unsigned Padding : 24;
};
struct tgsi_declaration_sampler_view {
unsigned Resource : 8; /**< one of TGSI_TEXTURE_ */
unsigned ReturnTypeX : 6; /**< one of enum pipe_type */
unsigned ReturnTypeY : 6; /**< one of enum pipe_type */
@ -372,16 +378,16 @@ struct tgsi_property_data {
#define TGSI_OPCODE_ENDSWITCH 144
/* resource related opcodes */
#define TGSI_OPCODE_LOAD 145
#define TGSI_OPCODE_LOAD_MS 146
#define TGSI_OPCODE_SAMPLE 147
#define TGSI_OPCODE_SAMPLE 145
#define TGSI_OPCODE_SAMPLE_I 146
#define TGSI_OPCODE_SAMPLE_I_MS 147
#define TGSI_OPCODE_SAMPLE_B 148
#define TGSI_OPCODE_SAMPLE_C 149
#define TGSI_OPCODE_SAMPLE_C_LZ 150
#define TGSI_OPCODE_SAMPLE_D 151
#define TGSI_OPCODE_SAMPLE_L 152
#define TGSI_OPCODE_GATHER4 153
#define TGSI_OPCODE_RESINFO 154
#define TGSI_OPCODE_SVIEWINFO 154
#define TGSI_OPCODE_SAMPLE_POS 155
#define TGSI_OPCODE_SAMPLE_INFO 156
@ -390,7 +396,9 @@ struct tgsi_property_data {
#define TGSI_OPCODE_IABS 159
#define TGSI_OPCODE_ISSG 160
#define TGSI_OPCODE_LAST 161
#define TGSI_OPCODE_LOAD 161
#define TGSI_OPCODE_LAST 162
#define TGSI_SAT_NONE 0 /* do not saturate */
#define TGSI_SAT_ZERO_ONE 1 /* clamp to [0,1] */

View File

@ -446,7 +446,7 @@ struct sm4_to_tgsi_converter
break;
case SM4_OPCODE_RESINFO:
// TODO: return type
ureg_RESINFO(ureg, _dst(), _src(1), resources[_idx(SM4_FILE_RESOURCE, 2)]);
ureg_SVIEWINFO(ureg, _dst(), _src(1), resources[_idx(SM4_FILE_RESOURCE, 2)]);
break;
// TODO: sample index, texture offset
case SM4_OPCODE_LD: // dst, coord_int, res; mipmap level in last coord_int arg
@ -750,11 +750,12 @@ next:;
}
if(resources.size() <= (unsigned)idx)
resources.resize(idx + 1);
resources[idx] = ureg_DECL_resource(ureg, idx, targets[idx].first,
res_return_type(dcl.rrt.x),
res_return_type(dcl.rrt.y),
res_return_type(dcl.rrt.z),
res_return_type(dcl.rrt.w));
resources[idx] = ureg_DECL_sampler_view(
ureg, idx, targets[idx].first,
res_return_type(dcl.rrt.x),
res_return_type(dcl.rrt.y),
res_return_type(dcl.rrt.z),
res_return_type(dcl.rrt.w));
break;
case SM4_OPCODE_DCL_SAMPLER:
check(idx >= 0);